@etsoo/react 1.4.6 → 1.4.10
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/lib/mu/DnDList.js +3 -1
- package/lib/mu/TooltipClick.d.ts +2 -1
- package/lib/mu/TooltipClick.js +2 -2
- package/lib/states/RouterProps.d.ts +12 -5
- package/lib/states/RouterProps.js +14 -1
- package/package.json +1 -1
- package/src/mu/DnDList.tsx +5 -1
- package/src/mu/TooltipClick.tsx +15 -7
- package/src/states/RouterProps.ts +19 -6
package/lib/mu/DnDList.js
CHANGED
|
@@ -49,7 +49,9 @@ export function DnDList(props) {
|
|
|
49
49
|
// Edit item
|
|
50
50
|
const editItem = (newItem, index) => {
|
|
51
51
|
// Existence check
|
|
52
|
-
|
|
52
|
+
const newIndex = items.findIndex((item) => item[labelField] === newItem[labelField]);
|
|
53
|
+
if (newIndex >= 0 && newIndex != index) {
|
|
54
|
+
// Label field is the same with a different item
|
|
53
55
|
return false;
|
|
54
56
|
}
|
|
55
57
|
// Clone
|
package/lib/mu/TooltipClick.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import React from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* Tooltip with click visibility props
|
|
5
5
|
*/
|
|
6
|
-
export interface TooltipClickProps extends Omit<TooltipProps, 'children' | 'open' | 'disableFocusListener' | '
|
|
6
|
+
export interface TooltipClickProps extends Omit<TooltipProps, 'children' | 'open' | 'disableFocusListener' | 'disableTouchListener'> {
|
|
7
7
|
children: (openTooltip: (newTitle?: string) => void) => React.ReactElement<any, any>;
|
|
8
|
+
disableHoverListener?: boolean;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Tooltip with click visibility
|
package/lib/mu/TooltipClick.js
CHANGED
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
export function TooltipClick(props) {
|
|
9
9
|
// Destruct
|
|
10
10
|
// leaveDelay set to 5 seconds to hide the tooltip automatically
|
|
11
|
-
const { children, leaveDelay = 5000, onClose, title, ...rest } = props;
|
|
11
|
+
const { children, disableHoverListener = true, leaveDelay = 5000, onClose, title, ...rest } = props;
|
|
12
12
|
// State
|
|
13
13
|
const [localTitle, setTitle] = React.useState(title);
|
|
14
14
|
const [open, setOpen] = React.useState(false);
|
|
@@ -42,5 +42,5 @@ export function TooltipClick(props) {
|
|
|
42
42
|
setOpen(false);
|
|
43
43
|
if (onClose)
|
|
44
44
|
onClose(event);
|
|
45
|
-
}, title: localTitle, open: open, disableFocusListener: true,
|
|
45
|
+
}, title: localTitle, open: open, disableFocusListener: true, disableTouchListener: true, disableHoverListener: disableHoverListener, onMouseOver: disableHoverListener ? undefined : () => setOpen(true), ...rest }, children(openTooltip))));
|
|
46
46
|
}
|
|
@@ -3,18 +3,25 @@ import { RouteComponentProps } from '@reach/router';
|
|
|
3
3
|
/**
|
|
4
4
|
* Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
|
|
5
5
|
*/
|
|
6
|
-
export declare type EditPageRouterProps
|
|
6
|
+
export declare type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
7
|
+
/**
|
|
8
|
+
* Get edit page id
|
|
9
|
+
* @param props Route props
|
|
10
|
+
* @param type Target data type
|
|
11
|
+
* @returns Data
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEditPageId<T extends DataTypes.BasicNames>(props: EditPageRouterProps, type: T): DataTypes.BasicConditional<T> | undefined;
|
|
7
14
|
/**
|
|
8
15
|
* Id router props, include 'id' (/:id) query parameter
|
|
9
16
|
*/
|
|
10
|
-
export declare type IdRouterProps
|
|
11
|
-
id:
|
|
17
|
+
export declare type IdRouterProps = RouteComponentProps<{
|
|
18
|
+
id: string;
|
|
12
19
|
}>;
|
|
13
20
|
/**
|
|
14
21
|
* Wildcard router props, (/*) query parameter
|
|
15
22
|
*/
|
|
16
|
-
export declare type WildcardRouterProps
|
|
17
|
-
'*':
|
|
23
|
+
export declare type WildcardRouterProps = RouteComponentProps<{
|
|
24
|
+
'*': string;
|
|
18
25
|
}>;
|
|
19
26
|
/**
|
|
20
27
|
* Id state router props, include 'id' in location.state
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { DataTypes } from '@etsoo/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Get edit page id
|
|
4
|
+
* @param props Route props
|
|
5
|
+
* @param type Target data type
|
|
6
|
+
* @returns Data
|
|
7
|
+
*/
|
|
8
|
+
export function getEditPageId(props, type) {
|
|
9
|
+
var _a;
|
|
10
|
+
const id = (_a = props.id) !== null && _a !== void 0 ? _a : props['*'];
|
|
11
|
+
if (id == null || id === '')
|
|
12
|
+
return undefined;
|
|
13
|
+
return DataTypes.convertByType(id, type);
|
|
14
|
+
}
|
package/package.json
CHANGED
package/src/mu/DnDList.tsx
CHANGED
|
@@ -146,7 +146,11 @@ export function DnDList<
|
|
|
146
146
|
// Edit item
|
|
147
147
|
const editItem = (newItem: D, index: number) => {
|
|
148
148
|
// Existence check
|
|
149
|
-
|
|
149
|
+
const newIndex = items.findIndex(
|
|
150
|
+
(item) => item[labelField] === newItem[labelField]
|
|
151
|
+
);
|
|
152
|
+
if (newIndex >= 0 && newIndex != index) {
|
|
153
|
+
// Label field is the same with a different item
|
|
150
154
|
return false;
|
|
151
155
|
}
|
|
152
156
|
|
package/src/mu/TooltipClick.tsx
CHANGED
|
@@ -7,15 +7,13 @@ import React from 'react';
|
|
|
7
7
|
export interface TooltipClickProps
|
|
8
8
|
extends Omit<
|
|
9
9
|
TooltipProps,
|
|
10
|
-
| '
|
|
11
|
-
| 'open'
|
|
12
|
-
| 'disableFocusListener'
|
|
13
|
-
| 'disableHoverListener'
|
|
14
|
-
| 'disableTouchListener'
|
|
10
|
+
'children' | 'open' | 'disableFocusListener' | 'disableTouchListener'
|
|
15
11
|
> {
|
|
16
12
|
children: (
|
|
17
13
|
openTooltip: (newTitle?: string) => void
|
|
18
14
|
) => React.ReactElement<any, any>;
|
|
15
|
+
|
|
16
|
+
disableHoverListener?: boolean;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -26,7 +24,14 @@ export interface TooltipClickProps
|
|
|
26
24
|
export function TooltipClick(props: TooltipClickProps) {
|
|
27
25
|
// Destruct
|
|
28
26
|
// leaveDelay set to 5 seconds to hide the tooltip automatically
|
|
29
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
children,
|
|
29
|
+
disableHoverListener = true,
|
|
30
|
+
leaveDelay = 5000,
|
|
31
|
+
onClose,
|
|
32
|
+
title,
|
|
33
|
+
...rest
|
|
34
|
+
} = props;
|
|
30
35
|
|
|
31
36
|
// State
|
|
32
37
|
const [localTitle, setTitle] = React.useState(title);
|
|
@@ -74,8 +79,11 @@ export function TooltipClick(props: TooltipClickProps) {
|
|
|
74
79
|
title={localTitle}
|
|
75
80
|
open={open}
|
|
76
81
|
disableFocusListener
|
|
77
|
-
disableHoverListener
|
|
78
82
|
disableTouchListener
|
|
83
|
+
disableHoverListener={disableHoverListener}
|
|
84
|
+
onMouseOver={
|
|
85
|
+
disableHoverListener ? undefined : () => setOpen(true)
|
|
86
|
+
}
|
|
79
87
|
{...rest}
|
|
80
88
|
>
|
|
81
89
|
{children(openTooltip)}
|
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { RouteComponentProps } from '@reach/router';
|
|
3
|
+
import { Props } from 'react-input-mask';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
|
|
6
7
|
*/
|
|
7
|
-
export type EditPageRouterProps
|
|
8
|
-
|
|
8
|
+
export type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get edit page id
|
|
12
|
+
* @param props Route props
|
|
13
|
+
* @param type Target data type
|
|
14
|
+
* @returns Data
|
|
15
|
+
*/
|
|
16
|
+
export function getEditPageId<T extends DataTypes.BasicNames>(
|
|
17
|
+
props: EditPageRouterProps,
|
|
18
|
+
type: T
|
|
19
|
+
): DataTypes.BasicConditional<T> | undefined {
|
|
20
|
+
const id = props.id ?? props['*'];
|
|
21
|
+
if (id == null || id === '') return undefined;
|
|
22
|
+
return DataTypes.convertByType(id, type);
|
|
23
|
+
}
|
|
9
24
|
|
|
10
25
|
/**
|
|
11
26
|
* Id router props, include 'id' (/:id) query parameter
|
|
12
27
|
*/
|
|
13
|
-
export type IdRouterProps
|
|
14
|
-
RouteComponentProps<{ id: T }>;
|
|
28
|
+
export type IdRouterProps = RouteComponentProps<{ id: string }>;
|
|
15
29
|
|
|
16
30
|
/**
|
|
17
31
|
* Wildcard router props, (/*) query parameter
|
|
18
32
|
*/
|
|
19
|
-
export type WildcardRouterProps
|
|
20
|
-
RouteComponentProps<{ '*': T }>;
|
|
33
|
+
export type WildcardRouterProps = RouteComponentProps<{ '*': string }>;
|
|
21
34
|
|
|
22
35
|
/**
|
|
23
36
|
* Id state router props, include 'id' in location.state
|