@adcops/autocore-react 3.0.5 → 3.0.8
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/FitText.d.ts +13 -0
- package/dist/components/FitText.js +1 -0
- package/dist/components/ValueIndicator.css +32 -0
- package/dist/components/ValueIndicator.d.ts +66 -0
- package/dist/components/ValueIndicator.js +1 -0
- package/dist/core/EventEmitterContext.js +1 -1
- package/package.json +1 -1
- package/src/components/FitText.tsx +36 -0
- package/src/components/ValueIndicator.css +32 -0
- package/src/components/ValueIndicator.tsx +136 -0
- package/src/core/EventEmitterContext.tsx +8 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FitTextProps {
|
|
3
|
+
/** The children prop expects any valid React node. */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* FitText dynamically adjusts the font size of its children to fit the parent container.
|
|
8
|
+
*
|
|
9
|
+
* @param {FitTextProps} props The props for the FitText component.
|
|
10
|
+
* @returns A div element that resizes its child text to fit.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FitText: React.FC<FitTextProps>;
|
|
13
|
+
export default FitText;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import useFitText from"use-fit-text";export const FitText=({children:t})=>{const{fontSize:e,ref:i}=useFitText();return _jsx("div",{ref:i,style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:_jsx("p",{style:{fontSize:e},children:t})})};export default FitText;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-03-22 06:26:45
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-03-22 07:07:50
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
.value-indicator-container {
|
|
13
|
+
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
background-color: var(--surface-ground);
|
|
17
|
+
border-color: var(--surface-border);
|
|
18
|
+
border-radius: var(--border-radius);
|
|
19
|
+
border-width: 1px;
|
|
20
|
+
border-style: solid;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
padding: 2mm;
|
|
24
|
+
flex-grow: 1; /* Allow the item to grow to fill available space */
|
|
25
|
+
flex-shrink: 0; /* Allow the item to shrink if necessary */
|
|
26
|
+
flex-basis: 0; /* Start with 0 width and then grow as needed, equal distribution */
|
|
27
|
+
min-width: 0; /* Prevents flex items from overflowing their container */
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.value-indicator-label {
|
|
31
|
+
padding-bottom: 1mm;
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import type { NumerableFormatOptions } from '../core/NumerableTypes';
|
|
3
|
+
import "./ValueIndicator.css";
|
|
4
|
+
/**
|
|
5
|
+
* Properties of the ValueDisplay component.
|
|
6
|
+
*/
|
|
7
|
+
interface ValueIndicatorProps {
|
|
8
|
+
/**
|
|
9
|
+
* Label for the indicator.
|
|
10
|
+
*/
|
|
11
|
+
label?: React.ReactNode | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Value to be displayed
|
|
14
|
+
*/
|
|
15
|
+
value?: string | number | null | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Tooltip to display on hover
|
|
18
|
+
*/
|
|
19
|
+
tooltip?: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Format for `value`<br/>
|
|
22
|
+
* See [numerable formats](https://github.com/gastonmesseri/numerable#1234-formatting-numbers)
|
|
23
|
+
*/
|
|
24
|
+
format?: string | null | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Format options for `value`<br/>
|
|
27
|
+
* See [numerable format options](https://github.com/gastonmesseri/numerable#format)
|
|
28
|
+
*/
|
|
29
|
+
formatOptions?: NumerableFormatOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Custom class name to be attached
|
|
32
|
+
*/
|
|
33
|
+
className?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The topic to monitor to display. Optional.
|
|
36
|
+
*/
|
|
37
|
+
topic?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional style properties.
|
|
40
|
+
*/
|
|
41
|
+
style?: React.CSSProperties | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* State of the ValueDisplay component.
|
|
45
|
+
*/
|
|
46
|
+
interface ValueIndicatorState {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `ValueIndicator` wraps `ValueDisplay` in a frame and label, giving it a widget appearance.
|
|
50
|
+
* Care is taken to adapt to the selected theme of the application.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export declare class ValueIndicator extends Component<ValueIndicatorProps, ValueIndicatorState> {
|
|
54
|
+
/**
|
|
55
|
+
* The constructor initializes the component state and binds the initial value.
|
|
56
|
+
* @param {ValueIndicatorProps} props The properties passed to the component, including initial value and other display options.
|
|
57
|
+
*/
|
|
58
|
+
constructor(props: ValueIndicatorProps);
|
|
59
|
+
/**
|
|
60
|
+
* Renders the component into the DOM.
|
|
61
|
+
* @returns A styled `div` element displaying the indicator.
|
|
62
|
+
*/
|
|
63
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
}
|
|
65
|
+
export default ValueIndicator;
|
|
66
|
+
export { NumerableFormatOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Component}from"react";import{Tooltip}from"primereact/tooltip";import{ValueDisplay}from"./ValueDisplay";import"./ValueIndicator.css";export class ValueIndicator extends Component{constructor(t){super(t),this.state={}}render(){return _jsxs("div",{className:"value-indicator-container",style:this.props.style,children:[_jsx(Tooltip,{target:".value-indicator-container"}),void 0!==this.props.label&&_jsx("div",{className:"value-indicator-label",children:this.props.label}),_jsx(ValueDisplay,{className:this.props.className,value:this.props.value,format:this.props.format,formatOptions:this.props.formatOptions,topic:this.props.topic,"data-pr-tooltip":this.props.tooltip,"data-pr-position":"down","data-pr-mousetrack":!0,"data-pr-showDelay":2e3})]})}}export default ValueIndicator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-03-21 13:03:38
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-03-21 13:36:25
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import useFitText from 'use-fit-text';
|
|
13
|
+
|
|
14
|
+
interface FitTextProps {
|
|
15
|
+
/** The children prop expects any valid React node. */
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* FitText dynamically adjusts the font size of its children to fit the parent container.
|
|
21
|
+
*
|
|
22
|
+
* @param {FitTextProps} props The props for the FitText component.
|
|
23
|
+
* @returns A div element that resizes its child text to fit.
|
|
24
|
+
*/
|
|
25
|
+
export const FitText: React.FC<FitTextProps> = ({ children }) => {
|
|
26
|
+
const { fontSize, ref } = useFitText();
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div ref={ref} style={{ width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
|
30
|
+
<p style={{ fontSize }}>{children}</p>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export default FitText;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-03-22 06:26:45
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-03-22 07:07:50
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
.value-indicator-container {
|
|
13
|
+
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
background-color: var(--surface-ground);
|
|
17
|
+
border-color: var(--surface-border);
|
|
18
|
+
border-radius: var(--border-radius);
|
|
19
|
+
border-width: 1px;
|
|
20
|
+
border-style: solid;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
padding: 2mm;
|
|
24
|
+
flex-grow: 1; /* Allow the item to grow to fill available space */
|
|
25
|
+
flex-shrink: 0; /* Allow the item to shrink if necessary */
|
|
26
|
+
flex-basis: 0; /* Start with 0 width and then grow as needed, equal distribution */
|
|
27
|
+
min-width: 0; /* Prevents flex items from overflowing their container */
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.value-indicator-label {
|
|
31
|
+
padding-bottom: 1mm;
|
|
32
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-01-16 14:17:02
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-03-22 06:42:57
|
|
6
|
+
* Modified By: ADC
|
|
7
|
+
* -----
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import React, { Component } from 'react';
|
|
14
|
+
|
|
15
|
+
import { Tooltip } from "primereact/tooltip";
|
|
16
|
+
|
|
17
|
+
import { ValueDisplay } from './ValueDisplay';
|
|
18
|
+
import type { NumerableFormatOptions } from '../core/NumerableTypes';
|
|
19
|
+
|
|
20
|
+
import "./ValueIndicator.css";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Properties of the ValueDisplay component.
|
|
25
|
+
*/
|
|
26
|
+
interface ValueIndicatorProps {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Label for the indicator.
|
|
30
|
+
*/
|
|
31
|
+
label?: React.ReactNode | undefined;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Value to be displayed
|
|
35
|
+
*/
|
|
36
|
+
value?: string | number | null | undefined;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Tooltip to display on hover
|
|
41
|
+
*/
|
|
42
|
+
tooltip?: string | undefined;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Format for `value`<br/>
|
|
46
|
+
* See [numerable formats](https://github.com/gastonmesseri/numerable#1234-formatting-numbers)
|
|
47
|
+
*/
|
|
48
|
+
format?: string | null | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Format options for `value`<br/>
|
|
52
|
+
* See [numerable format options](https://github.com/gastonmesseri/numerable#format)
|
|
53
|
+
*/
|
|
54
|
+
formatOptions?: NumerableFormatOptions;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Custom class name to be attached
|
|
58
|
+
*/
|
|
59
|
+
className?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The topic to monitor to display. Optional.
|
|
63
|
+
*/
|
|
64
|
+
topic?: string;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Optional style properties.
|
|
69
|
+
*/
|
|
70
|
+
style?: React.CSSProperties | undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* State of the ValueDisplay component.
|
|
75
|
+
*/
|
|
76
|
+
interface ValueIndicatorState {
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `ValueIndicator` wraps `ValueDisplay` in a frame and label, giving it a widget appearance.
|
|
83
|
+
* Care is taken to adapt to the selected theme of the application.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
export class ValueIndicator extends Component<ValueIndicatorProps, ValueIndicatorState> {
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The constructor initializes the component state and binds the initial value.
|
|
91
|
+
* @param {ValueIndicatorProps} props The properties passed to the component, including initial value and other display options.
|
|
92
|
+
*/
|
|
93
|
+
constructor(props: ValueIndicatorProps) {
|
|
94
|
+
super(props);
|
|
95
|
+
this.state = {
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Renders the component into the DOM.
|
|
101
|
+
* @returns A styled `div` element displaying the indicator.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
render() {
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div className='value-indicator-container' style={this.props.style}>
|
|
110
|
+
<Tooltip target=".value-indicator-container" />
|
|
111
|
+
|
|
112
|
+
{this.props.label !== undefined &&
|
|
113
|
+
<div className="value-indicator-label">
|
|
114
|
+
{this.props.label}
|
|
115
|
+
</div>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
<ValueDisplay
|
|
119
|
+
className={this.props.className}
|
|
120
|
+
|
|
121
|
+
value={this.props.value}
|
|
122
|
+
format={this.props.format}
|
|
123
|
+
formatOptions={this.props.formatOptions}
|
|
124
|
+
topic={this.props.topic}
|
|
125
|
+
data-pr-tooltip={this.props.tooltip}
|
|
126
|
+
data-pr-position="down"
|
|
127
|
+
data-pr-mousetrack={true}
|
|
128
|
+
data-pr-showDelay={2000}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export default ValueIndicator;
|
|
136
|
+
export { NumerableFormatOptions };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-01-17 11:45:10
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-03-
|
|
5
|
+
* Last Modified: 2024-03-22 14:25:08
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -135,6 +135,9 @@ export interface EventEmitterContextType {
|
|
|
135
135
|
getSubscriptions: (topic?: string) => Record<string, Subscription[]> | Subscription[];
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
|
|
139
|
+
let globalSubscriptionId = 1;
|
|
140
|
+
|
|
138
141
|
/**
|
|
139
142
|
* A global context for managing event emission and subscription.
|
|
140
143
|
*
|
|
@@ -324,7 +327,8 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
|
|
|
324
327
|
|
|
325
328
|
const subscribe = (topic: string, callback: React.Dispatch<any>) : number => {
|
|
326
329
|
|
|
327
|
-
|
|
330
|
+
globalSubscriptionId += 1;
|
|
331
|
+
const subscriptionId = globalSubscriptionId; // state.nextSubscriptionId;
|
|
328
332
|
|
|
329
333
|
setState(prevState => ({
|
|
330
334
|
...prevState,
|
|
@@ -332,7 +336,7 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
|
|
|
332
336
|
...prevState.subscriptions,
|
|
333
337
|
[topic]: [...(prevState.subscriptions[topic] || []), { id: subscriptionId, callback }]
|
|
334
338
|
},
|
|
335
|
-
nextSubscriptionId: prevState.nextSubscriptionId + 1
|
|
339
|
+
nextSubscriptionId: globalSubscriptionId + 1 // prevState.nextSubscriptionId + 1
|
|
336
340
|
}));
|
|
337
341
|
|
|
338
342
|
return subscriptionId;
|
|
@@ -357,7 +361,7 @@ export const EventEmitterProvider: React.FC<{ children: ReactNode }> = ({ childr
|
|
|
357
361
|
}
|
|
358
362
|
|
|
359
363
|
return { ...prevState, subscriptions: newSubscriptions };
|
|
360
|
-
});
|
|
364
|
+
});
|
|
361
365
|
};
|
|
362
366
|
|
|
363
367
|
|