pulse-ui-client 0.0.2 → 0.0.5
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/dist/client.d.ts +3 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +13 -9
- package/dist/pulse.d.ts +2 -8
- package/dist/renderer.d.ts +11 -12
- package/dist/renderer.test.d.ts +1 -0
- package/dist/serialize/clean.d.ts +3 -0
- package/dist/serialize/clean.test.d.ts +1 -0
- package/dist/serialize/elements.d.ts +1 -0
- package/dist/serialize/events.d.ts +1 -0
- package/dist/serialize/extractor.d.ts +5 -0
- package/dist/serialize/flatted.d.ts +2 -0
- package/dist/serialize/flatted.test.d.ts +1 -0
- package/dist/vdom.d.ts +2 -2
- package/package.json +11 -3
- package/dist/serialize.d.ts +0 -2351
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { RouteInfo } from "./helpers";
|
|
2
|
-
import type { VDOM,
|
|
2
|
+
import type { VDOM, VDOMUpdate } from "./vdom";
|
|
3
3
|
import type { ServerErrorInfo } from "./messages";
|
|
4
4
|
export interface MountedView {
|
|
5
|
-
vdom: VDOM;
|
|
6
|
-
listener: VDOMListener;
|
|
7
5
|
routeInfo: RouteInfo;
|
|
6
|
+
onInit: (vdom: VDOM) => void;
|
|
7
|
+
onUpdate: (ops: VDOMUpdate[]) => void;
|
|
8
8
|
}
|
|
9
|
-
export type VDOMListener = (node: VDOMNode) => void;
|
|
10
9
|
export type ConnectionStatusListener = (connected: boolean) => void;
|
|
11
10
|
export type ServerErrorListener = (path: string, error: ServerErrorInfo | null) => void;
|
|
12
11
|
export interface PulseClient {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
export { PulseProvider, usePulseClient, PulseView
|
|
1
|
+
export { PulseProvider, usePulseClient, PulseView } from "./pulse";
|
|
2
2
|
export type { PulseConfig, PulseProviderProps } from "./pulse";
|
|
3
3
|
export { PulseSocketIOClient } from "./client";
|
|
4
|
-
export type { PulseClient, MountedView,
|
|
4
|
+
export type { PulseClient, MountedView, ConnectionStatusListener, ServerErrorListener, } from "./client";
|
|
5
5
|
export type { VDOM, VDOMNode, VDOMElement, VDOMUpdate, ComponentRegistry, } from "./vdom";
|
|
6
|
-
export { VDOMRenderer,
|
|
6
|
+
export { VDOMRenderer, applyUpdates as applyReactTreeUpdates, RenderLazy, } from "./renderer";
|
|
7
7
|
export type { ServerMessage, ServerInitMessage, ServerUpdateMessage, ServerErrorMessage, ServerErrorInfo, ServerApiCallMessage, ServerNavigateToMessage, ClientMessage, ClientCallbackMessage, ClientMountMessage, ClientNavigateMessage, ClientUnmountMessage, ClientApiResultMessage, } from "./messages";
|
|
8
8
|
export { SocketIOTransport } from "./transport";
|
|
9
9
|
export type { Transport, MessageListener } from "./transport";
|
|
10
10
|
export { extractServerRouteInfo } from "./helpers";
|
|
11
11
|
export type { RouteInfo } from "./helpers";
|
|
12
|
-
export { extractEvent } from "./serialize";
|
|
12
|
+
export { extractEvent } from "./serialize/events";
|
|
13
|
+
export { encodeForWire, decodeFromWire, cleanForSerialization, } from "./serialize/clean";
|
|
14
|
+
export { stringify, parse } from "./serialize/flatted";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{useEffect as g,useState as v,useMemo as s,createContext as e,useContext as qq}from"react";import r,{Suspense as Wq}from"react";var p="$$fragment",k="$$";function F(q){return typeof q==="object"&&q!==null}function L(q){return typeof q==="object"&&q!==null&&q.tag.startsWith("$$")&&q.tag!=="$$fragment"}function c(q){if(!L(q))throw new Error("Node is not a mount point");return q.tag.slice(2)}import{jsxDEV as w,Fragment as u}from"react/jsx-dev-runtime";function H(q,J){if(F(q))return q.key||J;return J}var N=({node:q})=>{let{getCallback:J,getComponent:Y}=M();if(q===null||typeof q==="boolean"||q===void 0)return null;if(typeof q==="string"||typeof q==="number")return w(u,{children:q},void 0,!1,void 0,this);if(F(q)){if(!(("tag"in q)&&typeof q.tag==="string"))return console.error("Invalid VDOM element node received:",q),null;let{tag:$,props:Q={},children:X=[]}=q,A={};for(let[W,z]of Object.entries(Q))if(typeof z==="string"&&z.startsWith("$$fn:")){let f=z.substring(5);A[W]=J(f)}else A[W]=z;if(L(q)){let W=c(q),z=Y(W),f=X.map((C,_)=>w(N,{node:C},H(C,_),!1,void 0,this));return w(z,{...A,children:f},void 0,!1,void 0,this)}if($===p)return w(u,{children:X.map((W,z)=>w(N,{node:W},H(W,z),!1,void 0,this))},void 0,!1,void 0,this);let I=X.map((W,z)=>w(N,{node:W},H(W,z),!1,void 0,this));return r.createElement($,A,...I)}return console.error("Unknown VDOM node type:",q),null};N.displayName="VDOMRenderer";function zq(q,J={},Y=[],$){if(q.startsWith(k))console.error(`[Pulse] Error: The tag "${q}" starts with a reserved prefix "${k}". Please use a different tag name.`);let Q={tag:q,props:J,children:Y};if($!==void 0)Q.key=$;return Q}function Xq(q=[],J){let Y={tag:p,props:{},children:q};if(J!==void 0)Y.key=J;return Y}function Aq(q,J={},Y=[],$){let Q={tag:k+q,props:J,children:Y};if($!==void 0)Q.key=$;return Q}function Gq(q,J){if(J==="")return F(q)?q:null;let Y=J.split(".").map(Number),$=q;for(let Q of Y){if(!F($))return console.error("[findNodeByPath] Invalid path: part of it is not an element node."),null;if(!$.children||Q>=$.children.length)return console.error(`[findNodeByPath] Invalid path: index ${Q} out of bounds.`),null;$=$.children[Q]}return F($)?$:null}function fq(q){if(typeof q!=="object"||q===null)return q;return JSON.parse(JSON.stringify(q))}function h(q,J){let Y=fq(q);for(let $ of J){let{type:Q,path:X,data:A}=$;if(X===""){switch(Q){case"replace":Y=A;break;case"update_props":if(F(Y))Y.props={...Y.props??{},...A};break;default:console.error(`[applyUpdates] Invalid root operation: ${Q}`)}continue}let I=X.substring(0,X.lastIndexOf(".")),W=parseInt(X.substring(X.lastIndexOf(".")+1),10),z=Gq(Y,I);if(!z){console.error(`[applyUpdates] Could not find parent for path: ${X}`);continue}if(!z.children)z.children=[];switch(Q){case"replace":z.children[W]=A;break;case"update_props":let f=z.children[W];if(F(f))f.props={...f.props??{},...A};break;case"insert":z.children.splice(W,0,A);break;case"remove":z.children.splice(W,1);break;case"move":{let C=z.children.splice(A.from_index,1)[0];z.children.splice(A.to_index,0,C);break}}}return Y}function Rq(q,J){let Y=r.lazy(q);return({children:$,...Q})=>{return w(Wq,{fallback:J??w(u,{},void 0,!1,void 0,this),children:w(Y,{...Q,children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)}}function Uq(q){return{id:q.id,class_name:q.className,tag_name:q.tagName.toLowerCase(),local_name:q.localName,client_height:q.clientHeight,client_left:q.clientLeft,client_top:q.clientTop,client_width:q.clientWidth,scroll_height:q.scrollHeight,scroll_left:q.scrollLeft,scroll_top:q.scrollTop,scroll_width:q.scrollWidth,slot:q.slot}}function Kq(q){return{autofocus:q.autofocus,tab_index:q.tabIndex,nonce:q.nonce}}function Z(q){return{...Uq(q),...Kq(q),access_key:q.accessKey,access_key_label:q.accessKeyLabel,autocapitalize:q.autocapitalize,dir:q.dir,draggable:q.draggable,hidden:q.hidden,inert:q.inert,lang:q.lang,offset_height:q.offsetHeight,offset_left:q.offsetLeft,offset_top:q.offsetTop,offset_width:q.offsetWidth,popover:q.popover,spellcheck:q.spellcheck,title:q.title,translate:q.translate,writing_suggestions:q.writingSuggestions,content_editable:q.contentEditable,enter_key_hint:q.enterKeyHint,is_content_editable:q.isContentEditable,input_mode:q.inputMode}}function _q(q){return{...Z(q),hash:q.hash,host:q.host,hostname:q.hostname,href:q.href,origin:q.origin,password:q.password,pathname:q.pathname,port:q.port,protocol:q.protocol,search:q.search,target:q.target,download:q.download,rel:q.rel,hreflang:q.hreflang,type:q.type,username:q.username,ping:q.ping,referrer_policy:q.referrerPolicy,text:q.text}}function wq(q){return{...Z(q),alt:q.alt,coords:q.coords,download:q.download,hash:q.hash,host:q.host,hostname:q.hostname,href:q.href,origin:q.origin,password:q.password,pathname:q.pathname,port:q.port,protocol:q.protocol,rel:q.rel,search:q.search,shape:q.shape,target:q.target,username:q.username,ping:q.ping,referrer_policy:q.referrerPolicy}}function l(q){return{...Z(q),autoplay:q.autoplay,controls:q.controls,cross_origin:q.crossOrigin,current_src:q.currentSrc,current_time:q.currentTime,default_muted:q.defaultMuted,default_playback_rate:q.defaultPlaybackRate,duration:q.duration,ended:q.ended,loop:q.loop,muted:q.muted,network_state:q.networkState,paused:q.paused,playback_rate:q.playbackRate,preload:q.preload,ready_state:q.readyState,seeking:q.seeking,src:q.src,volume:q.volume,preserves_pitch:q.preservesPitch}}function Fq(q){return{...l(q)}}function Sq(q){return{...Z(q),disabled:q.disabled,name:q.name,type:q.type,value:q.value,form_action:q.formAction,form_enctype:q.formEnctype,form_method:q.formMethod,form_no_validate:q.formNoValidate,form_target:q.formTarget,popover_target_action:q.popoverTargetAction}}function Iq(q){return{...Z(q),value:q.value}}function Oq(q){return{...Z(q),height:q.height,src:q.src,type:q.type,width:q.width,align:q.align,name:q.name}}function Nq(q){return{...Z(q),disabled:q.disabled,name:q.name,type:q.type,validation_message:q.validationMessage,will_validate:q.willValidate}}function Cq(q){return{...Z(q),accept_charset:q.acceptCharset,action:q.action,autocomplete:q.autocomplete,encoding:q.encoding,enctype:q.enctype,length:q.length,method:q.method,name:q.name,no_validate:q.noValidate,target:q.target,rel:q.rel}}function Vq(q){return{...Z(q),allow:q.allow,allow_fullscreen:q.allowFullscreen,height:q.height,name:q.name,referrer_policy:q.referrerPolicy,src:q.src,srcdoc:q.srcdoc,width:q.width,align:q.align,frame_border:q.frameBorder,long_desc:q.longDesc,margin_height:q.marginHeight,margin_width:q.marginWidth,scrolling:q.scrolling,sandbox:q.sandbox}}function Pq(q){return{...Z(q),alt:q.alt,cross_origin:q.crossOrigin,decoding:q.decoding,height:q.height,is_map:q.isMap,loading:q.loading,natural_height:q.naturalHeight,natural_width:q.naturalWidth,referrer_policy:q.referrerPolicy,sizes:q.sizes,src:q.src,srcset:q.srcset,use_map:q.useMap,width:q.width,align:q.align,border:q.border,complete:q.complete,hspace:q.hspace,long_desc:q.longDesc,lowsrc:q.lowsrc,name:q.name,vspace:q.vspace,x:q.x,y:q.y,fetch_priority:q.fetchPriority}}function Dq(q){return{...Z(q),accept:q.accept,alt:q.alt,autocomplete:q.autocomplete,checked:q.checked,default_checked:q.defaultChecked,default_value:q.defaultValue,dir_name:q.dirName,disabled:q.disabled,height:q.height,indeterminate:q.indeterminate,max:q.max,max_length:q.maxLength,min:q.min,min_length:q.minLength,multiple:q.multiple,name:q.name,pattern:q.pattern,placeholder:q.placeholder,read_only:q.readOnly,required:q.required,selection_direction:q.selectionDirection,selection_end:q.selectionEnd,selection_start:q.selectionStart,size:q.size,src:q.src,step:q.step,type:q.type,value:q.value,value_as_number:q.valueAsNumber,width:q.width,align:q.align,capture:q.capture,form_action:q.formAction,form_enctype:q.formEnctype,form_method:q.formMethod,form_no_validate:q.formNoValidate,form_target:q.formTarget,use_map:q.useMap,validation_message:q.validationMessage,will_validate:q.willValidate,popover_target_action:q.popoverTargetAction}}function bq(q){return{...Z(q),html_for:q.htmlFor}}function kq(q){return{...Z(q),value:q.value,type:q.type}}function jq(q){return{...Z(q),as:q.as,cross_origin:q.crossOrigin,disabled:q.disabled,fetch_priority:q.fetchPriority,href:q.href,href_lang:q.hreflang,image_sizes:q.imageSizes,image_srcset:q.imageSrcset,integrity:q.integrity,media:q.media,referrer_policy:q.referrerPolicy,rel:q.rel,type:q.type,charset:q.charset,rev:q.rev,target:q.target,sizes:q.sizes}}function yq(q){return{...Z(q),name:q.name}}function Bq(q){return{...Z(q),high:q.high,low:q.low,max:q.max,min:q.min,optimum:q.optimum,value:q.value}}function gq(q){return{...Z(q),cite:q.cite,dateTime:q.dateTime}}function pq(q){return{...Z(q),reversed:q.reversed,start:q.start,type:q.type,compact:q.compact}}function Lq(q){return{...Z(q),data:q.data,height:q.height,name:q.name,type:q.type,use_map:q.useMap,width:q.width,validation_message:q.validationMessage,will_validate:q.willValidate,align:q.align,archive:q.archive,border:q.border,code:q.code,code_base:q.codeBase,code_type:q.codeType,declare:q.declare,hspace:q.hspace,standby:q.standby,vspace:q.vspace}}function Hq(q){return{...Z(q),disabled:q.disabled,label:q.label}}function uq(q){return{...Z(q),default_selected:q.defaultSelected,disabled:q.disabled,index:q.index,label:q.label,selected:q.selected,text:q.text,value:q.value}}function hq(q){return{...Z(q),default_value:q.defaultValue,name:q.name,type:q.type,value:q.value,html_for:q.htmlFor,validation_message:q.validationMessage,will_validate:q.willValidate}}function Mq(q){return{...Z(q),max:q.max,position:q.position,value:q.value}}function Tq(q){return{...Z(q),cite:q.cite}}function iq(q){return{...Z(q)}}function dq(q){return{...Z(q),async_:q.async,cross_origin:q.crossOrigin,defer:q.defer,fetch_priority:q.fetchPriority,integrity:q.integrity,no_module:q.noModule,referrer_policy:q.referrerPolicy,src:q.src,text:q.text,type:q.type,charset:q.charset,event:q.event,html_for:q.htmlFor}}function mq(q){return{...Z(q),autocomplete:q.autocomplete,disabled:q.disabled,length:q.length,multiple:q.multiple,name:q.name,required:q.required,selected_index:q.selectedIndex,size:q.size,type:q.type,value:q.value,validation_message:q.validationMessage,will_validate:q.willValidate}}function Eq(q){return{...Z(q),name:q.name}}function xq(q){return{...Z(q),height:q.height,media:q.media,sizes:q.sizes,src:q.src,srcset:q.srcset,type:q.type,width:q.width}}function vq(q){return{...Z(q),align:q.align}}function sq(q){return{...Z(q),abbr:q.abbr,cell_index:q.cellIndex,col_span:q.colSpan,headers:q.headers,row_span:q.rowSpan,scope:q.scope,align:q.align,axis:q.axis,bg_color:q.bgColor,ch:q.ch,ch_off:q.chOff,height:q.height,no_wrap:q.noWrap,v_align:q.vAlign,width:q.width}}function oq(q){return{...Z(q),span:q.span,align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign,width:q.width}}function cq(q){return{...Z(q),align:q.align,bg_color:q.bgColor,border:q.border,cell_padding:q.cellPadding,cell_spacing:q.cellSpacing,frame:q.frame,rules:q.rules,summary:q.summary,width:q.width}}function rq(q){return{...Z(q),row_index:q.rowIndex,section_row_index:q.sectionRowIndex,align:q.align,bg_color:q.bgColor,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign}}function nq(q){return{...Z(q),align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign}}function aq(q){return{...Z(q)}}function lq(q){return{...Z(q),autocomplete:q.autocomplete,cols:q.cols,default_value:q.defaultValue,dir_name:q.dirName,disabled:q.disabled,max_length:q.maxLength,min_length:q.minLength,name:q.name,placeholder:q.placeholder,read_only:q.readOnly,required:q.required,rows:q.rows,selection_direction:q.selectionDirection,selection_end:q.selectionEnd,selection_start:q.selectionStart,value:q.value,wrap:q.wrap,text_length:q.textLength,validation_message:q.validationMessage,will_validate:q.willValidate}}function tq(q){return{...Z(q),datetime:q.dateTime}}function eq(q){return{...Z(q),default:q.default,kind:q.kind,label:q.label,ready_state:q.readyState,src:q.src,srclang:q.srclang}}function q1(q){return{...l(q),height:q.height,poster:q.poster,video_height:q.videoHeight,video_width:q.videoWidth,width:q.width,plays_inline:q.playsInline}}function J1(q){return{...Z(q),clear:q.clear}}function Y1(q){return{...Z(q),href:q.href,target:q.target}}function Z1(q){return{...Z(q),a_link:q.aLink,background:q.background,bg_color:q.bgColor,link:q.link,text:q.text,v_link:q.vLink}}function $1(q){return{...Z(q),compact:q.compact}}function Q1(q){return{...Z(q),open:q.open}}function W1(q){return{...Z(q),open:q.open,return_value:q.returnValue}}function z1(q){return{...Z(q),align:q.align}}function X1(q){return{...Z(q)}}function A1(q){return{...Z(q),align:q.align}}function G1(q){return{...Z(q),align:q.align,color:q.color,no_shade:q.noShade,size:q.size,width:q.width}}function f1(q){return{...Z(q),version:q.version}}function R1(q){return{...Z(q)}}function U1(q){return{...Z(q),content:q.content,http_equiv:q.httpEquiv,name:q.name,scheme:q.scheme}}function K1(q){return{...Z(q),align:q.align}}function _1(q){return{...Z(q)}}function w1(q){return{...Z(q),width:q.width}}function F1(q){return{...Z(q)}}function S1(q){return{...Z(q),media:q.media,type:q.type,disabled:q.disabled}}function I1(q){return{...Z(q),text:q.text}}function O1(q){return{...Z(q),compact:q.compact,type:q.type}}function P(q){switch(q.tagName.toUpperCase()){case"A":return _q(q);case"AREA":return wq(q);case"AUDIO":return Fq(q);case"BASE":return Y1(q);case"BLOCKQUOTE":case"Q":return Tq(q);case"BODY":return Z1(q);case"BR":return J1(q);case"BUTTON":return Sq(q);case"CANVAS":return Z(q);case"CAPTION":return vq(q);case"CITE":return iq(q);case"COL":case"COLGROUP":return oq(q);case"DATA":return Iq(q);case"DETAILS":return Q1(q);case"DIALOG":return W1(q);case"DIV":return z1(q);case"DL":return $1(q);case"EMBED":return Oq(q);case"FIELDSET":return Nq(q);case"FORM":return Cq(q);case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return A1(q);case"HEAD":return X1(q);case"HR":return G1(q);case"HTML":return f1(q);case"IFRAME":return Vq(q);case"IMG":return Pq(q);case"INPUT":return Dq(q);case"LABEL":return bq(q);case"LI":return kq(q);case"LINK":return jq(q);case"MAP":return yq(q);case"MENU":return R1(q);case"META":return U1(q);case"METER":return Bq(q);case"INS":case"DEL":return gq(q);case"OBJECT":return Lq(q);case"OL":return pq(q);case"OPTGROUP":return Hq(q);case"OPTION":return uq(q);case"OUTPUT":return hq(q);case"P":return K1(q);case"PICTURE":return _1(q);case"PRE":return w1(q);case"PROGRESS":return Mq(q);case"SCRIPT":return dq(q);case"SELECT":return mq(q);case"SLOT":return Eq(q);case"SOURCE":return xq(q);case"SPAN":return F1(q);case"STYLE":return S1(q);case"TABLE":return cq(q);case"TBODY":case"THEAD":case"TFOOT":return nq(q);case"TD":case"TH":return sq(q);case"TEMPLATE":return aq(q);case"TEXTAREA":return lq(q);case"TIME":return tq(q);case"TITLE":return I1(q);case"TR":return rq(q);case"TRACK":return eq(q);case"UL":return O1(q);case"VIDEO":return q1(q);default:throw new Error(`Unexpected HTML element tag: ${q.tagName} (update .web/custom/serialize.ts)`)}}function K(q){return{target:P(q.target),bubbles:q.bubbles,cancelable:q.cancelable,default_prevented:q.defaultPrevented,event_phase:q.eventPhase,is_trusted:q.isTrusted,timestamp:q.timeStamp,type:q.type}}function y(q){return{...K(q),detail:q.detail}}function G(q){return{...y(q),alt_key:q.altKey,button:q.button,buttons:q.buttons,client_x:q.clientX,client_y:q.clientY,ctrl_key:q.ctrlKey,meta_key:q.metaKey,movement_x:q.movementX,movement_y:q.movementY,page_x:q.pageX,page_y:q.pageY,related_target:q.relatedTarget?P(q.relatedTarget):null,screen_x:q.screenX,screen_y:q.screenY,shift_key:q.shiftKey}}function T(q){return{...K(q),clipboard_data:t(q.clipboardData)}}function i(q){return{...K(q),data:q.data}}function S(q){return{...G(q),data_transfer:t(q.dataTransfer)}}function U(q){return{...G(q),pointer_id:q.pointerId,pressure:q.pressure,tangential_pressure:q.tangentialPressure,tilt_x:q.tiltX,tilt_y:q.tiltY,twist:q.twist,width:q.width,height:q.height,pointer_type:q.pointerType,is_primary:q.isPrimary}}function n(q){return{...K(q),related_target:q.relatedTarget?P(q.relatedTarget):null}}function E(q){return K(q)}function N1(q){return K(q)}function a(q){return E(q)}function d(q){return{...y(q),alt_key:q.altKey,ctrl_key:q.ctrlKey,code:q.code,key:q.key,locale:q.locale,location:q.location,meta_key:q.metaKey,repeat:q.repeat,shift_key:q.shiftKey}}function j(q){return{...y(q),alt_key:q.altKey,changed_touches:Array.from(q.changedTouches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY})),ctrl_key:q.ctrlKey,meta_key:q.metaKey,shift_key:q.shiftKey,target_touches:Array.from(q.targetTouches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY})),touches:Array.from(q.touches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY}))}}function C1(q){return{...G(q),delta_mode:q.deltaMode,delta_x:q.deltaX,delta_y:q.deltaY,delta_z:q.deltaZ}}function m(q){return{...K(q),animation_name:q.animationName,elapsed_time:q.elapsedTime,pseudo_element:q.pseudoElement}}function V1(q){return{...K(q),old_state:q.oldState,new_state:q.newState}}function P1(q){return{...K(q),elapsed_time:q.elapsedTime,property_name:q.propertyName,pseudo_element:q.pseudoElement}}function t(q){if(!q)return null;let J=[];if(q.items)for(let Y=0;Y<q.items.length;Y++){let $=q.items[Y];J.push({kind:$.kind,type:$.type})}return{drop_effect:q.dropEffect,effect_allowed:q.effectAllowed,items:J,types:Array.from(q.types||[])}}var D1={pointerdown:U,pointermove:U,pointerup:U,pointercancel:U,gotpointercapture:U,lostpointercapture:U,pointerenter:U,pointerleave:U,pointerover:U,pointerout:U,click:G,contextmenu:G,dblclick:G,mousedown:G,mouseenter:G,mouseleave:G,mousemove:G,mouseout:G,mouseover:G,mouseup:G,drag:S,dragend:S,dragenter:S,dragexit:S,dragleave:S,dragover:S,dragstart:S,drop:S,keydown:d,keypress:d,keyup:d,focus:n,blur:n,change:a,input:a,invalid:N1,reset:E,submit:E,copy:T,cut:T,paste:T,compositionend:i,compositionstart:i,compositionupdate:i,touchcancel:j,touchend:j,touchmove:j,touchstart:j,scroll:y,wheel:C1,animationstart:m,animationend:m,animationiteration:m,transitionend:P1,toggle:V1};function x(q){if(q&&typeof q==="object"&&"nativeEvent"in q&&typeof q.isDefaultPrevented==="function"){let J=q;if(typeof J.type!=="string")return q;let Y=D1[J.type.toLowerCase()];if(Y)return Y(J);return console.warn(`No specific extractor for event type "${J.type}". Using synthetic.`),K(J)}return q}import{io as b1}from"socket.io-client";class B{url;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(q,J){this.url=q;this.frameworkNavigate=J;this.socket=null,this.activeViews=new Map,this.messageQueue=[]}isConnected(){return this.socket?.connected??!1}async connect(){if(this.socket)return;return new Promise((q,J)=>{let Y=b1(this.url,{transports:["websocket"]});this.socket=Y,Y.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[$,Q]of this.activeViews)Y.emit("message",{type:"mount",path:$,routeInfo:Q.routeInfo});for(let $ of this.messageQueue){if($.type==="mount"&&this.activeViews.has($.path))continue;if($.type==="navigate")continue;Y.emit("message",$)}this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),Y.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),J($)}),Y.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Y.on("message",($)=>this.handleServerMessage($))})}onConnectionChange(q){return this.connectionListeners.add(q),q(this.isConnected()),()=>{this.connectionListeners.delete(q)}}notifyConnectionListeners(q){for(let J of this.connectionListeners)J(q)}onServerError(q){this.serverErrorListeners.add(q);for(let[J,Y]of this.serverErrors)q(J,Y);return()=>{this.serverErrorListeners.delete(q)}}notifyServerError(q,J){for(let Y of this.serverErrorListeners)Y(q,J)}async sendMessage(q){if(this.isConnected())this.socket.emit("message",q);else this.messageQueue.push(q)}mountView(q,J){if(this.activeViews.has(q))throw new Error(`Path ${q} is already mounted`);this.activeViews.set(q,J),this.sendMessage({type:"mount",path:q,routeInfo:J.routeInfo})}async navigate(q,J){await this.sendMessage({type:"navigate",path:q,routeInfo:J})}unmount(q){this.sendMessage({type:"unmount",path:q}),this.activeViews.delete(q)}disconnect(){this.socket?.disconnect(),this.socket=null,this.messageQueue=[],this.connectionListeners.clear(),this.activeViews.clear(),this.serverErrors.clear(),this.serverErrorListeners.clear()}handleServerMessage(q){switch(q.type){case"vdom_init":{let J=this.activeViews.get(q.path);if(J)J.vdom=q.vdom,J.listener(J.vdom);if(this.serverErrors.has(q.path))this.serverErrors.delete(q.path),this.notifyServerError(q.path,null);break}case"vdom_update":{let J=this.activeViews.get(q.path);if(!J||!J.vdom){console.error(`[PulseClient] Received VDOM update for path ${q.path} before initial tree was set.`);return}if(J.vdom=h(J.vdom,q.ops),J.listener(J.vdom),this.serverErrors.has(q.path))this.serverErrors.delete(q.path),this.notifyServerError(q.path,null);break}case"server_error":{this.serverErrors.set(q.path,q.error),this.notifyServerError(q.path,q.error);break}case"api_call":{this.performApiCall(q);break}case"navigate_to":{try{let J=q.path;if(this.frameworkNavigate)this.frameworkNavigate(J);else window.history.pushState({},"",J),window.dispatchEvent(new PopStateEvent("popstate"))}catch(J){console.error("Navigation error:",J)}break}}}async performApiCall(q){try{let J=await fetch(q.url,{method:q.method||"GET",headers:{...q.headers||{},...q.body!=null&&!("content-type"in(q.headers||{}))?{"content-type":"application/json"}:{}},body:q.body!=null?typeof q.body==="string"?q.body:JSON.stringify(q.body):void 0,credentials:q.credentials||"include"}),Y={};J.headers.forEach((A,I)=>Y[I]=A);let $=null;if((J.headers.get("content-type")||"").includes("application/json"))$=await J.json().catch(()=>null);else $=await J.text().catch(()=>null);let X={type:"api_result",id:q.id,ok:J.ok,status:J.status,headers:Y,body:$};await this.sendMessage(X)}catch(J){let Y={type:"api_result",id:q.id,ok:!1,status:0,headers:{},body:{error:String(J)}};await this.sendMessage(Y)}}async invokeCallback(q,J,Y){await this.sendMessage({type:"callback",path:q,callback:J,args:Y.map(x)})}}import{useLocation as k1,useParams as j1,useNavigate as y1}from"react-router";import{jsxDEV as R}from"react/jsx-dev-runtime";var Jq=e(null),Yq=()=>{let q=qq(Jq);if(!q)throw new Error("usePulseClient must be used within a PulseProvider");return q},Zq=e(null),M=()=>{let q=qq(Zq);if(!q)throw new Error("usePulseRenderHelpers must be used within a PulseRenderContext (provided by <PulseView>)");return q},o=typeof window!=="undefined";function B1({children:q,config:J}){let[Y,$]=v(!0),Q=y1(),X=s(()=>new B(`${J.serverAddress}`,Q),[J.serverAddress,Q]);return g(()=>X.onConnectionChange($),[X]),g(()=>{if(o)return X.connect(),()=>X.disconnect()},[X]),R(Jq.Provider,{value:X,children:[!Y&&R("div",{style:{position:"fixed",bottom:"20px",right:"20px",backgroundColor:"red",color:"white",padding:"10px",borderRadius:"5px",zIndex:1000},children:"Failed to connect to the server."},void 0,!1,void 0,this),q]},void 0,!0,void 0,this)}function g1({initialVDOM:q,externalComponents:J,path:Y}){let $=Yq(),[Q,X]=v(q),[A,I]=v(null),W=k1(),z=j1(),f=s(()=>{let{"*":_="",...D}=z,b=new URLSearchParams(W.search);return{hash:W.hash,pathname:W.pathname,query:W.search,queryParams:Object.fromEntries(b.entries()),pathParams:D,catchall:_.length>0?_.split("/"):[]}},[W.hash,W.pathname,W.search,JSON.stringify(z)]);g(()=>{if(o){$.mountView(Y,{vdom:q,listener:X,routeInfo:f});let _=$.onServerError((D,b)=>{if(D===Y)I(b)});return()=>{console.log("Unmounting",Y),_(),$.unmount(Y)}}},[$]),g(()=>{if(o)$.navigate(Y,f)},[$,Y,f]);let C=s(()=>{let _=new Map;return{getCallback:(V)=>{let O=_.get(V);if(!O)O=(...Qq)=>$.invokeCallback(Y,V,Qq),_.set(V,O);return O},getComponent:(V)=>{let O=J[V];if(!O)throw new Error(`Component with key "${V}" not found.`);return O}}},[$,J,Y]);return R(Zq.Provider,{value:C,children:A?R(p1,{error:A},void 0,!1,void 0,this):R(N,{node:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function p1({error:q}){return R("div",{style:{padding:16,border:"1px solid #e00",background:"#fff5f5",color:"#900",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',whiteSpace:"pre-wrap"},children:[R("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",q.phase]},void 0,!0,void 0,this),q.message&&R("div",{children:q.message},void 0,!1,void 0,this),q.stack&&R("details",{open:!0,style:{marginTop:8},children:[R("summary",{children:"Stack trace"},void 0,!1,void 0,this),R("pre",{style:{margin:0},children:q.stack},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{io as L1}from"socket.io-client";class $q{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(q){this.url=q}connect(q){return this.listener=q,new Promise((J,Y)=>{this.socket=L1(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let $ of this.messageQueue)this.socket?.emit("message",$);this.messageQueue=[],this.notifyConnectionListeners(!0),J()}),this.socket.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),Y($)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",($)=>{this.listener?.($)})})}disconnect(){this.socket?.disconnect(),this.socket=null,this.listener=null,this.messageQueue=[],this.connectionListeners.clear()}async sendMessage(q){if(this.isConnected())this.socket.emit("message",q);else this.messageQueue.push(q)}isConnected(){return this.socket?.connected||!1}onConnectionChange(q){return this.connectionListeners.add(q),q(this.isConnected()),()=>{this.connectionListeners.delete(q)}}notifyConnectionListeners(q){for(let J of this.connectionListeners)J(q)}}function H1({params:q,request:J}){let{"*":Y="",...$}=q,Q=new URL(J.url);return{hash:Q.hash,pathname:Q.pathname,query:Q.search,queryParams:Object.fromEntries(Q.searchParams.entries()),pathParams:$,catchall:Y.length>1?Y.split("/"):[]}}export{M as usePulseRenderHelpers,Yq as usePulseClient,H1 as extractServerRouteInfo,x as extractEvent,Aq as createMountPoint,Xq as createFragment,zq as createElementNode,h as applyVDOMUpdates,N as VDOMRenderer,$q as SocketIOTransport,Rq as RenderLazy,g1 as PulseView,B as PulseSocketIOClient,B1 as PulseProvider};
|
|
1
|
+
import{useEffect as h,useState as c,useMemo as l,createContext as xq,useContext as iq}from"react";import I,{isValidElement as AW,Suspense as DW}from"react";var t="$$fragment",e="$$";function WW(W){return typeof W==="object"&&W!==null}function qW(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}import{jsxDEV as m,Fragment as fW}from"react/jsx-dev-runtime";class H{client;path;components;callbackCache;constructor(W,q,Z){this.client=W;this.path=q;this.components=Z;this.callbackCache=new Map}getCallback(W){let q=this.callbackCache.get(W);if(!q)q=(...Z)=>this.client.invokeCallback(this.path,W,Z),this.callbackCache.set(W,q);return q}renderNode(W){if(W==null||typeof W==="boolean"||typeof W==="number"||typeof W==="string")return W;if(WW(W)){let{tag:q,props:Z={},children:$=[]}=W,z={};for(let[F,Q]of Object.entries(Z))if(typeof Q==="string"&&Q.startsWith("$$fn:")){let X=Q.substring(5);z[F]=this.getCallback(X)}else z[F]=Q;if(W.key)z.key=W.key;let J=[];for(let F of $)J.push(this.renderNode(F));if(qW(W)){let F=W.tag.slice(e.length),Q=this.components[F];return I.createElement(Q,z,...J)}return I.createElement(q===t?I.Fragment:q,z,...J)}return console.error("Unknown VDOM node type:",W),null}}function b(W){let q=W.props?.children;if(q==null)return[];return Array.isArray(q)?q.slice():[q]}function CW(W,q){let Z={};for(let[$,z]of Object.entries(q||{}))if(typeof z==="string"&&z.startsWith("$$fn:")){let J=z.substring(5);Z[$]=W.getCallback(J)}else Z[$]=z;return Z}function NW(W,q){return I.cloneElement(W,void 0,...q)}function p(W,q,Z){let $=W;for(let z of q){let J=z.path.split(".").filter((Q)=>Q.length>0).map(Number),F=(Q,X)=>{if(X<J.length){Y(Q,J,X),Q=Q;let G=J[X],U=b(Q),C=U[G];return U[G]=F(C,X+1),NW(Q,U)}switch(z.type){case"replace":return Z.renderNode(z.data);case"update_props":{Y(Q,J,X),Q=Q;let G=CW(Z,z.data);return I.cloneElement(Q,G)}case"insert":{Y(Q,J,X),Q=Q;let G=b(Q);return G.splice(z.idx,0,Z.renderNode(z.data)),I.cloneElement(Q,null,...G)}case"remove":{Y(Q,J,X),Q=Q;let G=b(Q);return G.splice(z.idx,1),I.cloneElement(Q,null,...G)}case"move":{Y(Q,J,X),Q=Q;let G=b(Q),U=G.splice(z.data.from_index,1)[0];return G.splice(z.data.to_index,0,U),I.cloneElement(Q,null,...G)}default:throw new Error(`[Pulse renderer] Unknown update type: ${z.type}`)}};$=F($,0)}return $}function OW(W,q){let Z=I.lazy(W);return({children:$,...z})=>{return m(DW,{fallback:q??m(fW,{},void 0,!1,void 0,this),children:m(Z,{...z,children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)}}function Y(W,q,Z){if(!AW(W))throw console.error("Invalid node:",W),new Error("Invalid node at path "+q.slice(0,Z).join("."));return!0}function V(){function W(q,Z){return($)=>{let z={};for(let J of q)z[J]=$[J];if(Z)for(let J in Z){let F=Z[J];z[J]=F($)}return z}}return W}var IW=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],kW=["autofocus","tabIndex","nonce"],yW=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],wW=V()(IW,{tagName:(W)=>W.tagName.toLowerCase()}),BW=V()(kW),KW=V()(yW);function k(W){return{...wW(W),...BW(W),...KW(W)}}function P(W,q){let Z=V()(W,q);return($)=>({...k($),...Z($)})}var jW=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],YW=P(jW),gW=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],MW=P(gW),bW=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],JW=P(bW),HW=(W)=>JW(W),SW=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],LW=P(SW),_W=["value"],TW=P(_W),hW=["height","src","type","width","align","name"],mW=P(hW),pW=["disabled","name","type","validationMessage","willValidate"],vW=P(pW),uW=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],xW=P(uW),iW=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],EW=P(iW),nW=["alt","crossOrigin","decoding","height","isMap","loading","naturalHeight","naturalWidth","referrerPolicy","sizes","src","srcset","useMap","width","align","border","complete","hspace","longDesc","lowsrc","name","vspace","x","y","fetchPriority"],dW=P(nW),sW=["accept","alt","autocomplete","checked","defaultChecked","defaultValue","dirName","disabled","height","indeterminate","max","maxLength","min","minLength","multiple","name","pattern","placeholder","readOnly","required","selectionDirection","selectionEnd","selectionStart","size","src","step","type","value","valueAsNumber","width","align","capture","formAction","formEnctype","formMethod","formNoValidate","formTarget","useMap","validationMessage","willValidate","popoverTargetAction"],cW=P(sW),lW=["htmlFor"],oW=P(lW),rW=["value","type"],aW=P(rW),tW=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],eW=P(tW),W1=["name"],q1=P(W1),z1=["high","low","max","min","optimum","value"],Z1=P(z1),$1=["cite","dateTime"],zW=P($1),Q1=["reversed","start","type","compact"],J1=P(Q1),X1=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],G1=P(X1),P1=["disabled","label"],F1=P(P1),U1=["defaultSelected","disabled","index","label","selected","text","value"],V1=P(U1),R1=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],A1=P(R1),D1=["max","position","value"],C1=P(D1),N1=["cite"],ZW=P(N1),O1=(W)=>k(W),f1=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],I1=V()(f1,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),k1=(W)=>({...k(W),...I1(W)}),y1=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],w1=P(y1),B1=["name"],K1=P(B1),j1=["height","media","sizes","src","srcset","type","width"],Y1=P(j1),g1=["align"],M1=P(g1),b1=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],$W=P(b1),H1=["span","align","ch","chOff","vAlign","width"],QW=P(H1),S1=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],L1=P(S1),_1=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],T1=P(_1),h1=["align","ch","chOff","vAlign"],v=P(h1),m1=(W)=>k(W),p1=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],v1=P(p1),u1=["dateTime"],x1=P(u1),i1=["default","kind","label","readyState","src","srclang"],E1=P(i1),n1=["height","poster","videoHeight","videoWidth","width","playsInline"],d1=V()(n1),s1=(W)=>({...JW(W),...d1(W)}),c1=["clear"],l1=P(c1),o1=["href","target"],r1=P(o1),a1=["aLink","background","bgColor","link","text","vLink"],t1=P(a1),e1=["compact"],Wq=P(e1),qq=["open"],zq=P(qq),Zq=["open","returnValue"],$q=P(Zq),Qq=["align"],Jq=P(Qq),Xq=(W)=>k(W),Gq=["align"],K=P(Gq),Pq=["align","color","noShade","size","width"],Fq=P(Pq),Uq=["version"],Vq=P(Uq),Rq=(W)=>k(W),Aq=["content","httpEquiv","name","scheme"],Dq=P(Aq),Cq=["align"],Nq=P(Cq),Oq=(W)=>k(W),fq=["width"],Iq=P(fq),kq=(W)=>k(W),yq=["media","type","disabled"],wq=P(yq),Bq=["text"],Kq=P(Bq),jq=["compact","type"],Yq=P(jq),gq={A:YW,AREA:MW,AUDIO:HW,BASE:r1,BLOCKQUOTE:ZW,Q:ZW,BODY:t1,BR:l1,BUTTON:LW,CANVAS:k,CAPTION:M1,CITE:O1,COL:QW,COLGROUP:QW,DATA:TW,DETAILS:zq,DIALOG:$q,DIV:Jq,DL:Wq,EMBED:mW,FIELDSET:vW,FORM:xW,H1:K,H2:K,H3:K,H4:K,H5:K,H6:K,HEAD:Xq,HR:Fq,HTML:Vq,IFRAME:EW,IMG:dW,INPUT:cW,LABEL:oW,LI:aW,LINK:eW,MAP:q1,MENU:Rq,META:Dq,METER:Z1,INS:zW,DEL:zW,OBJECT:G1,OL:J1,OPTGROUP:F1,OPTION:V1,OUTPUT:A1,P:Nq,PICTURE:Oq,PRE:Iq,PROGRESS:C1,SCRIPT:k1,SELECT:w1,SLOT:K1,SOURCE:Y1,SPAN:kq,STYLE:wq,TABLE:L1,TBODY:v,THEAD:v,TFOOT:v,TD:$W,TH:$W,TEMPLATE:m1,TEXTAREA:v1,TIME:x1,TITLE:Kq,TR:T1,TRACK:E1,UL:Yq,VIDEO:s1};function R(W){let q=W.tagName.toUpperCase(),Z=gq[q];if(Z)return Z(W);throw new Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var N=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],L=[...N,"detail"],_=[...L,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],Mq=[..._,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],bq=V()(N,{target:(W)=>R(W.target)}),Hq=V()(L,{target:(W)=>R(W.target)}),O=V()(_,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),u=V()(N,{target:(W)=>R(W.target),clipboardData:(W)=>FW(W.clipboardData)}),x=V()([...N,"data"],{target:(W)=>R(W.target)}),w=V()(_,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null,dataTransfer:(W)=>FW(W.dataTransfer)}),f=V()(Mq,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),XW=V()(N,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),GW=V()(N,{target:(W)=>R(W.target)}),Sq=V()(N,{target:(W)=>R(W.target)}),PW=V()(N,{target:(W)=>R(W.target)}),i=V()([...L,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"],{target:(W)=>R(W.target)}),S=V()([...L,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{target:(W)=>R(W.target),changedTouches:(W)=>n(W.changedTouches),targetTouches:(W)=>n(W.targetTouches),touches:(W)=>n(W.touches)}),Lq=V()([..._,"deltaMode","deltaX","deltaY","deltaZ"],{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),E=V()([...N,"animationName","elapsedTime","pseudoElement"],{target:(W)=>R(W.target)}),_q=V()([...N,"oldState","newState"],{target:(W)=>R(W.target)}),Tq=V()([...N,"elapsedTime","propertyName","pseudoElement"],{target:(W)=>R(W.target)});function n(W){return Array.from(W).map((q)=>({target:R(q.target),identifier:q.identifier,screenX:q.screenX,screenY:q.screenY,clientX:q.clientX,clientY:q.clientY,pageX:q.pageX,pageY:q.pageY}))}function FW(W){if(!W)return null;let q=[];if(W.items)for(let Z=0;Z<W.items.length;Z++){let $=W.items[Z];q.push({kind:$.kind,type:$.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:q,types:Array.from(W.types||[])}}var hq={pointerdown:f,pointermove:f,pointerup:f,pointercancel:f,gotpointercapture:f,lostpointercapture:f,pointerenter:f,pointerleave:f,pointerover:f,pointerout:f,click:O,contextmenu:O,dblclick:O,mousedown:O,mouseenter:O,mouseleave:O,mousemove:O,mouseout:O,mouseover:O,mouseup:O,drag:w,dragend:w,dragenter:w,dragexit:w,dragleave:w,dragover:w,dragstart:w,drop:w,keydown:i,keypress:i,keyup:i,focus:XW,blur:XW,change:PW,input:PW,invalid:Sq,reset:GW,submit:GW,copy:u,cut:u,paste:u,compositionend:x,compositionstart:x,compositionupdate:x,touchcancel:S,touchend:S,touchmove:S,touchstart:S,scroll:Hq,wheel:Lq,animationstart:E,animationend:E,animationiteration:E,transitionend:Tq,toggle:_q};function d(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let q=W;if(typeof q.type!=="string")return W;let Z=hq[q.type.toLowerCase()];if(Z)return Z(q);return bq(q)}return W}function mq(W){return W instanceof Date}function pq(W){return typeof File!=="undefined"&&W instanceof File}function vq(W){return typeof FormData!=="undefined"&&W instanceof FormData}function g(W){let q=new Map,Z=1,$=(z)=>{if(z===null||typeof z!=="object")return z;let J=z;if(q.has(J))return{__ref:q.get(J)};if(mq(z)){let X=Z++;return q.set(J,X),{__pulse:"date",__id:X,timestamp:z.getTime()}}if(pq(z)){let X=Z++;return q.set(J,X),{__pulse:"file",__id:X,name:z.name,type:z.type,size:z.size,lastModified:z.lastModified,file:z}}if(vq(z)){let X=Z++;q.set(J,X);let G={};for(let[U,C]of z.entries()){let A=$(C);if(Object.prototype.hasOwnProperty.call(G,U)){let D=G[U];if(Array.isArray(D))D.push(A);else G[U]=[D,A]}else G[U]=A}return{__pulse:"formdata",__id:X,fields:G}}let F=Z++;if(q.set(J,F),Array.isArray(z))return{__pulse:"array",__id:F,items:z.map($)};let Q={};for(let X in z){let G=z[X];if(typeof G==="function"||typeof G==="symbol"||typeof G==="undefined")continue;Q[X]=$(G)}return{__pulse:"object",__id:F,__data:Q}};return $(W)}function s(W){let q=new Map,Z=($)=>{if($===null||typeof $!=="object")return $;if(Array.isArray($))return $.map(Z);let z=$;if(z.__ref!==void 0){let F=z.__ref;return q.get(F)||null}if(z.__pulse==="date"){let F=z.__id,Q=new Date(z.timestamp);return q.set(F,Q),Q}if(z.__pulse==="file"){let{__id:F,file:Q}=z;return q.set(F,Q),Q}if(z.__pulse==="formdata"){let{__id:F,fields:Q}=z,X=new FormData;q.set(F,X);for(let[G,U]of Object.entries(Q))if(Array.isArray(U))for(let C of U){let A=Z(C);X.append(G,A)}else{let C=Z(U);X.append(G,C)}return X}if(z.__pulse==="array"){let F=z.__id,Q=[];q.set(F,Q);let X=z.items;for(let G=0;G<X.length;G++)Q[G]=Z(X[G]);return Q}if(z.__pulse==="object"){let F=z.__id,Q={};q.set(F,Q);let X=z.__data;for(let[G,U]of Object.entries(X))Q[G]=Z(U);return Q}let J={};for(let[F,Q]of Object.entries(z))J[F]=Z(Q);return J};return Z(W)}import{io as uq}from"socket.io-client";class T{url;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(W,q){this.url=W;this.frameworkNavigate=q;this.socket=null,this.activeViews=new Map,this.messageQueue=[]}isConnected(){return this.socket?.connected??!1}async connect(){if(this.socket)return;return new Promise((W,q)=>{let Z=uq(this.url,{transports:["websocket"]});this.socket=Z,Z.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[$,z]of this.activeViews)Z.emit("message",g({type:"mount",path:$,routeInfo:z.routeInfo}));for(let $ of this.messageQueue){if($.type==="mount"&&this.activeViews.has($.path))continue;if($.type==="navigate")continue;Z.emit("message",g($))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),Z.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),q($)}),Z.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Z.on("message",($)=>this.handleServerMessage(s($)))})}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}onServerError(W){this.serverErrorListeners.add(W);for(let[q,Z]of this.serverErrors)W(q,Z);return()=>{this.serverErrorListeners.delete(W)}}notifyServerError(W,q){for(let Z of this.serverErrorListeners)Z(W,q)}async sendMessage(W){if(this.isConnected())this.socket.emit("message",g(W));else this.messageQueue.push(W)}mountView(W,q){if(this.activeViews.has(W))throw new Error(`Path ${W} is already mounted`);this.activeViews.set(W,q),this.sendMessage({type:"mount",path:W,routeInfo:q.routeInfo})}async navigate(W,q){await this.sendMessage({type:"navigate",path:W,routeInfo:q})}unmount(W){this.sendMessage({type:"unmount",path:W}),this.activeViews.delete(W)}disconnect(){this.socket?.disconnect(),this.socket=null,this.messageQueue=[],this.connectionListeners.clear(),this.activeViews.clear(),this.serverErrors.clear(),this.serverErrorListeners.clear()}handleServerMessage(W){switch(W.type){case"vdom_init":{let q=this.activeViews.get(W.path);if(q)q.onInit(W.vdom);if(this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"vdom_update":{let q=this.activeViews.get(W.path);if(!q){console.error(`[PulseClient] Received VDOM update for path ${W.path} before initial tree was set.`);return}if(q.onUpdate(W.ops),this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"server_error":{this.serverErrors.set(W.path,W.error),this.notifyServerError(W.path,W.error);break}case"api_call":{this.performApiCall(W);break}case"navigate_to":{try{let q=W.path;if(this.frameworkNavigate)this.frameworkNavigate(q);else window.history.pushState({},"",q),window.dispatchEvent(new PopStateEvent("popstate"))}catch(q){console.error("Navigation error:",q)}break}default:console.error("Unexpected message:",W)}}async performApiCall(W){try{let q=await fetch(W.url,{method:W.method||"GET",headers:{...W.headers||{},...W.body!=null&&!("content-type"in(W.headers||{}))?{"content-type":"application/json"}:{}},body:W.body!=null?typeof W.body==="string"?W.body:JSON.stringify(W.body):void 0,credentials:W.credentials||"include"}),Z={};q.headers.forEach((F,Q)=>Z[Q]=F);let $=null;if((q.headers.get("content-type")||"").includes("application/json"))$=await q.json().catch(()=>null);else $=await q.text().catch(()=>null);let J={type:"api_result",id:W.id,ok:q.ok,status:q.status,headers:Z,body:$};await this.sendMessage(J)}catch(q){let Z={type:"api_result",id:W.id,ok:!1,status:0,headers:{},body:{error:String(q)}};await this.sendMessage(Z)}}async invokeCallback(W,q,Z){await this.sendMessage({type:"callback",path:W,callback:q,args:Z.map(d)})}}import{useLocation as Eq,useParams as nq,useNavigate as dq}from"react-router";import{jsxDEV as y}from"react/jsx-dev-runtime";var UW=xq(null),VW=()=>{let W=iq(UW);if(!W)throw new Error("usePulseClient must be used within a PulseProvider");return W},o=typeof window!=="undefined";function sq({children:W,config:q}){let[Z,$]=c(!0),z=dq(),J=l(()=>new T(`${q.serverAddress}`,z),[q.serverAddress,z]);return h(()=>J.onConnectionChange($),[J]),h(()=>{if(o)return J.connect(),()=>J.disconnect()},[J]),y(UW.Provider,{value:J,children:[!Z&&y("div",{style:{position:"fixed",bottom:"20px",right:"20px",backgroundColor:"red",color:"white",padding:"10px",borderRadius:"5px",zIndex:1000},children:"Failed to connect to the server."},void 0,!1,void 0,this),W]},void 0,!0,void 0,this)}function cq({initialVDOM:W,externalComponents:q,path:Z}){let $=VW(),z=l(()=>new H($,Z,q),[$,Z,q]),[J,F]=c(()=>z.renderNode(W)),[Q,X]=c(null),G=Eq(),U=nq(),C=l(()=>{let{"*":A="",...D}=U,B=new URLSearchParams(G.search);return{hash:G.hash,pathname:G.pathname,query:G.search,queryParams:Object.fromEntries(B.entries()),pathParams:D,catchall:A.length>0?A.split("/"):[]}},[G.hash,G.pathname,G.search,JSON.stringify(U)]);if(h(()=>{if(o){$.mountView(Z,{routeInfo:C,onInit:(D)=>{F(z.renderNode(D))},onUpdate:(D)=>{F((B)=>B==null?B:p(B,D,z))}});let A=$.onServerError((D,B)=>{if(D===Z)X(B)});return()=>{A(),$.unmount(Z)}}},[$]),h(()=>{if(o)$.navigate(Z,C)},[$,Z,C]),Q)return y(lq,{error:Q},void 0,!1,void 0,this);return J}function lq({error:W}){return y("div",{style:{padding:16,border:"1px solid #e00",background:"#fff5f5",color:"#900",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',whiteSpace:"pre-wrap"},children:[y("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]},void 0,!0,void 0,this),W.message&&y("div",{children:W.message},void 0,!1,void 0,this),W.stack&&y("details",{open:!0,style:{marginTop:8},children:[y("summary",{children:"Stack trace"},void 0,!1,void 0,this),y("pre",{style:{margin:0},children:W.stack},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{io as oq}from"socket.io-client";class RW{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(W){this.url=W}connect(W){return this.listener=W,new Promise((q,Z)=>{this.socket=oq(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let $ of this.messageQueue)this.socket?.emit("message",$);this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),this.socket.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),Z($)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",($)=>{this.listener?.($)})})}disconnect(){this.socket?.disconnect(),this.socket=null,this.listener=null,this.messageQueue=[],this.connectionListeners.clear()}async sendMessage(W){if(this.isConnected())this.socket.emit("message",W);else this.messageQueue.push(W)}isConnected(){return this.socket?.connected||!1}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}}function rq({params:W,request:q}){let{"*":Z="",...$}=W,z=new URL(q.url);return{hash:z.hash,pathname:z.pathname,query:z.search,queryParams:Object.fromEntries(z.searchParams.entries()),pathParams:$,catchall:Z.length>1?Z.split("/"):[]}}function aq(W){if(W===null||typeof W!=="object")return!1;let q=Object.getPrototypeOf(W);return q===Object.prototype||q===null}function r(W){return typeof W==="function"||typeof W==="symbol"||typeof W==="undefined"}async function tq(W){let q=await W.arrayBuffer();return Array.from(new Uint8Array(q))}async function eq(W){return await M(W,{seen:new WeakMap,nextId:1})}function Wz(W,q){if(W.seen.get(q)!==void 0)return null;let $=W.nextId++;return W.seen.set(q,$),$}async function M(W,q){if(W===null||typeof W!=="object")return W;if(W instanceof Date)return{__t:"datetime",timestamp:W.getTime()};if(W instanceof FormData){let Q=Wz(q,W);if(Q===null)return{__t:"ref",id:q.seen.get(W)};let X={};for(let[U,C]of W.entries()){let A=await M(C,q);if(A===void 0)continue;if(Object.prototype.hasOwnProperty.call(X,U)){let D=X[U];if(Array.isArray(D))D.push(A);else X[U]=[D,A]}else X[U]=A}return{__t:"formdata",fields:X,__id:Q}}if(W instanceof File){let Q=W,X=await tq(W);return{__t:"file",name:Q.name,type:Q.type,size:Q.size,lastModified:Q.lastModified,content:X}}let Z=W,$=q.seen.get(Z);if($!==void 0)return{__t:"ref",id:$};let z=q.nextId++;if(q.seen.set(Z,z),Array.isArray(W)){let X=(await Promise.all(W.map((U)=>M(U,q)))).filter((U)=>U!==void 0);return{__t:"array",__id:z,items:X}}let J={};if(aq(W))for(let Q of Object.keys(W)){let X=W[Q];if(r(X))continue;let G=await M(X,q);if(G!==void 0)J[Q]=G}else for(let Q in W){let X=W[Q];if(r(X))continue;let G=await M(X,q);if(G!==void 0)J[Q]=G}return{__t:"object",__id:z,props:J}}function qz(W){return j(W)}function j(W){if(W===null||typeof W!=="object")return W;let q=W,Z=q.__t;if(Z==="datetime"){let z=q.timestamp;return new Date(z)}if(Z==="file"){let z=q.content;if(Array.isArray(z))return{...q,content:new Uint8Array(z)};return q}if(Z==="formdata"){let z=q.fields,J={};for(let F of Object.keys(z)){let Q=z[F];if(Array.isArray(Q))J[F]=Q.map((X)=>j(X));else J[F]=j(Q)}return{__t:"formdata",fields:J}}if(Z==="array")return q.items.map((J)=>j(J));if(Z==="object"){let z=q.props,J={};for(let F of Object.keys(z))J[F]=j(z[F]);return J}if(Z==="ref")return q;let $={};for(let z of Object.keys(q))$[z]=j(q[z]);return $}function zz(W){return a(W,new WeakSet)}function a(W,q){if(W===null||typeof W!=="object")return W;if(q.has(W))return;if(q.add(W),Array.isArray(W))return W.map(($)=>a($,q)).filter(($)=>$!==void 0);let Z={};for(let $ in W){let z=W[$];if(r(z))continue;let J=a(z,q);if(J!==void 0)Z[$]=J}return Z}export{VW as usePulseClient,g as stringify,s as parse,rq as extractServerRouteInfo,d as extractEvent,eq as encodeForWire,qz as decodeFromWire,zz as cleanForSerialization,p as applyReactTreeUpdates,H as VDOMRenderer,RW as SocketIOTransport,OW as RenderLazy,cq as PulseView,T as PulseSocketIOClient,sq as PulseProvider};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=1CF1CFA868B5A2AA64756E2164756E21
|