@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.
@@ -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 onDragEnd = (result) => {
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
- if (items.some((item) => item[labelField] === newItem[labelField])) {
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: 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
@@ -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' | 'disableHoverListener' | 'disableTouchListener'> {
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
@@ -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, disableHoverListener: true, disableTouchListener: true, ...rest }, children(openTooltip))));
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 = 'number'>(props: EditPageRouterProps, type: T): DataTypes.BasicConditional<T> | undefined;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.7",
3
+ "version": "1.4.11",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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 onDragEnd = (result: DropResult) => {
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
- if (items.some((item) => item[labelField] === newItem[labelField])) {
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={onDragEnd}>
223
+ <DragDropContext onDragEnd={onDragEndLocal}>
211
224
  <Droppable droppableId={name}>
212
225
  {(provided, snapshot) => (
213
226
  <div
@@ -7,15 +7,13 @@ import React from 'react';
7
7
  export interface TooltipClickProps
8
8
  extends Omit<
9
9
  TooltipProps,
10
- | 'children'
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 { children, leaveDelay = 5000, onClose, title, ...rest } = props;
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 = 'number'>(
16
+ export function getEditPageId<T extends DataTypes.BasicNames>(
17
17
  props: EditPageRouterProps,
18
18
  type: T
19
19
  ): DataTypes.BasicConditional<T> | undefined {