@plurid/plurid-react 0.0.0-29 → 0.0.0-31

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.
@@ -508,7 +508,7 @@
508
508
  background-color: black;
509
509
  pointer-events: none;
510
510
  z-index: 999999;
511
- `,Dn=e=>{const[t,a]=r.useState(!1);return r.useEffect((()=>{setTimeout((()=>{a(!0)}),10)}),[]),t?x.default.createElement(x.default.Fragment,null):x.default.createElement(Un,null)},xn=e=>{const{routes:a,planes:n,exterior:o,shell:i,hostname:s,scrollToTop:c,static:d,view:f,cleanNavigation:p,notFoundPath:m}=e,g=m||"/not-found",h=((e,t)=>{const a=[];for(const t of e){if(t.planes)for(const e of t.planes){const n=ce(e),r={route:n.link?n.link:n.value.startsWith("/")?n.value:t.value+"/"+n.value,component:n.component};a.push(r)}t.spaces}if(t)for(const e of t){const t=ce(e),n={route:t.value,component:t.component};a.push(n)}return a})(a,n),T=r.useRef(null),E=r.useRef(new de(h,s)),v=r.useRef(new fe({routes:a,routePlanes:n},s)),S=u.useMounted(),[P,b]=r.useState((e=>e?e.path:"undefined"!=typeof window?window.location.pathname+window.location.search:"/")(d)),[R,I]=r.useState(v.current.match(P,"route")),[C,w]=r.useState(_n(R,E.current,v.current,d&&d.directPlane?v.current.match(d.directPlane,"route"):void 0,s)),O=e=>{let t;e&&e.detail&&e.detail.path&&!t&&(t=e.detail.path),p&&f&&!t&&(t=f);const a=window.location.pathname;t||(t=a+window.location.search),b(t),(()=>{if(!T.current||!1===c)return;const e=void 0===c||!0===c||"smooth"===c?"smooth":"auto";T.current.scrollIntoView({behavior:e})})()};let y;r.useEffect((()=>(window.addEventListener("popstate",O),window.addEventListener(t.PLURID_ROUTER_LOCATION_CHANGED,O),()=>{window.removeEventListener("popstate",O),window.removeEventListener(t.PLURID_ROUTER_LOCATION_CHANGED,O)})),[]),r.useEffect((()=>{if(!S)return;p||location.pathname!==P&&history.pushState(null,"",P);let e=v.current.match(P,"route");if(e&&"RoutePlane"===e.kind){const t=Ln(e,E.current,s);return I(e),void w(t)}e||(e=v.current.match(g,"route")),I(e),w(_n(e,E.current,v.current,void 0,s))}),[S,P]),r.useEffect((()=>{if(!R)return;if("Route"!==R.kind)return;const e=R.match.value;l.storage.saveState(e,t.PLURID_ROUTER_STORAGE);const a=new CustomEvent(t.PLURID_ROUTER_LOCATION_STORED,{detail:{path:e}});window.dispatchEvent(a)}),[p,R]),Zt(o)&&(y=o,y&&(y.displayName="PluridRouterExterior"));let _=({children:e})=>x.default.createElement(x.default.Fragment,null,e);return Zt(i)&&(_=i,_&&(_.displayName="PluridRouterShell")),x.default.createElement(x.default.Fragment,null,x.default.createElement(Dn,null),x.default.createElement(An,{ref:T}),y&&x.default.createElement(y,{matchedRoute:R}),x.default.createElement(_,{matchedRoute:R},x.default.createElement(C,null)))},Nn=e=>{const{path:t,directPlane:a,routes:n,planes:r,exterior:o,shell:i,protocol:l,hostname:s,gateway:c,gatewayQuery:u,gatewayEndpoint:d}=e,f=l||"http",p=s||"origin";return x.default.createElement(xn,{routes:n,planes:r,exterior:o,shell:i,static:{path:t,directPlane:a},protocol:f,hostname:p})};class Mn extends r.Component{constructor(e){super(e),this.properties=e}render(){const{metastate:e,children:t}=this.properties;return x.default.createElement(F.Provider,{value:e},t)}}Mn.displayName="PluridProvider";const kn={x:0,y:0},Fn=e=>{const{elementID:t,rootID:a,children:n}=e,r=u.usePortal(t,a);return p.createPortal(n,r)},Bn=M.default.div`
511
+ `,Dn=e=>{const{time:t}=e,[a,n]=r.useState(!1);return r.useEffect((()=>{t>0&&setTimeout((()=>{n(!0)}),t)}),[]),a||0===t?x.default.createElement(x.default.Fragment,null):x.default.createElement(Un,null)},xn=e=>{const{routes:a,planes:n,exterior:o,shell:i,hostname:s,scrollToTop:c,fadeIn:d,static:f,view:p,cleanNavigation:m,notFoundPath:g}=e,h=g||"/not-found",T=null!=d?d:10,E=((e,t)=>{const a=[];for(const t of e){if(t.planes)for(const e of t.planes){const n=ce(e),r={route:n.link?n.link:n.value.startsWith("/")?n.value:t.value+"/"+n.value,component:n.component};a.push(r)}t.spaces}if(t)for(const e of t){const t=ce(e),n={route:t.value,component:t.component};a.push(n)}return a})(a,n),v=r.useRef(null),S=r.useRef(new de(E,s)),P=r.useRef(new fe({routes:a,routePlanes:n},s)),b=u.useMounted(),[R,I]=r.useState((e=>e?e.path:"undefined"!=typeof window?window.location.pathname+window.location.search:"/")(f)),[C,w]=r.useState(P.current.match(R,"route")),[O,y]=r.useState(_n(C,S.current,P.current,f&&f.directPlane?P.current.match(f.directPlane,"route"):void 0,s)),_=e=>{let t;e&&e.detail&&e.detail.path&&!t&&(t=e.detail.path),m&&p&&!t&&(t=p);const a=window.location.pathname;t||(t=a+window.location.search),I(t),(()=>{if(!v.current||!1===c)return;const e=void 0===c||!0===c||"smooth"===c?"smooth":"auto";v.current.scrollIntoView({behavior:e})})()};let L;r.useEffect((()=>(window.addEventListener("popstate",_),window.addEventListener(t.PLURID_ROUTER_LOCATION_CHANGED,_),()=>{window.removeEventListener("popstate",_),window.removeEventListener(t.PLURID_ROUTER_LOCATION_CHANGED,_)})),[]),r.useEffect((()=>{if(!b)return;m||location.pathname!==R&&history.pushState(null,"",R);let e=P.current.match(R,"route");if(e&&"RoutePlane"===e.kind){const t=Ln(e,S.current,s);return w(e),void y(t)}e||(e=P.current.match(h,"route")),w(e),y(_n(e,S.current,P.current,void 0,s))}),[b,R]),r.useEffect((()=>{if(!C)return;if("Route"!==C.kind)return;const e=C.match.value;l.storage.saveState(e,t.PLURID_ROUTER_STORAGE);const a=new CustomEvent(t.PLURID_ROUTER_LOCATION_STORED,{detail:{path:e}});window.dispatchEvent(a)}),[m,C]),Zt(o)&&(L=o,L&&(L.displayName="PluridRouterExterior"));let A=({children:e})=>x.default.createElement(x.default.Fragment,null,e);return Zt(i)&&(A=i,A&&(A.displayName="PluridRouterShell")),x.default.createElement(x.default.Fragment,null,x.default.createElement(Dn,{time:T}),x.default.createElement(An,{ref:v}),L&&x.default.createElement(L,{matchedRoute:C}),x.default.createElement(A,{matchedRoute:C},x.default.createElement(O,null)))},Nn=e=>{const{path:t,directPlane:a,routes:n,planes:r,exterior:o,shell:i,protocol:l,hostname:s,gateway:c,gatewayQuery:u,gatewayEndpoint:d,routerProperties:f}=e,p=l||"http",m=s||"origin";return x.default.createElement(xn,Object.assign({routes:n,planes:r,exterior:o,shell:i,static:{path:t,directPlane:a},protocol:p,hostname:m},f))};class Mn extends r.Component{constructor(e){super(e),this.properties=e}render(){const{metastate:e,children:t}=this.properties;return x.default.createElement(F.Provider,{value:e},t)}}Mn.displayName="PluridProvider";const kn={x:0,y:0},Fn=e=>{const{elementID:t,rootID:a,children:n}=e,r=u.usePortal(t,a);return p.createPortal(n,r)},Bn=M.default.div`
512
512
  position: absolute;
