@adcops/autocore-react 3.0.19 → 3.0.21
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 +33 -0
- package/dist/components/FileList.js +1 -1
- package/dist/components/ValueDisplay.d.ts +49 -3
- package/dist/components/ValueDisplay.js +1 -1
- package/dist/components/ValueInput.d.ts +66 -77
- package/dist/components/ValueInput.js +1 -1
- package/dist/hooks/adsHooks.d.ts +49 -0
- package/dist/hooks/adsHooks.js +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useScaledValue.d.ts +57 -0
- package/dist/hooks/useScaledValue.js +1 -0
- package/package.json +2 -2
- package/src/components/FileList.tsx +176 -43
- package/src/components/FileSelect.tsx +1 -1
- package/src/components/ValueDisplay.tsx +72 -17
- package/src/components/ValueInput.tsx +213 -213
- package/src/hooks/adsHooks.tsx +76 -2
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useScaledValue.tsx +89 -0
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* using specific commands via websockets.
|
|
7
7
|
*/
|
|
8
8
|
import React from 'react';
|
|
9
|
+
/**
|
|
10
|
+
* Defines properties for the file list.
|
|
11
|
+
*/
|
|
9
12
|
/**
|
|
10
13
|
* Defines properties for the file list.
|
|
11
14
|
*/
|
|
@@ -13,6 +16,36 @@ type FileListProps = {
|
|
|
13
16
|
domain?: string;
|
|
14
17
|
enableUpload?: boolean;
|
|
15
18
|
subdir?: string;
|
|
19
|
+
/**
|
|
20
|
+
* A comma-separated list of file MIME types or file extensions.
|
|
21
|
+
* Default: .json
|
|
22
|
+
*
|
|
23
|
+
* ### Example: Filter by Extension:
|
|
24
|
+
* ```
|
|
25
|
+
* accept=".jpg,.png,.pdf" // Restricts uploads to JPG, PNG, and PDF files only
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ### Example: Filter by mime type.
|
|
29
|
+
* ```
|
|
30
|
+
* accept="image/*,application/pdf" // Allows any image type and PDF files
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Example: All files
|
|
34
|
+
* ```
|
|
35
|
+
* accept="/*"
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
filter?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Callback when an operation completes successfully.
|
|
42
|
+
* @returns void
|
|
43
|
+
*/
|
|
44
|
+
onSuccess?: (message: string) => void;
|
|
45
|
+
/***
|
|
46
|
+
* Callback when an operation results in an error.
|
|
47
|
+
*/
|
|
48
|
+
onError?: (message: string) => void;
|
|
16
49
|
};
|
|
17
50
|
/**
|
|
18
51
|
* `FileList` is a React functional component that displays a list of files retrieved from a specified domain
|
|
@@ -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{
|
|
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{FileUpload}from"primereact/fileupload";import{EventEmitterContext}from"../core/EventEmitterContext";export const FileList=({domain:e="DATASTORE",enableUpload:t=!1,subdir:o,filter:a=".json",onSuccess:n,onError:i})=>{const[r,l]=useState(0),{invoke:s}=useContext(EventEmitterContext),[c,m]=useState(),d=e=>null!==e?void 0!==o?`${o}/${e}`:e:"",p=async()=>{try{const t=void 0!==o?{subdir:o}:{};let a=await s(e,"list_files",t),n=[];for(let e=0;e<a.data.length;++e){const t=a.data[e];n.push({id:e+1,name:t})}m(n)}catch(e){i&&i(`Failed to upload file list: ${e}`)}};const u=()=>{l((e=>e+1))},f=`File Listing [/${void 0!==o?o:""}]`,x=_jsx(React.Fragment,{children:_jsx("span",{style:{fontWeight:600},children:f})}),b=_jsxs(React.Fragment,{children:[t&&_jsx(FileUpload,{customUpload:!0,auto:!0,uploadHandler:async t=>{const o=t.files[0];let a=d(o.name);const r=new FileReader;r.onload=async t=>{const r=t.target?.result,l=function c(e){let t="",o=new Uint8Array(e),a=o.byteLength;for(let e=0;e<a;e++)t+=String.fromCharCode(o[e]);return window.btoa(t)}(r);try{await s(e,"write_file",{file_name:a,value:l}),n&&n(`Uploaded file ${o.name}`),p()}catch(e){i&&i(`Failed to upload file: ${e}`)}u()},r.onerror=e=>{i&&i(`Error reading file: ${e}`)},r.readAsArrayBuffer(o)},accept:a,maxFileSize:25e3,mode:"basic",chooseLabel:"",chooseOptions:{icon:"pi pi-upload",className:"p-button-icon-only p-button-text p-button-rounded p-mr-2"}},r),_jsx(Button,{icon:"pi pi-refresh",onClick:()=>{p()},className:"p-button-rounded p-mr-2","aria-label":"Refresh",size:"small",rounded:!0,text:!0})]}),_=(t,o)=>{confirmPopup({target:o.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=>{let o=d(t);try{await s(e,"delete_file",{file_name:o}),n&&n(`Deleted file: ${t}`),p()}catch(e){i&&i(`Failed to delete file: ${e}`)}p()})(t.name)})};return useEffect((()=>(p(),()=>{})),[e,t]),_jsxs("div",{children:[_jsx(Toolbar,{start:x,end:b,style:{padding:"1mm"}}),_jsx(ConfirmPopup,{}),_jsxs(DataTable,{value:c,children:[_jsx(Column,{field:"name",header:"Name"}),_jsx(Column,{body:t=>_jsxs(_Fragment,{children:[_jsx(Button,{icon:"pi pi-download",onClick:()=>(async t=>{let o=d(t.name);try{await s(e,"download_file",{file_name:o}),n&&n(`Downloaded file: ${t.name}`)}catch(e){i&&i(`Failed downloading file: ${e}`)}})(t),className:"p-button-rounded p-button-success p-mr-2",style:{marginRight:"2mm"},size:"small"}),_jsx(Button,{icon:"pi pi-trash",onClick:e=>_(t,e),className:"p-button-rounded p-button-danger",size:"small"})]}),header:"Actions"})]})]})};export default FileList;
|
|
@@ -59,9 +59,55 @@ interface State {
|
|
|
59
59
|
fontSize?: string;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* `ValueDisplay` is a React component
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* `ValueDisplay` is a React component designed to display a value which can be a string, number, or null.
|
|
63
|
+
* It supports formatting numeric values using the `numerableFormat` function, and is capable of dynamic positioning
|
|
64
|
+
* and sizing within its parent container. The component integrates with an `EventEmitterContext` to listen for
|
|
65
|
+
* updates to its value based on a specified topic, making it ideal for real-time data display scenarios.
|
|
66
|
+
*
|
|
67
|
+
* The component can be absolutely positioned based on `x` and `y` props, and its size can be adjusted using
|
|
68
|
+
* `width` and `height` props. If `useAbsolutePositioning` is true, it will position itself based on the provided
|
|
69
|
+
* coordinates; otherwise, it will position relatively.
|
|
70
|
+
*
|
|
71
|
+
* ### Props:
|
|
72
|
+
* - `value`: The initial value to display, which can be updated via props or context events.
|
|
73
|
+
* - `x`, `y`: Coordinates for absolute positioning within the parent container.
|
|
74
|
+
* - `width`, `height`: Dimensions of the component. If height is not provided, it defaults to the width.
|
|
75
|
+
* - `format`: A string specifying the format for numeric values (see numerable.js documentation for format strings).
|
|
76
|
+
* - `formatOptions`: Additional formatting options as per numerable.js.
|
|
77
|
+
* - `className`: Custom class for CSS styling.
|
|
78
|
+
* - `useAbsolutePositioning`: Boolean to toggle absolute positioning.
|
|
79
|
+
* - `topic`: Optional string to subscribe to context updates for dynamic value changes.
|
|
80
|
+
*
|
|
81
|
+
* ### Usage Example:
|
|
82
|
+
* ```tsx
|
|
83
|
+
* import React from 'react';
|
|
84
|
+
* import ReactDOM from 'react-dom';
|
|
85
|
+
* import { ValueDisplay } from './components/ValueDisplay';
|
|
86
|
+
*
|
|
87
|
+
* const App = () => {
|
|
88
|
+
* return (
|
|
89
|
+
* <div>
|
|
90
|
+
* <ValueDisplay
|
|
91
|
+
* value={1234.56}
|
|
92
|
+
* x={100}
|
|
93
|
+
* y={200}
|
|
94
|
+
* width={150}
|
|
95
|
+
* height={50}
|
|
96
|
+
* format="0,0.00"
|
|
97
|
+
* className="numeric-display"
|
|
98
|
+
* useAbsolutePositioning={true}
|
|
99
|
+
* topic="priceUpdate"
|
|
100
|
+
* />
|
|
101
|
+
* </div>
|
|
102
|
+
* );
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* ReactDOM.render(<App />, document.getElementById('root'));
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* In this example, `ValueDisplay` is used to show a numeric value formatted as a string with two decimal places.
|
|
109
|
+
* It is positioned absolutely at coordinates (100, 200) with a specified width and height. The component listens
|
|
110
|
+
* for updates on the "priceUpdate" topic to dynamically update its displayed value.
|
|
65
111
|
*/
|
|
66
112
|
declare class ValueDisplay extends Component<Props, State> {
|
|
67
113
|
/** Defines the context type to subscribe to changes using EventEmitter. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{Component}from"react";import{format as numerableFormat}from"numerable";import clsx from"clsx";import{EventEmitterContext}from"../core/EventEmitterContext";class ValueDisplay extends Component{constructor(e){super(e),Object.defineProperty(this,"unsubscribeTopicId",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state={subscribedValue:e.value,fontSize:"100%"}}componentDidMount(){const{topic:e}=this.props;if(e){const{subscribe:t}=this.context;this.unsubscribeTopicId=t(e,(e=>{this.setState({subscribedValue:e})}))}}componentDidUpdate(e){this.props.value!==e.value&&this.setState({subscribedValue:this.props.value})}componentWillUnmount(){if(this.unsubscribeTopicId){const{unsubscribe:e}=this.context;e(this.unsubscribeTopicId)}}render(){const{x:e,y:t,width:i,height:s,format:o,formatOptions:r,className:n,useAbsolutePositioning:a}=this.props,{subscribedValue:l,fontSize:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{Component}from"react";import{format as numerableFormat}from"numerable";import clsx from"clsx";import{EventEmitterContext}from"../core/EventEmitterContext";class ValueDisplay extends Component{constructor(e){super(e),Object.defineProperty(this,"unsubscribeTopicId",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state={subscribedValue:e.value,fontSize:"100%"}}componentDidMount(){const{topic:e}=this.props;if(e){const{subscribe:t}=this.context;this.unsubscribeTopicId=t(e,(e=>{this.setState({subscribedValue:e})}))}}componentDidUpdate(e){this.props.value!==e.value&&this.setState({subscribedValue:this.props.value})}componentWillUnmount(){if(this.unsubscribeTopicId){const{unsubscribe:e}=this.context;e(this.unsubscribeTopicId)}}render(){const{x:e,y:t,width:i,height:s,format:o,formatOptions:r,className:n,useAbsolutePositioning:a}=this.props,{subscribedValue:l,fontSize:u}=this.state,{scale:c,xOffset:p,yOffset:b}=this.context,m={position:a?"absolute":"relative",display:a?"":"inline-block",verticalAlign:"middle",fontSize:u&&c>1?100*c+"%":u,top:a&&t?`${b+c*t}px`:void 0,left:a&&e?`${p+c*e}px`:void 0,width:i?i*c+"px":void 0,height:s?s*c+"px":void 0,lineHeight:s?s*c+"px":void 0,whiteSpace:"nowrap"};let d;return d="number"==typeof l||"string"==typeof l&&!isNaN(Number(l))?numerableFormat(l,o,r):l,_jsx("div",{className:clsx(n),style:m,children:d})}}Object.defineProperty(ValueDisplay,"contextType",{enumerable:!0,configurable:!0,writable:!0,value:EventEmitterContext});export{ValueDisplay};
|
|
@@ -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;
|
package/dist/hooks/adsHooks.d.ts
CHANGED
|
@@ -66,6 +66,55 @@ export declare const useAdsRegisterSymbols: (setters: Record<string, (value: any
|
|
|
66
66
|
* };
|
|
67
67
|
*/
|
|
68
68
|
export declare function useAdsWriteValue(symbolName: string): (value: object | boolean | number | string) => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* useAdsWriteScaledValue is a custom React hook that enables writing scaled numerical values to a backend system.
|
|
71
|
+
* It applies a specified scale and offset to a numeric value before sending it over an ADS connection.
|
|
72
|
+
* This hook is ideal for scenarios where numeric data needs to be adjusted according to dynamically configurable
|
|
73
|
+
* scale factors before being persisted or processed by a backend system.
|
|
74
|
+
*
|
|
75
|
+
* @param symbolName The symbol name in the backend system where the value will be written.
|
|
76
|
+
* @param scale The scale factor to be applied to the value.
|
|
77
|
+
* @param offset The offset to be applied after scaling the value.
|
|
78
|
+
* @returns A function that takes a numeric value, applies the scaling and offset, and sends the modified value to the backend.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* This example demonstrates how to use the `useAdsWriteScaledValue` hook within a component that allows users
|
|
82
|
+
* to input a value in inches, which is then automatically converted to millimeters (if the scale is set for such conversion)
|
|
83
|
+
* based on a dynamic scale factor managed in the component's state.
|
|
84
|
+
*
|
|
85
|
+
* ```tsx
|
|
86
|
+
* import React, { useState } from 'react';
|
|
87
|
+
* import { useAdsWriteScaledValue } from './hooks';
|
|
88
|
+
*
|
|
89
|
+
* const MeasurementInput: React.FC = () => {
|
|
90
|
+
* const [scale, setScale] = useState<number>(1 / 25.4); // Initial scale for converting inches to millimeters.
|
|
91
|
+
* const [offset, setOffset] = useState<number>(0); // No offset by default.
|
|
92
|
+
*
|
|
93
|
+
* // The hook is used here with the scale and offset state variables.
|
|
94
|
+
* const writeMeasurement = useAdsWriteScaledValue("GIO.axisX.position", scale, offset);
|
|
95
|
+
*
|
|
96
|
+
* // This function is called when the input field value changes.
|
|
97
|
+
* const handleMeasurementChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
98
|
+
* const valueInInches = parseFloat(event.target.value);
|
|
99
|
+
* writeMeasurement(valueInInches); // Write the scaled value (converted to millimeters).
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* return (
|
|
103
|
+
* <div>
|
|
104
|
+
* <label>Enter measurement in inches:</label>
|
|
105
|
+
* <input type="number" onChange={handleMeasurementChange} />
|
|
106
|
+
* </div>
|
|
107
|
+
* );
|
|
108
|
+
* };
|
|
109
|
+
*
|
|
110
|
+
* export default MeasurementInput;
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* In this component, `writeMeasurement` is a function returned by the `useAdsWriteScaledValue` hook that takes a value in inches,
|
|
114
|
+
* converts it to millimeters using the current `scale`, and writes the result to a backend symbol. The `scale` and `offset` can be adjusted
|
|
115
|
+
* dynamically if needed, for instance, based on user selection or other external configurations.
|
|
116
|
+
*/
|
|
117
|
+
export declare function useAdsWriteScaledValue(symbolName: string, scale: number, offset: number): (value: number) => Promise<void>;
|
|
69
118
|
/**
|
|
70
119
|
* Custom hook to send a "tap" action, which sends true followed by false after a short delay,
|
|
71
120
|
* to a specified symbol in the backend. This is used to simulate a button tap or momentary switch.
|
package/dist/hooks/adsHooks.js
CHANGED
|
@@ -1 +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){}}}
|
|
1
|
+
import{useContext,useRef,useEffect,useCallback}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 useAdsWriteScaledValue(e,t,n){const{invoke:r}=useContext(EventEmitterContext);return useCallback((async s=>{const o=(s-n)/t;try{await r("ADS","write_value",{symbol_name:e,value:o})}catch(e){}}),[e,t,n,r])}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){}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{useAdsRegisterSymbols,useAdsWriteValue,useAdsTapValue}from"./adsHooks";export{useScaledValue,kMillimeters2Inches}from"./useScaledValue";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const kMillimeters2Inches: number;
|
|
2
|
+
type UseScaledValueReturn = [number, (newValue: number) => void];
|
|
3
|
+
/**
|
|
4
|
+
* A custom React hook for converting values between different scales,
|
|
5
|
+
* with support for dynamically updating the scale and offset. This hook manages values
|
|
6
|
+
* in a base unit and allows for easy conversion to a display unit, updating
|
|
7
|
+
* reactively to changes in the conversion factors.
|
|
8
|
+
*
|
|
9
|
+
* @param initialValue - The initial value in the base unit.
|
|
10
|
+
* @param scale - The dynamic scale factor used for conversion to the display unit.
|
|
11
|
+
* @param offset - An optional offset applied after scaling (default is 0).
|
|
12
|
+
* @returns A tuple containing the display value and a setter function for updating
|
|
13
|
+
* the value in the display unit.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Here's how to use `useScaledValue` in a component that fetches a scale factor from a backend
|
|
17
|
+
* and allows the user to input values in a converted scale, which are then handled in a base unit:
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import React, { useState, useEffect } from 'react';
|
|
21
|
+
* import { useScaledValue } from './hooks/useScaledValue';
|
|
22
|
+
*
|
|
23
|
+
* const MeasurementInput: React.FC = () => {
|
|
24
|
+
* const [units, setUnits] = useState<number>(1); // Start with a default scale of 1
|
|
25
|
+
* const [xPosition, setXPosition] = useScaledValue(0, units);
|
|
26
|
+
*
|
|
27
|
+
* useEffect(() => {
|
|
28
|
+
* async function fetchScale() {
|
|
29
|
+
* try {
|
|
30
|
+
* // Simulate fetching scale factor from a backend
|
|
31
|
+
* const res = await invoke("GNV", "read_value", { group: "ux", key: "kSelectedUnits" });
|
|
32
|
+
* setUnits(res.data); // Update scale based on backend response
|
|
33
|
+
* } catch (error) {
|
|
34
|
+
* console.error('Failed to fetch units', error);
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* fetchScale();
|
|
38
|
+
* }, []);
|
|
39
|
+
*
|
|
40
|
+
* return (
|
|
41
|
+
* <input
|
|
42
|
+
* type="number"
|
|
43
|
+
* value={xPosition.toFixed(2)} // Display the value formatted to 2 decimal places
|
|
44
|
+
* onChange={(e) => setXPosition(parseFloat(e.target.value))}
|
|
45
|
+
* />
|
|
46
|
+
* );
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* export default MeasurementInput;
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* In this example, `useScaledValue` is used to manage a measurement input in a dynamic unit system.
|
|
53
|
+
* The component fetches the conversion scale from the backend upon component mounting and updates the
|
|
54
|
+
* input display accordingly. The user's input is converted back to the base unit before being processed.
|
|
55
|
+
*/
|
|
56
|
+
export declare function useScaledValue(initialValue: number, scale: number, offset?: number): UseScaledValueReturn;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback,useState}from"react";export const kMillimeters2Inches=1/25.4;export function useScaledValue(e,t,a=0){const[s,c]=useState(e*t+a);return[s,useCallback((e=>{c(e*t+a)}),[t,a])]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adcops/autocore-react",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.21",
|
|
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",
|