@adcops/autocore-react 3.0.33 → 3.0.34

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.
Files changed (62) hide show
  1. package/dist/assets/BlocklyLogo.js +9 -1
  2. package/dist/assets/Distance.js +5 -1
  3. package/dist/assets/JogLong.js +3 -1
  4. package/dist/assets/JogMedium.js +3 -1
  5. package/dist/assets/JogShort.js +3 -1
  6. package/dist/assets/PythonLogo.js +21 -1
  7. package/dist/assets/Rotation3D.js +3 -1
  8. package/dist/assets/RotationCcw.js +10 -1
  9. package/dist/assets/RotationCcwA.js +16 -1
  10. package/dist/assets/RotationCcwB.js +16 -1
  11. package/dist/assets/RotationCcwC.js +16 -1
  12. package/dist/assets/RotationCw.js +10 -1
  13. package/dist/assets/RotationCwA.js +16 -1
  14. package/dist/assets/RotationCwB.js +16 -1
  15. package/dist/assets/RotationCwC.js +16 -1
  16. package/dist/assets/Run.js +3 -1
  17. package/dist/assets/Speed.js +5 -1
  18. package/dist/assets/SpeedFast.js +3 -1
  19. package/dist/assets/SpeedMedium.js +3 -1
  20. package/dist/assets/SpeedNone.js +3 -1
  21. package/dist/assets/SpeedSlow.js +3 -1
  22. package/dist/assets/Walk.js +3 -1
  23. package/dist/assets/index.js +22 -1
  24. package/dist/components/BlocklyEditor.js +508 -1
  25. package/dist/components/CodeEditor.js +108 -1
  26. package/dist/components/FileList.js +218 -1
  27. package/dist/components/FileSelect.js +63 -1
  28. package/dist/components/FitText.js +13 -1
  29. package/dist/components/Indicator.js +113 -1
  30. package/dist/components/IndicatorButton.js +187 -1
  31. package/dist/components/IndicatorRect.js +93 -1
  32. package/dist/components/JogPanel.js +295 -1
  33. package/dist/components/Lamp.js +161 -1
  34. package/dist/components/Osk.js +125 -1
  35. package/dist/components/OskDialog.js +128 -1
  36. package/dist/components/ProgressBarWithValue.js +18 -1
  37. package/dist/components/TextInput.js +139 -1
  38. package/dist/components/ToggleGroup.js +204 -1
  39. package/dist/components/ValueDisplay.js +160 -1
  40. package/dist/components/ValueIndicator.js +38 -1
  41. package/dist/components/ValueInput.js +158 -1
  42. package/dist/core/ActionMode.js +18 -1
  43. package/dist/core/EventEmitterContext.js +252 -1
  44. package/dist/core/IndicatorButtonState.js +9 -1
  45. package/dist/core/IndicatorColor.js +36 -1
  46. package/dist/core/MaskPatterns.js +80 -1
  47. package/dist/core/NumerableTypes.js +10 -1
  48. package/dist/core/PositionContext.js +24 -1
  49. package/dist/core/UniqueId.js +32 -1
  50. package/dist/core/ValueSimulator.js +233 -1
  51. package/dist/core/hoc.js +44 -1
  52. package/dist/hooks/adsHooks.js +253 -1
  53. package/dist/hooks/commandHooks.js +252 -1
  54. package/dist/hooks/index.js +10 -1
  55. package/dist/hooks/useScaledValue.js +86 -1
  56. package/dist/hub/CommandMessage.js +9 -1
  57. package/dist/hub/HubBase.js +310 -1
  58. package/dist/hub/HubSimulate.js +46 -1
  59. package/dist/hub/HubTauri.js +130 -1
  60. package/dist/hub/HubWebSocket.js +240 -1
  61. package/dist/hub/index.js +57 -1
  62. package/package.json +3 -3
