@jointhedots/core 2.0.21 → 2.0.23
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/export.react.js +37 -2
- package/package.json +2 -8
- package/types.d.ts +32 -26
package/export.react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{h as
|
|
1
|
+
import{h as y,i as U,m as L}from"./chunk.3AAAY44Q.js";import{a as v,c as w,d as q}from"./chunk.YVZWYQZG.js";import"./chunk.H26D4GQC.js";import{z as a}from"zod";function Ve(t){let e=t||a.record(a.string(),a.any());return{$spec:"spec://jointhedots.org/view.react",version:"0.0",properties:a.object({props:e,requirements:a.object({servicePoints:a.record(a.string(),a.object({service:a.string().optional(),cardinality:a.number().optional()})).optional()}).optional()}),isAssignable(r){return r.$spec=this.$spec}}}var N=v.subservice("react"),ke=v.subservice("webc");import{useEffect as K,useState as z}from"react";function qe(t,e,r){let[o,i]=z(e);return K(()=>{t().then(i,console.error)},r),o}import T from"react";import{jsx as f}from"react/jsx-runtime";var x=class{constructor(e,r){this.value=e;this.updateTimeout=r}promise=null;dispatch=null;updateTimer=null;shallUpdate=!0;updater;deps;use(e,r){if(this.updater=e,r!==this.deps){let o=this.deps;if(this.deps=r,r?.length===o?.length){if(r){for(let i=0;i<r.length;i++)if(r[i]!==o[i])return this.update()}}else return this.update()}}initiate(e){this.dispatch=e,this.dispatch(this.value)}cancelAutoUpdate(){this.updateTimer&&(clearTimeout(this.updateTimer),this.updateTimer=null)}scheduleAutoUpdate(){this.cancelAutoUpdate(),this.shallUpdate?this.update():this.updateTimeout>0&&(this.updateTimer=setTimeout(()=>{this.updateTimer=null,this.update()},this.updateTimeout))}get isWaiting(){return this.promise!==null}get hasState(){return this.value!==void 0}get autoUpdate(){return this.updateTimeout}set autoUpdate(e){this.updateTimeout=e,this.cancelAutoUpdate(),this.update()}set(e){this.value!==e&&(this.value=e,this.dispatch&&this.dispatch(e))}get(){return this.value}update(){try{if(this.promise)this.shallUpdate=!0,this.cancelAutoUpdate();else{let e=this.updater();this.shallUpdate=!1,e instanceof Promise?(this.promise=e,e.then(r=>{this.promise=null,this.set(r),this.scheduleAutoUpdate()},r=>{this.promise=null,this.scheduleAutoUpdate(),console.log(r)})):this.scheduleAutoUpdate()}}catch(e){this.scheduleAutoUpdate(),console.log(e)}}cancel(){this.dispatch=null,this.promise=null,this.updateTimeout=0,this.cancelAutoUpdate()}waiting(e){return this.isWaiting==!0?f(m,{}):e(this.value)}using(e){return this.hasState==!1?f(m,{}):e(this.value)}};function Me(t,e,r,o){let[i]=T.useState(()=>new x(r,o)),[s,n]=T.useState(r);return i.use(t,e),T.useEffect(()=>(i.initiate(n),()=>i.cancel()),null),i}function Ae(t,...e){for(let r of e)if(r.isWaiting==!0)return f(m,{});return t()}function _e(t,...e){for(let r of e)if(r.hasState==!1)return f(m,{});return t()}function m(){return f("div",{children:"..."})}import D,{useContext as ie,useEffect as A,useMemo as oe,useState as ne}from"react";import G,{createContext as X,useContext as Y,useMemo as ee}from"react";var Q=`.JDT-ErrorBoundary {
|
|
2
2
|
background-color: rgb(216, 59, 59);
|
|
3
3
|
padding: 5px;
|
|
4
4
|
overflow: hidden;
|
|
@@ -14,4 +14,39 @@ import{h as g,i as U,m as k}from"./chunk.3AAAY44Q.js";import{a as v,c as y,d as
|
|
|
14
14
|
}
|
|
15
15
|
.JDT-ErrorBoundary > .btn:hover {
|
|
16
16
|
background-color: rgb(255, 142, 142);
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.JDT-Spinner {
|
|
20
|
+
display: inline-flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
gap: 6px;
|
|
23
|
+
padding: 8px 0;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
width: 100%;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.JDT-Spinner__dot {
|
|
29
|
+
width: 8px;
|
|
30
|
+
height: 8px;
|
|
31
|
+
border-radius: 50%;
|
|
32
|
+
background-color: currentColor;
|
|
33
|
+
opacity: 0.6;
|
|
34
|
+
animation: JDT-SpinnerBounce 1.4s ease-in-out infinite both;
|
|
35
|
+
}
|
|
36
|
+
.JDT-Spinner__dot:nth-child(1) {
|
|
37
|
+
animation-delay: -0.32s;
|
|
38
|
+
}
|
|
39
|
+
.JDT-Spinner__dot:nth-child(2) {
|
|
40
|
+
animation-delay: -0.16s;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@keyframes JDT-SpinnerBounce {
|
|
44
|
+
0%, 80%, 100% {
|
|
45
|
+
transform: scale(0.4);
|
|
46
|
+
opacity: 0.4;
|
|
47
|
+
}
|
|
48
|
+
40% {
|
|
49
|
+
transform: scale(1);
|
|
50
|
+
opacity: 1;
|
|
51
|
+
}
|
|
52
|
+
}`;document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(Q));import{jsx as S,jsxs as re}from"react/jsx-runtime";function h({error:t,onRetry:e}){let r=`${t.name}: ${t.message}`;return re("div",{className:"JDT-ErrorBoundary",title:r,children:[S("pre",{className:"msg",children:r}),e&&S("button",{className:"btn",onClick:e,children:"Retry"})]})}var P=X(null),R=class extends G.Component{},J=class extends R{static contextType=P;state={};componentDidCatch(e){let{context:r}=this,o=r?.getErrorDisplayer(e)||te(e);this.setState({error:e,displayer:o})}render(){let{error:e}=this.state;if(e){let r=this.state.displayer;return S(r,{error:e,onRetry:()=>this.setState({error:void 0})})}return this.props.children||null}};function Ze({errorClass:t,errorDisplayer:e,children:r}){let o=Y(P),i=ee(()=>({getErrorDisplayer(s){for(let n=s;n;n=Object.getPrototypeOf(n))if(n.constructor===t)return e;return o?.getErrorDisplayer(s)??null}}),[o,t,e]);return S(P.Provider,{value:i,children:r})}function te(t){for(let e=t;e;e=Object.getPrototypeOf(e)){let r=e.constructor,o=b.get(r);if(o)return o}return null}var b=new Map;b.set(Error,h);function $e(t,e){b.set(t,e)}import{jsx as p,jsxs as H}from"react/jsx-runtime";function M(){return H("div",{className:"JDT-Spinner",children:[p("div",{className:"JDT-Spinner__dot"}),p("div",{className:"JDT-Spinner__dot"}),p("div",{className:"JDT-Spinner__dot"})]})}var se=(i=>(i[i.NotReady=0]="NotReady",i[i.Loading=1]="Loading",i[i.Ready=2]="Ready",i[i.Failed=3]="Failed",i))(se||{}),d=class extends Error{constructor(r,o){super(`Missing service point: ${r.map(i=>i.id).join(", ")}`);this.missings=r;this.requireds=o}},C=class{consumers=new Set;getService(e){return e.services}addController(e){this.consumers.add(e)}removeController(e){return this.consumers.delete(e)}onServiceChangeHandler=e=>{for(let r of this.consumers)r.notifyChange(e)}},E=class{constructor(e){this.controller=e}getService(e){return this.controller.getService(e)}},I=class{constructor(e,r,o,i){this.support=e;this.requireds=r;this.requirements=o;this.onUpdate=i;e.addController(this)}services=new Map;provider=null;state=null;get status(){return this.state instanceof Promise?1:this.state instanceof d?3:this.state===null?0:2}get error(){if(this.state instanceof d)return this.state}getService(e){let r=this.services.get(e);return!r&&this.support&&(r=this.support.getService(e),this.services.set(e,this.support.getService(e))),e.services}notifyChange(e){this.services.has(e)&&this.update()}updateState(e){let r=this.state;r!==e&&(this.state=e,this.onUpdate?.(e,r,this))}update(){let{requireds:e,requirements:r}=this,o=[],i=null;function s(n){i||(i=new d([])),i.missings.includes(n)||i.missings.push(n)}if(e)for(let n of e)if(n.ready){let c=n.services;c&&this.services.set(n,c)}else o.push(n.fetch());if(r){let{servicePoints:n}=r;for(let c in n){let u=L(c);if(u.ready){let k=u.services,g=n[c];g.service&&u.service!==g.service||k.length<(g.cardinality||1)?s(u):this.services.set(u,k)}else o.push(u.fetch())}}if(o.length>0){let n=Promise.all(o).then(()=>this.update());return this.updateState(n),n}else i?this.updateState(i):(this.provider=new E(this),this.updateState(this.provider));return null}dispose(){this.support&&(this.support.removeController(this),this.support=null)}},V=new C;y(V.onServiceChangeHandler);var ce=D.createContext(V),_=D.createContext(V);function Ye(t){A(()=>{let e=y(t);return()=>U(e)},[t])}function ae(t,e){let r=D.useContext(_);if(!r)return console.error("Wrap in <MountServicePoints> before using service point:",t.id),null;let o=r.getService(t);if(o.length<(e===void 0?1:e))throw new d([t],[t]);return o}function et(t,e){return ae(t,e?0:1)[0]}function le(t,e){let r=ie(ce),[,o]=ne(null),i=oe(()=>new I(r,t,e,o),[t,e]);return A(()=>(i.update(),()=>i?.dispose()),[i]),i}function O(t){let{requireds:e,requirements:r,children:o}=t,i=le(e,r),{provider:s,error:n}=i;if(n){let c=t.configurator;return c?p(c,{services:n.missings}):p(h,{error:n})}else return s?H(_.Provider,{value:s,children:[o,i.status===1&&p(M,{})]}):p(M,{})}import{useState as W,useEffect as j}from"react";function ot(){let[t,e]=W(window.location);return j(()=>{let r=()=>{e(window.location)};return window.addEventListener("popstate",r),window.addEventListener("hashchange",r),()=>{window.removeEventListener("popstate",r),window.removeEventListener("hashchange",r)}},[]),t}function F(){let[t,e]=W(window.location.hash);return j(()=>{let r=()=>{e(window.location.hash)};return window.addEventListener("hashchange",r),()=>{window.removeEventListener("hashchange",r)}},[]),t}function nt(){let{search:t}=window.location,e={};if(t.startsWith("?"))for(let r of t.slice(1).split("&")){let o=r.split("=");e[o[0]]=decodeURIComponent(o[1])}return e}import{useCallback as ue,useState as pe}from"react";function de(t,e){try{let r=window.localStorage.getItem(t);if(typeof r=="string")return JSON.parse(r)}catch{}return e instanceof Function?e():e}function ve(t,e){return e===void 0?window.localStorage.removeItem(t):window.localStorage.setItem(t,JSON.stringify(e)),e}function at(t,e){let[r,o]=pe(de(t,e)),i=ue(s=>o(ve(t,s)),[t]);return[r,i]}import{useCallback as fe,useState as he}from"react";function me(t,e){try{let r=window.sessionStorage.getItem(t);if(typeof r=="string")return JSON.parse(r)}catch{}return e instanceof Function?e():e}function Se(t,e){return e===void 0?window.sessionStorage.removeItem(t):window.sessionStorage.setItem(t,JSON.stringify(e)),e}function pt(t,e){let[r,o]=he(me(t,e)),i=fe(s=>o(Se(t,s)),[t]);return[r,i]}import{useState as ge,useCallback as ye}from"react";function ft(){let[,t]=ge(0);return ye(()=>{t(r=>r+1)},[])}import we,{useContext as Te,useEffect as xe,useMemo as Z,useState as Pe}from"react";import{jsx as l}from"react/jsx-runtime";var $=we.createContext(null);async function Re(t,e,r){if(t)try{let{component:o,properties:i}=await q(t,e),s=v.spec(o),n=await N.fetch(o);if(!n)throw new Error(`Component '${t.name}' has no 'view.react' service`);let c=l($.Provider,{value:t,children:l(n,{...i})});return s?.requirements&&(c=l(O,{requirements:s?.requirements,configurator:null,children:c})),c}catch(o){return l(h,{error:o})}return r}function be(){return Te($)}function B(t){let{view:e,origin:r,fallback:o}=t,[i,s]=Pe(null),n=Z(()=>typeof e!="string"?e:w(e),[e]);return xe(()=>{Re(n,r,o).then(s)},[n]),i||null}function Ce(t){let{hash:e,fallback:r}=t,o=Z(()=>w(e),[e]);return l(B,{view:o,origin:"url",fallback:r})}function Ee(t){let e=F();return l(Ce,{hash:e,fallback:t.fallback})}function xt(t){let e=be();return e?e?.nested?l(B,{view:e?.nested,origin:"url",fallback:t.fallback}):t.fallback||null:l(Ee,{fallback:t.fallback})}export{x as AsyncState,J as ErrorBoundary,h as ErrorDisplayer,Ze as ErrorReconcilier,xt as InvokeNestedView,Ee as InvokeURLView,Ce as InvokeUrlHashView,B as InvokeView,d as MissingServiceError,Ve as ReactComponentSchema,_ as ServicePointsProviderContext,ce as ServicePointsSupportContext,se as ServiceStatus,O as UseServicePoints,N as ViewReactKey,ke as ViewWebComponentKey,nt as getLocationQuery,$e as registerErrorDisplayer,qe as useAsyncMemo,Me as useAsyncState,be as useCurrentView,ft as useForceUpdate,at as useLocalStorage,ot as useLocation,F as useLocationHash,et as useService,ae as useServices,le as useServicesController,Ye as useServicesListener,pt as useSessionStorage,_e as using,Ae as waiting};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jointhedots/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"singleton": true,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./export.js",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"astring": "^1.9.0",
|
|
35
35
|
"json-schema": "^0.4.0",
|
|
36
36
|
"query-string": "^9.1.0",
|
|
37
|
-
"react-lightning-design-system": "^5.9.1",
|
|
38
37
|
"vscode-uri": "^3.1.0",
|
|
39
38
|
"yaml": "^2.8.2",
|
|
40
39
|
"zod": "^4.2.1"
|
|
@@ -42,10 +41,5 @@
|
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"react": "^18.2.0",
|
|
44
43
|
"react-dom": "^18.2.0"
|
|
45
|
-
},
|
|
46
|
-
"overrides": {
|
|
47
|
-
"react-lightning-design-system": {
|
|
48
|
-
"react-relative-portal": "../../deps/react-relative-portal-1.3.1.tgz"
|
|
49
|
-
}
|
|
50
44
|
}
|
|
51
45
|
}
|
package/types.d.ts
CHANGED
|
@@ -409,6 +409,7 @@ declare module '@jointhedots/core/src/components/components' {
|
|
|
409
409
|
import type { DocumentationSchema, JSONSchema, ResourceEntry } from '@jointhedots/core/src/schema/schema';
|
|
410
410
|
import type { ComponentEntry } from '@jointhedots/core/src/components/manifold';
|
|
411
411
|
import { ServiceEntry, type ServiceType } from '@jointhedots/core/src/services/service-entry';
|
|
412
|
+
import React from 'react';
|
|
412
413
|
export type ComponentID = string;
|
|
413
414
|
export interface ComponentPublication {
|
|
414
415
|
id: ComponentID;
|
|
@@ -1549,35 +1550,38 @@ declare module '@jointhedots/core/src/interfaces/react/ErrorBoundary' {
|
|
|
1549
1550
|
error: E;
|
|
1550
1551
|
onRetry?: () => void;
|
|
1551
1552
|
}>;
|
|
1552
|
-
export
|
|
1553
|
+
export function ErrorDisplayer({ error, onRetry }: {
|
|
1553
1554
|
error: Error;
|
|
1554
1555
|
onRetry?: () => void;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1556
|
+
}): any;
|
|
1557
|
+
interface IErrorReconcilier {
|
|
1558
|
+
getErrorDisplayer(error: Error): ErrorDisplayerType | null;
|
|
1559
|
+
} class Component<P = {}, S = {}> extends React.Component<P, S> {
|
|
1560
|
+
props: Readonly<P>;
|
|
1561
|
+
setState: React.Component<P, S>['setState'];
|
|
1562
|
+
}
|
|
1563
|
+
export class ErrorBoundary extends Component<{
|
|
1559
1564
|
children: React.ReactNode;
|
|
1565
|
+
}, {
|
|
1566
|
+
error?: Error;
|
|
1567
|
+
displayer?: ErrorDisplayerType;
|
|
1560
1568
|
}> {
|
|
1561
|
-
static contextType:
|
|
1562
|
-
context:
|
|
1569
|
+
static contextType: any;
|
|
1570
|
+
context: IErrorReconcilier;
|
|
1563
1571
|
state: {
|
|
1564
1572
|
error?: Error;
|
|
1565
1573
|
displayer?: ErrorDisplayerType;
|
|
1566
1574
|
};
|
|
1567
1575
|
componentDidCatch(error: Error): void;
|
|
1568
|
-
render():
|
|
1576
|
+
render(): any;
|
|
1569
1577
|
}
|
|
1570
|
-
export
|
|
1578
|
+
export function ErrorReconcilier({ errorClass, errorDisplayer, children }: {
|
|
1571
1579
|
errorClass: new () => Error;
|
|
1572
1580
|
errorDisplayer: ErrorDisplayerType;
|
|
1573
1581
|
children: React.ReactNode;
|
|
1574
|
-
}
|
|
1575
|
-
static contextType: React.Context<ErrorReconcilier>;
|
|
1576
|
-
context: ErrorReconcilier;
|
|
1577
|
-
getErrorDisplayer(error: Error): ErrorDisplayerType<Error>;
|
|
1578
|
-
render(): string | number | true | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>;
|
|
1579
|
-
}
|
|
1582
|
+
}): any;
|
|
1580
1583
|
export function registerErrorDisplayer<E extends Error>(errorClass: new (...args: any[]) => E, displayer: ErrorDisplayerType<E>): void;
|
|
1584
|
+
export {};
|
|
1581
1585
|
}
|
|
1582
1586
|
|
|
1583
1587
|
declare module '@jointhedots/core/view' {
|
|
@@ -1611,7 +1615,8 @@ declare module '@jointhedots/core/src/interfaces/react/useLocation' {
|
|
|
1611
1615
|
|
|
1612
1616
|
declare module '@jointhedots/core/src/interfaces/react/interface' {
|
|
1613
1617
|
import { z, type ZodObject, type ZodRawShape } from 'zod';
|
|
1614
|
-
import {
|
|
1618
|
+
import { type ServiceDefinition, type ServiceInterface } from 'src/services';
|
|
1619
|
+
import React from 'react';
|
|
1615
1620
|
export type ViewServicePoint = {
|
|
1616
1621
|
service?: string;
|
|
1617
1622
|
cardinality?: number;
|
|
@@ -1710,9 +1715,9 @@ declare module '@jointhedots/core/src/interfaces/react/interface' {
|
|
|
1710
1715
|
requirements?: ViewRequirements;
|
|
1711
1716
|
};
|
|
1712
1717
|
export type ViewReactService<T = any> = React.ComponentType<T>;
|
|
1713
|
-
export const ViewReactKey: ServiceEntry<
|
|
1718
|
+
export const ViewReactKey: import( '@jointhedots/core').ServiceEntry<React.ComponentType<T>, any>;
|
|
1714
1719
|
export type ViewWebComponentService = new (...props: any[]) => HTMLElement;
|
|
1715
|
-
export const ViewWebComponentKey: ServiceEntry<ViewWebComponentService, any>;
|
|
1720
|
+
export const ViewWebComponentKey: import( '@jointhedots/core').ServiceEntry<ViewWebComponentService, any>;
|
|
1716
1721
|
}
|
|
1717
1722
|
|
|
1718
1723
|
declare module '@jointhedots/core/src/interfaces/react/useServices' {
|
|
@@ -1760,28 +1765,28 @@ declare module '@jointhedots/core/src/interfaces/react/useServices' {
|
|
|
1760
1765
|
requirements?: ViewRequirements;
|
|
1761
1766
|
configurator: ServiceConfiguratorComponent;
|
|
1762
1767
|
children: any;
|
|
1763
|
-
}):
|
|
1768
|
+
}): any;
|
|
1764
1769
|
}
|
|
1765
1770
|
|
|
1766
1771
|
declare module '@jointhedots/core/src/interfaces/react/ViewUrl' {
|
|
1767
|
-
import
|
|
1772
|
+
import { type ReactElement } from 'react';
|
|
1768
1773
|
import { type ViewInfos } from '@jointhedots/core/view';
|
|
1769
|
-
export function useCurrentView():
|
|
1774
|
+
export function useCurrentView(): any;
|
|
1770
1775
|
export function InvokeView(props: {
|
|
1771
1776
|
view: string | ViewInfos;
|
|
1772
1777
|
origin?: string;
|
|
1773
1778
|
fallback?: ReactElement;
|
|
1774
|
-
}):
|
|
1779
|
+
}): any;
|
|
1775
1780
|
export function InvokeUrlHashView(props: {
|
|
1776
1781
|
hash: string;
|
|
1777
1782
|
fallback?: ReactElement;
|
|
1778
|
-
}):
|
|
1783
|
+
}): any;
|
|
1779
1784
|
export function InvokeURLView(props: {
|
|
1780
1785
|
fallback?: ReactElement;
|
|
1781
|
-
}):
|
|
1786
|
+
}): any;
|
|
1782
1787
|
export function InvokeNestedView(props: {
|
|
1783
1788
|
fallback?: ReactElement;
|
|
1784
|
-
}):
|
|
1789
|
+
}): any;
|
|
1785
1790
|
}
|
|
1786
1791
|
|
|
1787
1792
|
declare module '@jointhedots/core/src/interfaces/react/useAsyncMemo' {
|
|
@@ -1833,7 +1838,7 @@ declare module '@jointhedots/core/src/interfaces/react/useSessionStorage' {
|
|
|
1833
1838
|
}
|
|
1834
1839
|
|
|
1835
1840
|
declare module '@jointhedots/core/src/interfaces/react/useForceUpdate' {
|
|
1836
|
-
export function useForceUpdate():
|
|
1841
|
+
export function useForceUpdate(): any;
|
|
1837
1842
|
}
|
|
1838
1843
|
|
|
1839
1844
|
declare module '@jointhedots/core/react' {
|
|
@@ -1964,6 +1969,7 @@ declare module '@jointhedots/core/src/scripting/graph/log' {
|
|
|
1964
1969
|
declare module '@jointhedots/core/src/scripting/graph/uses' {
|
|
1965
1970
|
import type { AST } from '@jointhedots/core/src/scripting/ast/api';
|
|
1966
1971
|
import { type Node, type ContextInstance, type FeatureID } from '@jointhedots/core/src/scripting/graph/model';
|
|
1972
|
+
import React from 'react';
|
|
1967
1973
|
export type ValueRecast = (x: any) => any;
|
|
1968
1974
|
export class ValueType {
|
|
1969
1975
|
accept(ty: ValueType): boolean;
|