@adcops/autocore-react 3.3.34 → 3.3.36
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/components/IndicatorButton.d.ts +10 -0
- package/dist/components/IndicatorButton.d.ts.map +1 -1
- package/dist/components/IndicatorButton.js +1 -1
- package/dist/core/AutoCoreTagContext.d.ts.map +1 -1
- package/dist/core/AutoCoreTagContext.js +1 -1
- package/dist/core/AutoCoreTagTypes.d.ts +8 -0
- package/dist/core/AutoCoreTagTypes.d.ts.map +1 -1
- package/dist/hooks/useAutoCoreTag.d.ts +2 -0
- package/dist/hooks/useAutoCoreTag.d.ts.map +1 -1
- package/dist/hooks/useAutoCoreTag.js +1 -1
- package/package.json +1 -1
- package/src/components/IndicatorButton.tsx +29 -6
- package/src/core/AutoCoreTagContext.tsx +41 -5
- package/src/core/AutoCoreTagTypes.ts +10 -0
- package/src/hooks/useAutoCoreTag.ts +5 -1
|
@@ -43,6 +43,16 @@ export interface IndicatorButtonProps extends Omit<ButtonProps, "value"> {
|
|
|
43
43
|
* cycle on onColor.
|
|
44
44
|
*/
|
|
45
45
|
flash?: boolean;
|
|
46
|
+
/** Callback fired when the button is pressed (mouse down or touch start). */
|
|
47
|
+
onPress?: (e: React.MouseEvent | React.TouchEvent) => void;
|
|
48
|
+
/** Callback fired when the button is released (mouse up, touch end, or mouse leave). */
|
|
49
|
+
onRelease?: (e: React.MouseEvent | React.TouchEvent) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Momentary tag writer. When the button is pressed, this is called with `true`.
|
|
52
|
+
* When the button is released or the mouse leaves, it is called with `false`.
|
|
53
|
+
* Pass the `write` function from `useAutoCoreTag` directly to this prop.
|
|
54
|
+
*/
|
|
55
|
+
momentary?: (value: boolean) => void | Promise<void>;
|
|
46
56
|
}
|
|
47
57
|
export declare const IndicatorButton: React.FC<IndicatorButtonProps>;
|
|
48
58
|
export default IndicatorButton;
|
|
@@ -1 +1 @@
|
|
|
1
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,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,mDAAmD;IACnD,WAAW,CAAC,EAAE,GAAG,CAAC;IAElB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAE3D,wFAAwF;IACxF,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAE7D;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD;AAKD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAkK1D,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import React,{useCallback,useContext,useEffect,useState}from"react";import clsx from"clsx";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};import"./IndicatorButton.css";const toPrimeIcon=o=>o?o.includes("pi ")?o:`pi ${o}`:void 0;export const IndicatorButton=({topic:o,value:t,onColor:e=IndicatorColor.IndicatorGreen,offColor:n="gray",options:r,icon:i,onIcon:c,offIcon:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import React,{useCallback,useContext,useEffect,useState}from"react";import clsx from"clsx";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};import"./IndicatorButton.css";const toPrimeIcon=o=>o?o.includes("pi ")?o:`pi ${o}`:void 0;export const IndicatorButton=({topic:o,value:t,onColor:e=IndicatorColor.IndicatorGreen,offColor:n="gray",options:r,icon:i,onIcon:c,offIcon:s,command:a,commandTopic:l,commandArgs:d,actionMode:u,invert:f,className:m,label:p,style:x,disabled:C,hidden:b,flash:I,onPress:h,onRelease:v,momentary:g,...M})=>{const{subscribe:y,unsubscribe:E,dispatch:A}=useContext(EventEmitterContext),[S,k]=useState(void 0),[B,T]=useState(!1);useEffect(()=>{if(!o||!y)return;const t=y(o,o=>k(o));return()=>{try{E&&void 0!==t&&E(t)}catch{}}},[o,y,E]);const j=void 0!==t?t:S,P=(()=>{if(!r||0===r.length)return p;if(r.length>2){if("number"==typeof j){const o=Math.trunc(j);if(o>=0&&o<r.length&&null!=r[o])return String(r[o])}else if("string"==typeof j){const o=r.findIndex(o=>o===j);if(o>=0)return String(r[o])}return p}const o=j?r[1]:r[0];return null!=o&&String(o).length>0?String(o):p})(),R=toPrimeIcon((j?c:s)??i);let w=j?e:n;void 0===j&&(w=IndicatorColor.IndicatorInvalid);const N=useCallback(o=>{if(!a||!A)return;const t={topic:l,value:f?!o:o,...d??{}};A({topic:a,payload:t})},[a,A,f,d,l]),_=useCallback(o=>{B||C||(T(!0),g&&g(!0),h&&h(o),u!==ActionMode.Tap&&u!==ActionMode.Pressed||N(!0))},[B,C,u,N,h,g]),D=useCallback(o=>{B&&!C&&(T(!1),g&&g(!1),v&&v(o),u===ActionMode.Tap?N(!1):u===ActionMode.Released&&N(!0))},[B,C,u,N,v,g]),G={color:"white",backgroundColor:I?void 0:w,display:b?"none":void 0,...I?{"--flash-on":e,"--flash-off":n}:{},...x??{}};return _jsx(Button,{...M,label:P,icon:R,className:clsx(m,I&&"indicator-button-flash"),style:G,disabled:!!C,onMouseDown:_,onTouchStart:_,onMouseUp:D,onTouchEnd:D,onMouseLeave:D})};export default IndicatorButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCoreTagContext.d.ts","sourceRoot":"","sources":["../../src/core/AutoCoreTagContext.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,KAAK,EAAE,EAQV,KAAK,SAAS,EACjB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EACT,WAAW,EACd,MAAM,oBAAoB,CAAC;AAI5B;;;GAGG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AutoCoreTagContext.d.ts","sourceRoot":"","sources":["../../src/core/AutoCoreTagContext.tsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,KAAK,EAAE,EAQV,KAAK,SAAS,EACjB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EACT,WAAW,EACd,MAAM,oBAAoB,CAAC;AAI5B;;;GAGG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,8CAU7B,CAAC;AAsBH;;;;GAIG;AAIH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC;IACvC,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAufA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import React,{useRef,createContext,useCallback,useContext,useEffect,useMemo,useState}from"react";import{EventEmitterContext}from"./EventEmitterContext";import{MessageType}from"../hub/CommandMessage";export const AutoCoreTagContext=createContext({values:{},rawValues:{},isLoading:!0,write:async()=>{},tap:async()=>{},scales:{},updateScale:async()=>{}});const sleep=e=>new Promise(t=>setTimeout(t,e));export const AutoCoreTagProvider=({children:e,tags:t,scales:a,eagerRead:s=!0})=>{const n=useRef(!1),c=useMemo(()=>({}),[]),r=a??c,{invoke:o,read:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import React,{useRef,createContext,useCallback,useContext,useEffect,useMemo,useState}from"react";import{EventEmitterContext}from"./EventEmitterContext";import{MessageType}from"../hub/CommandMessage";export const AutoCoreTagContext=createContext({values:{},rawValues:{},isLoading:!0,write:async()=>{},tap:async()=>{},press:async()=>{},release:async()=>{},scales:{},updateScale:async()=>{}});const sleep=e=>new Promise(t=>setTimeout(t,e));export const AutoCoreTagProvider=({children:e,tags:t,scales:a,eagerRead:s=!0})=>{const n=useRef(!1),c=useMemo(()=>({}),[]),r=a??c,{invoke:o,read:l,write:u,serverSubscribe:i,isConnected:f,subscribe:m,unsubscribe:y}=useContext(EventEmitterContext),[b,d]=useState(()=>{const e={};for(const a of t)void 0!==a.initialValue&&(e[a.tagName]=a.initialValue);return e}),[g,p]=useState({}),[v,C]=useState(r),N=useRef(v),h=useRef(b);useEffect(()=>{N.current=v},[v]),useEffect(()=>{h.current=b},[b]);const[T,w]=useState(!0),x=useCallback((e,t)=>{const{valueType:a,scale:s,codec:n}=e;if("number"===a&&"number"==typeof t&&s){const e=N.current[s];return t*(e?.scale??1)}if("json"===a&&n?.fromServer)try{return n.fromServer(t)}catch{}return t},[]),E=useCallback((e,t)=>{const{valueType:a,scale:s,codec:n}=e;if("json"===a&&n?.toServer)try{t=n.toServer(t)}catch{}if("number"===a&&"number"==typeof t&&s){const e=N.current[s];return t/(e?.scale??1)}return t},[]),k=useCallback(e=>{const a=t.filter(t=>t.scale===e);a.length&&p(e=>{const t={...e};for(const e of a){const a=h.current[e.tagName];if("number"!=typeof a)continue;const s=x(e,a);t[e.tagName]!==s&&(t[e.tagName]=s)}return t})},[t,x]),S=useCallback((e,t)=>{d(a=>a[e.tagName]===t?a:{...a,[e.tagName]:t});const a=x(e,t);p(t=>t[e.tagName]===a?t:{...t,[e.tagName]:a})},[x]),M=useCallback(async(e,t,a)=>{const s=a?.concurrency??4,n=a?.minDelayMs??20,c=a?.jitterMs??40;let r=0;const u=Array.from({length:s},()=>(async()=>{for(;;){const a=r++;if(a>=t.length)return;const s=t[a];try{let t=!1;try{await o(s.fqdn,MessageType.Request,{action:"refresh"}),t=!0}catch{}if(!t){const t="GNV"===e.toUpperCase()?{group:"ux"}:{};try{const e=await l(s.fqdn,t);e?.success&&S(s,e.data)}catch(e){}}}catch(e){}finally{const e=Math.floor(Math.random()*c);await sleep(n+e)}}})());await Promise.all(u)},[o,l,S]),j=useCallback(async()=>{for(const[e,t]of Object.entries(r)){if(!t.serverTag)continue;const{domain:a,symbolName:s}=t.serverTag;try{const t=await l(`${a}.${s}`,{group:"ux"});if(t.data&&(t.success??1)&&(t.valid??1)){const a=JSON.parse(t.data);if(a&&"number"==typeof a.scale){const{scale:t,label:s}=a;C(a=>({...a,[e]:{...a[e],scale:t,label:s??a[e]?.label??"---"}})),k(e)}}}catch{}}},[l,r,k]);useEffect(()=>{let e=!0;const a=[],c=async()=>{if(e&&!n.current){n.current=!0;try{await(async()=>{try{await j();for(const n of t){await i(n.tagName,n.fqdn,n.subscriptionOptions);const t=m(n.tagName,t=>{e&&S(n,t)});a.push(t),s&&l(n.fqdn).then(t=>{e&&t?.success&&S(n,t.data)}).catch(e=>{})}}finally{e&&setTimeout(()=>e&&w(!1),100)}})()}finally{e&&setTimeout(()=>e&&w(!1),100)}}};if(f())c();else{const e=m("HUB/connected",()=>{y(e),c()});a.push(e)}return()=>{e=!1,a.forEach(y),n.current=!1}},[m,y,f,o,i,s,t,j,M,S]);const q=useMemo(()=>Object.entries(r).filter(([,e])=>e.serverTag).map(([e,t])=>({scaleName:e,domain:t.serverTag.domain,symbolName:t.serverTag.symbolName})),[r]);useEffect(()=>{let e=!0;const t=[];for(const{scaleName:a,domain:s,symbolName:n}of q){const c=m(`${s}.${n}`,t=>{if(!e)return;const s=t?.value;if(s&&"object"==typeof s&&"number"==typeof s.scale){const{scale:e,label:t}=s;C(s=>({...s,[a]:{...s[a],scale:e,label:t??s[a]?.label??"---"}})),k(a)}});t.push(c)}return()=>{e=!1,t.forEach(y)}},[m,y,q,k]);const R=useCallback(async(e,a)=>{const s=t.find(t=>t.tagName===e);if(!s)return;const n=E(s,a);await u(s.fqdn,n)},[t,u,E]),$=useCallback(async e=>{const a=t.find(t=>t.tagName===e);a&&"boolean"===a.valueType&&(u(a.fqdn,!0).catch(e=>{}),await sleep(300),u(a.fqdn,!1).catch(e=>{}))},[t,u]),V=useCallback(async e=>{const a=t.find(t=>t.tagName===e);a&&"boolean"===a.valueType&&await u(a.fqdn,!0)},[t,u]),A=useCallback(async e=>{const a=t.find(t=>t.tagName===e);a&&"boolean"===a.valueType&&await u(a.fqdn,!1)},[t,u]),O=useCallback(async(e,t,a)=>{const s=v[e];if(s){if(s.serverTag){const n=`${s.serverTag.domain}.${s.serverTag.symbolName}`;await u(n,{name:e,scale:t,label:a})}C(s=>({...s,[e]:{...s[e],scale:t,label:a}})),k(e)}},[v,u,k]);useEffect(()=>{p(e=>{const a={...e};for(const e of t){const t=h.current[e.tagName];if(void 0===t)continue;const s=x(e,t);a[e.tagName]!==s&&(a[e.tagName]=s)}return a})},[t,x,v]);const P=useMemo(()=>({values:g,rawValues:b,isLoading:T,write:R,tap:$,press:V,release:A,scales:v,updateScale:O}),[g,b,T,R,$,V,A,v,O]);return _jsx(AutoCoreTagContext.Provider,{value:P,children:e})};
|
|
@@ -39,6 +39,10 @@ export type TagBinding<T> = Readonly<{
|
|
|
39
39
|
write: (displayValue: T) => Promise<void>;
|
|
40
40
|
/** Momentary action; typically boolean true→false pulse. */
|
|
41
41
|
tap: () => Promise<void>;
|
|
42
|
+
/** Sets boolean tag to true. */
|
|
43
|
+
press: () => Promise<void>;
|
|
44
|
+
/** Sets boolean tag to false. */
|
|
45
|
+
release: () => Promise<void>;
|
|
42
46
|
/** True while initial read/bootstrapping is in progress. */
|
|
43
47
|
isLoading: boolean;
|
|
44
48
|
}>;
|
|
@@ -268,6 +272,10 @@ export interface BaseContextValue<VMap extends Record<string, any>> {
|
|
|
268
272
|
* Typically used for boolean "request" bits.
|
|
269
273
|
*/
|
|
270
274
|
tap: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
275
|
+
/** Sets boolean tag to true. */
|
|
276
|
+
press: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
277
|
+
/** Sets boolean tag to false. */
|
|
278
|
+
release: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
271
279
|
/** Current scale configurations by name. */
|
|
272
280
|
scales: Record<string, ScaleConfig>;
|
|
273
281
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCoreTagTypes.d.ts","sourceRoot":"","sources":["../../src/core/AutoCoreTagTypes.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AAEH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAErE,oDAAoD;AACpD,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AACtD,MAAM,MAAM,SAAS,GACf,aAAa,GACb;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,SAAS,EA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,CAAC,CAAC;IAEtB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,yCAAyC;IACzC,SAAS,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpF;;;OAGG;IACH,GAAG,EAAE,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAElE,gCAAgC;IAChC,KAAK,EAAE,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE,iCAAiC;IACjC,OAAO,EAAE,CAAC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtE,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEpC;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzF"}
|
|
@@ -5,6 +5,8 @@ export declare function makeAutoCoreTagHooks<Spec extends readonly TagConfig[]>(
|
|
|
5
5
|
readonly rawValue: unknown;
|
|
6
6
|
readonly write: (displayValue: TagValueMap<Spec>[K]) => Promise<void>;
|
|
7
7
|
readonly tap: () => Promise<void>;
|
|
8
|
+
readonly press: () => Promise<void>;
|
|
9
|
+
readonly release: () => Promise<void>;
|
|
8
10
|
readonly isLoading: boolean;
|
|
9
11
|
};
|
|
10
12
|
readonly useAutoCoreTags: <K extends Spec[number]["tagName"]>(tagNames: readonly K[]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAutoCoreTag.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoCoreTag.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEzF,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,SAAS,SAAS,EAAE,EAClE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3D,IAAI,EAAE,IAAI;8BAYc,CAAC,2CAA4B,CAAC
|
|
1
|
+
{"version":3,"file":"useAutoCoreTag.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoCoreTag.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEzF,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,SAAS,SAAS,EAAE,EAClE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3D,IAAI,EAAE,IAAI;8BAYc,CAAC,2CAA4B,CAAC;;;;;;;;;+BA6B7B,CAAC,4CAA6B,SAAS,CAAC,EAAE;4BAO/C,CAAC;;kCAYyB,CAAC;;;iCAUpB,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,mBAAM,CAAC,KAAK,CAAC,SAAQ,GAAG,EAAE;;;;;;;uCAW3C,MAAM;;EAKtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:
|
|
1
|
+
import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:s=>{const{values:t,rawValues:u,isLoading:o,write:r,tap:l,press:n,release:c}=useContext(e),i=(e=>a.find(a=>a.tagName===e))(s);if(!i)throw new Error(`useAutoCoreTag: unknown tagName '${String(s)}'`);const C=useCallback(e=>r(s,e),[r,s]),g=useCallback(()=>l?.(s),[l,s]),m=useCallback(()=>n?.(s),[n,s]),w=useCallback(()=>c?.(s),[c,s]);return{value:t[s],rawValue:u[s],write:C,tap:g,press:m,release:w,isLoading:o}},useAutoCoreTags:a=>{const{values:s,rawValues:t,isLoading:u,write:o}=useContext(e);return{values:useMemo(()=>Object.fromEntries(a.map(e=>[e,s[e]])),[s,a]),rawValues:useMemo(()=>Object.fromEntries(a.map(e=>[e,t[e]])),[t,a]),write:useCallback(async(e,a)=>{await o(e,a)},[o]),isLoading:u}},useAutoCoreSelect:(a,s=[])=>{const{values:t,isLoading:u}=useContext(e);return{selected:useMemo(()=>a(t),[t,...s]),isLoading:u}},useScales:()=>{const{scales:a,updateScale:s}=useContext(e),t=useCallback(e=>a[e],[a]);return{scales:a,updateScale:s,getScale:t}}}}
|
package/package.json
CHANGED
|
@@ -69,6 +69,19 @@ export interface IndicatorButtonProps extends Omit<ButtonProps, "value"> {
|
|
|
69
69
|
* cycle on onColor.
|
|
70
70
|
*/
|
|
71
71
|
flash?: boolean;
|
|
72
|
+
|
|
73
|
+
/** Callback fired when the button is pressed (mouse down or touch start). */
|
|
74
|
+
onPress?: (e: React.MouseEvent | React.TouchEvent) => void;
|
|
75
|
+
|
|
76
|
+
/** Callback fired when the button is released (mouse up, touch end, or mouse leave). */
|
|
77
|
+
onRelease?: (e: React.MouseEvent | React.TouchEvent) => void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Momentary tag writer. When the button is pressed, this is called with `true`.
|
|
81
|
+
* When the button is released or the mouse leaves, it is called with `false`.
|
|
82
|
+
* Pass the `write` function from `useAutoCoreTag` directly to this prop.
|
|
83
|
+
*/
|
|
84
|
+
momentary?: (value: boolean) => void | Promise<void>;
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
const toPrimeIcon = (cls?: string) =>
|
|
@@ -94,6 +107,9 @@ export const IndicatorButton: React.FC<IndicatorButtonProps> = ({
|
|
|
94
107
|
disabled,
|
|
95
108
|
hidden,
|
|
96
109
|
flash,
|
|
110
|
+
onPress,
|
|
111
|
+
onRelease,
|
|
112
|
+
momentary,
|
|
97
113
|
...restProps
|
|
98
114
|
}) => {
|
|
99
115
|
const { subscribe, unsubscribe, dispatch } = useContext(
|
|
@@ -179,25 +195,31 @@ export const IndicatorButton: React.FC<IndicatorButtonProps> = ({
|
|
|
179
195
|
[command, dispatch, invert, commandArgs, commandTopic]
|
|
180
196
|
);
|
|
181
197
|
|
|
182
|
-
const handleOnPressed = useCallback(() => {
|
|
183
|
-
if (isPressed) return;
|
|
198
|
+
const handleOnPressed = useCallback((e: React.MouseEvent | React.TouchEvent) => {
|
|
199
|
+
if (isPressed || disabled) return;
|
|
184
200
|
setIsPressed(true);
|
|
185
201
|
|
|
202
|
+
if (momentary) momentary(true);
|
|
203
|
+
if (onPress) onPress(e);
|
|
204
|
+
|
|
186
205
|
if (actionMode === ActionMode.Tap || actionMode === ActionMode.Pressed) {
|
|
187
206
|
dispatchCommand(true);
|
|
188
207
|
}
|
|
189
|
-
}, [isPressed, actionMode, dispatchCommand]);
|
|
208
|
+
}, [isPressed, disabled, actionMode, dispatchCommand, onPress, momentary]);
|
|
190
209
|
|
|
191
|
-
const handleOnReleased = useCallback(() => {
|
|
192
|
-
if (!isPressed) return;
|
|
210
|
+
const handleOnReleased = useCallback((e: React.MouseEvent | React.TouchEvent) => {
|
|
211
|
+
if (!isPressed || disabled) return;
|
|
193
212
|
setIsPressed(false);
|
|
194
213
|
|
|
214
|
+
if (momentary) momentary(false);
|
|
215
|
+
if (onRelease) onRelease(e);
|
|
216
|
+
|
|
195
217
|
if (actionMode === ActionMode.Tap) {
|
|
196
218
|
dispatchCommand(false);
|
|
197
219
|
} else if (actionMode === ActionMode.Released) {
|
|
198
220
|
dispatchCommand(true);
|
|
199
221
|
}
|
|
200
|
-
}, [isPressed, actionMode, dispatchCommand]);
|
|
222
|
+
}, [isPressed, disabled, actionMode, dispatchCommand, onRelease, momentary]);
|
|
201
223
|
|
|
202
224
|
const mergedStyle: React.CSSProperties = {
|
|
203
225
|
color: "white",
|
|
@@ -224,6 +246,7 @@ export const IndicatorButton: React.FC<IndicatorButtonProps> = ({
|
|
|
224
246
|
onTouchStart={handleOnPressed}
|
|
225
247
|
onMouseUp={handleOnReleased}
|
|
226
248
|
onTouchEnd={handleOnReleased}
|
|
249
|
+
onMouseLeave={handleOnReleased} // Safety net for drag-offs
|
|
227
250
|
/>
|
|
228
251
|
);
|
|
229
252
|
};
|
|
@@ -104,6 +104,8 @@ export const AutoCoreTagContext = createContext<BaseContextValue<VMapRuntime>>({
|
|
|
104
104
|
isLoading: true,
|
|
105
105
|
write: async () => { },
|
|
106
106
|
tap: async () => { },
|
|
107
|
+
press: async () => { },
|
|
108
|
+
release: async () => { },
|
|
107
109
|
scales: {},
|
|
108
110
|
updateScale: async () => { },
|
|
109
111
|
});
|
|
@@ -538,6 +540,8 @@ export const AutoCoreTagProvider: React.FC<{
|
|
|
538
540
|
|
|
539
541
|
/**
|
|
540
542
|
* Momentary pulse for boolean tags (True -> Wait 300ms -> False).
|
|
543
|
+
* Now uses try...finally to ensure the tag is always reset to false
|
|
544
|
+
* even if the connection is lost or an error occurs during the pulse.
|
|
541
545
|
*/
|
|
542
546
|
const tap = useCallback(
|
|
543
547
|
async (tagName: string) => {
|
|
@@ -551,9 +555,40 @@ export const AutoCoreTagProvider: React.FC<{
|
|
|
551
555
|
return;
|
|
552
556
|
}
|
|
553
557
|
|
|
554
|
-
|
|
558
|
+
// Fire and forget the writes. WebSockets guarantee ordered delivery.
|
|
559
|
+
// We don't await them here so that the pulse is responsive and
|
|
560
|
+
// doesn't hang if the server is slow to acknowledge the first write.
|
|
561
|
+
hubWrite(cfg.fqdn, true).catch(e => console.error(`tap(): write true failed`, e));
|
|
562
|
+
|
|
555
563
|
await sleep(300);
|
|
556
|
-
|
|
564
|
+
|
|
565
|
+
hubWrite(cfg.fqdn, false).catch(e => console.error(`tap(): write false failed`, e));
|
|
566
|
+
},
|
|
567
|
+
[tags, hubWrite]
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Sets a boolean tag to TRUE.
|
|
572
|
+
*/
|
|
573
|
+
const press = useCallback(
|
|
574
|
+
async (tagName: string) => {
|
|
575
|
+
const cfg = tags.find((t) => t.tagName === tagName);
|
|
576
|
+
if (cfg && cfg.valueType === "boolean") {
|
|
577
|
+
await hubWrite(cfg.fqdn, true);
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
[tags, hubWrite]
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Sets a boolean tag to FALSE.
|
|
585
|
+
*/
|
|
586
|
+
const release = useCallback(
|
|
587
|
+
async (tagName: string) => {
|
|
588
|
+
const cfg = tags.find((t) => t.tagName === tagName);
|
|
589
|
+
if (cfg && cfg.valueType === "boolean") {
|
|
590
|
+
await hubWrite(cfg.fqdn, false);
|
|
591
|
+
}
|
|
557
592
|
},
|
|
558
593
|
[tags, hubWrite]
|
|
559
594
|
);
|
|
@@ -612,11 +647,12 @@ export const AutoCoreTagProvider: React.FC<{
|
|
|
612
647
|
isLoading,
|
|
613
648
|
write,
|
|
614
649
|
tap,
|
|
650
|
+
press,
|
|
651
|
+
release,
|
|
615
652
|
scales: scaleValues,
|
|
616
653
|
updateScale,
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
);
|
|
654
|
+
}), [values, rawValues, isLoading, write, tap, press, release, scaleValues, updateScale]);
|
|
655
|
+
|
|
620
656
|
|
|
621
657
|
return (
|
|
622
658
|
<AutoCoreTagContext.Provider value={ctxValue}>
|
|
@@ -58,6 +58,10 @@ export type TagBinding<T> = Readonly<{
|
|
|
58
58
|
write: (displayValue: T) => Promise<void>;
|
|
59
59
|
/** Momentary action; typically boolean true→false pulse. */
|
|
60
60
|
tap: () => Promise<void>;
|
|
61
|
+
/** Sets boolean tag to true. */
|
|
62
|
+
press: () => Promise<void>;
|
|
63
|
+
/** Sets boolean tag to false. */
|
|
64
|
+
release: () => Promise<void>;
|
|
61
65
|
/** True while initial read/bootstrapping is in progress. */
|
|
62
66
|
isLoading: boolean;
|
|
63
67
|
}>;
|
|
@@ -320,6 +324,12 @@ export interface BaseContextValue<VMap extends Record<string, any>> {
|
|
|
320
324
|
*/
|
|
321
325
|
tap: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
322
326
|
|
|
327
|
+
/** Sets boolean tag to true. */
|
|
328
|
+
press: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
329
|
+
|
|
330
|
+
/** Sets boolean tag to false. */
|
|
331
|
+
release: <K extends keyof VMap & string>(tagName: K) => Promise<void>;
|
|
332
|
+
|
|
323
333
|
/** Current scale configurations by name. */
|
|
324
334
|
scales: Record<string, ScaleConfig>;
|
|
325
335
|
|
|
@@ -31,7 +31,7 @@ export function makeAutoCoreTagHooks<Spec extends readonly TagConfig[]>(
|
|
|
31
31
|
* Returns current value, raw value, direct server writer, and tap helper.
|
|
32
32
|
*/
|
|
33
33
|
const useAutoCoreTag = <K extends TagNames>(tagName: K) => {
|
|
34
|
-
const { values, rawValues, isLoading, write: ctxWrite, tap: ctxTap } = useContext(Context);
|
|
34
|
+
const { values, rawValues, isLoading, write: ctxWrite, tap: ctxTap, press: ctxPress, release: ctxRelease } = useContext(Context);
|
|
35
35
|
|
|
36
36
|
const cfg = findCfg(tagName as string);
|
|
37
37
|
if (!cfg) throw new Error(`useAutoCoreTag: unknown tagName '${String(tagName)}'`);
|
|
@@ -42,12 +42,16 @@ export function makeAutoCoreTagHooks<Spec extends readonly TagConfig[]>(
|
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
const tap = useCallback(() => ctxTap?.(tagName), [ctxTap, tagName]);
|
|
45
|
+
const press = useCallback(() => ctxPress?.(tagName), [ctxPress, tagName]);
|
|
46
|
+
const release = useCallback(() => ctxRelease?.(tagName), [ctxRelease, tagName]);
|
|
45
47
|
|
|
46
48
|
return {
|
|
47
49
|
value: values[tagName] as VMap[K],
|
|
48
50
|
rawValue: rawValues[tagName as string],
|
|
49
51
|
write,
|
|
50
52
|
tap,
|
|
53
|
+
press,
|
|
54
|
+
release,
|
|
51
55
|
isLoading,
|
|
52
56
|
} as const;
|
|
53
57
|
};
|