@@ -1 +1,125 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useEffect,useRef}from"react";import{InputText}from"primereact/inputtext";import Keyboard from"react-simple-keyboard";import"./osk.css";import{RegExMaskPatterns}from"../core/MaskPatterns";const numpadLayout={numbers:["1 2 3","4 5 6","7 8 9","- 0 .","{symbols} {backspace}"],default:["! / #","$ % ^","& * (","= ) +","{numbers} {backspace}"]},englishLayout={default:["q w e r t y u i o p","a s d f g h j k l","{shift} z x c v b n m {backspace}","{numbers} {space} {ent}"],shift:["Q W E R T Y U I O P","A S D F G H J K L","{shift} Z X C V B N M {backspace}","{numbers} {space} {ent}"],numbers:["1 2 3","4 5 6","7 8 9","{abc} 0 {backspace}"]},keyboardDisplay={"{numbers}":"123","{ent}":"return","{escape}":"esc ⎋","{tab}":"tab ⇥","{backspace}":"⌫","{capslock}":"caps lock ⇪","{shift}":"⇧","{controlleft}":"ctrl ⌃","{controlright}":"ctrl ⌃","{altleft}":"alt ⌥","{altright}":"alt ⌥","{metaleft}":"cmd ⌘","{metaright}":"cmd ⌘","{abc}":"ABC","{space}":"space","{symbols}":"#+="};export const Osk=({onAccept:e,onChange:t,isNumPad:s=!1,input:a="",label:r="",inputPattern:n,checkValue:i,description:o})=>{const[u,c]=useState({isVisible:!1,layoutName:s?"numbers":"default",minWidth:500,maxWidth:800,input:a,label:r,isNumPad:s,inputPattern:n||RegExMaskPatterns.IntegerPositive,checkValue:i,description:o,firstKeyPressed:!1,onAccept:e||void 0,onChange:t||void 0}),l=useRef(null);useEffect((()=>()=>{l.current&&l.current.destroy()}),[]);const p=()=>{let e="default"===u.layoutName?"shift":"default";c((t=>({...t,layoutName:e})))},m=()=>{let e="numbers"!==u.layoutName?"numbers":"default";c((t=>({...t,layoutName:e})))};return _jsxs("div",{children:[_jsx(InputText,{value:u.input,readOnly:!0,tooltip:u.description}),_jsx("br",{}),_jsx(Keyboard,{keyboardRef:e=>l.current=e,name:"keyboard",layoutName:u.layoutName,layout:(()=>{if(u.isNumPad)return u.isNumPad?(void 0!==u.inputPattern&&null!==u.inputPattern||c((e=>({...e,inputPattern:RegExMaskPatterns.IntegerPositive}))),numpadLayout):englishLayout})(),display:keyboardDisplay,physicalKeyboardHighlight:!0,physicalKeyboardHighlightPress:!0,onChange:e=>(e=>{let t=e;u.firstKeyPressed||(t=u.input+e,l.current.setInput(t)),u.onChange&&u.onChange(t),c((e=>({...e,input:t,firstKeyPressed:!0})))})(e),onKeyPress:e=>(e=>{"{shift}"!==e&&"{lock}"!==e&&"{symbols}"!=e||p(),"{numbers}"!==e&&"{abc}"!==e||m(),"{backspace}"===e&&(u.firstKeyPressed||c((e=>({...e,input:"",firstKeyPressed:!0}))))})(e)})]})};export default Osk;
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from 'react';
3
+ import { InputText } from 'primereact/inputtext';
4
+ import Keyboard from "react-simple-keyboard";
5
+ import "./osk.css";
6
+ import { RegExMaskPatterns } from "../core/MaskPatterns";
7
+ const numpadLayout = {
8
+ numbers: ["1 2 3", "4 5 6", "7 8 9", "- 0 .", "{symbols} {backspace}"],
9
+ default: ["! / #", "$ % ^", "& * (", "= ) +", "{numbers} {backspace}"]
10
+ };
11
+ const englishLayout = {
12
+ default: [
13
+ "q w e r t y u i o p",
14
+ "a s d f g h j k l",
15
+ "{shift} z x c v b n m {backspace}",
16
+ "{numbers} {space} {ent}"
17
+ ],
18
+ shift: [
19
+ "Q W E R T Y U I O P",
20
+ "A S D F G H J K L",
21
+ "{shift} Z X C V B N M {backspace}",
22
+ "{numbers} {space} {ent}"
23
+ ],
24
+ numbers: ["1 2 3", "4 5 6", "7 8 9", "{abc} 0 {backspace}"]
25
+ };
26
+ const keyboardDisplay = {
27
+ "{numbers}": "123",
28
+ "{ent}": "return",
29
+ "{escape}": "esc ⎋",
30
+ "{tab}": "tab ⇥",
31
+ "{backspace}": "⌫",
32
+ "{capslock}": "caps lock ⇪",
33
+ "{shift}": "⇧",
34
+ "{controlleft}": "ctrl ⌃",
35
+ "{controlright}": "ctrl ⌃",
36
+ "{altleft}": "alt ⌥",
37
+ "{altright}": "alt ⌥",
38
+ "{metaleft}": "cmd ⌘",
39
+ "{metaright}": "cmd ⌘",
40
+ "{abc}": "ABC",
41
+ "{space}": "space",
42
+ "{symbols}": "#+="
43
+ };
44
+ export const Osk = ({ onAccept, onChange, isNumPad = false, input = "", label = "", inputPattern, checkValue, description, }) => {
45
+ const [state, setState] = useState({
46
+ isVisible: false,
47
+ layoutName: isNumPad ? "numbers" : "default",
48
+ minWidth: 500,
49
+ maxWidth: 800,
50
+ input,
51
+ label,
52
+ isNumPad,
53
+ inputPattern: inputPattern || RegExMaskPatterns.IntegerPositive,
54
+ checkValue,
55
+ description,
56
+ firstKeyPressed: false,
57
+ onAccept: onAccept || undefined,
58
+ onChange: onChange || undefined
59
+ });
60
+ const keyboardRef = useRef(null);
61
+ useEffect(() => {
62
+ return () => {
63
+ if (keyboardRef.current) {
64
+ keyboardRef.current.destroy();
65
+ }
66
+ };
67
+ }, []);
68
+ // const setProperty = (key: keyof typeof state, val: any) => {
69
+ // setState((prev) => ({ ...prev, [key]: val }));
70
+ // };
71
+ const onChanged = (val) => {
72
+ let newInput = val;
73
+ if (!state.firstKeyPressed) {
74
+ newInput = state.input + val;
75
+ keyboardRef.current.setInput(newInput);
76
+ }
77
+ if (state.onChange) {
78
+ state.onChange(newInput);
79
+ }
80
+ setState(prevState => ({ ...prevState, input: newInput, firstKeyPressed: true }));
81
+ };
82
+ const getLayout = () => {
83
+ if (state.isNumPad) {
84
+ if (state.isNumPad) {
85
+ if (state.inputPattern === undefined || state.inputPattern === null) {
86
+ setState(prevState => ({ ...prevState, inputPattern: RegExMaskPatterns.IntegerPositive }));
87
+ }
88
+ return numpadLayout;
89
+ }
90
+ else {
91
+ return englishLayout;
92
+ }
93
+ }
94
+ };
95
+ const onKeyPress = (button) => {
96
+ if (button === "{shift}" || button === "{lock}" || button == "{symbols}")
97
+ handleShift();
98
+ if (button === "{numbers}" || button === "{abc}")
99
+ handleNumbers();
100
+ if (button === "{backspace}") {
101
+ // Backspace was pressed
102
+ if (!state.firstKeyPressed) {
103
+ setState(prevState => ({ ...prevState, input: "", firstKeyPressed: true }));
104
+ }
105
+ }
106
+ };
107
+ /**
108
+ * Toggle between the shifted and default display when the shift key is pressed.
109
+ */
110
+ const handleShift = () => {
111
+ let currentLayout = state.layoutName;
112
+ let shiftToggle = currentLayout === "default" ? "shift" : "default";
113
+ setState(prevState => ({ ...prevState, layoutName: shiftToggle }));
114
+ };
115
+ /**
116
+ * Toggle between the number and alpha-numeric display when the numbers key is pressed.
117
+ */
118
+ const handleNumbers = () => {
119
+ let currentLayout = state.layoutName;
120
+ let numbersToggle = currentLayout !== "numbers" ? "numbers" : "default";
121
+ setState(prevState => ({ ...prevState, layoutName: numbersToggle }));
122
+ };
123
+ return (_jsxs("div", { children: [_jsx(InputText, { value: state.input, readOnly: true, tooltip: state.description }), _jsx("br", {}), _jsx(Keyboard, { keyboardRef: (r) => (keyboardRef.current = r), name: 'keyboard', layoutName: state.layoutName, layout: getLayout(), display: keyboardDisplay, physicalKeyboardHighlight: true, physicalKeyboardHighlightPress: true, onChange: (val) => onChanged(val), onKeyPress: (button) => onKeyPress(button) })] }));
124
+ };
125
+ export default Osk;
@@ -1 +1,128 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import ReactDOM from"react-dom";import{Dialog}from"primereact/dialog";import{Button}from"primereact/button";import{Osk}from"./Osk";export class OskDialog extends React.Component{constructor(e){super(e),Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"checkValue",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var t=!0;if(null!=e&&e.length>0)if(void 0!==this.props.inputPattern)t=this.props.inputPattern.test(e);else if(this.props.textMode)void 0!==this.props.minLength&&e.length<this.props.minLength&&(t=!1);else{e.length<0&&(t=!1),isNaN(parseFloat(e))&&(t=!1);var i=parseFloat(e);void 0!==this.props.minValue&&null!==this.props.minValue&&i<this.props.minValue&&(t=!1),void 0!==this.props.maxValue&&null!==this.props.maxValue&&i>this.props.maxValue&&(t=!1)}else t=!1;return t?"":"Invalid value."}}),Object.defineProperty(this,"onAccepted",{enumerable:!0,configurable:!0,writable:!0,value:()=>{const e=this.checkValue(this.state.input);e?this.setState({errorMessage:e}):(this.props.onAccept?.(this.state.input),this.closeDialog())}}),Object.defineProperty(this,"onChanged",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({input:e,errorMessage:""}),this.props.onChange&&this.props.onChange(e)}}),Object.defineProperty(this,"closeDialog",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.container&&(ReactDOM.unmountComponentAtNode(this.container),this.container=null),this.props.onReject?.()}}),Object.defineProperty(this,"show",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.container||(this.container=document.createElement("div"),document.body.appendChild(this.container));const e=_jsxs("div",{children:[_jsx(Button,{label:"Cancel",icon:"pi pi-times",onClick:()=>this.closeDialog(),className:"p-button-text"}),_jsx(Button,{label:"Accept",icon:"pi pi-check",onClick:()=>this.onAccepted(),autoFocus:!0})]});ReactDOM.render(_jsxs(Dialog,{visible:this.props.isVisible,onHide:this.closeDialog,header:this.props.label,style:{width:this.props.maxWidth||"50vw"},footer:e,children:[_jsx(Osk,{onChange:this.onChanged,isNumPad:this.props.isNumPad,inputPattern:this.props.inputPattern,input:this.state.input}),this.state.errorMessage&&_jsx("div",{className:"error-message",children:this.state.errorMessage})]}),this.container)}}),this.state={input:e.input||"",errorMessage:""}}componentWillUnmount(){this.container&&document.body.removeChild(this.container)}render(){return null}}export default OskDialog;
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import ReactDOM from 'react-dom';
4
+ import { Dialog } from 'primereact/dialog';
5
+ import { Button } from "primereact/button";
6
+ import { Osk } from './Osk';
7
+ export class OskDialog extends React.Component {
8
+ constructor(props) {
9
+ super(props);
10
+ Object.defineProperty(this, "container", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: null
15
+ });
16
+ Object.defineProperty(this, "checkValue", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: (value) => {
21
+ // Checks the value against settings and returns an error message
22
+ // if invalid. If the value is valid and should be accepted,
23
+ // a blank error message is returned.
24
+ var ok = true;
25
+ if (value !== undefined && value !== null && value.length > 0) {
26
+ if (this.props.inputPattern !== undefined) {
27
+ ok = this.props.inputPattern.test(value);
28
+ }
29
+ else if (!this.props.textMode) {
30
+ if (value.length < 0)
31
+ ok = false;
32
+ if (isNaN(parseFloat(value)))
33
+ ok = false;
34
+ var checkValue = parseFloat(value);
35
+ if (this.props.minValue !== undefined && this.props.minValue !== null) {
36
+ if (checkValue < this.props.minValue)
37
+ ok = false;
38
+ }
39
+ if (this.props.maxValue !== undefined && this.props.maxValue !== null) {
40
+ if (checkValue > this.props.maxValue)
41
+ ok = false;
42
+ }
43
+ }
44
+ else {
45
+ if (this.props.minLength !== undefined
46
+ && value.length < this.props.minLength) {
47
+ ok = false;
48
+ }
49
+ }
50
+ }
51
+ else {
52
+ ok = false;
53
+ }
54
+ if (ok) {
55
+ return "";
56
+ }
57
+ else {
58
+ return "Invalid value.";
59
+ }
60
+ }
61
+ });
62
+ Object.defineProperty(this, "onAccepted", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: () => {
67
+ const error = this.checkValue(this.state.input);
68
+ if (!error) {
69
+ this.props.onAccept?.(this.state.input);
70
+ this.closeDialog();
71
+ }
72
+ else {
73
+ this.setState({ errorMessage: error });
74
+ }
75
+ }
76
+ });
77
+ Object.defineProperty(this, "onChanged", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: (val) => {
82
+ this.setState({ input: val, errorMessage: "" });
83
+ if (this.props.onChange) {
84
+ this.props.onChange(val);
85
+ }
86
+ }
87
+ });
88
+ Object.defineProperty(this, "closeDialog", {
89
+ enumerable: true,
90
+ configurable: true,
91
+ writable: true,
92
+ value: () => {
93
+ if (this.container) {
94
+ ReactDOM.unmountComponentAtNode(this.container);
95
+ this.container = null;
96
+ }
97
+ this.props.onReject?.();
98
+ }
99
+ });
100
+ Object.defineProperty(this, "show", {
101
+ enumerable: true,
102
+ configurable: true,
103
+ writable: true,
104
+ value: () => {
105
+ if (!this.container) {
106
+ this.container = document.createElement('div');
107
+ document.body.appendChild(this.container);
108
+ }
109
+ const footerContent = (_jsxs("div", { children: [_jsx(Button, { label: "Cancel", icon: "pi pi-times", onClick: () => this.closeDialog(), className: "p-button-text" }), _jsx(Button, { label: "Accept", icon: "pi pi-check", onClick: () => this.onAccepted(), autoFocus: true })] }));
110
+ ReactDOM.render(_jsxs(Dialog, { visible: this.props.isVisible, onHide: this.closeDialog, header: this.props.label, style: { width: this.props.maxWidth || '50vw' }, footer: footerContent, children: [_jsx(Osk, { onChange: this.onChanged, isNumPad: this.props.isNumPad, inputPattern: this.props.inputPattern, input: this.state.input }), this.state.errorMessage && _jsx("div", { className: "error-message", children: this.state.errorMessage })] }), this.container);
111
+ }
112
+ });
113
+ this.state = {
114
+ input: props.input || "",
115
+ errorMessage: ""
116
+ };
117
+ }
118
+ componentWillUnmount() {
119
+ if (this.container) {
120
+ document.body.removeChild(this.container);
121
+ }
122
+ }
123
+ render() {
124
+ // The actual rendering is handled by the show method.
125
+ return null;
126
+ }
127
+ }
128
+ export default OskDialog;
@@ -1 +1,18 @@
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;
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ProgressBar } from 'primereact/progressbar';
3
+ import './ProgressBarWithValue.css'; // Import your custom CSS
4
+ export const ProgressBarWithValue = ({ value, max, label }) => {
5
+ let progressValue = value;
6
+ let indeterminate = false;
7
+ if (max !== undefined) {
8
+ if (max > 0) {
9
+ progressValue = (value / max) * 100; // Calculate percentage
10
+ }
11
+ else { // max === 0
12
+ progressValue = 0;
13
+ indeterminate = true;
14
+ }
15
+ }
16
+ return (_jsxs("div", { className: "custom-progress-bar", children: [_jsx(ProgressBar, { showValue: false, value: progressValue, mode: indeterminate ? 'indeterminate' : 'determinate' }), _jsxs("div", { className: "centered-value", children: [label ? `${label} ` : '', " ", value, " ", max ? `of ${max}` : ''] })] }));
17
+ };
18
+ export default ProgressBarWithValue;
@@ -1 +1,139 @@
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(){const{prefix:t,...e}=this.props;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,{...e,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";
2
+ /*
3
+ * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
4
+ * Created Date: 2024-03-20 13:05:42
5
+ * -----
6
+ * Last Modified: 2024-05-17 10:04:53
7
+ * -----
8
+ *
9
+ */
10
+ import React from "react";
11
+ import { InputText } from 'primereact/inputtext';
12
+ import { Button } from "primereact/button";
13
+ import { EventEmitterContext } from "../core/EventEmitterContext.js";
14
+ /**
15
+ * A convenient field with all the usual features of inputing values.
16
+ * Wraps the common features of use of a InputText, p-inputgroup, some icon buttons,
17
+ * accepting and rejecting values and keyboard management.
18
+ */
19
+ export class TextInput extends React.Component {
20
+ /**
21
+ *
22
+ * @param {FooterViewProps} props
23
+ */
24
+ constructor(props) {
25
+ super(props);
26
+ /**
27
+ * Check the new value against the validator RegEx, if one was specified.
28
+ * @param val The new value.
29
+ * @returns True if no validator specified or the value is valid, false if not valid.
30
+ */
31
+ Object.defineProperty(this, "validateValue", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: (val) => {
36
+ if (this.props.validator !== undefined && this.props.validator !== null) {
37
+ return this.props.validator.test(val);
38
+ }
39
+ else {
40
+ return true;
41
+ }
42
+ }
43
+ });
44
+ this.state = {
45
+ entryValue: props.value,
46
+ isValid: props.value !== undefined ? this.validateValue(props.value) : false,
47
+ editing: false
48
+ };
49
+ }
50
+ /**
51
+ * The component has been loaded into the DOM.
52
+ */
53
+ componentDidMount() {
54
+ }
55
+ componentDidUpdate(prevProps) {
56
+ // Check if the value prop has changed
57
+ if (prevProps.value !== this.props.value) {
58
+ this.setState({
59
+ entryValue: this.props.value,
60
+ editing: false
61
+ });
62
+ }
63
+ }
64
+ /**
65
+ * The user has elected to accept the input value. Validate and store, if valid.
66
+ */
67
+ onAcceptValue() {
68
+ if (this.state.entryValue !== undefined) {
69
+ if (this.validateValue(this.state.entryValue)) {
70
+ this.setState({ isValid: true, editing: false });
71
+ if (this.props.onValueChanged)
72
+ this.props.onValueChanged(this.state.entryValue);
73
+ if (this.props.dispatchTopic !== undefined) {
74
+ this.context.dispatch({ topic: this.props.dispatchTopic, payload: this.state.entryValue });
75
+ }
76
+ }
77
+ else {
78
+ this.setState({ isValid: false });
79
+ }
80
+ }
81
+ else {
82
+ this.setState({ isValid: false });
83
+ }
84
+ }
85
+ /**
86
+ * The user wishes to reset/cancel the previous value.
87
+ */
88
+ onResetValue() {
89
+ this.setState({
90
+ entryValue: this.props.value,
91
+ isValid: this.props.value !== undefined ? this.validateValue(this.props.value) : false,
92
+ editing: false
93
+ });
94
+ }
95
+ render() {
96
+ const { prefix, ...restProps } = this.props;
97
+ return (_jsxs("div", { children: [_jsxs("div", { className: "p-inputgroup flex-1", children: [_jsx("span", { className: "p-inputgroup-addon", children: this.props.label }), this.props.prefix !== undefined &&
98
+ _jsx("span", { className: "p-inputgroup-addon", children: this.props.prefix }), _jsx(InputText, { ...restProps, keyfilter: this.props.keyFilter, placeholder: this.props.placeholder, value: this.state.entryValue, onChange: (e) => { this.setState({ entryValue: e.target.value, editing: true }); }, className: this.state.isValid ? '' : 'p-invalid', onKeyDown: (e) => {
99
+ if (e.key === 'Enter') {
100
+ this.onAcceptValue();
101
+ }
102
+ else if (e.key === 'Escape') {
103
+ this.onResetValue();
104
+ }
105
+ }, disabled: this.props.disabled }), this.props.suffix !== undefined &&
106
+ _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 })] }), this.props.description !== undefined &&
107
+ _jsx("small", { children: this.props.description })] }));
108
+ }
109
+ }
110
+ // Here's an example of using the Application-wide EventEmitter con
111
+ // Define the contextType for the class to access the context
112
+ Object.defineProperty(TextInput, "contextType", {
113
+ enumerable: true,
114
+ configurable: true,
115
+ writable: true,
116
+ value: EventEmitterContext
117
+ });
118
+ /**
119
+ * Default properties for the component.
120
+ */
121
+ Object.defineProperty(TextInput, "defaultProps", {
122
+ enumerable: true,
123
+ configurable: true,
124
+ writable: true,
125
+ value: {
126
+ label: '',
127
+ value: undefined,
128
+ keyFilter: undefined,
129
+ writeTopic: undefined,
130
+ onValueChanged: undefined,
131
+ description: undefined,
132
+ prefix: undefined,
133
+ suffix: undefined,
134
+ disabled: false,
135
+ dispatchTopic: undefined,
136
+ placeholder: undefined,
137
+ validator: undefined
138
+ }
139
+ });
@@ -1 +1,204 @@
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
4
+ * Created Date: 2024-03-12 10:14:48
5
+ * -----
6
+ * Last Modified: 2024-04-29 10:43:49
7
+ * -----
8
+ *
9
+ */
10
+ import { useState, useEffect, useContext } from 'react';
11
+ import { SelectButton } from 'primereact/selectbutton';
12
+ import { EventEmitterContext } from '../core/EventEmitterContext';
13
+ import { IndicatorColor } from "../core/IndicatorColor";
14
+ export { IndicatorColor };
15
+ import { ActionMode } from '../core/ActionMode';
16
+ export { ActionMode };
17
+ import clsx from 'clsx';
18
+ export const ToggleGroup = ({ label, topic, onColor, offColor, command, commandTopic, commandArgs, disableTopic, invisibleTopic, actionMode, invert, onValueChanged: onValueChange, ...restProps }) => {
19
+ const [uniqueId] = useState(() => `toggleGroup-${Math.random().toString(36).substr(2, 9)}`);
20
+ const [currentValue, setCurrentValue] = useState(undefined);
21
+ const [isDisabled, setIsDisabled] = useState(false);
22
+ const [isInvisible, setIsInvisible] = useState(false);
23
+ const [isPressed, setIsPressed] = useState(false);
24
+ const context = useContext(EventEmitterContext);
25
+ useEffect(() => {
26
+ const setupSubscriptions = () => {
27
+ if (topic) {
28
+ context.subscribe(topic, handleTopicUpdate);
29
+ }
30
+ if (disableTopic) {
31
+ context.subscribe(disableTopic, handleDisableTopicUpdate);
32
+ }
33
+ if (invisibleTopic) {
34
+ context.subscribe(invisibleTopic, handleInvisibleTopicUpdate);
35
+ }
36
+ };
37
+ setupSubscriptions();
38
+ return () => {
39
+ // Unsubscribe logic here
40
+ };
41
+ }, [topic, disableTopic, invisibleTopic]);
42
+ const handleTopicUpdate = (value) => {
43
+ setCurrentValue(value);
44
+ };
45
+ const handleDisableTopicUpdate = (value) => {
46
+ setIsDisabled(value);
47
+ };
48
+ const handleInvisibleTopicUpdate = (value) => {
49
+ setIsInvisible(value);
50
+ };
51
+ const handleOnPressed = () => {
52
+ if (!isPressed) {
53
+ setIsPressed(true);
54
+ if (actionMode === ActionMode.Tap || actionMode === ActionMode.Pressed) {
55
+ dispatchCommand(true);
56
+ }
57
+ }
58
+ };
59
+ const handleOnReleased = () => {
60
+ if (isPressed) {
61
+ setIsPressed(false);
62
+ if (actionMode === ActionMode.Tap) {
63
+ dispatchCommand(false);
64
+ }
65
+ else if (actionMode === ActionMode.Released) {
66
+ dispatchCommand(true);
67
+ }
68
+ }
69
+ };
70
+ const dispatchCommand = (value) => {
71
+ if (command && command.length > 0) {
72
+ const payload = {
73
+ topic: commandTopic,
74
+ value: value,
75
+ ...commandArgs
76
+ };
77
+ context.dispatch({
78
+ topic: command,
79
+ payload: payload
80
+ });
81
+ }
82
+ };
83
+ let displayValue = currentValue;
84
+ if (restProps.value !== undefined) {
85
+ displayValue = restProps.value;
86
+ }
87
+ /**
88
+ *
89
+ * @param currentValue
90
+ * @param options
91
+ * @returns
92
+ */
93
+ const selectOnColor = (currentValue, options, onColorProp) => {
94
+ if (!options || options.length === 0)
95
+ return IndicatorColor.IndicatorInvalid;
96
+ let colorArray = Array.isArray(onColorProp) ? onColorProp :
97
+ onColorProp !== undefined ? [onColorProp] : [IndicatorColor.IndicatorInvalid];
98
+ let t = typeof (currentValue);
99
+ if (t === "boolean") {
100
+ return currentValue ? colorArray[0] : colorArray.length > 1 ? colorArray[1] : colorArray[0];
101
+ }
102
+ else if (t === "number" && options.length > currentValue) {
103
+ if (colorArray.length > currentValue) {
104
+ let index = currentValue;
105
+ return colorArray[index];
106
+ }
107
+ else {
108
+ return colorArray[0];
109
+ }
110
+ }
111
+ else if (t === "string") {
112
+ let index = options.indexOf(currentValue);
113
+ if (index !== -1 && index < colorArray.length)
114
+ return colorArray[index];
115
+ else
116
+ return colorArray[0];
117
+ }
118
+ if (onColorProp !== undefined && onColorProp !== null) {
119
+ return Array.isArray(onColorProp) ? onColorProp[0] : onColorProp;
120
+ }
121
+ else {
122
+ return IndicatorColor.IndicatorInvalid;
123
+ }
124
+ };
125
+ /**
126
+ *
127
+ * @param currentValue
128
+ * @param options
129
+ * @returns
130
+ */
131
+ const matchCurrentValue = (currentValue, options) => {
132
+ if (options === undefined || options === null || options.length === 0)
133
+ return undefined;
134
+ let t = typeof (currentValue);
135
+ if (t == "boolean") {
136
+ let b = currentValue;
137
+ if (b) {
138
+ if (options.length > 1)
139
+ return options[1];
140
+ else
141
+ return options[0];
142
+ }
143
+ else {
144
+ return options[0];
145
+ }
146
+ }
147
+ else if (t == "number") {
148
+ let n = currentValue;
149
+ if (n !== undefined && n < options.length) {
150
+ return options[n];
151
+ }
152
+ }
153
+ else if (t == "string") {
154
+ // The SelectButton should match to this value automatically, if it's in the
155
+ // options array. No reason to search twice.
156
+ return currentValue;
157
+ }
158
+ return undefined;
159
+ };
160
+ let color = selectOnColor(displayValue, restProps.options, onColor);
161
+ if (displayValue === undefined) {
162
+ color = IndicatorColor.IndicatorInvalid;
163
+ }
164
+ const isMultiple = restProps.options !== undefined
165
+ && restProps.options !== null
166
+ && restProps.options.length !== undefined
167
+ && restProps.options.length > 2;
168
+ const toggleGroupName = `${uniqueId}-togglegroup-selectbutton-container`;
169
+ const handleValueChange = (label) => {
170
+ if (onValueChange !== undefined && onValueChange !== null) {
171
+ if (restProps.options === undefined || restProps.options === null || restProps.options.length === 0) {
172
+ if (isMultiple)
173
+ onValueChange(0);
174
+ else
175
+ onValueChange(false);
176
+ }
177
+ else {
178
+ let index = 0;
179
+ for (let i = 0; i < restProps.options.length; ++i) {
180
+ if (label === restProps.options[i]) {
181
+ index = i;
182
+ break;
183
+ }
184
+ }
185
+ if (isMultiple)
186
+ onValueChange(index);
187
+ else
188
+ onValueChange(index > 0);
189
+ }
190
+ }
191
+ };
192
+ return (_jsxs("div", { className: "flex", children: [_jsx("style", { children: `
193
+ ${offColor !== undefined ? `
194
+ .${toggleGroupName} .p-selectbutton .p-button {
195
+ background-color: ${offColor};
196
+ }
197
+ ` : ''}
198
+ .${toggleGroupName} .p-selectbutton .p-button.p-highlight {
199
+ background-color: ${color} !important;
200
+ border-color: ${color} !important;
201
+ }
202
+ ` }), _jsx("div", { className: toggleGroupName, children: _jsxs("div", { className: "p-inputgroup", children: [_jsx("span", { className: "p-inputgroup-addon", style: { flexGrow: 1 }, children: label }), _jsx(SelectButton, { ...restProps, options: restProps.options, disabled: isDisabled || restProps.disabled, multiple: isMultiple, className: clsx(uniqueId, restProps.className, { 'p-invalid': restProps.value === undefined }), style: isInvisible ? { display: 'none' } : {}, value: matchCurrentValue(displayValue, restProps.options), allowEmpty: false, onMouseDown: handleOnPressed, onTouchStart: handleOnPressed, onMouseUp: handleOnReleased, onTouchEnd: handleOnReleased, onChange: (e) => handleValueChange(e.value) })] }) })] }));
203
+ };
204
+ export default ToggleGroup;