@dvrd/dvr-controls 1.0.1 → 1.0.4

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/index.ts CHANGED
@@ -30,7 +30,6 @@ import InputControllerV2 from './src/js/input/v2/inputController_v2';
30
30
  import WithEvents from './src/js/events/withEvents';
31
31
  import AppNavigator from "./src/js/navigator/navigator";
32
32
  import DVRHead from './src/js/head/DVRHead';
33
- import AnalyticsRouter from './src/js/analytics/analyticsRouter';
34
33
  import TopButton from './src/js/topButton/topButton';
35
34
  import DVRCarouselController from './src/js/carousel/DVRCarouselController';
36
35
  import DVRSlider from './src/js/slider/DVRSlider';
@@ -76,7 +75,6 @@ export {
76
75
  WithEvents,
77
76
  AppNavigator,
78
77
  DVRHead,
79
- AnalyticsRouter,
80
78
  TopButton,
81
79
  DVRCarouselController as DVRCarousel,
82
80
  DVRSlider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvrd/dvr-controls",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -17,11 +17,11 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@types/js-cookie": "^2.2.6",
20
- "@types/lodash": "^4.14.168",
20
+ "@types/lodash": "^4.14.181",
21
21
  "@types/node": "^14.14.34",
22
- "@types/react": "^17.0.3",
23
- "@types/react-dom": "^17.0.2",
24
- "@types/react-router-dom": "^5.1.7",
22
+ "@types/react": "^18.0.5",
23
+ "@types/react-dom": "^18.0.0",
24
+ "@types/react-router-dom": "^5.3.3",
25
25
  "@types/uuid": "^8.3.0",
26
26
  "@types/react-color": "^3.0.6",
27
27
  "@types/dompurify": "^2.2.3",
@@ -30,12 +30,12 @@
30
30
  "js-cookie": "^2.2.1",
31
31
  "lodash": "^4.17.21",
32
32
  "moment": "^2.29.1",
33
- "react": "^17.0.1",
34
- "react-dom": "^17.0.1",
33
+ "react": "^18.0.0",
34
+ "react-dom": "^18.0.0",
35
35
  "react-color": "^2.19.3",
36
- "react-router-dom": "^5.2.0",
36
+ "react-router-dom": "^6.3.0",
37
37
  "react-rnd": "^10.3.5",
38
- "typescript": "^4.2.3",
38
+ "typescript": "^4.6.3",
39
39
  "uuid": "^8.3.2",
40
40
  "dompurify": "^2.3.3"
41
41
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import './style/button.scss';
6
6
 
7
- import React from 'react';
7
+ import React, { PropsWithChildren } from 'react';
8
8
  import classNames from 'classnames';
9
9
  import {convertColor, editColor, ThemeShape} from "../../..";
10
10
  import {isNotNull, isNull} from "../util/controlUtil";
@@ -29,7 +29,7 @@ interface Props {
29
29
  tabIndex?: number;
30
30
  }
31
31
 
32
- export class Button extends React.Component<Props> {
32
+ export class Button extends React.Component<PropsWithChildren<Props>> {
33
33
  getContainerClass = (): string => {
34
34
  const {disabled, withRipple, padding, containerClass} = this.props,
35
35
  classes = ['buttonController'];
@@ -34,6 +34,7 @@ interface State {
34
34
  }
35
35
 
36
36
  export default class ButtonController extends React.Component<Props, State> {
37
+ declare context: React.ContextType<typeof ControlContext>;
37
38
  static contextType = ControlContext;
38
39
 
39
40
  static defaultProps = {
@@ -4,7 +4,7 @@
4
4
 
5
5
  import './style/outlinedButton.scss';
6
6
 
7
- import React from 'react';
7
+ import React, { PropsWithChildren } from 'react';
8
8
  import classNames from 'classnames';
9
9
  import {colorIsWhite, convertColor, editColor} from "../util/colorUtil";
10
10
  import {isNotNull, isNull} from "../util/controlUtil";
@@ -29,7 +29,7 @@ interface ButtonProps {
29
29
  tabIndex?: number;
30
30
  }
31
31
 
32
- export class OutlinedButton extends React.Component<ButtonProps, {}> {
32
+ export class OutlinedButton extends React.Component<PropsWithChildren<ButtonProps>> {
33
33
  getContainerClass = (): string => {
34
34
  const {containerClass, disabled, padding} = this.props, classes: string[] = ['outlinedButtonContainer'];
35
35
  if (disabled) classes.push('disabled');
@@ -4,7 +4,7 @@
4
4
 
5
5
  import './style/simpleButton.scss';
6
6
 
7
- import React, {CSSProperties, PureComponent} from 'react';
7
+ import React, {CSSProperties, PureComponent, ReactNode} from 'react';
8
8
  import {ControlContext} from "../util/controlContext";
9
9
  import {colorIsWhite, convertColor, editColor} from "../util/colorUtil";
10
10
  import {ControlPadding, ElementPosition, OrnamentShape} from "../util/interfaces";
@@ -29,9 +29,11 @@ interface Props {
29
29
  withRipple: boolean;
30
30
  primary: boolean;
31
31
  tabIndex?: number;
32
+ children?: ReactNode | ReactNode[] | OrnamentShape | OrnamentShape[];
32
33
  }
33
34
 
34
35
  export default class SimpleButton extends PureComponent<Props> {
36
+ declare context: React.ContextType<typeof ControlContext>;
35
37
  static contextType = ControlContext;
36
38
 
37
39
  getBaseColor = (trueBase: boolean = false): string => {
@@ -36,6 +36,7 @@ interface CheckboxProps {
36
36
  }
37
37
 
38
38
  export class Checkbox extends React.Component<CheckboxProps> {
39
+ declare context: React.ContextType<typeof ControlContext>;
39
40
  static contextType = ControlContext;
40
41
 
41
42
  getContainerClass = (): string => {
@@ -40,6 +40,7 @@ interface DataShape {
40
40
  }
41
41
 
42
42
  export default class Dialog extends React.Component<Props, State> {
43
+ declare context: React.ContextType<typeof ControlContext>;
43
44
  static contextType = ControlContext;
44
45
  static defaultProps = {
45
46
  className: '',
@@ -25,8 +25,9 @@ interface DialogProps {
25
25
  }
26
26
 
27
27
  export default class InlineDialog extends React.Component<DialogProps> {
28
- // noinspection JSUnusedGlobalSymbols
28
+ declare context: React.ContextType<typeof ControlContext>;
29
29
  static contextType = ControlContext;
30
+
30
31
  static defaultProps = {
31
32
  title: 'Bericht van Klaverjassen',
32
33
  actions: null,
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2021. Dave van Rijn Development
3
3
  */
4
4
 
5
- import React from 'react';
5
+ import React, { PropsWithChildren } from 'react';
6
6
  import {addCustomEventListener, removeCustomEventListener} from '../util/eventUtil';
7
7
  import {CustomAppEvent} from '../util/interfaces';
8
8
  import {generateComponentId} from "../util/componentUtil";
@@ -12,7 +12,7 @@ interface Props {
12
12
  componentName?: string;
13
13
  }
14
14
 
15
- export default class WithEvents extends React.PureComponent<Props> {
15
+ export default class WithEvents extends React.PureComponent<PropsWithChildren<Props>> {
16
16
  private readonly componentName: string;
17
17
 
18
18
  constructor(props: Props) {
@@ -62,7 +62,9 @@ enum Phase {HEADER = 'header', MENU = 'menu', CALCULATING = 'calculating'}
62
62
  const RESIZE_TIMEOUT = Math.ceil(1000 / 120); // 30 fps
63
63
 
64
64
  export default class DVRHeader extends PureComponent<Props, State> {
65
+ declare context: React.ContextType<typeof ControlContext>;
65
66
  static contextType = ControlContext;
67
+
66
68
  static defaultProps = {
67
69
  forcedMenu: false,
68
70
  containerClass: '',
@@ -31,6 +31,7 @@ interface State {
31
31
  }
32
32
 
33
33
  export default class Info extends PureComponent<Props, State> {
34
+ declare context: React.ContextType<typeof ControlContext>;
34
35
  static contextType = ControlContext;
35
36
 
36
37
  private messageContainer: HTMLDivElement;
@@ -57,6 +57,7 @@ interface State {
57
57
  export enum PickerKey {DAY = 'day', MONTH = 'month', YEAR = 'year'}
58
58
 
59
59
  export default class DateField extends PureComponent<Props, State> {
60
+ declare context: React.ContextType<typeof ControlContext>;
60
61
  static contextType = ControlContext;
61
62
 
62
63
  constructor(props: Props) {
@@ -27,6 +27,7 @@ interface Props {
27
27
  }
28
28
 
29
29
  export default class DatePicker extends PureComponent<Props> {
30
+ declare context: React.ContextType<typeof ControlContext>;
30
31
  static contextType = ControlContext;
31
32
 
32
33
  onClickReset = (type: 'year' | 'month') => () => {
@@ -21,6 +21,7 @@ interface Props {
21
21
  const SCROLL_TIMEOUT = 120;
22
22
 
23
23
  export default class TimePicker extends PureComponent<Props> {
24
+ declare context: React.ContextType<typeof ControlContext>;
24
25
  static contextType = ControlContext;
25
26
 
26
27
  private hourTimeout: number | null = null;
@@ -4,18 +4,19 @@
4
4
 
5
5
  import '../style/simpleInput.scss';
6
6
 
7
- import React from 'react';
8
- import {CSSProperties, PureComponent} from 'react';
7
+ import React, {CSSProperties, PureComponent} from 'react';
9
8
  import classNames from "classnames";
10
9
  import {ControlContext} from "../../../util/controlContext";
11
10
  import {colorIsWhite, convertColor, editColor} from "../../../util/colorUtil";
12
- import {OrnamentShape, ElementPosition} from "../../../util/interfaces";
11
+ import {ElementPosition, OrnamentShape} from "../../../util/interfaces";
13
12
  import AwesomeIcon from '../../../icon/awesomeIcon';
14
13
  import {stopPropagation} from "../../../util/controlUtil";
15
14
  import {DVRInputProps} from "../../v2/inputController_v2";
16
15
 
17
16
  export default class SimpleInput extends PureComponent<DVRInputProps> {
17
+ declare context: React.ContextType<typeof ControlContext>;
18
18
  static contextType = ControlContext;
19
+
19
20
  private input: HTMLInputElement | HTMLTextAreaElement | null = null;
20
21
 
21
22
  private onFocus = (evt: React.FocusEvent) => {
@@ -3,14 +3,14 @@
3
3
  */
4
4
  import React, {
5
5
  ChangeEventHandler, CSSProperties, EventHandler, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler,
6
- MouseEventHandler, PureComponent, TextareaHTMLAttributes
6
+ MouseEventHandler, PureComponent, ReactNode, TextareaHTMLAttributes
7
7
  } from 'react';
8
8
  import {assert, enterPressed} from "../../util/controlUtil";
9
9
  import SimpleInput from "../simple/v2/simpleInputV2";
10
10
  import {ControlVariant, ErrorType, OrnamentShape} from "../../util/interfaces";
11
11
  import { generateComponentId } from '../../../..';
12
12
 
13
- type HTMLProps = Omit<InputHTMLAttributes<any>, 'onChange' | 'step'>;
13
+ type HTMLProps = Omit<InputHTMLAttributes<any>, 'onChange' | 'step' | 'children'>;
14
14
 
15
15
  export interface DVRInputControllerProps extends HTMLProps {
16
16
  // Events
@@ -44,6 +44,7 @@ export interface DVRInputControllerProps extends HTMLProps {
44
44
  value?: string | number;
45
45
  step?: number;
46
46
  unControlled?: boolean;
47
+ children?: ReactNode | ReactNode[] | OrnamentShape | OrnamentShape[];
47
48
  }
48
49
 
49
50
  export interface DVRInputProps extends Omit<DVRInputControllerProps, 'value' | 'onChange'> {
@@ -37,7 +37,9 @@ interface State {
37
37
  * text until the number of lines is reached. Remaining text will be shown in the title.
38
38
  */
39
39
  export default class Label extends React.Component<Props, State> {
40
+ declare context: React.ContextType<typeof ControlContext>;
40
41
  static contextType = ControlContext;
42
+
41
43
  static defaultProps = {
42
44
  labelType: LabelType.LABEL,
43
45
  className: '',
@@ -23,6 +23,7 @@ interface LoaderProps {
23
23
 
24
24
  export default class LoaderController extends React.Component<LoaderProps> {
25
25
  // noinspection JSUnusedGlobalSymbols
26
+ declare context: React.ContextType<typeof ControlContext>;
26
27
  static contextType = ControlContext;
27
28
 
28
29
  static defaultProps = {
@@ -3,30 +3,49 @@
3
3
  */
4
4
 
5
5
  import React from 'react';
6
- import {RouteComponentProps, withRouter} from "react-router";
6
+ // import {RouteComponentProps, withRouter} from "react-router";
7
+ import { useNavigate } from 'react-router-dom';
8
+ import { useLocation } from 'react-router-dom';
7
9
  import {debug} from '../util/miscUtil';
8
10
 
9
- let navigationData: any = null;
11
+ // let navigationData: any = null;
10
12
 
11
- class AppNavigator extends React.Component<RouteComponentProps> {
12
- static setNavigationData = (data: any) => {
13
- navigationData = data;
14
- };
13
+ export default function AppNavigator() {
14
+ const location = useLocation();
15
+ const navigate = useNavigate();
15
16
 
16
- static getNavigationData = (): any => navigationData;
17
-
18
- navigate = (evt: any) => {
19
- const {location, history} = this.props;
20
- const navigator = evt.target,
21
- url = navigator.dataset.url + (navigator.dataset.strip === '0' ? location.search : '');
17
+ function onNavigate(evt: React.MouseEvent) {
18
+ const navigator: HTMLButtonElement = evt.target as HTMLButtonElement;
19
+ const url = navigator.dataset.url + (navigator.dataset.strip === '0' ? location.search : '');
22
20
  navigator.dataset.strip = '0';
23
21
  debug(`Navigating to ${url}`);
24
- history.push(url);
25
- };
26
-
27
- render = () => {
28
- return <button id='appNavigator' style={{display: 'none'}} data-url='' data-strip='0' onClick={this.navigate}/>
22
+ navigate(url);
29
23
  }
24
+
25
+ return (
26
+ <button id='appNavigator' style={{display: 'none'}} data-url='' data-strip='0' onClick={onNavigate}/>
27
+ )
30
28
  }
31
29
 
32
- export default withRouter(AppNavigator);
30
+ // class AppNavigator extends React.Component<RouteComponentProps> {
31
+ // static setNavigationData = (data: any) => {
32
+ // navigationData = data;
33
+ // };
34
+ //
35
+ // static getNavigationData = (): any => navigationData;
36
+ //
37
+ // navigate = (evt: any) => {
38
+ // const {location, history} = this.props;
39
+ // const navigator = evt.target,
40
+ // url = navigator.dataset.url + (navigator.dataset.strip === '0' ? location.search : '');
41
+ // navigator.dataset.strip = '0';
42
+ // debug(`Navigating to ${url}`);
43
+ // history.push(url);
44
+ // };
45
+ //
46
+ // render = () => {
47
+ // return <button id='appNavigator' style={{display: 'none'}} data-url='' data-strip='0' onClick={this.navigate}/>
48
+ // }
49
+ // }
50
+ //
51
+ // export default withRouter(AppNavigator);
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import './style/pdfElement.scss';
5
5
 
6
- import React, {MouseEventHandler, PureComponent} from 'react';
6
+ import React, {MouseEventHandler, PropsWithChildren, PureComponent} from 'react';
7
7
  import {DraggableData, HandleClasses, HandleStyles, ResizeEnable, Rnd} from 'react-rnd';
8
8
  import {
9
9
  CustomAppEvent, ElementPosition, IndexedObject, PDFElementDimensions, PDFElementParams, PDFElementPersist, PdfFont,
@@ -145,7 +145,7 @@ interface DraggableState {
145
145
  height: number | string;
146
146
  }
147
147
 
148
- export class PDFDraggable extends PureComponent<DraggableProps, DraggableState> {
148
+ export class PDFDraggable extends PureComponent<PropsWithChildren<DraggableProps>, DraggableState> {
149
149
  static defaultProps = {
150
150
  resizeable: true,
151
151
  resizeHoriz: true,
@@ -4,7 +4,7 @@
4
4
 
5
5
  import './style/withBackground.scss';
6
6
 
7
- import React, {CSSProperties} from 'react';
7
+ import React, {CSSProperties, PropsWithChildren} from 'react';
8
8
  import classNames from 'classnames';
9
9
  import {escapePressed, hasHover} from "../util/controlUtil";
10
10
 
@@ -21,7 +21,7 @@ interface Props {
21
21
  zIndex?: number;
22
22
  }
23
23
 
24
- export default class WithBackground extends React.Component<Props> {
24
+ export default class WithBackground extends React.Component<PropsWithChildren<Props>> {
25
25
  static defaultProps = {
26
26
  backgroundColor: 'rgba(0,0,0,.2)',
27
27
  transparent: false,
@@ -62,7 +62,9 @@ interface Props {
62
62
  }
63
63
 
64
64
  export class Select extends React.Component<Props> {
65
+ declare context: React.ContextType<typeof ControlContext>;
65
66
  static contextType = ControlContext;
67
+
66
68
  getBaseColor = (allowWhite: boolean = true): string => {
67
69
  const {baseColor} = this.props, {contrastColor} = this.context;
68
70
  let color = convertColor(baseColor);
@@ -83,7 +83,7 @@ interface State {
83
83
 
84
84
  // noinspection JSUnusedGlobalSymbols
85
85
  export default class SelectController extends React.Component<SelectProps, State> {
86
- // noinspection JSUnusedGlobalSymbols
86
+ declare context: React.ContextType<typeof ControlContext>;
87
87
  static contextType = ControlContext;
88
88
 
89
89
  static defaultProps = SelectDefaultProps;
@@ -7,7 +7,7 @@ import React, {MouseEventHandler, ReactNode, useContext, useEffect, useRef, useS
7
7
  import {useLocation} from 'react-router';
8
8
  import {SidebarItem, SideMenuMode} from "../util/interfaces";
9
9
  import classNames from 'classnames';
10
- import {AwesomeIcon, generateComponentId} from "../../../index";
10
+ import {AwesomeIcon, generateComponentId, isAbsoluteLink} from "../../../index";
11
11
  import {ControlContext} from "../util/controlContext";
12
12
  import {defer} from 'lodash';
13
13
 
@@ -67,7 +67,14 @@ export default function SidebarMenu(props: Props) {
67
67
  function _onClickItem(item: SidebarItem) {
68
68
  return function (evt: React.MouseEvent) {
69
69
  evt.stopPropagation();
70
- setActiveItem(item.id);
70
+ const {route} = item;
71
+ let _route: string | null = null;
72
+ if (route) {
73
+ if (Array.isArray(route) && route.length) _route = route[0];
74
+ else _route = route as string;
75
+ }
76
+ if (_route && !isAbsoluteLink(_route))
77
+ setActiveItem(item.id);
71
78
  onClickItem(item)(evt);
72
79
  }
73
80
  }
@@ -36,7 +36,7 @@ export default class DVRSlider extends PureComponent<Props> {
36
36
  labelClassName: '',
37
37
  labelPosition: ElementPosition.RIGHT,
38
38
  };
39
-
39
+ declare context: React.ContextType<typeof ControlContext>;
40
40
  static contextType = ControlContext;
41
41
 
42
42
  constructor(props: Props) {
@@ -22,6 +22,7 @@ interface ViewProps {
22
22
 
23
23
  export class Snackbar extends React.Component<ViewProps> {
24
24
  // noinspection JSUnusedGlobalSymbols
25
+ declare context: React.ContextType<typeof ControlContext>;
25
26
  static contextType = ControlContext;
26
27
 
27
28
  getBackgroundColor = (): string => {
@@ -6,7 +6,7 @@ import React from 'react';
6
6
  import {Snackbar} from "./snackbar";
7
7
  import {CustomAppEvent, DialogConfig, Snack} from "../util/interfaces";
8
8
  import WithEvents from '../events/withEvents';
9
- import { delay } from 'lodash';
9
+ import {delay} from 'lodash';
10
10
 
11
11
  interface Props {
12
12
  containerClass: string;
@@ -94,9 +94,11 @@ export default class SnackbarController extends React.Component<Props, State> {
94
94
 
95
95
  render = () => {
96
96
  const {snack, active} = this.state, {containerClass, textClass, textColor, backgroundColor} = this.props;
97
- return <WithEvents events={this.getEvents()}>
98
- <Snackbar snack={snack} containerClass={containerClass} textClass={textClass} active={active}
99
- onClick={this.onClick} textColor={textColor} backgroundColor={backgroundColor}/>
100
- </WithEvents>
97
+ return (
98
+ <WithEvents events={this.getEvents()}>
99
+ <Snackbar snack={snack} containerClass={containerClass} textClass={textClass} active={active}
100
+ onClick={this.onClick} textColor={textColor} backgroundColor={backgroundColor}/>
101
+ </WithEvents>
102
+ )
101
103
  };
102
104
  }
@@ -33,7 +33,7 @@ interface SwitchState {
33
33
 
34
34
  // noinspection JSUnusedGlobalSymbols
35
35
  export default class SwitchController extends React.Component<SwitchProps, SwitchState> {
36
- // noinspection JSUnusedGlobalSymbols
36
+ declare context: React.ContextType<typeof ControlContext>
37
37
  static contextType = ControlContext;
38
38
 
39
39
  static defaultProps = {
@@ -27,6 +27,7 @@ interface State {
27
27
  }
28
28
 
29
29
  export default class TopButton extends PureComponent<TopButtonProps, State> {
30
+ declare context: React.ContextType<typeof ControlContext>
30
31
  static contextType = ControlContext;
31
32
  static defaultProps = {
32
33
  disabled: false,
@@ -163,4 +163,8 @@ export function webpSupported(): boolean {
163
163
  } catch {
164
164
  return false;
165
165
  }
166
+ }
167
+
168
+ export function isAbsoluteLink(link: string): boolean {
169
+ return /^(https?|www).*/.test(link);
166
170
  }
@@ -1,31 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Dave van Rijn Development
3
- */
4
-
5
- import React from 'react';
6
- import {RouteComponentProps, withRouter} from 'react-router-dom';
7
- import {Location} from 'history';
8
-
9
- class AnalyticsRouter extends React.Component<RouteComponentProps> {
10
- private lastPathname: string;
11
- componentDidMount = () => {
12
- this.sendPageView(this.props.location);
13
- this.props.history.listen(this.sendPageView);
14
- };
15
-
16
- sendPageView = (location: Location) => {
17
- if (!window.gtag) {
18
- console.debug('gtag function not found.');
19
- return;
20
- }
21
- if (this.lastPathname === location.pathname) return;
22
- this.lastPathname = location.pathname;
23
-
24
- window.gtag('set', 'page', location.pathname)
25
- window.gtag('send', 'pageview');
26
- };
27
-
28
- render = () => this.props.children;
29
- }
30
-
31
- export default withRouter(AnalyticsRouter);