react-admin-base-bootstrap 0.9.7 → 0.9.9

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/bun.lockb CHANGED
Binary file
@@ -12,12 +12,10 @@ import { RefreshScope, useFetch, useRefresh } from 'react-admin-base';
12
12
  import { FormattedMessage, useIntl } from 'react-intl';
13
13
  import Select, { components } from "react-select";
14
14
  import CreatableSelect from 'react-select/creatable';
15
- import { SortableContainer, SortableElement, SortableHandle, } from 'react-sortable-hoc';
16
- function arrayMove(array, from, to) {
17
- const slicedArray = array.slice();
18
- slicedArray.splice(to < 0 ? array.length + to : to, 0, slicedArray.splice(from, 1)[0]);
19
- return slicedArray;
20
- }
15
+ import { closestCenter, DndContext } from '@dnd-kit/core';
16
+ import { restrictToParentElement } from '@dnd-kit/modifiers';
17
+ import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable, } from '@dnd-kit/sortable';
18
+ import { CSS } from '@dnd-kit/utilities';
21
19
  function Option(props) {
22
20
  return React.createElement(components.Option, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || (props.data.__isNew__ ? React.createElement(FormattedMessage, { id: "CREATE_VALUE", values: { text: props.children } }) : props.children));
23
21
  }
@@ -53,18 +51,26 @@ function MultiValueRemove(props) {
53
51
  React.createElement(components.MultiValueRemove, Object.assign({}, props)));
54
52
  }
55
53
  const Components = { Option, SingleValue, MultiValue, IndicatorsContainer, MultiValueRemove };
