@adcops/autocore-react 3.0.18 → 3.0.20
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/FileList.d.ts +1 -0
- package/dist/components/FileList.js +1 -1
- package/dist/components/FileSelect.d.ts +10 -0
- package/dist/components/FileSelect.js +1 -0
- package/dist/components/ProgressBarWithValue.css +27 -0
- package/dist/components/ProgressBarWithValue.d.ts +9 -0
- package/dist/components/ProgressBarWithValue.js +1 -0
- package/dist/components/TextInput.d.ts +1 -0
- package/dist/components/TextInput.js +1 -1
- package/dist/components/ToggleGroup.d.ts +1 -0
- package/dist/components/ToggleGroup.js +1 -1
- package/dist/components/ValueInput.d.ts +66 -77
- package/dist/components/ValueInput.js +1 -1
- package/dist/hooks/adsHooks.d.ts +96 -0
- package/dist/hooks/adsHooks.js +1 -0
- package/package.json +2 -2
- package/src/components/FileList.tsx +11 -5
- package/src/components/FileSelect.tsx +115 -0
- package/src/components/ProgressBarWithValue.css +27 -0
- package/src/components/ProgressBarWithValue.tsx +49 -0
- package/src/components/TextInput.tsx +11 -1
- package/src/components/ToggleGroup.tsx +38 -1
- package/src/components/ValueInput.tsx +213 -213
- package/src/hooks/adsHooks.tsx +208 -0
- package/dist/hooks/useAdsRegisterSymbol.d.ts +0 -32
- package/dist/hooks/useAdsRegisterSymbol.js +0 -1
- package/src/hooks/useAdsRegisterSymbol.ts +0 -97
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import React,{useState,useContext,useEffect}from"react";import{DataTable}from"primereact/datatable";import{Column}from"primereact/column";import{Toolbar}from"primereact/toolbar";import{Button}from"primereact/button";import{ConfirmPopup,confirmPopup}from"primereact/confirmpopup";import{MessageSeverity}from"primereact/api";import{EventEmitterContext}from"../core/EventEmitterContext";export const FileList=({domain:e="DATASTORE",enableUpload:t=!1})=>{const{invoke:
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import React,{useState,useContext,useEffect}from"react";import{DataTable}from"primereact/datatable";import{Column}from"primereact/column";import{Toolbar}from"primereact/toolbar";import{Button}from"primereact/button";import{ConfirmPopup,confirmPopup}from"primereact/confirmpopup";import{MessageSeverity}from"primereact/api";import{EventEmitterContext}from"../core/EventEmitterContext";export const FileList=({domain:e="DATASTORE",enableUpload:t=!1,subdir:a})=>{const{invoke:o,dispatch:r}=useContext(EventEmitterContext),[i,s]=useState(),n=async()=>{try{const t=void 0!==a?{subdir:a}:{};let r=await o(e,"list_files",t),i=[];for(let e=0;e<r.data.length;++e){const t=r.data[e];i.push({id:e+1,name:t})}s(i)}catch(e){r({topic:"autocore-react/alert/error",payload:{message:`Failed to upload file list: ${e}`,timeoutSec:7,severity:MessageSeverity.ERROR}})}},l=`File Listing [/${void 0!==a?a:""}]`,c=_jsx(React.Fragment,{children:_jsx("span",{style:{fontWeight:600},children:l})}),m=_jsxs(React.Fragment,{children:[t&&_jsx(Button,{icon:"pi pi-upload",className:"p-button-rounded p-mr-2","aria-label":"Upload",size:"small",rounded:!0,text:!0}),_jsx(Button,{icon:"pi pi-refresh",onClick:()=>{n()},className:"p-button-rounded p-mr-2","aria-label":"Refresh",size:"small",rounded:!0,text:!0})]}),p=(t,a)=>{confirmPopup({target:a.currentTarget,message:`Are you want to delete file ${t.name}?\nWARNING: This cannot be undone.`,icon:"pi pi-info-circle",defaultFocus:"reject",acceptClassName:"p-button-danger",accept:()=>(async t=>{try{await o(e,"delete_file",{file_name:t})}catch(e){r({topic:"autocore-react/alert/error",payload:{message:`Failed deleting file: ${e}`,timeoutSec:7,severity:MessageSeverity.ERROR}})}n()})(t.name)})};return useEffect((()=>(n(),()=>{})),[e,t]),_jsxs("div",{children:[_jsx(Toolbar,{start:c,end:m,style:{padding:"1mm"}}),_jsx(ConfirmPopup,{}),_jsxs(DataTable,{value:i,children:[_jsx(Column,{field:"name",header:"Name"}),_jsx(Column,{body:t=>_jsxs(_Fragment,{children:[_jsx(Button,{icon:"pi pi-download",onClick:()=>(async t=>{try{await o(e,"download_file",{file_name:t.name})}catch(e){r({topic:"autocore-react/alert/error",payload:{message:`Failed to downloading file: ${e}`,timeoutSec:7,severity:MessageSeverity.ERROR}})}})(t),className:"p-button-rounded p-button-success p-mr-2",style:{marginRight:"2mm"},size:"small"}),_jsx(Button,{icon:"pi pi-trash",onClick:e=>p(t,e),className:"p-button-rounded p-button-danger",size:"small"})]}),header:"Actions"})]})]})};export default FileList;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type FileSelectProps = {
|
|
3
|
+
domain?: string;
|
|
4
|
+
subdir?: string;
|
|
5
|
+
onFileSelected?: (fileName: string) => void;
|
|
6
|
+
onAccept?: (fileName: string) => void;
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const FileSelect: React.FC<FileSelectProps>;
|
|
10
|
+
export default FileSelect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useContext,useEffect}from"react";import{DataTable}from"primereact/datatable";import{Column}from"primereact/column";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext";export const FileSelect=({domain:e="DATASTORE",subdir:t,onFileSelected:n,onAccept:a,onCancel:l})=>{const{invoke:i}=useContext(EventEmitterContext),[o,s]=useState([]),[c,m]=useState(null),r=e=>{m(e),n&&n(e.name)};return useEffect((()=>{(async()=>{try{const n=t?{subdir:t}:{},a=(await i(e,"list_files",n)).data.map(((e,t)=>({id:t+1,name:e})));s(a)}catch(e){}})()}),[e,t]),_jsxs("div",{children:[_jsxs(DataTable,{value:o,selectionMode:"single",selection:c,onSelectionChange:e=>r(e.value),children:[_jsx(Column,{field:"name",header:"File Name"}),_jsx(Column,{body:e=>_jsx(Button,{label:c?.name===e.name?"Selected":"Select",icon:c?.name===e.name?"pi pi-check-circle":"pi pi-circle-off",onClick:()=>r(e),className:"p-button-rounded "+(c?.name===e.name?"p-button-success":"p-button-outlined"),"aria-label":"Select",size:"small"}),header:"Select"})]}),_jsxs("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"10px"},children:[_jsx(Button,{label:"Cancel",icon:"pi pi-times",className:"p-button-text",onClick:l}),_jsx(Button,{label:"Accept",icon:"pi pi-check",className:"p-button",onClick:()=>{void 0!==a&&null!==c&&a(null!==c?void 0!==t?`${t}/${c.name}`:c.name:"")},disabled:!c})]})]})};export default FileSelect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-04-27 12:46:35
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-04-27 13:10:43
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
.custom-progress-bar {
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%; /* Ensure the progress bar fills the container */
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.centered-value {
|
|
18
|
+
position: absolute;
|
|
19
|
+
width: 100%;
|
|
20
|
+
text-align: center;
|
|
21
|
+
font-weight: 600;
|
|
22
|
+
z-index: 10;
|
|
23
|
+
top: 50%;
|
|
24
|
+
left: 50%;
|
|
25
|
+
transform: translate(-50%, -50%); /* Centering magic */
|
|
26
|
+
}
|
|
27
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './ProgressBarWithValue.css';
|
|
3
|
+
interface ProgressBarWithValueProps {
|
|
4
|
+
value: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
label?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const ProgressBarWithValue: React.FC<ProgressBarWithValueProps>;
|
|
9
|
+
export default ProgressBarWithValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{ProgressBar}from"primereact/progressbar";import"./ProgressBarWithValue.css";export const ProgressBarWithValue=({value:r,max:e,label:s})=>{let a=r,t=!1;return void 0!==e&&(e>0?a=r/e*100:(a=0,t=!0)),_jsxs("div",{className:"custom-progress-bar",children:[_jsx(ProgressBar,{showValue:!1,value:a,mode:t?"indeterminate":"determinate"}),_jsxs("div",{className:"centered-value",children:[s?`${s} `:""," ",r," ",e?`of ${e}`:""]})]})};export default ProgressBarWithValue;
|
|
@@ -90,6 +90,7 @@ export declare class TextInput extends React.Component<TextInputProps, TextInput
|
|
|
90
90
|
* The component has been loaded into the DOM.
|
|
91
91
|
*/
|
|
92
92
|
componentDidMount(): void;
|
|
93
|
+
componentDidUpdate(prevProps: TextInputProps): void;
|
|
93
94
|
/**
|
|
94
95
|
* Check the new value against the validator RegEx, if one was specified.
|
|
95
96
|
* @param val The new value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import{InputText}from"primereact/inputtext";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext.js";export class TextInput extends React.Component{constructor(t){super(t),Object.defineProperty(this,"validateValue",{enumerable:!0,configurable:!0,writable:!0,value:t=>void 0===this.props.validator||null===this.props.validator||this.props.validator.test(t)}),this.state={entryValue:t.value,isValid:void 0!==t.value&&this.validateValue(t.value),editing:!1}}componentDidMount(){}onAcceptValue(){void 0!==this.state.entryValue&&this.validateValue(this.state.entryValue)?(this.setState({isValid:!0,editing:!1}),this.props.onValueChanged&&this.props.onValueChanged(this.state.entryValue),void 0!==this.props.dispatchTopic&&this.context.dispatch({topic:this.props.dispatchTopic,payload:this.state.entryValue})):this.setState({isValid:!1})}onResetValue(){this.setState({entryValue:this.props.value,isValid:void 0!==this.props.value&&this.validateValue(this.props.value),editing:!1})}render(){return _jsxs("div",{children:[_jsxs("div",{className:"p-inputgroup flex-1",children:[_jsx("span",{className:"p-inputgroup-addon",children:this.props.label}),void 0!==this.props.prefix&&_jsx("span",{className:"p-inputgroup-addon",children:this.props.prefix}),_jsx(InputText,{keyfilter:this.props.keyFilter,placeholder:this.props.placeholder,value:this.state.entryValue,onChange:t=>{this.setState({entryValue:t.target.value,editing:!0})},className:this.state.isValid?"":"p-invalid",onKeyDown:t=>{"Enter"===t.key?this.onAcceptValue():"Escape"===t.key&&this.onResetValue()},disabled:this.props.disabled}),void 0!==this.props.suffix&&_jsx("span",{className:"p-inputgroup-addon",children:this.props.suffix}),_jsx(Button,{icon:"pi pi-check",disabled:this.props.disabled||!this.state.editing,className:"p-button-success",onClick:()=>this.onAcceptValue(),visible:this.state.editing}),_jsx(Button,{icon:"pi pi-times",disabled:this.props.disabled||!this.state.editing,className:"p-button-danger",onClickCapture:()=>this.onResetValue(),visible:this.state.editing})]}),void 0!==this.props.description&&_jsx("small",{children:this.props.description})]})}}Object.defineProperty(TextInput,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext}),Object.defineProperty(TextInput,"defaultProps",{enumerable:!0,configurable:!0,writable:!0,value:{label:"",value:void 0,keyFilter:void 0,writeTopic:void 0,onValueChanged:void 0,description:void 0,prefix:void 0,suffix:void 0,disabled:!1,dispatchTopic:void 0,placeholder:void 0,validator:void 0}});
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import{InputText}from"primereact/inputtext";import{Button}from"primereact/button";import{EventEmitterContext}from"../core/EventEmitterContext.js";export class TextInput extends React.Component{constructor(t){super(t),Object.defineProperty(this,"validateValue",{enumerable:!0,configurable:!0,writable:!0,value:t=>void 0===this.props.validator||null===this.props.validator||this.props.validator.test(t)}),this.state={entryValue:t.value,isValid:void 0!==t.value&&this.validateValue(t.value),editing:!1}}componentDidMount(){}componentDidUpdate(t){t.value!==this.props.value&&this.setState({entryValue:this.props.value,editing:!1})}onAcceptValue(){void 0!==this.state.entryValue&&this.validateValue(this.state.entryValue)?(this.setState({isValid:!0,editing:!1}),this.props.onValueChanged&&this.props.onValueChanged(this.state.entryValue),void 0!==this.props.dispatchTopic&&this.context.dispatch({topic:this.props.dispatchTopic,payload:this.state.entryValue})):this.setState({isValid:!1})}onResetValue(){this.setState({entryValue:this.props.value,isValid:void 0!==this.props.value&&this.validateValue(this.props.value),editing:!1})}render(){return _jsxs("div",{children:[_jsxs("div",{className:"p-inputgroup flex-1",children:[_jsx("span",{className:"p-inputgroup-addon",children:this.props.label}),void 0!==this.props.prefix&&_jsx("span",{className:"p-inputgroup-addon",children:this.props.prefix}),_jsx(InputText,{keyfilter:this.props.keyFilter,placeholder:this.props.placeholder,value:this.state.entryValue,onChange:t=>{this.setState({entryValue:t.target.value,editing:!0})},className:this.state.isValid?"":"p-invalid",onKeyDown:t=>{"Enter"===t.key?this.onAcceptValue():"Escape"===t.key&&this.onResetValue()},disabled:this.props.disabled}),void 0!==this.props.suffix&&_jsx("span",{className:"p-inputgroup-addon",children:this.props.suffix}),_jsx(Button,{icon:"pi pi-check",disabled:this.props.disabled||!this.state.editing,className:"p-button-success",onClick:()=>this.onAcceptValue(),visible:this.state.editing}),_jsx(Button,{icon:"pi pi-times",disabled:this.props.disabled||!this.state.editing,className:"p-button-danger",onClickCapture:()=>this.onResetValue(),visible:this.state.editing})]}),void 0!==this.props.description&&_jsx("small",{children:this.props.description})]})}}Object.defineProperty(TextInput,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext}),Object.defineProperty(TextInput,"defaultProps",{enumerable:!0,configurable:!0,writable:!0,value:{label:"",value:void 0,keyFilter:void 0,writeTopic:void 0,onValueChanged:void 0,description:void 0,prefix:void 0,suffix:void 0,disabled:!1,dispatchTopic:void 0,placeholder:void 0,validator:void 0}});
|
|
@@ -16,6 +16,7 @@ export interface ToggleGroupProps extends SelectButtonProps {
|
|
|
16
16
|
invisibleTopic?: string;
|
|
17
17
|
actionMode?: ActionMode;
|
|
18
18
|
invert?: boolean;
|
|
19
|
+
onValueChanged?: (value: boolean | number) => void;
|
|
19
20
|
}
|
|
20
21
|
export declare const ToggleGroup: React.FC<ToggleGroupProps>;
|
|
21
22
|
export default ToggleGroup;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import{SelectButton}from"primereact/selectbutton";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};import clsx from"clsx";export const ToggleGroup=({label:o,topic:t,onColor:e,offColor:n,command:r,commandTopic:i,commandArgs:l,disableTopic:s,invisibleTopic:a,actionMode:c,invert:d,...
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import{SelectButton}from"primereact/selectbutton";import{EventEmitterContext}from"../core/EventEmitterContext";import{IndicatorColor}from"../core/IndicatorColor";export{IndicatorColor};import{ActionMode}from"../core/ActionMode";export{ActionMode};import clsx from"clsx";export const ToggleGroup=({label:o,topic:t,onColor:e,offColor:n,command:r,commandTopic:i,commandArgs:l,disableTopic:s,invisibleTopic:a,actionMode:c,invert:d,onValueChanged:u,...p})=>{const[m]=useState((()=>`toggleGroup-${Math.random().toString(36).substr(2,9)}`)),[f,g]=useState(void 0),[v,h]=useState(!1),[b,x]=useState(!1),[C,I]=useState(!1),y=useContext(EventEmitterContext);useEffect((()=>(t&&y.subscribe(t,A),s&&y.subscribe(s,j),a&&y.subscribe(a,M),()=>{})),[t,s,a]);const A=o=>{g(o)},j=o=>{h(o)},M=o=>{x(o)},E=()=>{C||(I(!0),c!==ActionMode.Tap&&c!==ActionMode.Pressed||T(!0))},S=()=>{C&&(I(!1),c===ActionMode.Tap?T(!1):c===ActionMode.Released&&T(!0))},T=o=>{if(r&&r.length>0){const t={topic:i,value:o,...l};y.dispatch({topic:r,payload:t})}};let $=f;void 0!==p.value&&($=p.value);let _=((o,t,e)=>{if(!t||0===t.length)return IndicatorColor.IndicatorInvalid;let n=Array.isArray(e)?e:void 0!==e?[e]:[IndicatorColor.IndicatorInvalid],r=typeof o;if("boolean"===r)return o?n[0]:n.length>1?n[1]:n[0];if("number"===r&&t.length>o){if(n.length>o){return n[o]}return n[0]}if("string"===r){let e=t.indexOf(o);return-1!==e&&e<n.length?n[e]:n[0]}return null!=e?Array.isArray(e)?e[0]:e:IndicatorColor.IndicatorInvalid})($,p.options,e);void 0===$&&(_=IndicatorColor.IndicatorInvalid);const N=void 0!==p.options&&null!==p.options&&void 0!==p.options.length&&p.options.length>2,G=`${m}-togglegroup-selectbutton-container`;return _jsxs("div",{className:"flex",children:[_jsx("style",{children:`\n ${void 0!==n?`\n .${G} .p-selectbutton .p-button {\n background-color: ${n};\n }\n `:""}\n .${G} .p-selectbutton .p-button.p-highlight {\n background-color: ${_} !important;\n border-color: ${_} !important;\n }\n `}),_jsx("div",{className:G,children:_jsxs("div",{className:"p-inputgroup",children:[_jsx("span",{className:"p-inputgroup-addon",style:{flexGrow:1},children:o}),_jsx(SelectButton,{...p,options:p.options,disabled:v||p.disabled,multiple:N,className:clsx(m,p.className,{"p-invalid":void 0===p.value}),style:b?{display:"none"}:{},value:((o,t)=>{if(null==t||0===t.length)return;let e=typeof o;if("boolean"==e){return o&&t.length>1?t[1]:t[0]}if("number"==e){let e=o;if(void 0!==e&&e<t.length)return t[e]}else if("string"==e)return o})($,p.options),allowEmpty:!1,onMouseDown:E,onTouchStart:E,onMouseUp:S,onTouchEnd:S,onChange:o=>(o=>{if(null!=u)if(void 0===p.options||null===p.options||0===p.options.length)u(!!N&&0);else{let t=0;for(let e=0;e<p.options.length;++e)if(o===p.options[e]){t=e;break}u(N?t:t>0)}})(o.value)})]})})]})};export default ToggleGroup;
|
|
@@ -1,5 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/** @file
|
|
2
|
+
* `ValueInput` is a React component for number input that encapsulates various features
|
|
3
|
+
* such as custom numeric formatting, optional currency formatting, increment and decrement
|
|
4
|
+
* buttons, and validation. This component uses the PrimeReact `InputNumber` control
|
|
5
|
+
* to provide a rich input experience, including handling both decimal and currency modes,
|
|
6
|
+
* with configurable precision and optional prefix/suffix text.
|
|
7
|
+
*
|
|
8
|
+
* Properties:
|
|
9
|
+
* - `label`: Label text displayed on the input field.
|
|
10
|
+
* - `value`: Current numeric value of the input field.
|
|
11
|
+
* - `min`: Minimum allowable value.
|
|
12
|
+
* - `max`: Maximum allowable value.
|
|
13
|
+
* - `minPrecision`: Minimum number of decimal places to display.
|
|
14
|
+
* - `maxPrecision`: Maximum number of decimal places allowed.
|
|
15
|
+
* - `mode`: Determines whether the input is treated as a plain decimal or currency. Defaults to "decimal".
|
|
16
|
+
* - `currency`: ISO 4217 currency code for formatting the value as currency.
|
|
17
|
+
* - `prefix`: String to display before the value.
|
|
18
|
+
* - `suffix`: String to display after the value.
|
|
19
|
+
* - `showButtons`: Whether to display increment and decrement buttons.
|
|
20
|
+
* - `step`: The amount by which the value should be incremented or decremented.
|
|
21
|
+
* - `locale`: Locale code for formatting the value.
|
|
22
|
+
* - `description`: Additional descriptive text to display below the input.
|
|
23
|
+
* - `disabled`: Whether the input is disabled.
|
|
24
|
+
* - `dispatchTopic`: Event topic to dispatch on value change.
|
|
25
|
+
* - `placeholder`: Placeholder text when the input is empty.
|
|
26
|
+
* - `onValueChanged`: Callback function that is called when the user accepts a new value.
|
|
27
|
+
*
|
|
28
|
+
* Example Usage:
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <ValueInput
|
|
31
|
+
* label="Quantity"
|
|
32
|
+
* value={10}
|
|
33
|
+
* min={1}
|
|
34
|
+
* max={100}
|
|
35
|
+
* minPrecision={0}
|
|
36
|
+
* maxPrecision={2}
|
|
37
|
+
* mode="decimal"
|
|
38
|
+
* showButtons={true}
|
|
39
|
+
* step={1}
|
|
40
|
+
* locale="en-US"
|
|
41
|
+
* onValueChanged={(newValue) => console.log("New Value:", newValue)}
|
|
42
|
+
* />
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* This example creates a `ValueInput` component for entering quantities, with values ranging from 1 to 100,
|
|
46
|
+
* allowing up to 2 decimal places. Increment and decrement buttons are visible, and the new value is logged
|
|
47
|
+
* to the console when accepted.
|
|
48
|
+
*/
|
|
49
|
+
import React from 'react';
|
|
3
50
|
/**
|
|
4
51
|
* Properties of the ValueInput component.
|
|
5
52
|
*/
|
|
@@ -15,11 +62,11 @@ interface ValueInputProps {
|
|
|
15
62
|
/**
|
|
16
63
|
* Minimum value for the field.
|
|
17
64
|
*/
|
|
18
|
-
min
|
|
65
|
+
min?: number | undefined;
|
|
19
66
|
/**
|
|
20
67
|
* Minimum value for the field.
|
|
21
68
|
*/
|
|
22
|
-
max
|
|
69
|
+
max?: number | undefined;
|
|
23
70
|
/**
|
|
24
71
|
* Minimum number of decimal points. The user will not
|
|
25
72
|
* be required to type the decimal values, but this minimum
|
|
@@ -28,21 +75,21 @@ interface ValueInputProps {
|
|
|
28
75
|
* the component will throw an error.
|
|
29
76
|
* @default 0
|
|
30
77
|
*/
|
|
31
|
-
minPrecision
|
|
78
|
+
minPrecision?: number | undefined;
|
|
32
79
|
/**
|
|
33
80
|
* Maximum number of decimal points.
|
|
34
81
|
* Set to 0 for integer-only. Must be greater or equal to than minPrecision, or
|
|
35
82
|
* the component will throw an error.
|
|
36
83
|
* @default 3
|
|
37
84
|
*/
|
|
38
|
-
maxPrecision
|
|
85
|
+
maxPrecision?: number | undefined;
|
|
39
86
|
/**
|
|
40
87
|
* Defines the behavior of the component.
|
|
41
88
|
* If set to "currency", then you need to specify the
|
|
42
89
|
* currency type using the currency property.
|
|
43
90
|
* @default "decimal"
|
|
44
91
|
*/
|
|
45
|
-
mode
|
|
92
|
+
mode?: "currency" | "decimal" | undefined;
|
|
46
93
|
/**
|
|
47
94
|
* The currency to use in currency formatting. Possible values are the
|
|
48
95
|
* [ISO 4217 currency codes](https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=maintenance-agency),
|
|
@@ -51,117 +98,59 @@ interface ValueInputProps {
|
|
|
51
98
|
*
|
|
52
99
|
* @default "USD"
|
|
53
100
|
*/
|
|
54
|
-
currency
|
|
101
|
+
currency?: string;
|
|
55
102
|
/**
|
|
56
103
|
* An optional prefix before the value of the field.
|
|
57
104
|
* Unlike the TextInput control, this prefix is internal to the field.
|
|
58
105
|
*/
|
|
59
|
-
prefix
|
|
106
|
+
prefix?: string | undefined;
|
|
60
107
|
/**
|
|
61
108
|
* An optional suffix after the value of the field.
|
|
62
109
|
* Unlike the TextInput control, this prefix is internal to the field.
|
|
63
110
|
*/
|
|
64
|
-
suffix
|
|
111
|
+
suffix?: string | undefined;
|
|
65
112
|
/**
|
|
66
113
|
* Set true to display buttons to increment/decrement the value.
|
|
67
114
|
* Use the step property to adjust the amount that the value will change.
|
|
68
115
|
*
|
|
69
116
|
* @default false
|
|
70
117
|
*/
|
|
71
|
-
showButtons
|
|
118
|
+
showButtons?: boolean;
|
|
72
119
|
/**
|
|
73
120
|
* The amount clicking an increment/decrement buttion will change the value.
|
|
74
121
|
*/
|
|
75
|
-
step
|
|
122
|
+
step?: number | undefined;
|
|
76
123
|
/**
|
|
77
124
|
* Locale to be used in formatting. Changes how the numbers/separators are displayed
|
|
78
125
|
* for international users. The typical locale codes are used.
|
|
79
126
|
*
|
|
80
127
|
* @default "en-US"
|
|
81
128
|
*/
|
|
82
|
-
locale
|
|
129
|
+
locale?: string | undefined;
|
|
83
130
|
/**
|
|
84
131
|
* A small, advisory text below the field.
|
|
85
132
|
*/
|
|
86
|
-
description
|
|
133
|
+
description?: React.ReactNode | undefined;
|
|
87
134
|
/**
|
|
88
135
|
* If true, all functions of the field will be disabled.
|
|
89
136
|
*/
|
|
90
|
-
disabled
|
|
137
|
+
disabled?: boolean | undefined;
|
|
91
138
|
/** Topic on which the value will be dispatched through the user interfave on successful data entry. */
|
|
92
|
-
dispatchTopic
|
|
139
|
+
dispatchTopic?: string | undefined;
|
|
93
140
|
/**
|
|
94
141
|
* Placeholder string to display if the value is empty.
|
|
95
142
|
*/
|
|
96
|
-
placeholder
|
|
143
|
+
placeholder?: string | undefined;
|
|
97
144
|
/**
|
|
98
145
|
* The user has accepted a new value.
|
|
99
146
|
* @param newValue New value accepted by the user.
|
|
100
147
|
*/
|
|
101
148
|
onValueChanged?(newValue: number): void;
|
|
102
149
|
}
|
|
103
|
-
/**
|
|
104
|
-
* State variables of the ValueInput component.
|
|
105
|
-
*/
|
|
106
|
-
interface ValueInputState {
|
|
107
|
-
entryValue: number | null;
|
|
108
|
-
currentValue: number | null;
|
|
109
|
-
editing: boolean;
|
|
110
|
-
}
|
|
111
150
|
/**
|
|
112
151
|
* A convenient field with all the usual features of inputing numbers.
|
|
113
152
|
* Wraps the common features of use of a InputNumber, p-inputgroup, some icon buttons,
|
|
114
153
|
* accepting and rejecting values and keyboard management.
|
|
115
154
|
*/
|
|
116
|
-
export declare
|
|
117
|
-
|
|
118
|
-
context: React.ContextType<typeof EventEmitterContext>;
|
|
119
|
-
/**
|
|
120
|
-
* Default properties for the component.
|
|
121
|
-
*/
|
|
122
|
-
static defaultProps: {
|
|
123
|
-
label: string;
|
|
124
|
-
value: undefined;
|
|
125
|
-
keyFilter: undefined;
|
|
126
|
-
writeTopic: undefined;
|
|
127
|
-
onValueChanged: undefined;
|
|
128
|
-
description: undefined;
|
|
129
|
-
prefix: undefined;
|
|
130
|
-
suffix: undefined;
|
|
131
|
-
disabled: boolean;
|
|
132
|
-
dispatchTopic: undefined;
|
|
133
|
-
placeholder: undefined;
|
|
134
|
-
validator: undefined;
|
|
135
|
-
min: undefined;
|
|
136
|
-
max: undefined;
|
|
137
|
-
minPrecision: number;
|
|
138
|
-
maxPrecision: number;
|
|
139
|
-
mode: string;
|
|
140
|
-
showButtons: boolean;
|
|
141
|
-
step: number;
|
|
142
|
-
locale: string;
|
|
143
|
-
currency: string;
|
|
144
|
-
};
|
|
145
|
-
inputRef: React.RefObject<HTMLInputElement>;
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param {FooterViewProps} props
|
|
149
|
-
*/
|
|
150
|
-
constructor(props: ValueInputProps);
|
|
151
|
-
/**
|
|
152
|
-
* The component has been loaded into the DOM.
|
|
153
|
-
*/
|
|
154
|
-
componentDidMount(): void;
|
|
155
|
-
componentDidUpdate(prevProps: ValueInputProps): void;
|
|
156
|
-
private onBufferValue;
|
|
157
|
-
/**
|
|
158
|
-
* The user has elected to accept the input value. Validate and store, if valid.
|
|
159
|
-
*/
|
|
160
|
-
private onAcceptValue;
|
|
161
|
-
/**
|
|
162
|
-
* The user wishes to reset/cancel the previous value.
|
|
163
|
-
*/
|
|
164
|
-
private onResetValue;
|
|
165
|
-
render(): import("react/jsx-runtime").JSX.Element;
|
|
166
|
-
}
|
|
167
|
-
export {};
|
|
155
|
+
export declare const ValueInput: React.FC<ValueInputProps>;
|
|
156
|
+
export default ValueInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useRef,useEffect,useContext}from"react";import{InputNumber}from"primereact/inputnumber";import{EventEmitterContext}from"../core/EventEmitterContext";import{Button}from"primereact/button";export const ValueInput=({label:e="",value:t=null,min:s,max:i,minPrecision:n=0,maxPrecision:o=3,mode:a="decimal",currency:u="USD",prefix:l,suffix:r,showButtons:c=!1,step:p=1,locale:m="en-US",description:d,disabled:x=!1,dispatchTopic:f,placeholder:v,onValueChanged:b})=>{const[h,j]=useState(t),[C,E]=useState(t),[_,S]=useState(t),[g,y]=useState(!1),[N,k]=useState(!1),B=useRef(null),D=useContext(EventEmitterContext);useEffect((()=>{null!==_?(E(_),S(null),k(!1)):t!==C&&(E(t),j(t),y(!1),k(!1))}),[t,C]);const F=()=>{var e;g&&null!==h&&(e=h,void 0!==i&&e>i||void 0!==s&&e<s?k(!0):(E(h),y(!1),b?.(h),k(!1),f&&D.dispatch({topic:f,payload:h})))},I=()=>{g&&(j(null),E(null),y(!1),k(!1))};return _jsxs("div",{children:[_jsxs("div",{className:"p-inputgroup flex-1",children:[_jsx("span",{className:"p-inputgroup-addon",children:e}),_jsx(InputNumber,{ref:B,invalid:N,min:s,max:i,minFractionDigits:n,maxFractionDigits:o,mode:a,prefix:l,suffix:r,showButtons:c,step:p,placeholder:v,value:C,onChange:e=>{return t=e.value,g||(S(C),y(!0)),void j(t);var t},locale:m,currency:u,onKeyDown:e=>{"Enter"===e.key?F():"Escape"===e.key&&I()},disabled:x}),_jsx(Button,{icon:"pi pi-check",disabled:x||!g,className:"p-button-success",onClick:()=>F(),visible:g,size:"small",autoFocus:!1}),_jsx(Button,{icon:"pi pi-times",disabled:x||!g,className:"p-button-danger",onClickCapture:()=>I(),visible:g,size:"small",autoFocus:!1})]}),d&&_jsx("small",{children:d})]})};export default ValueInput;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook for registering symbols and subscribing to updates on the
|
|
3
|
+
* ADS domain via the EventEmitterContext.
|
|
4
|
+
* This hook abstracts the common pattern of registering symbols and handling subscriptions
|
|
5
|
+
* to updates in components that need real-time data from a backend service.
|
|
6
|
+
*
|
|
7
|
+
* @param setters A mapping of state setter functions, where each key corresponds to a piece of state
|
|
8
|
+
* related to a symbol, and each value is the setter function for that state.
|
|
9
|
+
* @param symbols A mapping of state keys to their corresponding symbol names in the backend system.
|
|
10
|
+
* Each key should match a key in the `setters` object, and each value should be a string
|
|
11
|
+
* that represents the symbol name to register and subscribe to.
|
|
12
|
+
*
|
|
13
|
+
* ## Usage Example:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const setters = {
|
|
16
|
+
* speed: setSpeed,
|
|
17
|
+
* temperature: setTemperature
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* const symbols = {
|
|
21
|
+
* speed: "Sensor.speed",
|
|
22
|
+
* temperature: "Sensor.temperature"
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* useRegisterSymbols(setters, symbols);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* This will register and subscribe to updates for "Sensor.speed" and "Sensor.temperature",
|
|
29
|
+
* and update the `speed` and `temperature` states via `setSpeed` and `setTemperature` respectively
|
|
30
|
+
* whenever new data is received.
|
|
31
|
+
*/
|
|
32
|
+
export declare const useAdsRegisterSymbols: (setters: Record<string, (value: any) => void>, symbols: Record<string, string>) => null;
|
|
33
|
+
/**
|
|
34
|
+
* Custom hook to create a function that sends a specified value to a remote device or server.
|
|
35
|
+
* This hook abstracts the repetitive logic involved in sending these values,
|
|
36
|
+
* such as invoking the command and handling errors.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} domain The domain under which the backend function is grouped.
|
|
39
|
+
* @param {string} fname The name of the function to be called on the backend.
|
|
40
|
+
* @param {string} symbolName The symbol name that identifies the specific value or setting in the backend.
|
|
41
|
+
* @returns {Function} A function that accepts a value (number or boolean) and sends it to the configured backend.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* import React, { useState } from 'react';
|
|
46
|
+
* import { Button } from 'primereact/button';
|
|
47
|
+
* import useWriteValue from './useWriteValue'; // adjust the import path as necessary
|
|
48
|
+
*
|
|
49
|
+
* const Component: React.FC = () => {
|
|
50
|
+
* const [value, setValue] = useState<number>(0);
|
|
51
|
+
* const writeToBackend = useAdsWriteValue("ADS", "write_value", "GNV.mySymbol");
|
|
52
|
+
*
|
|
53
|
+
* return (
|
|
54
|
+
* <div>
|
|
55
|
+
* <input
|
|
56
|
+
* type="number"
|
|
57
|
+
* value={value}
|
|
58
|
+
* onChange={(e) => setValue(Number(e.target.value))}
|
|
59
|
+
* />
|
|
60
|
+
* <Button
|
|
61
|
+
* label="Send to Backend"
|
|
62
|
+
* onClick={() => writeToBackend(value)}
|
|
63
|
+
* />
|
|
64
|
+
* </div>
|
|
65
|
+
* );
|
|
66
|
+
* };
|
|
67
|
+
*/
|
|
68
|
+
export declare function useAdsWriteValue(symbolName: string): (value: object | boolean | number | string) => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Custom hook to send a "tap" action, which sends true followed by false after a short delay,
|
|
71
|
+
* to a specified symbol in the backend. This is used to simulate a button tap or momentary switch.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} domain - The domain under which the backend function is grouped.
|
|
74
|
+
* @param {string} fname - The function name to be called on the backend.
|
|
75
|
+
* @param {string} symbolName - The symbol name to target for the tap action.
|
|
76
|
+
* @returns {Function} A function that triggers the tap action.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* import React from 'react';
|
|
81
|
+
* import { Button } from 'primereact/button';
|
|
82
|
+
* import useTapValue from './useTapValue'; // Ensure the correct import path
|
|
83
|
+
*
|
|
84
|
+
* const MyComponent: React.FC = () => {
|
|
85
|
+
* const sendTapAction = useTapValue("ADS", "write_value", "GNV.myButton");
|
|
86
|
+
*
|
|
87
|
+
* return (
|
|
88
|
+
* <Button
|
|
89
|
+
* label="Tap Button"
|
|
90
|
+
* onClick={() => sendTapAction()}
|
|
91
|
+
* />
|
|
92
|
+
* );
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function useAdsTapValue(symbolName: string): () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useContext,useRef,useEffect}from"react";import{EventEmitterContext}from"../core/EventEmitterContext";function sleep(e){return new Promise((t=>setTimeout(t,e)))}export const useAdsRegisterSymbols=(e,t)=>{const{invoke:n,subscribe:r,unsubscribe:s,isConnected:o}=useContext(EventEmitterContext),u=useRef([]),c=useRef(!0);return useEffect((()=>{c.current=!0;const a=async()=>{for(const[s,o]of Object.entries(t))try{await n("ADS","register_symbol",{symbol_name:o});const t=r(`ADS/${o}`,(t=>{if(c.current){const n=e[s];n&&n(t.value)}}));u.current.push(t)}catch(e){}await n("ADS","refresh",{})};if(o())a();else{let e=r("HUB/connected",(()=>{a(),s(e)}));u.current.push(e)}return()=>{c.current=!1,u.current.forEach((e=>s(e))),u.current=[]}}),[]),null};export function useAdsWriteValue(e){const{invoke:t}=useContext(EventEmitterContext);return async n=>{try{await t("ADS","write_value",{symbol_name:e,value:n})}catch(e){}}}export function useAdsTapValue(e){const{invoke:t}=useContext(EventEmitterContext),n="write_value";return async()=>{try{await t("ADS",n,{symbol_name:e,value:!0}),await sleep(300),await t("ADS",n,{symbol_name:e,value:!1})}catch(e){}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adcops/autocore-react",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.20",
|
|
4
4
|
"description": "A React component library for industrial user interfaces.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/react-transition-group": "^4.4.1",
|
|
51
51
|
"clsx": "^2.1.0",
|
|
52
52
|
"numerable": "^0.3.15",
|
|
53
|
-
"primereact": "^10.3
|
|
53
|
+
"primereact": "^10.6.3",
|
|
54
54
|
"react-blockly": "^8.1.1",
|
|
55
55
|
"react-simple-keyboard": "^3.7.65",
|
|
56
56
|
"react-transition-group": "^4.4.1",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-04-24 16:01:53
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-04-
|
|
5
|
+
* Last Modified: 2024-04-29 11:01:41
|
|
6
6
|
* -----
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
@@ -34,7 +34,11 @@ type FileListProps = {
|
|
|
34
34
|
domain?: string,
|
|
35
35
|
/// Enable the upload button so that files can be uploaded to the datastore.
|
|
36
36
|
/// Default: false
|
|
37
|
-
enableUpload?: boolean
|
|
37
|
+
enableUpload?: boolean,
|
|
38
|
+
|
|
39
|
+
/// The subdirectory of the datastore to list.
|
|
40
|
+
/// If blank, the base directory is listed.
|
|
41
|
+
subdir? : string
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
/**
|
|
@@ -69,7 +73,8 @@ type FileItem = {
|
|
|
69
73
|
*/
|
|
70
74
|
export const FileList: React.FC<FileListProps> = ({
|
|
71
75
|
domain = "DATASTORE",
|
|
72
|
-
enableUpload = false
|
|
76
|
+
enableUpload = false,
|
|
77
|
+
subdir
|
|
73
78
|
}) => {
|
|
74
79
|
|
|
75
80
|
const { invoke, dispatch } = useContext(EventEmitterContext);
|
|
@@ -81,7 +86,8 @@ export const FileList: React.FC<FileListProps> = ({
|
|
|
81
86
|
*/
|
|
82
87
|
const listFiles = async () => {
|
|
83
88
|
try {
|
|
84
|
-
|
|
89
|
+
const args = subdir !== undefined ? {"subdir" : subdir} : {};
|
|
90
|
+
let res = await invoke(domain, "list_files", args);
|
|
85
91
|
|
|
86
92
|
let items = [];
|
|
87
93
|
for (let i = 0; i < res.data.length; ++i) {
|
|
@@ -157,7 +163,7 @@ export const FileList: React.FC<FileListProps> = ({
|
|
|
157
163
|
listFiles();
|
|
158
164
|
};
|
|
159
165
|
|
|
160
|
-
const title =
|
|
166
|
+
const title = `File Listing [/${subdir !== undefined ? subdir : ''}]`;
|
|
161
167
|
const toolbarStartContents = (
|
|
162
168
|
<React.Fragment>
|
|
163
169
|
<span style={{ fontWeight: 600 }}>{title}</span>
|