513
513
  min-width: 600px;
514
514
  min-height: 300px;
@@ -534,7 +534,7 @@
534
534
  ::after {
535
535
  content: "${({devisible:e,suffix:t})=>e?"":t||"'"}";
536
536
  }
537
- `,Xn=o.connect((e=>({stateTree:Ot.space.getTree(e),stateLastClosedPlane:Ot.space.getLastClosedPlane(e),stateGeneralTheme:Ot.themes.getGeneralTheme(e),stateConfiguration:Ot.configuration.getConfiguration(e),stateViewSize:Ot.space.getViewSize(e)})),(e=>({dispatch:e,dispatchSetTree:t=>e(qe.space.setTree(t)),dispatchSetSpaceField:t=>e(qe.space.setSpaceField(t)),dispatchUpdateSpaceLinkCoordinates:t=>e(qe.space.updateSpaceLinkCoordinates(t))})),null,{context:Ge})((e=>{const n=r.useContext(He);if(!n)return x.default.createElement(x.default.Fragment,null,e.children);const{hostname:o,planesRegistrar:i,defaultPubSub:s}=n,c=ie(i);if(!c)return x.default.createElement(x.default.Fragment,null,e.children);const{children:d,route:f,devisible:p,suffix:m,atClick:g,style:h,className:T,preview:E,previewComponent:v,previewFadeIn:S,previewFadeOut:P,previewOffsetX:b,previewOffsetY:R,stateTree:I,stateLastClosedPlane:C,stateGeneralTheme:w,stateConfiguration:O,stateViewSize:y,dispatch:_,dispatchSetTree:L,dispatchSetSpaceField:A,dispatchUpdateSpaceLinkCoordinates:U}=e,D=O.elements.plane.controls.show,N=S||t.PLURID_DEFAULT_CONFIGURATION_LINK_PREVIEW_FADE_IN,M=P||t.PLURID_DEFAULT_CONFIGURATION_LINK_PREVIEW_FADE_OUT,k=me(f),F=pe(k,O.network.protocol,o||O.network.host),B=null!=m?m:t.PLURID_DEFAULT_CONFIGURATION_LINK_SUFFIX,Y=null!=p&&p,$=r.useRef(null),X=r.useRef(null),V=r.useRef(null),[z,K]=r.useState(!1),[Z,j]=r.useState(!1),[G,W]=r.useState(!1),[H,q]=r.useState(""),[J,Q]=r.useState(le($.current)),[ee,te]=r.useState(kn),ae=()=>{const e=$.current;if(!e)return Object.assign({},kn);let t=0,a=0,n=!1,r=e,o=!0,i=0,l=0;for(;o;)if("static"!==window.getComputedStyle(r).position||n||(t+=r.offsetTop,a+=r.offsetLeft,n=!0),"relative"===window.getComputedStyle(r).position&&(i+=t,l+=a,t=0,a=0,n=!1),r.scrollLeft&&(l+=-r.scrollLeft),r.scrollTop&&(i+=-r.scrollTop),r.parentElement){"PluridPlane"===r.parentElement.dataset.pluridEntity&&(o=!1),r=r.parentElement}else o=!1;const s=D?56:0;return{x:l+e.offsetWidth,y:i+s}},ne=u.useDebouncedCallback((()=>{(()=>{const e=ae();U({planeID:H,linkCoordinates:e});const t=a.space.tree.logic.updatePlaneLocation(l.objects.clone(I),J,H,l.objects.clone(e));L(t)})()}),t.PLURID_DEFAULT_RESIZE_DEBOUNCE_TIME),re=e=>{const{updatedTree:t,updatedPlane:n}=a.space.tree.logic.togglePlaneFromTree(l.objects.clone(I),H,e);return L(t),W((e=>!e)),j(!1),{updatedPlane:n}},oe=(e,t)=>{t&&(G||(A({field:"isolatePlane",value:""}),Et(_,t,e)))},se=e=>{if(e.altKey&&G&&H){const t=a.space.tree.logic.getTreePlaneByID(I,H);Et(_,t,e)}else G||H?(e=>{const{updatedPlane:t}=re();oe(e,t)})(e):(e=>{if(!J||!F)return;const{route:t}=F,n=ae(),{pluridPlaneID:r,updatedTree:i,updatedTreePlane:s}=a.space.tree.logic.updateTreeWithNewPlane(t,J,n,l.objects.clone(I),c.getAll(),O,o);r&&(oe(e,s),L(i),W(!0),q(r))})(e)},ce=()=>{$.current&&$.current.blur()},ue=r.useCallback((e=>{e.preventDefault(),void 0!==g&&g(e),se(e),ce()}),[J,JSON.stringify(I),$.current]);return r.useEffect((()=>{const e=le($.current);Q(e);const t=ae();te(t)}),[]),r.useEffect((()=>{G&&ne()}),[G,JSON.stringify(y),JSON.stringify(I)]),r.useEffect((()=>{if(E)return z&&V.current&&(X.current=setTimeout((()=>{j(!0)}),N),clearTimeout(V.current)),z||(V.current=setTimeout((()=>{j(!1),X.current&&clearTimeout(X.current)}),M)),()=>{V.current&&clearTimeout(V.current),X.current&&clearTimeout(X.current)}}),[E,z]),r.useEffect((()=>{}),[]),r.useEffect((()=>{const e=s.subscribe({topic:t.PLURID_PUBSUB_TOPIC.OPEN_CLOSED_PLANE,callback:()=>{C===H&&(re(),A({field:"lastClosedPlane",value:""}))}});return()=>{s.unsubscribe(e)}}),[G,H,JSON.stringify(I)]),r.useEffect((()=>{const e=s.subscribe({topic:t.PLURID_PUBSUB_TOPIC.CLOSE_PLANE,callback:e=>{const{id:t}=e;if(t===H&&G){re(!1),A({field:"lastClosedPlane",value:t})}}});return()=>{s.unsubscribe(e)}}),[G,H,JSON.stringify(I)]),r.useEffect((()=>()=>{G&&null===$.current&&(()=>{const e=a.space.tree.logic.removePlaneFromTree(l.objects.clone(I),H);L(e),W((e=>!e)),j(!1)})()}),[G,Z,H,J,JSON.stringify(I)]),x.default.createElement($n,{ref:$,onClick:e=>ue(e),onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),onKeyUp:e=>(e=>{if("Enter"===e.code)return ue(e),void ce()})(e),theme:w,suffix:B,devisible:Y,style:Object.assign({},h),className:T,"data-plurid-entity":t.PLURID_ENTITY_LINK,tabIndex:0},d,Z&&!G&&x.default.createElement(Fn,{elementID:`preview-${J}`,rootID:J},x.default.createElement(Yn,{planeRoute:k,linkCoordinates:ee,previewComponent:v,previewOffsetX:b,previewOffsetY:R})))})),Vn=c.css`
537
+ `,Xn=o.connect((e=>({stateTree:Ot.space.getTree(e),stateLastClosedPlane:Ot.space.getLastClosedPlane(e),stateGeneralTheme:Ot.themes.getGeneralTheme(e),stateConfiguration:Ot.configuration.getConfiguration(e),stateViewSize:Ot.space.getViewSize(e)})),(e=>({dispatch:e,dispatchSetTree:t=>e(qe.space.setTree(t)),dispatchSetSpaceField:t=>e(qe.space.setSpaceField(t)),dispatchUpdateSpaceLinkCoordinates:t=>e(qe.space.updateSpaceLinkCoordinates(t))})),null,{context:Ge})((e=>{const n=r.useContext(He);if(!n)return x.default.createElement(x.default.Fragment,null,e.children);const{hostname:o,planesRegistrar:i,defaultPubSub:s}=n,c=ie(i);if(!c)return x.default.createElement(x.default.Fragment,null,e.children);const{children:d,route:f,devisible:p,suffix:m,atClick:g,style:h,className:T,preview:E,previewComponent:v,previewFadeIn:S,previewFadeOut:P,previewOffsetX:b,previewOffsetY:R,stateTree:I,stateLastClosedPlane:C,stateGeneralTheme:w,stateConfiguration:O,stateViewSize:y,dispatch:_,dispatchSetTree:L,dispatchSetSpaceField:A,dispatchUpdateSpaceLinkCoordinates:U}=e,D=O.elements.plane.controls.show,N=S||t.PLURID_DEFAULT_CONFIGURATION_LINK_PREVIEW_FADE_IN,M=P||t.PLURID_DEFAULT_CONFIGURATION_LINK_PREVIEW_FADE_OUT,k=me(f),F=pe(k,O.network.protocol,o||O.network.host),B=null!=m?m:t.PLURID_DEFAULT_CONFIGURATION_LINK_SUFFIX,Y=null!=p&&p,$=r.useRef(null),X=r.useRef(null),V=r.useRef(null),z=r.useRef(),[K,Z]=r.useState(!1),[j,G]=r.useState(!1),[W,H]=r.useState(!1),[q,J]=r.useState(""),[Q,ee]=r.useState(le($.current)),[te,ae]=r.useState(kn),ne=()=>{const e=$.current;if(!e)return Object.assign({},kn);let t=0,a=0,n=!1,r=e,o=!0,i=0,l=0;for(;o;)if("static"!==window.getComputedStyle(r).position||n||(t+=r.offsetTop,a+=r.offsetLeft,n=!0),"relative"===window.getComputedStyle(r).position&&(i+=t,l+=a,t=0,a=0,n=!1),r.scrollLeft&&(l+=-r.scrollLeft),r.scrollTop&&(i+=-r.scrollTop),r.parentElement){"PluridPlane"===r.parentElement.dataset.pluridEntity&&(o=!1),r=r.parentElement}else o=!1;const s=D?56:0;return{x:l+e.offsetWidth,y:i+s}},re=u.useDebouncedCallback((()=>{(()=>{const e=ne();U({planeID:q,linkCoordinates:e});const t=a.space.tree.logic.updatePlaneLocation(l.objects.clone(I),Q,q,l.objects.clone(e));L(t)})()}),t.PLURID_DEFAULT_RESIZE_DEBOUNCE_TIME),oe=e=>{const{updatedTree:t,updatedPlane:n}=a.space.tree.logic.togglePlaneFromTree(l.objects.clone(I),q,e);return L(t),H((e=>!e)),G(!1),{updatedPlane:n}},se=(e,t)=>{t&&(W||(A({field:"isolatePlane",value:""}),Et(_,t,e)))},ce=e=>{if(e.altKey&&W&&q){const t=a.space.tree.logic.getTreePlaneByID(I,q);Et(_,t,e)}else W||q?(e=>{const{updatedPlane:t}=oe();se(e,t)})(e):(e=>{if(!Q||!F)return;const{route:t}=F,n=ne(),{pluridPlaneID:r,updatedTree:i,updatedTreePlane:s}=a.space.tree.logic.updateTreeWithNewPlane(t,Q,n,l.objects.clone(I),c.getAll(),O,o);r&&(se(e,s),L(i),H(!0),J(r))})(e)},ue=()=>{$.current&&$.current.blur()},de=r.useCallback((e=>{e.preventDefault(),void 0!==g&&g(e),ce(e),ue()}),[Q,JSON.stringify(I),$.current]);return r.useEffect((()=>{const e=le($.current);ee(e);const t=ne();ae(t);((e,t)=>{if(e&&e.children)for(const a of e.children)a.linkCoordinates&&(a.linkCoordinates.x!==t.x&&a.linkCoordinates.y!==t.y||(H(!0),J(a.planeID)))})(a.space.tree.logic.getTreePlaneByID(I,e),t)}),[]),r.useEffect((()=>{W&&re()}),[W,JSON.stringify(y),JSON.stringify(I)]),r.useEffect((()=>{if(E)return K&&V.current&&(X.current=setTimeout((()=>{G(!0)}),N),clearTimeout(V.current)),K||(V.current=setTimeout((()=>{G(!1),X.current&&clearTimeout(X.current)}),M)),()=>{V.current&&clearTimeout(V.current),X.current&&clearTimeout(X.current)}}),[E,K]),r.useEffect((()=>{}),[]),r.useEffect((()=>{const e=s.subscribe({topic:t.PLURID_PUBSUB_TOPIC.OPEN_CLOSED_PLANE,callback:()=>{C===q&&(oe(),A({field:"lastClosedPlane",value:""}))}});return()=>{s.unsubscribe(e)}}),[W,q,JSON.stringify(I)]),r.useEffect((()=>{const e=s.subscribe({topic:t.PLURID_PUBSUB_TOPIC.CLOSE_PLANE,callback:e=>{const{id:t}=e;if(t===q&&W){oe(!1),A({field:"lastClosedPlane",value:t})}}});return()=>{s.unsubscribe(e)}}),[W,q,JSON.stringify(I)]),r.useEffect((()=>{const e=a.space.tree.logic.getTreePlaneByID(I,q);return z.current=e,()=>{setTimeout((()=>{var e;W&&null===$.current&&!1===(null===(e=z.current)||void 0===e?void 0:e.show)&&(()=>{const e=a.space.tree.logic.removePlaneFromTree(l.objects.clone(I),q);L(e),H((e=>!e)),G(!1)})()}),10)}}),[W,j,q,Q,JSON.stringify(I)]),x.default.createElement($n,{ref:$,onClick:e=>de(e),onMouseEnter:()=>Z(!0),onMouseLeave:()=>Z(!1),onKeyUp:e=>(e=>{if("Enter"===e.code)return de(e),void ue()})(e),theme:w,suffix:B,devisible:Y,style:Object.assign({},h),className:T,"data-plurid-entity":t.PLURID_ENTITY_LINK,tabIndex:0},d,j&&!W&&x.default.createElement(Fn,{elementID:`preview-${Q}`,rootID:Q},x.default.createElement(Yn,{planeRoute:k,linkCoordinates:te,previewComponent:v,previewOffsetX:b,previewOffsetY:R})))})),Vn=c.css`
538
538
  color: ${({theme:e})=>e.colorTertiary};
539
539
 
540
540
  @media (hover:hover) {