react-admin-base-bootstrap 0.9.8 → 0.9.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/bun.lockb
CHANGED
|
Binary file
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
1
3
|
import React from 'react';
|
|
2
4
|
export interface ApiSelectProps<Option = any> {
|
|
3
5
|
url?: string;
|
|
@@ -18,8 +20,8 @@ export interface ApiSelectProps<Option = any> {
|
|
|
18
20
|
onAddOrEdit?: (item: any) => void;
|
|
19
21
|
getNewOptionData?: (name: string, elem: React.ReactNode) => any | null;
|
|
20
22
|
}
|
|
21
|
-
export default function ApiSelect<Option = any>(props: ApiSelectProps<Option>):
|
|
23
|
+
export default function ApiSelect<Option = any>(props: ApiSelectProps<Option>): jsx.JSX.Element;
|
|
22
24
|
export interface CreateSelectProps<Option = any> extends ApiSelectProps<Option> {
|
|
23
25
|
Component: any;
|
|
24
26
|
}
|
|
25
|
-
export declare function CreateSelect(props: CreateSelectProps):
|
|
27
|
+
export declare function CreateSelect(props: CreateSelectProps): jsx.JSX.Element;
|
|
@@ -7,29 +7,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
import { jsx } from '@emotion/react';
|
|
10
12
|
import React, { Fragment, useCallback, useMemo, useState } from 'react';
|
|
11
13
|
import { RefreshScope, useFetch, useRefresh } from 'react-admin-base';
|
|
12
14
|
import { FormattedMessage, useIntl } from 'react-intl';
|
|
13
15
|
import Select, { components } from "react-select";
|
|
14
16
|
import CreatableSelect from 'react-select/creatable';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return slicedArray;
|
|
20
|
-
}
|
|
17
|
+
import { closestCenter, DndContext } from '@dnd-kit/core';
|
|
18
|
+
import { restrictToParentElement } from '@dnd-kit/modifiers';
|
|
19
|
+
import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable, } from '@dnd-kit/sortable';
|
|
20
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
21
21
|
function Option(props) {
|
|
22
|
-
return
|
|
22
|
+
return jsx(components.Option, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || (props.data.__isNew__ ? jsx(FormattedMessage, { id: "CREATE_VALUE", values: { text: props.children } }) : props.children));
|
|
23
23
|
}
|
|
24
24
|
function SingleValue(props) {
|
|
25
|
-
return
|
|
25
|
+
return jsx(components.SingleValue, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || (props.data.__isNew__ ? jsx(FormattedMessage, { id: "CREATE_VALUE", values: { text: props.children } }) : props.children));
|
|
26
26
|
}
|
|
27
27
|
function MultiValue(props) {
|
|
28
|
-
return
|
|
28
|
+
return jsx(components.MultiValue, Object.assign({}, props), (props.selectProps.children && props.selectProps.children(props.data)) || props.children);
|
|
29
29
|
}
|
|
30
30
|
function EditOrAddIndicator(props) {
|
|
31
31
|
const { className, cx, getStyles, innerProps, isMulti } = props;
|
|
32
|
-
return (
|
|
32
|
+
return (jsx("div", Object.assign({}, innerProps, { className: cx({
|
|
33
33
|
indicator: true,
|
|
34
34
|
'clear-indicator': true
|
|
35
35
|
}, className), css: getStyles('clearIndicator', props), onMouseDown: e => {
|
|
@@ -37,34 +37,42 @@ function EditOrAddIndicator(props) {
|
|
|
37
37
|
e.preventDefault();
|
|
38
38
|
props.selectProps.onAddOrEdit();
|
|
39
39
|
} }),
|
|
40
|
-
|
|
40
|
+
jsx("i", { className: "fas " + (props.hasValue && !isMulti ? 'fa-pencil-alt' : 'fa-plus') })));
|
|
41
41
|
}
|
|
42
42
|
function IndicatorsContainer(props) {
|
|
43
|
-
return
|
|
44
|
-
props.selectProps.onAddOrEdit &&
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
return jsx(components.IndicatorsContainer, Object.assign({}, props),
|
|
44
|
+
props.selectProps.onAddOrEdit && jsx(React.Fragment, null,
|
|
45
|
+
jsx(EditOrAddIndicator, Object.assign({}, props)),
|
|
46
|
+
jsx(components.IndicatorSeparator, Object.assign({}, props))),
|
|
47
47
|
props.children);
|
|
48
48
|
}
|
|
49
49
|
function MultiValueRemove(props) {
|
|
50
|
-
return
|
|
51
|
-
props.selectProps.onAddOrEdit &&
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
return jsx(Fragment, null,
|
|
51
|
+
props.selectProps.onAddOrEdit && jsx(components.MultiValueRemove, Object.assign({}, props, { innerProps: Object.assign(Object.assign({}, props.innerProps), { onClick: () => props.selectProps.onAddOrEdit(props.data) }) }),
|
|
52
|
+
jsx("i", { className: "fas fa-pencil", style: { fontSize: '.75em' } })),
|
|
53
|
+
jsx(components.MultiValueRemove, Object.assign({}, props)));
|
|
54
54
|
}
|
|
55
55
|
const Components = { Option, SingleValue, MultiValue, IndicatorsContainer, MultiValueRemove };
|
|
56
|
-
const SortableMultiValue =
|
|
56
|
+
const SortableMultiValue = (props) => {
|
|
57
57
|
const onMouseDown = (e) => {
|
|
58
58
|
e.preventDefault();
|
|
59
59
|
e.stopPropagation();
|
|
60
60
|
};
|
|
61
61
|
const innerProps = Object.assign(Object.assign({}, props.innerProps), { onMouseDown });
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
63
|
+
id: props.selectProps.getOptionValue(props.data),
|
|
64
|
+
});
|
|
65
|
+
const style = {
|
|
66
|
+
transform: CSS.Transform.toString(transform),
|
|
67
|
+
transition,
|
|
68
|
+
};
|
|
69
|
+
return (jsx("div", Object.assign({ style: style, ref: setNodeRef }, attributes, listeners),
|
|
70
|
+
jsx(MultiValue, Object.assign({}, props, { innerProps: innerProps }))));
|
|
71
|
+
};
|
|
72
|
+
const SortableMultiValueRemove = (props) => {
|
|
73
|
+
return (jsx(MultiValueRemove, Object.assign({}, props, { innerProps: Object.assign({ onPointerDown: (e) => e.stopPropagation() }, props.innerProps) })));
|
|
74
|
+
};
|
|
75
|
+
const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, IndicatorsContainer, MultiValueRemove: SortableMultiValueRemove };
|
|
68
76
|
export default function ApiSelect(props) {
|
|
69
77
|
const { disabled, url, getOptionLabel, sortable, getOptionValue, idKey, nameKey, filter, group, onCreateOption, getNewOptionData, isMulti, onChange, value, placeholder, staticOptions } = props;
|
|
70
78
|
const intl = useIntl();
|
|
@@ -104,13 +112,20 @@ export default function ApiSelect(props) {
|
|
|
104
112
|
const onMenuClose = useCallback(function () {
|
|
105
113
|
setIsMenuOpen(false);
|
|
106
114
|
}, [setIsMenuOpen]);
|
|
107
|
-
const
|
|
115
|
+
const _getOptionValue = getOptionValue || ((row) => row[idKey || 'id']);
|
|
116
|
+
const onDragEnd = useCallback(({ active, over }) => {
|
|
117
|
+
if (!active || !over)
|
|
118
|
+
return;
|
|
119
|
+
const oldIndex = value.findIndex((item) => _getOptionValue(item) === active.id);
|
|
120
|
+
const newIndex = value.findIndex((item) => _getOptionValue(item) === over.id);
|
|
108
121
|
const newValue = arrayMove(value, oldIndex, newIndex);
|
|
109
122
|
onChange(newValue);
|
|
110
|
-
}, [value, onChange]);
|
|
111
|
-
const Component = (onCreateOption ?
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
}, [_getOptionValue, value, onChange]);
|
|
124
|
+
const Component = (onCreateOption ? CreatableSelect : Select);
|
|
125
|
+
const useSort = isMulti && sortable;
|
|
126
|
+
const elem = jsx(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 }));
|
|
127
|
+
return jsx(RefreshScope, { update: update }, useSort ? jsx(DndContext, { modifiers: [restrictToParentElement], onDragEnd: onDragEnd, collisionDetection: closestCenter },
|
|
128
|
+
jsx(SortableContext, { items: (value || []).map(_getOptionValue), strategy: horizontalListSortingStrategy }, elem)) : elem);
|
|
114
129
|
}
|
|
115
130
|
export function CreateSelect(props) {
|
|
116
131
|
const { Component, onChange, value, isMulti, idKey } = props;
|
|
@@ -122,7 +137,7 @@ export function CreateSelect(props) {
|
|
|
122
137
|
data && onChange(isMulti ? isOpenId ? value.map(b => b.id === isOpenId ? data : b) : (value || []).concat([data]) : data);
|
|
123
138
|
update && update();
|
|
124
139
|
}, [value, onChange, isMulti, isOpenId, isOpen, update, setIsOpen]);
|
|
125
|
-
return
|
|
126
|
-
isOpen &&
|
|
127
|
-
|
|
140
|
+
return jsx(Fragment, null,
|
|
141
|
+
isOpen && jsx(Component, { id: isOpenId || (!isMulti && value && value[idKey || "id"]), onReload: onReload }),
|
|
142
|
+
jsx(ApiSelect, Object.assign({}, props, { onAddOrEdit: item => setIsOpen(item || true) })));
|
|
128
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-admin-base-bootstrap",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
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.
|
|
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",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
1
2
|
import { jsx } from '@emotion/react';
|
|
2
3
|
import React, {Fragment, useCallback, useMemo, useState} from 'react';
|
|
3
4
|
import {RefreshScope, useFetch, useRefresh} from 'react-admin-base';
|
|
@@ -5,23 +6,15 @@ import { FormattedMessage, useIntl } from 'react-intl';
|
|
|
5
6
|
import Select, { components } from "react-select";
|
|
6
7
|
import CreatableSelect from 'react-select/creatable';
|
|
7
8
|
|
|
9
|
+
import { closestCenter, DndContext, DragEndEvent } from '@dnd-kit/core';
|
|
10
|
+
import { restrictToParentElement } from '@dnd-kit/modifiers';
|
|
8
11
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from '
|
|
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
|
-
|
|
12
|
+
arrayMove,
|
|
13
|
+
horizontalListSortingStrategy,
|
|
14
|
+
SortableContext,
|
|
15
|
+
useSortable,
|
|
16
|
+
} from '@dnd-kit/sortable';
|
|
17
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
25
18
|
|
|
26
19
|
function Option(props) {
|
|
27
20
|
return <components.Option {...props}>
|
|
@@ -91,25 +84,41 @@ function MultiValueRemove(props) {
|
|
|
91
84
|
|
|
92
85
|
const Components = { Option, SingleValue, MultiValue, IndicatorsContainer, MultiValueRemove };
|
|
93
86
|
|
|
94
|
-
const SortableMultiValue =
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
87
|
+
const SortableMultiValue = (props) => {
|
|
88
|
+
const onMouseDown = (e) => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
};
|
|
92
|
+
const innerProps = { ...props.innerProps, onMouseDown };
|
|
93
|
+
const { attributes, listeners, setNodeRef, transform, transition } =
|
|
94
|
+
useSortable({
|
|
95
|
+
id: props.selectProps.getOptionValue(props.data),
|
|
96
|
+
});
|
|
97
|
+
const style = {
|
|
98
|
+
transform: CSS.Transform.toString(transform),
|
|
99
|
+
transition,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div style={style} ref={setNodeRef} {...attributes} {...listeners}>
|
|
104
|
+
<MultiValue {...props} innerProps={innerProps} />
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const SortableMultiValueRemove = (props) => {
|
|
110
|
+
return (
|
|
111
|
+
<MultiValueRemove
|
|
112
|
+
{...props}
|
|
113
|
+
innerProps={{
|
|
114
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
115
|
+
...props.innerProps,
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
110
120
|
|
|
111
|
-
const
|
|
112
|
-
const SortableCreateableSelect = SortableContainer(CreatableSelect);
|
|
121
|
+
const SortableComponents = { Option, SingleValue, MultiValue: SortableMultiValue, IndicatorsContainer, MultiValueRemove: SortableMultiValueRemove };
|
|
113
122
|
|
|
114
123
|
export interface ApiSelectProps<Option = any> {
|
|
115
124
|
url?: string;
|
|
@@ -173,40 +182,50 @@ export default function ApiSelect<Option = any>(props: ApiSelectProps<Option>) {
|
|
|
173
182
|
setIsMenuOpen(false);
|
|
174
183
|
}, [ setIsMenuOpen ]);
|
|
175
184
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
const _getOptionValue = getOptionValue || ((row:any) => row[idKey || 'id']);
|
|
186
|
+
|
|
187
|
+
const onDragEnd = useCallback(({ active, over }) => {
|
|
188
|
+
if (!active || !over) return;
|
|
189
|
+
|
|
190
|
+
const oldIndex = (value as any).findIndex((item) => _getOptionValue(item) === active.id);
|
|
191
|
+
const newIndex = (value as any).findIndex((item) => _getOptionValue(item) === over.id);
|
|
192
|
+
const newValue = arrayMove(value as any, oldIndex, newIndex);
|
|
193
|
+
onChange(newValue as any);
|
|
194
|
+
}, [ _getOptionValue, value, onChange ]);
|
|
195
|
+
|
|
196
|
+
const Component = (onCreateOption ? CreatableSelect : Select);
|
|
197
|
+
|
|
198
|
+
const useSort = isMulti && sortable;
|
|
199
|
+
const elem = <Component
|
|
200
|
+
{...props}
|
|
201
|
+
className='react-select-container'
|
|
202
|
+
classNamePrefix="react-select"
|
|
203
|
+
onCreateOption={(onCreateOption && handleCreateOption) as any}
|
|
204
|
+
getNewOptionData={(onCreateOption && (getNewOptionData || ((inputValue) =>( { [nameKey || 'name']: inputValue, __isNew__: true })))) || undefined}
|
|
205
|
+
inputValue={search}
|
|
206
|
+
onInputChange={a => setSearch(a)}
|
|
207
|
+
components={(useSort ? SortableComponents : Components) as any}
|
|
208
|
+
isLoading={!!loading || creating}
|
|
209
|
+
getOptionLabel={getOptionLabel || ((row:any) => row[nameKey || 'name'])}
|
|
210
|
+
getOptionValue={_getOptionValue}
|
|
211
|
+
isDisabled={!!disabled || creating}
|
|
212
|
+
isClearable
|
|
213
|
+
isSearchable
|
|
214
|
+
placeholder={placeholder || intl.formatMessage({ id: 'SELECT' })}
|
|
215
|
+
options={!options ? [] : ((filter && options.filter(filter)) || options)}
|
|
216
|
+
onMenuOpen={onMenuOpen}
|
|
217
|
+
onMenuClose={onMenuClose}
|
|
218
|
+
/>;
|
|
182
219
|
|
|
183
220
|
return <RefreshScope update={update}>
|
|
184
|
-
<
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
useDragHandle
|
|
205
|
-
axis="xy"
|
|
206
|
-
onSortEnd={onSortEnd}
|
|
207
|
-
distance={4}
|
|
208
|
-
getHelperDimensions={({ node }) => node.getBoundingClientRect()}
|
|
209
|
-
/>
|
|
221
|
+
{ useSort ? <DndContext modifiers={[restrictToParentElement]} onDragEnd={onDragEnd} collisionDetection={closestCenter}>
|
|
222
|
+
<SortableContext
|
|
223
|
+
items={((value || []) as any).map(_getOptionValue)}
|
|
224
|
+
strategy={horizontalListSortingStrategy}
|
|
225
|
+
>
|
|
226
|
+
{elem}
|
|
227
|
+
</SortableContext>
|
|
228
|
+
</DndContext> : elem }
|
|
210
229
|
</RefreshScope>;
|
|
211
230
|
}
|
|
212
231
|
|