react-admin-base-bootstrap 0.8.2 → 0.8.4

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.
@@ -86,7 +86,6 @@ export default function BootstrapTable({ url, bordered, noStrip, defaultParams,
86
86
  const [page, lastPage, setPage, data, itemPerPage, setItemPerPage, update] = useDataTable(url, params, body);
87
87
  const intl = useIntl();
88
88
  const [api] = useAuth();
89
- console.log(children[1]);
90
89
  const ref = useRef(defaultParams);
91
90
  useEffect(function () {
92
91
  if (ref.current !== defaultParams) {
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { InputProps } from "reactstrap";
3
3
  interface CheckBoxProps extends InputProps {
4
- id: string;
4
+ id?: string;
5
5
  type?: "checkbox" | "radio";
6
6
  label?: React.ReactNode;
7
7
  children?: React.ReactNode;
@@ -1,7 +1,8 @@
1
- import React from "react";
1
+ import React, { useId } from "react";
2
2
  import { FormGroup, Input, Label } from "reactstrap";
3
3
  export default function CheckBox(props) {
4
+ const id = useId();
4
5
  return React.createElement(FormGroup, { check: true },
5
- React.createElement(Input, Object.assign({ type: props.type || "checkbox" }, props, { children: undefined, label: undefined })),
6
- React.createElement(Label, { check: true, for: props.id }, props.children || props.label));
6
+ React.createElement(Input, Object.assign({ id: props.id || id, type: props.type || "checkbox" }, props, { children: undefined, label: undefined })),
7
+ React.createElement(Label, { check: true, for: props.id || id }, props.children || props.label));
7
8
  }
@@ -0,0 +1,2 @@
1
+ import { ButtonProps } from "reactstrap";
2
+ export default function DragAndDropArrow(props: ButtonProps): JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { Button } from "reactstrap";
3
+ import { useDragContext } from "react-admin-base";
4
+ export default function DragAndDropArrow(props) {
5
+ const [ref, isDragging] = useDragContext();
6
+ if (!ref)
7
+ return null;
8
+ return React.createElement(Button, Object.assign({ type: "button", innerRef: ref, outline: true, size: "sm", color: "primary" }, props),
9
+ React.createElement("i", { className: "fas fa-" + (isDragging ? "circle-dot" : "arrows-up-down-left-right") }),
10
+ props.children);
11
+ }
@@ -0,0 +1,2 @@
1
+ import { ButtonProps } from "reactstrap";
2
+ export declare function DragAndDropArrow(props: ButtonProps): JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { Button } from "reactstrap";
3
+ import { useDragContext } from "react-admin-base";
4
+ export function DragAndDropArrow(props) {
5
+ const [ref, isDragging] = useDragContext();
6
+ if (!ref)
7
+ return null;
8
+ return React.createElement(Button, Object.assign({ type: "button", innerRef: ref, outline: true, size: "sm", color: "primary" }, props),
9
+ React.createElement("i", { className: "fas fa-arrows-up-down-left-right" }),
10
+ props.children);
11
+ }
@@ -6,8 +6,10 @@ export declare function Relative({ children }: RelativeProps): React.FunctionCom
6
6
  export declare function Preview({ value }: {
7
7
  value: any;
8
8
  }): JSX.Element | null;
9
- export default function FilePickerCore({ disabled, className, accepts, value, onNotify, children, transform }: {
9
+ export default function FilePickerCore({ disabled, index, move, className, accepts, value, onNotify, children, transform }: {
10
10
  disabled?: any;
11
+ index?: number;
12
+ move?: any;
11
13
  className?: any;
12
14
  accepts?: any;
13
15
  value?: any;
@@ -1,8 +1,9 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import prettysize from 'prettysize';
3
3
  import { Button } from "reactstrap";
4
- import { useApp, useFilePicker, usePreviewComponent } from "react-admin-base";
4
+ import { useApp, useFilePicker, usePreviewComponent, DragAndDropItem } from "react-admin-base";
5
5
  import { FormattedMessage } from "react-intl";
6
+ import DragAndDropArrow from './DragAndDropArrow';
6
7
  const photo_ext = ["png", "jpg", "jpeg", "svg"];
7
8
  function is_photo(name) {
8
9
  return photo_ext.indexOf(name.split('.')[1]) !== -1;
@@ -33,7 +34,7 @@ export function Preview({ value }) {
33
34
  }
34
35
  return null;
35
36
  }
36
- export default function FilePickerCore({ disabled, className, accepts, value, onNotify, children, transform }) {
37
+ export default function FilePickerCore({ disabled, index, move, className, accepts, value, onNotify, children, transform }) {
37
38
  const [uc, cancel, pick] = useFilePicker(value, onNotify);
38
39
  const CustomPreview = usePreviewComponent() || Preview;
39
40
  const chooseFile = useCallback(function (e) {
@@ -62,21 +63,23 @@ export default function FilePickerCore({ disabled, className, accepts, value, on
62
63
  children && children(uc));
63
64
  }
64
65
  else if (uc.$state === 3) { // yuklendi
65
- return React.createElement("div", { className: className },
66
- !disabled && React.createElement(Button, { color: "danger", outline: true, size: "sm", onClick: cancel },
67
- React.createElement("i", { className: "fa fa-trash" })),
68
- "\u00A0",
69
- React.createElement(Relative, null,
70
- React.createElement("a", { href: uc.$src, target: "_blank", className: "btn btn-sm btn-outline-primary" },
71
- React.createElement("i", { className: "fa fa-download" }),
72
- " ",
73
- uc.name)),
74
- React.createElement("span", null,
75
- "\u00A0(",
76
- prettysize(uc.$size),
77
- ")"),
78
- React.createElement(CustomPreview, { value: uc }),
79
- children && children(uc));
66
+ return React.createElement(DragAndDropItem, { item: index },
67
+ React.createElement("div", { className: className },
68
+ React.createElement(DragAndDropArrow, { className: "me-1" }),
69
+ !disabled && React.createElement(Button, { color: "danger", outline: true, size: "sm", onClick: cancel },
70
+ React.createElement("i", { className: "fa fa-trash" })),
71
+ "\u00A0",
72
+ React.createElement(Relative, null,
73
+ React.createElement("a", { href: uc.$src, target: "_blank", className: "btn btn-sm btn-outline-primary" },
74
+ React.createElement("i", { className: "fa fa-download" }),
75
+ " ",
76
+ uc.name)),
77
+ React.createElement("span", null,
78
+ "\u00A0(",
79
+ prettysize(uc.$size),
80
+ ")"),
81
+ React.createElement(CustomPreview, { value: uc }),
82
+ children && children(uc)));
80
83
  }
81
84
  return null;
82
85
  }
@@ -5,7 +5,8 @@ declare type MultiFilePickerProps = {
5
5
  accepts?: string;
6
6
  value: any;
7
7
  onChange: (value: any) => void;
8
+ noMove?: boolean;
8
9
  children?: (value: any) => React.ReactNode;
9
10
  };
10
- export default function MultiFilePicker({ disabled, className, accepts, value, onChange, children }: MultiFilePickerProps): JSX.Element;
11
+ export default function MultiFilePicker({ disabled, className, noMove, accepts, value, onChange, children }: MultiFilePickerProps): JSX.Element;
11
12
  export {};
@@ -1,11 +1,11 @@
1
1
  import React, { useMemo } from 'react';
2
- import { useMultiFilePicker } from "react-admin-base";
2
+ import { useMultiFilePicker, DragAndDropProvider } from "react-admin-base";
3
3
  import { FormattedMessage } from "react-intl";
4
4
  import { Button } from "reactstrap";
5
5
  import FilePickerCore from "./FilePickerCore";
6
- export default function MultiFilePicker({ disabled, className, accepts, value, onChange, children }) {
6
+ export default function MultiFilePicker({ disabled, className, noMove, accepts, value, onChange, children }) {
7
7
  const uniqueIdList = useMemo(() => [], []);
8
- const [controllers, _onChange, chooseFile] = useMultiFilePicker(value, onChange);
8
+ const [controllers, _onChange, chooseFile, onMove] = useMultiFilePicker(value, onChange);
9
9
  function getConstantUniqueIdFor(element) {
10
10
  if (uniqueIdList.indexOf(element) < 0) {
11
11
  uniqueIdList.push(element);
@@ -18,5 +18,5 @@ export default function MultiFilePicker({ disabled, className, accepts, value, o
18
18
  " ",
19
19
  React.createElement(FormattedMessage, { id: "CHOOSE_FILE" })),
20
20
  children && children(null),
21
- controllers.map((a, i) => React.createElement(FilePickerCore, { key: getConstantUniqueIdFor(a), disabled: !!disabled, className: "mt-2", accepts: accepts, value: a, onNotify: _onChange.bind(null, a) }, children)));
21
+ React.createElement(DragAndDropProvider, { onMove: !noMove && onMove }, controllers.map((a, i) => React.createElement(FilePickerCore, { key: getConstantUniqueIdFor(a), disabled: !!disabled, className: "mt-2", accepts: accepts, value: a, index: i, onNotify: _onChange.bind(null, a) }, children))));
22
22
  }
@@ -20,4 +20,5 @@ import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvide
20
20
  import StepList, { StepItem } from './Components/StepList';
21
21
  import PasswordInput from './Components/PasswordInput';
22
22
  import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
23
- export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox };
23
+ import DragAndDropArrow from './Components/DragAndDropArrow';
24
+ export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox, DragAndDropArrow };
package/lib/esm/index.js CHANGED
@@ -20,4 +20,5 @@ import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvide
20
20
  import StepList, { StepItem } from './Components/StepList';
21
21
  import PasswordInput from './Components/PasswordInput';
22
22
  import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
23
- export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox };
23
+ import DragAndDropArrow from './Components/DragAndDropArrow';
24
+ export { ThemeProvider, useTheme, useAllThemes, useIsMobile, useMenuState, DefaultValidatorOptions, PasswordInput, StepList, StepItem, TopProgressBar, CRUD, ModalEntityEditor, CRUDActions, Relative, ApiSelect, Preview, ExcelExportButton, ExternalLoginButton, SingleFilePicker, MultiFilePicker, ImagePicker, BootstrapTable, EntityEditor, GoToTop, Validator, ValueValidator, ValidationErrors, LoadingButton, BootstrapDataTable, IdColumn, Column, ActionsColumn, Actions, useDataTableContext, RowRenderer, LanguageProvider, useLanguage, LanguageSwitcher, ErrorBoundary, CheckBox, DragAndDropArrow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-admin-base-bootstrap",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -31,26 +31,28 @@
31
31
  "react-router-dom": "^6.4.2"
32
32
  },
33
33
  "dependencies": {
34
- "@emotion/react": "^11.10.4",
34
+ "@emotion/react": "^11.10.5",
35
35
  "@fortawesome/fontawesome-free": "^6.2.0",
36
36
  "bootstrap": "^5.2.2",
37
37
  "file-dialog": "^0.0.8",
38
38
  "modal-cropper": "^1.2.3",
39
39
  "nprogress": "^0.2.0",
40
40
  "prettysize": "^2.0.0",
41
- "react-admin-base": "^0.8.0",
41
+ "react-admin-base": "^0.8.3",
42
+ "react-dnd": "^16.0.1",
43
+ "react-dnd-html5-backend": "^16.0.1",
42
44
  "react-password-strength-bar": "^0.4.1",
43
45
  "react-responsive": "^9.0.0",
44
- "react-select": "^5.4.0",
45
- "reactstrap": "^9.1.4",
46
+ "react-select": "^5.5.7",
47
+ "reactstrap": "^9.1.5",
46
48
  "rewire": "^6.0.0",
47
- "sweetalert2": "^11.5.1"
49
+ "sweetalert2": "^11.6.4"
48
50
  },
49
51
  "devDependencies": {
50
- "@types/react": "^18.0.21",
52
+ "@types/react": "^18.0.24",
51
53
  "cross-env": "^7.0.3",
52
54
  "nodemon": "^2.0.20",
53
- "react-intl": "^6.1.2",
55
+ "react-intl": "^6.2.1",
54
56
  "typescript": "^4.8.4"
55
57
  }
56
58
  }
@@ -114,8 +114,6 @@ export default function BootstrapTable({url, bordered, noStrip, defaultParams, a
114
114
  const intl = useIntl();
115
115
  const [ api ] = useAuth();
116
116
 
117
- console.log(children[1]);
118
-
119
117
  const ref = useRef(defaultParams);
120
118
  useEffect(function () {
121
119
  if (ref.current !== defaultParams) {
@@ -1,16 +1,18 @@
1
- import React from "react";
1
+ import React, {useId} from "react";
2
2
  import { FormGroup, Input, InputProps, Label } from "reactstrap";
3
3
 
4
4
  interface CheckBoxProps extends InputProps {
5
- id: string;
5
+ id?: string;
6
6
  type?: "checkbox"|"radio";
7
7
  label?: React.ReactNode;
8
8
  children?: React.ReactNode;
9
9
  }
10
10
 
11
11
  export default function CheckBox(props: CheckBoxProps) {
12
+ const id = useId();
13
+
12
14
  return <FormGroup check>
13
- <Input type={props.type || "checkbox"} {...props} children={undefined} label={undefined} />
14
- <Label check for={props.id}>{props.children || props.label}</Label>
15
+ <Input id={props.id || id} type={props.type || "checkbox"} {...props} children={undefined} label={undefined} />
16
+ <Label check for={props.id || id}>{props.children || props.label}</Label>
15
17
  </FormGroup>;
16
18
  }
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import {Button, ButtonProps} from "reactstrap";
3
+ import { useDragContext } from "react-admin-base";
4
+
5
+ export default function DragAndDropArrow(props: ButtonProps) {
6
+ const [ ref, isDragging ] = useDragContext();
7
+
8
+ if (!ref)
9
+ return null;
10
+
11
+ return <Button type="button" innerRef={ref} outline size="sm" color="primary" {...props}>
12
+ <i className={"fas fa-" + (isDragging ? "circle-dot" : "arrows-up-down-left-right")} />{props.children}
13
+ </Button>;
14
+ }
@@ -2,8 +2,9 @@
2
2
  import React, { useCallback } from 'react';
3
3
  import prettysize from 'prettysize';
4
4
  import {Button} from "reactstrap";
5
- import { useApp, useFilePicker, usePreviewComponent } from "react-admin-base";
5
+ import { useApp, useFilePicker, usePreviewComponent, DragAndDropItem } from "react-admin-base";
6
6
  import {FormattedMessage} from "react-intl";
7
+ import DragAndDropArrow from './DragAndDropArrow';
7
8
 
8
9
  const photo_ext = ["png", "jpg", "jpeg", "svg"];
9
10
 
@@ -52,7 +53,7 @@ export function Preview({ value }) {
52
53
  return null;
53
54
  }
54
55
 
55
- export default function FilePickerCore({ disabled, className, accepts, value, onNotify, children, transform } : { disabled?: any, className?: any, accepts?: any, value?:any, onNotify?:any, children?:any, transform?:any }) {
56
+ export default function FilePickerCore({ disabled, index, move, className, accepts, value, onNotify, children, transform } : { disabled?: any, index?: number, move?: any, className?: any, accepts?: any, value?:any, onNotify?:any, children?:any, transform?:any }) {
56
57
  const [ uc, cancel, pick ] = useFilePicker(value, onNotify);
57
58
  const CustomPreview = usePreviewComponent() || Preview;
58
59
 
@@ -78,13 +79,16 @@ export default function FilePickerCore({ disabled, className, accepts, value, on
78
79
  { children && children(uc) }
79
80
  </div>;
80
81
  } else if(uc.$state === 3) { // yuklendi
81
- return <div className={className}>
82
- { !disabled && <Button color="danger" outline size="sm" onClick={cancel}><i className="fa fa-trash" /></Button> }
83
- &nbsp;<Relative><a href={uc.$src} target="_blank" className="btn btn-sm btn-outline-primary"><i className="fa fa-download" /> { uc.name }</a></Relative>
84
- <span>&nbsp;({ prettysize(uc.$size) })</span>
85
- { <CustomPreview value={uc} /> }
86
- { children && children(uc) }
87
- </div>;
82
+ return <DragAndDropItem item={index}>
83
+ <div className={className}>
84
+ <DragAndDropArrow className="me-1" />
85
+ { !disabled && <Button color="danger" outline size="sm" onClick={cancel}><i className="fa fa-trash" /></Button> }
86
+ &nbsp;<Relative><a href={uc.$src} target="_blank" className="btn btn-sm btn-outline-primary"><i className="fa fa-download" /> { uc.name }</a></Relative>
87
+ <span>&nbsp;({ prettysize(uc.$size) })</span>
88
+ { <CustomPreview value={uc} /> }
89
+ { children && children(uc) }
90
+ </div>
91
+ </DragAndDropItem>;
88
92
  }
89
93
 
90
94
  return null;
@@ -1,9 +1,9 @@
1
1
 
2
- import React, { useMemo } from 'react';
3
- import { useMultiFilePicker } from "react-admin-base";
4
- import { FormattedMessage } from "react-intl";
5
- import { Button } from "reactstrap";
6
- import FilePickerCore from "./FilePickerCore";
2
+ import React, { useMemo } from 'react';
3
+ import { useMultiFilePicker, DragAndDropProvider } from "react-admin-base";
4
+ import { FormattedMessage } from "react-intl";
5
+ import { Button } from "reactstrap";
6
+ import FilePickerCore from "./FilePickerCore";
7
7
 
8
8
  type MultiFilePickerProps = {
9
9
  disabled?: boolean;
@@ -11,12 +11,13 @@ type MultiFilePickerProps = {
11
11
  accepts?: string;
12
12
  value: any;
13
13
  onChange: (value: any) => void;
14
+ noMove?: boolean;
14
15
  children?: (value: any) => React.ReactNode;
15
16
  }
16
17
 
17
- export default function MultiFilePicker({ disabled, className, accepts, value, onChange, children }: MultiFilePickerProps) {
18
+ export default function MultiFilePicker({ disabled, className, noMove, accepts, value, onChange, children }: MultiFilePickerProps) {
18
19
  const uniqueIdList = useMemo(() => [] as any, []);
19
- const [ controllers, _onChange, chooseFile ] = useMultiFilePicker(value, onChange);
20
+ const [ controllers, _onChange, chooseFile, onMove ] = useMultiFilePicker(value, onChange);
20
21
 
21
22
  function getConstantUniqueIdFor(element) {
22
23
  if (uniqueIdList.indexOf(element) < 0) {
@@ -31,13 +32,16 @@ export default function MultiFilePicker({ disabled, className, accepts, value, o
31
32
  </Button>
32
33
  { children && children(null) }
33
34
 
34
- { controllers.map((a,i) => <FilePickerCore
35
- key={getConstantUniqueIdFor(a)}
36
- disabled={!!disabled}
37
- className="mt-2"
38
- accepts={accepts}
39
- value={a}
40
- onNotify={_onChange.bind(null, a)}
41
- >{children}</FilePickerCore>) }
35
+ <DragAndDropProvider onMove={!noMove && onMove}>
36
+ { controllers.map((a,i) => <FilePickerCore
37
+ key={getConstantUniqueIdFor(a)}
38
+ disabled={!!disabled}
39
+ className="mt-2"
40
+ accepts={accepts}
41
+ value={a}
42
+ index={i}
43
+ onNotify={_onChange.bind(null, a)}
44
+ >{children}</FilePickerCore>) }
45
+ </DragAndDropProvider>
42
46
  </div>;
43
47
  }
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ import ThemeProvider, { useTheme, useAllThemes } from './Components/ThemeProvide
21
21
  import StepList, { StepItem } from './Components/StepList';
22
22
  import PasswordInput from './Components/PasswordInput';
23
23
  import DefaultValidatorOptions from './Components/DefaultValidatorOptions';
24
+ import DragAndDropArrow from './Components/DragAndDropArrow';
24
25
 
25
26
  export {
26
27
  ThemeProvider, useTheme, useAllThemes,
@@ -47,5 +48,6 @@ export {
47
48
  RowRenderer,
48
49
  LanguageProvider, useLanguage, LanguageSwitcher,
49
50
  ErrorBoundary,
50
- CheckBox
51
+ CheckBox,
52
+ DragAndDropArrow
51
53
  };