@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.
- package/dist/assets/BlocklyLogo.js +9 -1
- package/dist/assets/Distance.js +5 -1
- package/dist/assets/JogLong.js +3 -1
- package/dist/assets/JogMedium.js +3 -1
- package/dist/assets/JogShort.js +3 -1
- package/dist/assets/PythonLogo.js +21 -1
- package/dist/assets/Rotation3D.js +3 -1
- package/dist/assets/RotationCcw.js +10 -1
- package/dist/assets/RotationCcwA.js +16 -1
- package/dist/assets/RotationCcwB.js +16 -1
- package/dist/assets/RotationCcwC.js +16 -1
- package/dist/assets/RotationCw.js +10 -1
- package/dist/assets/RotationCwA.js +16 -1
- package/dist/assets/RotationCwB.js +16 -1
- package/dist/assets/RotationCwC.js +16 -1
- package/dist/assets/Run.js +3 -1
- package/dist/assets/Speed.js +5 -1
- package/dist/assets/SpeedFast.js +3 -1
- package/dist/assets/SpeedMedium.js +3 -1
- package/dist/assets/SpeedNone.js +3 -1
- package/dist/assets/SpeedSlow.js +3 -1
- package/dist/assets/Walk.js +3 -1
- package/dist/assets/index.js +22 -1
- package/dist/components/BlocklyEditor.js +508 -1
- package/dist/components/CodeEditor.js +108 -1
- package/dist/components/FileList.js +218 -1
- package/dist/components/FileSelect.js +63 -1
- package/dist/components/FitText.js +13 -1
- package/dist/components/Indicator.js +113 -1
- package/dist/components/IndicatorButton.js +187 -1
- package/dist/components/IndicatorRect.js +93 -1
- package/dist/components/JogPanel.js +295 -1
- package/dist/components/Lamp.js +161 -1
- package/dist/components/Osk.js +125 -1
- package/dist/components/OskDialog.js +128 -1
- package/dist/components/ProgressBarWithValue.js +18 -1
- package/dist/components/TextInput.js +139 -1
- package/dist/components/ToggleGroup.js +204 -1
- package/dist/components/ValueDisplay.js +160 -1
- package/dist/components/ValueIndicator.js +38 -1
- package/dist/components/ValueInput.js +158 -1
- package/dist/core/ActionMode.js +18 -1
- package/dist/core/EventEmitterContext.js +252 -1
- package/dist/core/IndicatorButtonState.js +9 -1
- package/dist/core/IndicatorColor.js +36 -1
- package/dist/core/MaskPatterns.js +80 -1
- package/dist/core/NumerableTypes.js +10 -1
- package/dist/core/PositionContext.js +24 -1
- package/dist/core/UniqueId.js +32 -1
- package/dist/core/ValueSimulator.js +233 -1
- package/dist/core/hoc.js +44 -1
- package/dist/hooks/adsHooks.js +253 -1
- package/dist/hooks/commandHooks.js +252 -1
- package/dist/hooks/index.js +10 -1
- package/dist/hooks/useScaledValue.js +86 -1
- package/dist/hub/CommandMessage.js +9 -1
- package/dist/hub/HubBase.js +310 -1
- package/dist/hub/HubSimulate.js +46 -1
- package/dist/hub/HubTauri.js +130 -1
- package/dist/hub/HubWebSocket.js +240 -1
- package/dist/hub/index.js +57 -1
- package/package.json +3 -3
package/dist/components/Osk.js
CHANGED
|
@@ -1 +1,125 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";
|
|
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";
|
|
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";
|
|
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";
|
|
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";
|
|
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;
|