56
- const SortableMultiValue = SortableElement((props) => {
54
+ const SortableMultiValue = (props) => {
57
55
  const onMouseDown = (e) => {
58
56
  e.preventDefault();
59
57
  e.stopPropagation();
60
58
  };
61
59
  const innerProps = Object.assign(Object.assign({}, props.innerProps), { onMouseDown });
62
- return React.createElement(MultiValue, Object.assign({}, props, { innerProps: innerProps }));
63
- });
64
- const SortableMultiValueLabel = SortableHandle((props) => React.createElement(components.MultiValueLabel, Object.assign({}, props)));
65
- const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, MultiValueLabel: SortableMultiValueLabel, IndicatorsContainer, MultiValueRemove };
66
- const SortableSelect = SortableContainer(Select);
67
- const SortableCreateableSelect = SortableContainer(CreatableSelect);
60
+ const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
61
+ id: props.data.id,
62
+ });
63
+ const style = {
64
+ transform: CSS.Transform.toString(transform),
65
+ transition,
66
+ };
67
+ return (React.createElement("div", Object.assign({ style: style, ref: setNodeRef }, attributes, listeners),
68
+ React.createElement(MultiValue, Object.assign({}, props, { innerProps: innerProps }))));
69
+ };
70
+ const SortableMultiValueRemove = (props) => {
71
+ return (React.createElement(MultiValueRemove, Object.assign({}, props, { innerProps: Object.assign({ onPointerDown: (e) => e.stopPropagation() }, props.innerProps) })));
72
+ };
73
+ const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, IndicatorsContainer, MultiValueRemove: SortableMultiValueRemove };
68
74
  export default function ApiSelect(props) {
69
75
  const { disabled, url, getOptionLabel, sortable, getOptionValue, idKey, nameKey, filter, group, onCreateOption, getNewOptionData, isMulti, onChange, value, placeholder, staticOptions } = props;
70
76
  const intl = useIntl();
@@ -104,13 +110,20 @@ export default function ApiSelect(props) {
104
110
  const onMenuClose = useCallback(function () {
105
111
  setIsMenuOpen(false);
106
112
  }, [setIsMenuOpen]);
107
- const onSortEnd = useCallback(({ oldIndex, newIndex }) => {
113
+ const _getOptionValue = getOptionValue || ((row) => row[idKey || 'id']);
114
+ const onDragEnd = useCallback(({ active, over }) => {
115
+ if (!active || !over)
116
+ return;
117
+ const oldIndex = value.findIndex((item) => _getOptionValue(item) === active.id);
118
+ const newIndex = value.findIndex((item) => _getOptionValue(item) === over.id);
108
119
  const newValue = arrayMove(value, oldIndex, newIndex);
109
120
  onChange(newValue);
110
- }, [value, onChange]);
111
- const Component = (onCreateOption ? (sortable && isMulti ? SortableCreateableSelect : CreatableSelect) : (sortable && isMulti ? SortableSelect : Select));
112
- return React.createElement(RefreshScope, { update: update },
113
- React.createElement(Component, Object.assign({}, props, { className: 'react-select-container', classNamePrefix: "react-select", onCreateOption: (onCreateOption && handleCreateOption), getNewOptionData: (onCreateOption && (getNewOptionData || ((inputValue) => ({ [nameKey || 'name']: inputValue, __isNew__: true })))) || undefined, inputValue: search, onInputChange: a => setSearch(a), components: (isMulti && sortable ? SortableComponents : Components), isLoading: !!loading || creating, getOptionLabel: getOptionLabel || ((row) => row[nameKey || 'name']), getOptionValue: getOptionValue || ((row) => row[idKey || 'id']), isDisabled: !!disabled || creating, isClearable: true, isSearchable: true, placeholder: placeholder || intl.formatMessage({ id: 'SELECT' }), options: !options ? [] : ((filter && options.filter(filter)) || options), onMenuOpen: onMenuOpen, onMenuClose: onMenuClose, axis: "xy", onSortEnd: onSortEnd, distance: 4, getHelperDimensions: ({ node }) => node.getBoundingClientRect() })));
121
+ }, [_getOptionValue, value, onChange]);
122
+ const Component = (onCreateOption ? CreatableSelect : Select);
123
+ const useSort = isMulti && sortable;
124
+ const elem = React.createElement(Component, Object.assign({}, props, { className: 'react-select-container', classNamePrefix: "react-select", onCreateOption: (onCreateOption && handleCreateOption), getNewOptionData: (onCreateOption && (getNewOptionData || ((inputValue) => ({ [nameKey || 'name']: inputValue, __isNew__: true })))) || undefined, inputValue: search, onInputChange: a => setSearch(a), components: (useSort ? SortableComponents : Components), isLoading: !!loading || creating, getOptionLabel: getOptionLabel || ((row) => row[nameKey || 'name']), getOptionValue: _getOptionValue, isDisabled: !!disabled || creating, isClearable: true, isSearchable: true, placeholder: placeholder || intl.formatMessage({ id: 'SELECT' }), options: !options ? [] : ((filter && options.filter(filter)) || options), onMenuOpen: onMenuOpen, onMenuClose: onMenuClose }));
125
+ return React.createElement(RefreshScope, { update: update }, useSort ? React.createElement(DndContext, { modifiers: [restrictToParentElement], onDragEnd: onDragEnd, collisionDetection: closestCenter },
126
+ React.createElement(SortableContext, { items: (value || []).map(_getOptionValue), strategy: horizontalListSortingStrategy }, elem)) : elem);
114
127
  }
115
128
  export function CreateSelect(props) {
116
129
  const { Component, onChange, value, isMulti, idKey } = props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-admin-base-bootstrap",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -44,9 +44,12 @@
44
44
  "react-password-strength-bar": "^0.4.1",
45
45
  "react-responsive": "^9.0.2",
46
46
  "react-select": "^5.8.0",
47
- "react-sortable-hoc": "1.9.1",
48
47
  "reactstrap": "^9.2.2",
49
- "sweetalert2": "^11.10.4"
48
+ "sweetalert2": "^11.10.5",
49
+ "@dnd-kit/core": "^6.1.0",
50
+ "@dnd-kit/modifiers": "^7.0.0",
51
+ "@dnd-kit/sortable": "^8.0.0",
52
+ "@dnd-kit/utilities": "^3.2.2"
50
53
  },
51
54
  "devDependencies": {
52
55
  "nodemon": "^3.0.3",
@@ -5,23 +5,15 @@ import { FormattedMessage, useIntl } from 'react-intl';
5
5
  import Select, { components } from "react-select";
6
6
  import CreatableSelect from 'react-select/creatable';
7
7
 
8
+ import { closestCenter, DndContext, DragEndEvent } from '@dnd-kit/core';
9
+ import { restrictToParentElement } from '@dnd-kit/modifiers';
8
10
  import {
9
- SortableContainer,
10
- SortableElement,
11
- SortEndHandler,
12
- SortableHandle,
13
- } from 'react-sortable-hoc';
14
-
15
- function arrayMove<T>(array: readonly T[], from: number, to: number) {
16
- const slicedArray = array.slice();
17
- slicedArray.splice(
18
- to < 0 ? array.length + to : to,
19
- 0,
20
- slicedArray.splice(from, 1)[0]
21
- );
22
- return slicedArray;
23
- }
24
-
11
+ arrayMove,
12
+ horizontalListSortingStrategy,
13
+ SortableContext,
14
+ useSortable,
15
+ } from '@dnd-kit/sortable';
16
+ import { CSS } from '@dnd-kit/utilities';
25
17
 
26
18
  function Option(props) {
27
19
  return <components.Option {...props}>
@@ -91,25 +83,41 @@ function MultiValueRemove(props) {
91
83
 
92
84
  const Components = { Option, SingleValue, MultiValue, IndicatorsContainer, MultiValueRemove };
93
85
 
94
- const SortableMultiValue = SortableElement(
95
- (props) => {
96
- const onMouseDown = (e) => {
97
- e.preventDefault();
98
- e.stopPropagation();
99
- };
100
- const innerProps = { ...props.innerProps, onMouseDown };
101
- return <MultiValue {...props} innerProps={innerProps} />;
102
- }
103
- );
104
-
105
- const SortableMultiValueLabel = SortableHandle(
106
- (props) => <components.MultiValueLabel {...props} />
107
- );
108
-
109
- const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, MultiValueLabel: SortableMultiValueLabel, IndicatorsContainer, MultiValueRemove };
86
+ const SortableMultiValue = (props) => {
87
+ const onMouseDown = (e) => {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ };
91
+ const innerProps = { ...props.innerProps, onMouseDown };
92
+ const { attributes, listeners, setNodeRef, transform, transition } =
93
+ useSortable({
94
+ id: props.data.id,
95
+ });
96
+ const style = {
97
+ transform: CSS.Transform.toString(transform),
98
+ transition,
99
+ };
100
+
101
+ return (
102
+ <div style={style} ref={setNodeRef} {...attributes} {...listeners}>
103
+ <MultiValue {...props} innerProps={innerProps} />
104
+ </div>
105
+ );
106
+ };
107
+
108
+ const SortableMultiValueRemove = (props) => {
109
+ return (
110
+ <MultiValueRemove
111
+ {...props}
112
+ innerProps={{
113
+ onPointerDown: (e) => e.stopPropagation(),
114
+ ...props.innerProps,
115
+ }}
116
+ />
117
+ );
118
+ };
110
119
 
111
- const SortableSelect = SortableContainer(Select);
112
- const SortableCreateableSelect = SortableContainer(CreatableSelect);
120
+ const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, IndicatorsContainer, MultiValueRemove: SortableMultiValueRemove };
113
121
 
114
122
  export interface ApiSelectProps<Option = any> {
115
123
  url?: string;
@@ -173,39 +181,50 @@ export default function ApiSelect<Option = any>(props: ApiSelectProps<Option>) {
173
181
  setIsMenuOpen(false);
174
182
  }, [ setIsMenuOpen ]);
175
183
 
176
- const onSortEnd: SortEndHandler = useCallback(({ oldIndex, newIndex }) => {
177
- const newValue = arrayMove(value as any, oldIndex, newIndex);
178
- onChange(newValue as any);
179
- }, [ value, onChange ]);
180
-
181
- const Component = (onCreateOption ? (sortable && isMulti ? SortableCreateableSelect : CreatableSelect) : (sortable && isMulti ? SortableSelect : Select)) as any;
184
+ const _getOptionValue = getOptionValue || ((row:any) => row[idKey || 'id']);
185
+
186
+ const onDragEnd = useCallback(({ active, over }) => {
187
+ if (!active || !over) return;
188
+
189
+ const oldIndex = (value as any).findIndex((item) => _getOptionValue(item) === active.id);
190
+ const newIndex = (value as any).findIndex((item) => _getOptionValue(item) === over.id);
191
+ const newValue = arrayMove(value as any, oldIndex, newIndex);
192
+ onChange(newValue as any);
193
+ }, [ _getOptionValue, value, onChange ]);
194
+
195
+ const Component = (onCreateOption ? CreatableSelect : Select);
196
+
197
+ const useSort = isMulti && sortable;
198
+ const elem = <Component
199
+ {...props}
200
+ className='react-select-container'
201
+ classNamePrefix="react-select"
202
+ onCreateOption={(onCreateOption && handleCreateOption) as any}
203
+ getNewOptionData={(onCreateOption && (getNewOptionData || ((inputValue) =>( { [nameKey || 'name']: inputValue, __isNew__: true })))) || undefined}
204
+ inputValue={search}
205
+ onInputChange={a => setSearch(a)}
206
+ components={(useSort ? SortableComponents : Components) as any}
207
+ isLoading={!!loading || creating}
208
+ getOptionLabel={getOptionLabel || ((row:any) => row[nameKey || 'name'])}
209
+ getOptionValue={_getOptionValue}
210
+ isDisabled={!!disabled || creating}
211
+ isClearable
212
+ isSearchable
213
+ placeholder={placeholder || intl.formatMessage({ id: 'SELECT' })}
214
+ options={!options ? [] : ((filter && options.filter(filter)) || options)}
215
+ onMenuOpen={onMenuOpen}
216
+ onMenuClose={onMenuClose}
217
+ />;
182
218
 
183
219
  return <RefreshScope update={update}>
184
- <Component
185
- {...props}
186
- className='react-select-container'
187
- classNamePrefix="react-select"
188
- onCreateOption={(onCreateOption && handleCreateOption) as any}
189
- getNewOptionData={(onCreateOption && (getNewOptionData || ((inputValue) =>( { [nameKey || 'name']: inputValue, __isNew__: true })))) || undefined}
190
- inputValue={search}
191
- onInputChange={a => setSearch(a)}
192
- components={(isMulti && sortable ? SortableComponents : Components) as any}
193
- isLoading={!!loading || creating}
194
- getOptionLabel={getOptionLabel || ((row:any) => row[nameKey || 'name'])}
195
- getOptionValue={getOptionValue || ((row:any) => row[idKey || 'id'])}
196
- isDisabled={!!disabled || creating}
197
- isClearable
198
- isSearchable
199
- placeholder={placeholder || intl.formatMessage({ id: 'SELECT' })}
200
- options={!options ? [] : ((filter && options.filter(filter)) || options)}
201
- onMenuOpen={onMenuOpen}
202
- onMenuClose={onMenuClose}
203
-
204
- axis="xy"
205
- onSortEnd={onSortEnd}
206
- distance={4}
207
- getHelperDimensions={({ node }) => node.getBoundingClientRect()}
208
- />
220
+ { useSort ? <DndContext modifiers={[restrictToParentElement]} onDragEnd={onDragEnd} collisionDetection={closestCenter}>
221
+ <SortableContext
222
+ items={((value || []) as any).map(_getOptionValue)}
223
+ strategy={horizontalListSortingStrategy}
224
+ >
225
+ {elem}
226
+ </SortableContext>
227
+ </DndContext> : elem }
209
228
  </RefreshScope>;
210
229
  }
211
230