@dvrd/dvr-controls 1.0.24 → 1.0.25
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvrd/dvr-controls",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "Custom web controls",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -24,26 +24,26 @@
|
|
|
24
24
|
"@fortawesome/free-solid-svg-icons": "6.3.0",
|
|
25
25
|
"@fortawesome/react-fontawesome": "0.2.0",
|
|
26
26
|
"@types/dompurify": "2.4.0",
|
|
27
|
-
"@types/js-cookie": "3.0.
|
|
28
|
-
"@types/lodash": "4.14.
|
|
29
|
-
"@types/node": "18.
|
|
30
|
-
"@types/react": "18.0.
|
|
27
|
+
"@types/js-cookie": "3.0.3",
|
|
28
|
+
"@types/lodash": "4.14.191",
|
|
29
|
+
"@types/node": "18.14.0",
|
|
30
|
+
"@types/react": "18.0.28",
|
|
31
31
|
"@types/react-color": "3.0.6",
|
|
32
|
-
"@types/react-dom": "18.0.
|
|
32
|
+
"@types/react-dom": "18.0.11",
|
|
33
33
|
"@types/react-router-dom": "5.3.3",
|
|
34
|
-
"@types/uuid": "
|
|
34
|
+
"@types/uuid": "9.0.0",
|
|
35
35
|
"classnames": "2.3.2",
|
|
36
36
|
"cross-env": "7.0.3",
|
|
37
|
-
"dompurify": "
|
|
37
|
+
"dompurify": "3.0.0",
|
|
38
38
|
"js-cookie": "3.0.1",
|
|
39
39
|
"lodash": "4.17.21",
|
|
40
40
|
"moment": "2.29.4",
|
|
41
41
|
"react": "18.2.0",
|
|
42
42
|
"react-color": "2.19.3",
|
|
43
43
|
"react-dom": "18.2.0",
|
|
44
|
-
"react-rnd": "10.
|
|
45
|
-
"react-router-dom": "6.
|
|
46
|
-
"typescript": "4.9.
|
|
44
|
+
"react-rnd": "10.4.1",
|
|
45
|
+
"react-router-dom": "6.8.1",
|
|
46
|
+
"typescript": "4.9.5",
|
|
47
47
|
"uuid": "9.0.0"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -50,6 +50,7 @@ interface Props {
|
|
|
50
50
|
menuLabelColor?: string;
|
|
51
51
|
topControl: boolean;
|
|
52
52
|
topControlProps?: Partial<TopButtonProps>;
|
|
53
|
+
onClickItem?: (item: HeaderItem) => MouseEventHandler;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
interface State {
|
|
@@ -236,7 +237,7 @@ export default class DVRHeader extends PureComponent<Props, State> {
|
|
|
236
237
|
const {onClick, component, customClass, icon, iconOnly, label} = item,
|
|
237
238
|
renderAble: RenderAble = {
|
|
238
239
|
toRender: null,
|
|
239
|
-
clickHandler: onClick,
|
|
240
|
+
clickHandler: this.props.onClickItem?.(item) ?? onClick,
|
|
240
241
|
isComp: false,
|
|
241
242
|
}, className = classNames('dvr-header-item', customClass);
|
|
242
243
|
if (iconOnly) {
|
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
* Copyright (c) 2021. Dave van Rijn Development
|
|
3
3
|
*/
|
|
4
4
|
import React, {
|
|
5
|
-
ChangeEventHandler,
|
|
6
|
-
|
|
5
|
+
ChangeEventHandler,
|
|
6
|
+
CSSProperties,
|
|
7
|
+
DetailedHTMLProps,
|
|
8
|
+
EventHandler,
|
|
9
|
+
FocusEventHandler,
|
|
10
|
+
InputHTMLAttributes,
|
|
11
|
+
KeyboardEventHandler,
|
|
12
|
+
MouseEventHandler,
|
|
13
|
+
PureComponent,
|
|
14
|
+
ReactNode,
|
|
15
|
+
TextareaHTMLAttributes
|
|
7
16
|
} from 'react';
|
|
8
17
|
import {assert, enterPressed} from "../../util/controlUtil";
|
|
9
18
|
import SimpleInput from "../simple/v2/simpleInputV2";
|
|
10
19
|
import {ControlVariant, ErrorType, OrnamentShape} from "../../util/interfaces";
|
|
11
|
-
import {
|
|
20
|
+
import {generateComponentId} from '../../../..';
|
|
12
21
|
|
|
13
22
|
type HTMLProps = Omit<InputHTMLAttributes<any>, 'onChange' | 'step' | 'children'>;
|
|
14
23
|
|
|
@@ -76,7 +85,7 @@ export interface DVRInputProps extends Omit<DVRInputControllerProps, 'value' | '
|
|
|
76
85
|
inputStyle?: CSSProperties;
|
|
77
86
|
// Other
|
|
78
87
|
error: ErrorType;
|
|
79
|
-
inputProps?: InputHTMLAttributes<
|
|
88
|
+
inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, HTMLInputElement | HTMLTextAreaElement>, 'crossOrigin'>;
|
|
80
89
|
ornaments?: OrnamentShape | OrnamentShape[];
|
|
81
90
|
clearAble: boolean;
|
|
82
91
|
fullWidth: boolean;
|
|
@@ -206,7 +215,7 @@ export default class InputControllerV2 extends PureComponent<DVRInputControllerP
|
|
|
206
215
|
|
|
207
216
|
getViewValue = (): string | number => {
|
|
208
217
|
const {value, unControlled} = this.props;
|
|
209
|
-
if(unControlled || value === undefined) return this.state.value;
|
|
218
|
+
if (unControlled || value === undefined) return this.state.value;
|
|
210
219
|
return value;
|
|
211
220
|
};
|
|
212
221
|
|
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import { useLocation } from 'react-router-dom';
|
|
6
|
+
import {useNavigate} from 'react-router-dom';
|
|
8
7
|
import {debug} from '../util/miscUtil';
|
|
9
8
|
|
|
10
|
-
// let navigationData: any = null;
|
|
11
|
-
|
|
12
9
|
export default function AppNavigator() {
|
|
13
|
-
const location = useLocation();
|
|
14
10
|
const navigate = useNavigate();
|
|
15
11
|
|
|
16
12
|
function onNavigate(evt: React.MouseEvent) {
|
|
17
13
|
const navigator: HTMLButtonElement = evt.target as HTMLButtonElement;
|
|
18
|
-
const
|
|
14
|
+
const search = window.location.search;
|
|
15
|
+
const url = navigator.dataset.url + (navigator.dataset.strip === '0' ? search : '');
|
|
19
16
|
navigator.dataset.strip = '0';
|
|
20
17
|
debug(`Navigating to ${url}`);
|
|
21
18
|
navigate(url);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import './style/DVRSlider.scss';
|
|
5
5
|
|
|
6
|
-
import React, {CSSProperties, MouseEventHandler, PureComponent} from 'react';
|
|
6
|
+
import React, {CSSProperties, DetailedHTMLProps, InputHTMLAttributes, MouseEventHandler, PureComponent} from 'react';
|
|
7
7
|
import {ChangeFunction, Colors, convertColor, generateComponentId} from "../../..";
|
|
8
8
|
import {ElementPosition} from '../util/interfaces';
|
|
9
9
|
import {ControlContext} from "../util/controlContext";
|
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
asNumber?: boolean;
|
|
23
23
|
label?: string;
|
|
24
24
|
labelPosition: ElementPosition;
|
|
25
|
-
inputProps?:
|
|
25
|
+
inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'crossOrigin'>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export default class DVRSlider extends PureComponent<Props> {
|
|
@@ -62,7 +62,7 @@ export default class DVRSlider extends PureComponent<Props> {
|
|
|
62
62
|
if (onMouseLeave) onMouseLeave(evt);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
getInputProps = ():
|
|
65
|
+
getInputProps = (): Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, 'crossOrigin'> => {
|
|
66
66
|
const {inputProps} = this.props, defaultProps = {min: 0, max: 100, step: 1};
|
|
67
67
|
return Object.assign({}, defaultProps, inputProps);
|
|
68
68
|
}
|
|
@@ -4,14 +4,23 @@
|
|
|
4
4
|
import './style/dvrdInput.scss';
|
|
5
5
|
|
|
6
6
|
import React, {
|
|
7
|
-
ChangeEventHandler,
|
|
8
|
-
|
|
7
|
+
ChangeEventHandler,
|
|
8
|
+
CSSProperties,
|
|
9
|
+
DetailedHTMLProps,
|
|
10
|
+
FocusEventHandler,
|
|
11
|
+
InputHTMLAttributes,
|
|
12
|
+
KeyboardEventHandler,
|
|
13
|
+
MouseEventHandler,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useRef,
|
|
17
|
+
useState
|
|
9
18
|
} from 'react';
|
|
10
19
|
import classNames from "classnames";
|
|
11
20
|
import {ElementPosition, ErrorType, OrnamentShape} from '../util/interfaces';
|
|
12
21
|
import AwesomeIcon from '../icon/awesomeIcon';
|
|
13
22
|
import {directTimeout} from '../util/componentUtil';
|
|
14
|
-
import {
|
|
23
|
+
import {stopPropagation} from "../util/controlUtil";
|
|
15
24
|
|
|
16
25
|
interface Props {
|
|
17
26
|
onChange: ChangeEventHandler;
|
|
@@ -25,7 +34,8 @@ interface Props {
|
|
|
25
34
|
autoSelect?: boolean;
|
|
26
35
|
label?: string;
|
|
27
36
|
ornaments?: OrnamentShape | OrnamentShape[];
|
|
28
|
-
inputProps?: InputHTMLAttributes<any>;
|
|
37
|
+
// inputProps?: InputHTMLAttributes<any> & TextareaHTMLAttributes<any>;
|
|
38
|
+
inputProps?: Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement | HTMLTextAreaElement>, HTMLInputElement | HTMLTextAreaElement>, 'crossOrigin'>;
|
|
29
39
|
className?: string;
|
|
30
40
|
inputClassName?: string;
|
|
31
41
|
labelClassName?: string;
|
|
@@ -38,48 +48,47 @@ interface Props {
|
|
|
38
48
|
noResize?: boolean;
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
51
|
+
export default function DvrdInput(props: Props) {
|
|
52
|
+
const {
|
|
53
|
+
area, id, label, labelClassName, errorClassName, inputClassName, className, ornamentClassName, inputProps,
|
|
54
|
+
disabled, onBlur, value, onChange, onFocus, autoSelect, autoFocus, onClearInput, noResize, onKeyDown, fullWidth,
|
|
55
|
+
ornaments, error
|
|
56
|
+
} = props;
|
|
57
|
+
const inputRef = useRef<HTMLInputElement & HTMLTextAreaElement>(null);
|
|
58
|
+
const [active, setActive] = useState(props.autoFocus ?? false);
|
|
59
|
+
const hasOrnaments = useMemo(() => !(!ornaments || (Array.isArray(ornaments) && !ornaments.length)),
|
|
60
|
+
[ornaments]);
|
|
61
|
+
|
|
62
|
+
function onClickElement(evt: React.MouseEvent) {
|
|
63
|
+
stopPropagation(evt);
|
|
64
|
+
focusInput();
|
|
65
|
+
}
|
|
57
66
|
|
|
58
|
-
onFocusInput
|
|
59
|
-
const {disabled, onFocus, autoSelect, value} = this.props;
|
|
67
|
+
function onFocusInput(evt: React.FocusEvent) {
|
|
60
68
|
if (!disabled) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
setActive(true);
|
|
70
|
+
const input = inputRef.current;
|
|
71
|
+
if (autoSelect && input) {
|
|
72
|
+
input.selectionStart = 0;
|
|
73
|
+
input.selectionEnd = value.toString().length;
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
76
|
+
onFocus?.(evt);
|
|
77
|
+
}
|
|
70
78
|
|
|
71
|
-
onBlurInput
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
onBlur(evt);
|
|
76
|
-
};
|
|
79
|
+
function onBlurInput(evt: React.FocusEvent) {
|
|
80
|
+
if (!disabled) setActive(false);
|
|
81
|
+
onBlur?.(evt);
|
|
82
|
+
}
|
|
77
83
|
|
|
78
|
-
|
|
84
|
+
function focusInput(retry: boolean = false) {
|
|
85
|
+
if (inputRef.current) inputRef.current.focus();
|
|
86
|
+
else if (retry) directTimeout(focusInput);
|
|
87
|
+
}
|
|
79
88
|
|
|
80
|
-
getContentStyle
|
|
81
|
-
const style: CSSProperties = {gridTemplateColumns: '1fr'}
|
|
82
|
-
if (!
|
|
89
|
+
function getContentStyle(): CSSProperties {
|
|
90
|
+
const style: CSSProperties = {gridTemplateColumns: '1fr'};
|
|
91
|
+
if (!hasOrnaments) style.gridTemplateColumns = '1fr';
|
|
83
92
|
let hasLeft: boolean = false, hasRight: boolean = onClearInput !== undefined;
|
|
84
93
|
if (Array.isArray(ornaments))
|
|
85
94
|
for (const ornament of ornaments) {
|
|
@@ -106,114 +115,84 @@ export default class DvrdInput extends PureComponent<Props, State> {
|
|
|
106
115
|
style.paddingRight = paddingRight;
|
|
107
116
|
style.paddingLeft = paddingLeft;
|
|
108
117
|
return style;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
focusInput = (retry: boolean = false) => {
|
|
112
|
-
if (this.input) this.input.focus();
|
|
113
|
-
else if (retry) directTimeout(this.focusInput);
|
|
114
|
-
};
|
|
118
|
+
}
|
|
115
119
|
|
|
116
|
-
renderLabel
|
|
117
|
-
const {label, labelClassName} = this.props;
|
|
120
|
+
function renderLabel() {
|
|
118
121
|
if (!label) return null;
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
return (
|
|
123
|
+
<label className={classNames('dvrd-input-label', labelClassName)} onClick={onClickElement}>{label}</label>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
122
126
|
|
|
123
|
-
renderInput
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
onFocus: this.onFocusInput,
|
|
130
|
-
onBlur: this.onBlurInput,
|
|
131
|
-
onKeyDown,
|
|
132
|
-
disabled,
|
|
133
|
-
className: classNames('dvrd-input', inputClassName, noResize && 'no-resize'),
|
|
134
|
-
id: `${id}-input`,
|
|
135
|
-
ref: (ref: HTMLInputElement & HTMLTextAreaElement) => {
|
|
136
|
-
this.input = ref
|
|
137
|
-
},
|
|
138
|
-
};
|
|
127
|
+
function renderInput() {
|
|
128
|
+
const elementProps = {
|
|
129
|
+
...inputProps, value, onChange, onFocus: onFocusInput, onBlur: onBlurInput, onKeyDown, disabled,
|
|
130
|
+
className: classNames('dvrd-input', inputClassName, noResize && 'no-resize'), id: `${id}-input`,
|
|
131
|
+
ref: inputRef,
|
|
132
|
+
};
|
|
139
133
|
if (area) return <textarea {...elementProps}/>;
|
|
140
134
|
return <input {...elementProps}/>
|
|
141
|
-
}
|
|
135
|
+
}
|
|
142
136
|
|
|
143
|
-
renderLeftOrnament
|
|
144
|
-
|
|
145
|
-
if (!ornaments || (Array.isArray(ornaments) && !ornaments.length)) return null;
|
|
137
|
+
function renderLeftOrnament() {
|
|
138
|
+
if (!hasOrnaments) return null;
|
|
146
139
|
if (Array.isArray(ornaments)) {
|
|
147
140
|
for (const ornament of ornaments) {
|
|
148
141
|
if (!ornament.placement || ornament.placement === ElementPosition.LEFT)
|
|
149
|
-
return
|
|
142
|
+
return renderOrnament(ornament);
|
|
150
143
|
}
|
|
151
|
-
} else if (!ornaments.placement || ornaments.placement === ElementPosition.LEFT)
|
|
152
|
-
return
|
|
144
|
+
} else if (ornaments && (!ornaments.placement || ornaments.placement === ElementPosition.LEFT))
|
|
145
|
+
return renderOrnament(ornaments);
|
|
153
146
|
return null;
|
|
154
|
-
}
|
|
147
|
+
}
|
|
155
148
|
|
|
156
|
-
renderRightOrnament
|
|
157
|
-
|
|
158
|
-
if (onClearInput && value) return this.renderOrnament({
|
|
149
|
+
function renderRightOrnament() {
|
|
150
|
+
if (onClearInput && value) return renderOrnament({
|
|
159
151
|
element: <AwesomeIcon onClick={onClearInput} name='backspace' className='clear-btn'/>,
|
|
160
152
|
placement: ElementPosition.RIGHT
|
|
161
153
|
});
|
|
162
|
-
if (!
|
|
154
|
+
if (!hasOrnaments) return null;
|
|
163
155
|
if (Array.isArray(ornaments)) {
|
|
164
156
|
for (const ornament of ornaments) {
|
|
165
157
|
if (ornament.placement === ElementPosition.RIGHT)
|
|
166
|
-
return
|
|
158
|
+
return renderOrnament(ornament);
|
|
167
159
|
}
|
|
168
|
-
} else if (ornaments.placement === ElementPosition.RIGHT)
|
|
169
|
-
return
|
|
160
|
+
} else if (ornaments && ornaments.placement === ElementPosition.RIGHT)
|
|
161
|
+
return renderOrnament(ornaments);
|
|
170
162
|
return null;
|
|
171
|
-
}
|
|
163
|
+
}
|
|
172
164
|
|
|
173
|
-
renderOrnament
|
|
174
|
-
const {ornamentClassName} = this.props;
|
|
165
|
+
function renderOrnament(ornament: OrnamentShape) {
|
|
175
166
|
if (typeof ornament.element === 'string')
|
|
176
167
|
return <span className={classNames('dvrd-input-ornament', ornamentClassName)}
|
|
177
|
-
onClick={
|
|
168
|
+
onClick={onClickElement}>{ornament.element}</span>;
|
|
178
169
|
else return React.cloneElement(ornament.element, {
|
|
179
170
|
className: classNames(ornament.element.props.className, ornamentClassName),
|
|
180
171
|
onClick: (evt: React.MouseEvent) => {
|
|
181
|
-
|
|
182
|
-
if (React.isValidElement(ornament.element)){
|
|
172
|
+
onClickElement(evt);
|
|
173
|
+
if (React.isValidElement(ornament.element)) {
|
|
183
174
|
const element: React.ReactElement = ornament.element;
|
|
184
175
|
element.props.onClick?.(evt);
|
|
185
176
|
}
|
|
186
177
|
}
|
|
187
178
|
});
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
renderError = () => {
|
|
191
|
-
const {error, errorClassName} = this.props;
|
|
192
|
-
return <span className={classNames('dvrd-input-error', errorClassName)}>{error}</span>
|
|
193
179
|
}
|
|
194
180
|
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
active && 'active', fullWidth && 'full', className)}>
|
|
209
|
-
{this.renderLabel()}
|
|
210
|
-
<div className='content-container' style={this.getContentStyle()}>
|
|
211
|
-
{this.renderLeftOrnament()}
|
|
212
|
-
{this.renderInput()}
|
|
213
|
-
{this.renderRightOrnament()}
|
|
214
|
-
</div>
|
|
215
|
-
{this.renderError()}
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (autoFocus) focusInput(true);
|
|
183
|
+
}, [autoFocus]);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div onClick={onClickElement} id={id}
|
|
187
|
+
className={classNames('dvrd-input-container', disabled && 'disabled', !!error && 'error',
|
|
188
|
+
active && 'active', fullWidth && 'full', className)}>
|
|
189
|
+
{renderLabel()}
|
|
190
|
+
<div className='content-container' style={getContentStyle()}>
|
|
191
|
+
{renderLeftOrnament()}
|
|
192
|
+
{renderInput()}
|
|
193
|
+
{renderRightOrnament()}
|
|
216
194
|
</div>
|
|
217
|
-
|
|
218
|
-
|
|
195
|
+
<span className={classNames('dvrd-input-error', errorClassName)}>{error}</span>
|
|
196
|
+
</div>
|
|
197
|
+
)
|
|
219
198
|
}
|