@etsoo/react 1.4.7 → 1.4.11
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.d.ts +4 -0
- package/lib/mu/DnDList.js +9 -4
- package/lib/mu/TooltipClick.d.ts +2 -1
- package/lib/mu/TooltipClick.js +2 -2
- package/lib/states/RouterProps.d.ts +1 -1
- package/package.json +1 -1
- package/src/mu/DnDList.tsx +16 -3
- package/src/mu/TooltipClick.tsx +15 -7
- package/src/states/RouterProps.ts +1 -1
package/lib/mu/DnDList.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
|
|
|
36
36
|
* Data change handler
|
|
37
37
|
*/
|
|
38
38
|
onChange?: (items: D[]) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Drag end handler
|
|
41
|
+
*/
|
|
42
|
+
onDragEnd?: (items: D[]) => void;
|
|
39
43
|
/**
|
|
40
44
|
* Top and bottom sides renderer
|
|
41
45
|
*/
|
package/lib/mu/DnDList.js
CHANGED
|
@@ -9,7 +9,7 @@ import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
|
|
|
9
9
|
*/
|
|
10
10
|
export function DnDList(props) {
|
|
11
11
|
// Destruct
|
|
12
|
-
const { children, Component = 'div', componentProps, getItemStyle = (_isDragging) => ({}), getListStyle = () => undefined, labelField, loadData, name, onChange, sideRenderer } = props;
|
|
12
|
+
const { children, Component = 'div', componentProps, getItemStyle = (_isDragging) => ({}), getListStyle = () => undefined, labelField, loadData, name, onChange, onDragEnd, sideRenderer } = props;
|
|
13
13
|
// State
|
|
14
14
|
const [items, setItems] = React.useState([]);
|
|
15
15
|
const changeItems = (items) => {
|
|
@@ -20,7 +20,7 @@ export function DnDList(props) {
|
|
|
20
20
|
setItems(items);
|
|
21
21
|
};
|
|
22
22
|
// Drag end handler
|
|
23
|
-
const
|
|
23
|
+
const onDragEndLocal = (result) => {
|
|
24
24
|
// Dropped outside the list
|
|
25
25
|
if (!result.destination) {
|
|
26
26
|
return;
|
|
@@ -33,6 +33,9 @@ export function DnDList(props) {
|
|
|
33
33
|
newItems.splice(result.destination.index, 0, removed);
|
|
34
34
|
// Update the state
|
|
35
35
|
changeItems(newItems);
|
|
36
|
+
// Drag end handler
|
|
37
|
+
if (onDragEnd)
|
|
38
|
+
onDragEnd(newItems);
|
|
36
39
|
};
|
|
37
40
|
// Add item
|
|
38
41
|
const addItem = (newItem) => {
|
|
@@ -49,7 +52,9 @@ export function DnDList(props) {
|
|
|
49
52
|
// Edit item
|
|
50
53
|
const editItem = (newItem, index) => {
|
|
51
54
|
// Existence check
|
|
52
|
-
|
|
55
|
+
const newIndex = items.findIndex((item) => item[labelField] === newItem[labelField]);
|
|
56
|
+
if (newIndex >= 0 && newIndex != index) {
|
|
57
|
+
// Label field is the same with a different item
|
|
53
58
|
return false;
|
|
54
59
|
}
|
|
55
60
|
// Clone
|
|
@@ -93,7 +98,7 @@ export function DnDList(props) {
|
|
|
93
98
|
return (React.createElement(React.Fragment, null,
|
|
94
99
|
sideRenderer && sideRenderer(true, addItem, addItems),
|
|
95
100
|
React.createElement(Component, { ...componentProps },
|
|
96
|
-
React.createElement(DragDropContext, { onDragEnd:
|
|
101
|
+
React.createElement(DragDropContext, { onDragEnd: onDragEndLocal },
|
|
97
102
|
React.createElement(Droppable, { droppableId: name }, (provided, snapshot) => (React.createElement("div", { ...provided.droppableProps, ref: provided.innerRef, style: getListStyle(snapshot.isDraggingOver) },
|
|
98
103
|
items.map((item, index) => {
|
|
99
104
|
// Id
|
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
|
}
|
|
@@ -10,7 +10,7 @@ export declare type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
|
10
10
|
* @param type Target data type
|
|
11
11
|
* @returns Data
|
|
12
12
|
*/
|
|
13
|
-
export declare function getEditPageId<T extends DataTypes.BasicNames
|
|
13
|
+
export declare function getEditPageId<T extends DataTypes.BasicNames>(props: EditPageRouterProps, type: T): DataTypes.BasicConditional<T> | undefined;
|
|
14
14
|
/**
|
|
15
15
|
* Id router props, include 'id' (/:id) query parameter
|
|
16
16
|
*/
|
package/package.json
CHANGED
package/src/mu/DnDList.tsx
CHANGED
|
@@ -57,6 +57,11 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
|
|
|
57
57
|
*/
|
|
58
58
|
onChange?: (items: D[]) => void;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Drag end handler
|
|
62
|
+
*/
|
|
63
|
+
onDragEnd?: (items: D[]) => void;
|
|
64
|
+
|
|
60
65
|
/**
|
|
61
66
|
* Top and bottom sides renderer
|
|
62
67
|
*/
|
|
@@ -93,6 +98,7 @@ export function DnDList<
|
|
|
93
98
|
loadData,
|
|
94
99
|
name,
|
|
95
100
|
onChange,
|
|
101
|
+
onDragEnd,
|
|
96
102
|
sideRenderer
|
|
97
103
|
} = props;
|
|
98
104
|
|
|
@@ -108,7 +114,7 @@ export function DnDList<
|
|
|
108
114
|
};
|
|
109
115
|
|
|
110
116
|
// Drag end handler
|
|
111
|
-
const
|
|
117
|
+
const onDragEndLocal = (result: DropResult) => {
|
|
112
118
|
// Dropped outside the list
|
|
113
119
|
if (!result.destination) {
|
|
114
120
|
return;
|
|
@@ -125,6 +131,9 @@ export function DnDList<
|
|
|
125
131
|
|
|
126
132
|
// Update the state
|
|
127
133
|
changeItems(newItems);
|
|
134
|
+
|
|
135
|
+
// Drag end handler
|
|
136
|
+
if (onDragEnd) onDragEnd(newItems);
|
|
128
137
|
};
|
|
129
138
|
|
|
130
139
|
// Add item
|
|
@@ -146,7 +155,11 @@ export function DnDList<
|
|
|
146
155
|
// Edit item
|
|
147
156
|
const editItem = (newItem: D, index: number) => {
|
|
148
157
|
// Existence check
|
|
149
|
-
|
|
158
|
+
const newIndex = items.findIndex(
|
|
159
|
+
(item) => item[labelField] === newItem[labelField]
|
|
160
|
+
);
|
|
161
|
+
if (newIndex >= 0 && newIndex != index) {
|
|
162
|
+
// Label field is the same with a different item
|
|
150
163
|
return false;
|
|
151
164
|
}
|
|
152
165
|
|
|
@@ -207,7 +220,7 @@ export function DnDList<
|
|
|
207
220
|
<React.Fragment>
|
|
208
221
|
{sideRenderer && sideRenderer(true, addItem, addItems)}
|
|
209
222
|
<Component {...componentProps}>
|
|
210
|
-
<DragDropContext onDragEnd={
|
|
223
|
+
<DragDropContext onDragEnd={onDragEndLocal}>
|
|
211
224
|
<Droppable droppableId={name}>
|
|
212
225
|
{(provided, snapshot) => (
|
|
213
226
|
<div
|
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)}
|
|
@@ -13,7 +13,7 @@ export type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
|
|
|
13
13
|
* @param type Target data type
|
|
14
14
|
* @returns Data
|
|
15
15
|
*/
|
|
16
|
-
export function getEditPageId<T extends DataTypes.BasicNames
|
|
16
|
+
export function getEditPageId<T extends DataTypes.BasicNames>(
|
|
17
17
|
props: EditPageRouterProps,
|
|
18
18
|
type: T
|
|
19
19
|
): DataTypes.BasicConditional<T> | undefined {
|