@adcops/autocore-react 3.0.25 → 3.0.28

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.
@@ -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{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;
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,options:{base64:!0}}),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;
@@ -1,4 +1,11 @@
1
+ /**
2
+ * Multiple millimeters by this constant for inches.
3
+ */
1
4
  export declare const kMillimeters2Inches: number;
5
+ /**
6
+ * Multiply netwons by this constant for pounds.
7
+ */
8
+ export declare const kNewtons2Pounds: number;
2
9
  type UseScaledValueReturn = [number, (newValue: number) => void];
3
10
  /**
4
11
  * A custom React hook for converting values between different scales,
@@ -1 +1 @@
1
- import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export function useScaledValue(e,t,s=0){const[u,a]=useState(e),[c,l]=useState((()=>e*t+s));useEffect((()=>{l(u*t+s)}),[u,t,s]);return[c,useCallback((e=>{a(e)}),[t,s])]}
1
+ import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export const kNewtons2Pounds=1/4.4482216153;export function useScaledValue(e,t,s=0){const[u,c]=useState(e),[o,a]=useState((()=>e*t+s));useEffect((()=>{a(u*t+s)}),[u,t,s]);return[o,useCallback((e=>{c(e)}),[t,s])]}
package/dist/hub/index.js CHANGED
@@ -1 +1 @@
1
- import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";export function createHub(){return void 0!==window.__TAURI__&&null!==window.__TAURI__?new HubTauri:new HubWebSocket}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};
1
+ import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";let hubInstance=null;export function createHub(){return hubInstance||(hubInstance=void 0!==window.__TAURI__&&null!==window.__TAURI__?new HubTauri:new HubWebSocket),hubInstance}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adcops/autocore-react",
3
- "version": "3.0.25",
3
+ "version": "3.0.28",
4
4
  "description": "A React component library for industrial user interfaces.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -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-05-02 11:18:50
5
+ * Last Modified: 2024-05-21 13:38:23
6
6
  * -----
7
7
  *
8
8
  */
@@ -247,7 +247,7 @@ export const FileList: React.FC<FileListProps> = ({
247
247
  const base64String = arrayBufferToBase64(arrayBuffer);
248
248
 
249
249
  try {
250
- await invoke(domain, "write_file", { file_name: target, value: base64String });
250
+ await invoke(domain, "write_file", { file_name: target, value: base64String, options :{"base64" : true} });
251
251
 
252
252
  if (onSuccess)
253
253
  onSuccess(`Uploaded file ${file.name}`);
@@ -2,7 +2,7 @@
2
2
  * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
3
3
  * Created Date: 2024-04-30 11:41:59
4
4
  * -----
5
- * Last Modified: 2024-05-02 15:14:03
5
+ * Last Modified: 2024-05-21 19:58:23
6
6
  * -----
7
7
  *
8
8
  */
@@ -11,9 +11,16 @@
11
11
 
12
12
  import { useCallback, useState, useEffect } from 'react';
13
13
 
14
-
14
+ /**
15
+ * Multiple millimeters by this constant for inches.
16
+ */
15
17
  export const kMillimeters2Inches: number = 1 / 25.4;
16
18
 
19
+ /**
20
+ * Multiply netwons by this constant for pounds.
21
+ */
22
+ export const kNewtons2Pounds : number = 1 / 4.4482216153;
23
+
17
24
 
18
25
  type UseScaledValueReturn = [number, (newValue: number) => void];
19
26
 
package/src/hub/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
3
3
  * Created Date: 2024-01-16 21:07:29
4
4
  * -----
5
- * Last Modified: 2024-04-25 07:18:48
5
+ * Last Modified: 2024-05-31 07:51:19
6
6
  * Modified By: ADC
7
7
  * -----
8
8
  *
@@ -14,35 +14,49 @@ import { HubWebSocket } from "./HubWebSocket";
14
14
  import {HubSimulate} from "./HubSimulate"
15
15
  import { CommandMessage, CommandMessageResult } from './CommandMessage';
16
16
 
17
+
18
+ let hubInstance: Hub | null = null;
19
+
17
20
  /**
18
21
  * Creates a connection to the backend.
19
22
  * @returns Hub
20
23
  */
21
24
  export function createHub(): Hub {
22
25
 
23
- if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
24
- // Standalone Tauri application
25
- console.log("HUB: Starting link to Tauri backend.");
26
- return new HubTauri();
26
+ if (!hubInstance) {
27
+ if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
28
+ console.log("HUB: Starting link to Tauri backend.");
29
+ hubInstance = new HubTauri();
30
+ } else {
31
+ console.log("HUB: Starting websocket connection.");
32
+ hubInstance = new HubWebSocket();
33
+ }
27
34
  }
28
- // else if (
29
- // window.location.port !== undefined
30
- // && window.location.port.length > 0
31
- // && window.location.port !== '80'
32
- // && window.location.port !== '8080'
33
- // && window.location.port !== '443'
34
- // ) {
35
+ return hubInstance;
36
+
37
+ // if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
38
+ // // Standalone Tauri application
39
+ // console.log("HUB: Starting link to Tauri backend.");
40
+ // return new HubTauri();
41
+ // }
42
+ // // else if (
43
+ // // window.location.port !== undefined
44
+ // // && window.location.port.length > 0
45
+ // // && window.location.port !== '80'
46
+ // // && window.location.port !== '8080'
47
+ // // && window.location.port !== '443'
48
+ // // ) {
35
49
 
36
- // // We're loaded in some development environment
37
- // console.log("HUB: Starting HUB SIMULATOR.");
38
- // return new HubSimulate();
39
-
40
- // }
41
- else {
42
- // A web-app that must communicate with a backend in another process.
43
- console.log("HUB: Starting websocket connection.");
44
- return new HubWebSocket();
45
- }
50
+ // // // We're loaded in some development environment
51
+ // // console.log("HUB: Starting HUB SIMULATOR.");
52
+ // // return new HubSimulate();
53
+
54
+ // // }
55
+ // else {
56
+ // // A web-app that must communicate with a backend in another process.
57
+ // console.log("HUB: Starting websocket connection.");
58
+ // return new HubWebSocket();
59
+ // }
46
60
  }
47
61
 
48
62