@rulab/adminjs-components 0.0.13 → 0.1.0-alpha.2

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.
Files changed (71) hide show
  1. package/LICENSE +21 -21
  2. package/dist/index.cjs +10 -762
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +10 -21
  5. package/dist/index.d.ts +10 -21
  6. package/dist/index.js +3 -754
  7. package/dist/index.js.map +1 -0
  8. package/package.json +12 -8
  9. package/src/components/ColorStatus/ColorStatusEdit.tsx +94 -94
  10. package/src/components/ColorStatus/ColorStatusList.tsx +20 -20
  11. package/src/components/ColorStatus/ColorStatusShow.tsx +23 -23
  12. package/src/components/ColorStatus/index.ts +3 -3
  13. package/src/components/ColorStatus/styles.ts +30 -30
  14. package/src/components/ColorStatus/types.ts +5 -5
  15. package/src/components/Editor/Editor.jsx +49 -49
  16. package/src/components/Editor/EditorList.jsx +22 -22
  17. package/src/components/Editor/EditorShow.jsx +24 -24
  18. package/src/components/Editor/config.ts +35 -35
  19. package/src/components/Editor/index.ts +3 -3
  20. package/src/components/Editor/styles.ts +151 -151
  21. package/src/components/{CustomSlug/CustomSlug.tsx → Slug/SlugEdit.tsx} +68 -68
  22. package/src/components/Slug/SlugFeature.ts +30 -0
  23. package/src/components/Slug/index.ts +1 -0
  24. package/src/components/{CustomSlug → Slug}/styles.ts +24 -24
  25. package/src/components/StringList/SortableList/SortableList.tsx +98 -98
  26. package/src/components/StringList/SortableList/components/SortableItem/DragHandle.tsx +20 -20
  27. package/src/components/StringList/SortableList/components/SortableItem/SortableItem.tsx +59 -59
  28. package/src/components/StringList/SortableList/components/SortableItem/styles.ts +22 -22
  29. package/src/components/StringList/SortableList/components/SortableItem/types.ts +7 -7
  30. package/src/components/StringList/SortableList/components/index.ts +2 -2
  31. package/src/components/StringList/SortableList/index.ts +1 -1
  32. package/src/components/StringList/SortableList/styles.ts +9 -9
  33. package/src/components/StringList/StringList.tsx +136 -136
  34. package/src/components/StringList/StringListShow.tsx +37 -37
  35. package/src/components/StringList/constants.ts +1 -1
  36. package/src/components/StringList/index.ts +2 -2
  37. package/src/components/StringList/styles.ts +41 -41
  38. package/src/components/index.ts +10 -9
  39. package/dist/bundle.js +0 -8
  40. package/dist/components/CustomSlug/CustomSlug.jsx +0 -29
  41. package/dist/components/CustomSlug/index.js +0 -1
  42. package/dist/components/CustomSlug/styles.js +0 -15
  43. package/dist/components/Editor/config.js +0 -11
  44. package/dist/components/Editor/index.js +0 -1
  45. package/dist/components/Editor/styles.js +0 -64
  46. package/dist/components/StringList/SortableList/SortableList.jsx +0 -43
  47. package/dist/components/StringList/SortableList/components/SortableItem/DragHandle.jsx +0 -10
  48. package/dist/components/StringList/SortableList/components/SortableItem/SortableItem.jsx +0 -32
  49. package/dist/components/StringList/SortableList/components/SortableItem/styles.js +0 -20
  50. package/dist/components/StringList/SortableList/components/SortableItem/types.js +0 -1
  51. package/dist/components/StringList/SortableList/components/index.js +0 -2
  52. package/dist/components/StringList/SortableList/index.js +0 -1
  53. package/dist/components/StringList/SortableList/styles.js +0 -8
  54. package/dist/components/StringList/StringList.jsx +0 -67
  55. package/dist/components/StringList/index.js +0 -1
  56. package/dist/components/StringList/styles.js +0 -16
  57. package/dist/components/index.js +0 -3
  58. package/dist/editorFeature.js +0 -16
  59. package/dist/index.d.mts +0 -8
  60. package/dist/index.mjs +0 -37
  61. package/dist/utils/index.js +0 -1
  62. package/dist/utils/slugifyImport.js +0 -3
  63. package/dist/utils/slugifyTitle.js +0 -10
  64. package/src/components/CustomSlug/index.ts +0 -1
  65. package/src/index.ts +0 -2
  66. package/src/types.d.ts +0 -3
  67. package/src/utils/index.ts +0 -3
  68. package/src/utils/parseHtml.ts +0 -56
  69. package/src/utils/slugifyImport.ts +0 -4
  70. package/src/utils/slugifyTitle.ts +0 -11
  71. package/tsconfig.json +0 -17
@@ -1,136 +1,136 @@
1
- import { Button, Input, theme } from "@adminjs/design-system";
2
- import { EditPropertyProps } from "adminjs";
3
- import React, {
4
- ChangeEvent,
5
- FC,
6
- KeyboardEvent,
7
- SyntheticEvent,
8
- useEffect,
9
- useState,
10
- } from "react";
11
- import { ThemeProvider } from "styled-components";
12
-
13
- import {
14
- StyledCustomInput,
15
- StyledInputWrapper,
16
- StyledLabel,
17
- StyledListWrapper,
18
- StyledWrapper,
19
- } from "./styles.js";
20
-
21
- import { SortableList } from "./SortableList/SortableList.js";
22
- import { separator } from "./constants.js";
23
-
24
- type ListDataTypes = {
25
- id: string;
26
- value: string;
27
- };
28
-
29
- type StringListTypes = Omit<EditPropertyProps, "where" | "resource">;
30
-
31
- interface StringListShowPropsType extends StringListTypes {
32
- stringListSeparator?: string;
33
- }
34
-
35
- const StringList: FC<StringListShowPropsType> = ({
36
- record,
37
- onChange,
38
- property,
39
- stringListSeparator = separator,
40
- }) => {
41
- const stringListValue =
42
- record.params?.[property.path] ?? property.props.value ?? "";
43
-
44
- const initialList = stringListValue
45
- ? prepareDataForList(stringListValue)
46
- : [];
47
-
48
- const [inputValue, setInputValue] = useState("");
49
- const [list, setList] = useState<ListDataTypes[]>(initialList);
50
-
51
- const serializedData = prepareDataForDatabase(list);
52
-
53
- useEffect(() => {
54
- onChange(property.path, serializedData);
55
- }, [serializedData]);
56
-
57
- return (
58
- <ThemeProvider theme={theme}>
59
- <StyledLabel htmlFor="custom">{property.path}</StyledLabel>
60
- <StyledWrapper>
61
- <StyledListWrapper>
62
- <SortableList
63
- items={list}
64
- onChange={setList}
65
- renderItem={(item) => (
66
- <SortableList.Item id={item.id} onDelete={handleDeleteButton}>
67
- {item.value}
68
- </SortableList.Item>
69
- )}
70
- />
71
- </StyledListWrapper>
72
- <StyledInputWrapper>
73
- <Input
74
- id="stringList"
75
- name={property.path}
76
- value={serializedData}
77
- hidden
78
- />
79
- <StyledCustomInput
80
- id="custom"
81
- name="customInput"
82
- value={inputValue}
83
- onChange={handleInput}
84
- onKeyPress={handleEnterPress}
85
- />
86
- <Button variant="outlined" onClick={handleAddButton}>
87
- Add
88
- </Button>
89
- </StyledInputWrapper>
90
- </StyledWrapper>
91
- </ThemeProvider>
92
- );
93
-
94
- function handleInput(e: ChangeEvent<HTMLInputElement>) {
95
- setInputValue(e.target.value);
96
- }
97
-
98
- function handleEnterPress(e: KeyboardEvent<HTMLInputElement>) {
99
- if (e.key === "Enter") {
100
- handleAddButton(e);
101
- }
102
- }
103
-
104
- function handleAddButton(e: SyntheticEvent<HTMLInputElement>) {
105
- e.preventDefault();
106
-
107
- if (Boolean(inputValue)) {
108
- setList([...list, createListObject(inputValue)]);
109
-
110
- setInputValue("");
111
- }
112
- }
113
-
114
- function handleDeleteButton(e: ChangeEvent<HTMLInputElement>, id: string) {
115
- e.preventDefault();
116
- const newData = list.filter((item: ListDataTypes) => item.id !== id);
117
- setList(newData);
118
- }
119
-
120
- function prepareDataForDatabase(list: ListDataTypes[]) {
121
- return list.map(({ value }) => value).join(stringListSeparator);
122
- }
123
-
124
- function prepareDataForList(str: string) {
125
- return str.split(stringListSeparator).map((item) => createListObject(item));
126
- }
127
-
128
- function createListObject(value: string) {
129
- return {
130
- id: `${Date.now()}-${Math.floor(Math.random() * 1000)}`,
131
- value: value,
132
- };
133
- }
134
- };
135
-
136
- export default StringList;
1
+ import { Button, Input, theme } from "@adminjs/design-system";
2
+ import { EditPropertyProps } from "adminjs";
3
+ import React, {
4
+ ChangeEvent,
5
+ FC,
6
+ KeyboardEvent,
7
+ SyntheticEvent,
8
+ useEffect,
9
+ useState,
10
+ } from "react";
11
+ import { ThemeProvider } from "styled-components";
12
+
13
+ import {
14
+ StyledCustomInput,
15
+ StyledInputWrapper,
16
+ StyledLabel,
17
+ StyledListWrapper,
18
+ StyledWrapper,
19
+ } from "./styles.js";
20
+
21
+ import { SortableList } from "./SortableList/SortableList.js";
22
+ import { separator } from "./constants.js";
23
+
24
+ type ListDataTypes = {
25
+ id: string;
26
+ value: string;
27
+ };
28
+
29
+ type StringListTypes = Omit<EditPropertyProps, "where" | "resource">;
30
+
31
+ interface StringListShowPropsType extends StringListTypes {
32
+ stringListSeparator?: string;
33
+ }
34
+
35
+ const StringList: FC<StringListShowPropsType> = ({
36
+ record,
37
+ onChange,
38
+ property,
39
+ stringListSeparator = separator,
40
+ }) => {
41
+ const stringListValue =
42
+ record.params?.[property.path] ?? property.props.value ?? "";
43
+
44
+ const initialList = stringListValue
45
+ ? prepareDataForList(stringListValue)
46
+ : [];
47
+
48
+ const [inputValue, setInputValue] = useState("");
49
+ const [list, setList] = useState<ListDataTypes[]>(initialList);
50
+
51
+ const serializedData = prepareDataForDatabase(list);
52
+
53
+ useEffect(() => {
54
+ onChange(property.path, serializedData);
55
+ }, [serializedData]);
56
+
57
+ return (
58
+ <ThemeProvider theme={theme}>
59
+ <StyledLabel htmlFor="custom">{property.path}</StyledLabel>
60
+ <StyledWrapper>
61
+ <StyledListWrapper>
62
+ <SortableList
63
+ items={list}
64
+ onChange={setList}
65
+ renderItem={(item) => (
66
+ <SortableList.Item id={item.id} onDelete={handleDeleteButton}>
67
+ {item.value}
68
+ </SortableList.Item>
69
+ )}
70
+ />
71
+ </StyledListWrapper>
72
+ <StyledInputWrapper>
73
+ <Input
74
+ id="stringList"
75
+ name={property.path}
76
+ value={serializedData}
77
+ hidden
78
+ />
79
+ <StyledCustomInput
80
+ id="custom"
81
+ name="customInput"
82
+ value={inputValue}
83
+ onChange={handleInput}
84
+ onKeyPress={handleEnterPress}
85
+ />
86
+ <Button variant="outlined" onClick={handleAddButton}>
87
+ Add
88
+ </Button>
89
+ </StyledInputWrapper>
90
+ </StyledWrapper>
91
+ </ThemeProvider>
92
+ );
93
+
94
+ function handleInput(e: ChangeEvent<HTMLInputElement>) {
95
+ setInputValue(e.target.value);
96
+ }
97
+
98
+ function handleEnterPress(e: KeyboardEvent<HTMLInputElement>) {
99
+ if (e.key === "Enter") {
100
+ handleAddButton(e);
101
+ }
102
+ }
103
+
104
+ function handleAddButton(e: SyntheticEvent<HTMLInputElement>) {
105
+ e.preventDefault();
106
+
107
+ if (Boolean(inputValue)) {
108
+ setList([...list, createListObject(inputValue)]);
109
+
110
+ setInputValue("");
111
+ }
112
+ }
113
+
114
+ function handleDeleteButton(e: ChangeEvent<HTMLInputElement>, id: string) {
115
+ e.preventDefault();
116
+ const newData = list.filter((item: ListDataTypes) => item.id !== id);
117
+ setList(newData);
118
+ }
119
+
120
+ function prepareDataForDatabase(list: ListDataTypes[]) {
121
+ return list.map(({ value }) => value).join(stringListSeparator);
122
+ }
123
+
124
+ function prepareDataForList(str: string) {
125
+ return str.split(stringListSeparator).map((item) => createListObject(item));
126
+ }
127
+
128
+ function createListObject(value: string) {
129
+ return {
130
+ id: `${Date.now()}-${Math.floor(Math.random() * 1000)}`,
131
+ value: value,
132
+ };
133
+ }
134
+ };
135
+
136
+ export default StringList;
@@ -1,37 +1,37 @@
1
- import React, { memo, useState, useEffect, useRef, FC } from "react";
2
- import { ShowPropertyProps } from "adminjs";
3
-
4
- import { ThemeProvider } from "styled-components";
5
- import { theme } from "@adminjs/design-system";
6
-
7
- import { StyledShowLabel, StyledShowWrapper, StyledListItem } from "./styles";
8
- import { separator } from "./constants";
9
-
10
- interface StringListShowPropsType extends ShowPropertyProps {
11
- stringListSeparator?: string;
12
- }
13
-
14
- const StringListShow: FC<StringListShowPropsType> = ({
15
- property,
16
- record,
17
- stringListSeparator = separator,
18
- }) => {
19
- return (
20
- <ThemeProvider theme={theme}>
21
- <StyledShowWrapper>
22
- <StyledShowLabel>{property.path}</StyledShowLabel>
23
- {record.params.facts && (
24
- <ul>
25
- {record.params.facts
26
- .split(stringListSeparator)
27
- .map((item: string, index: number) => (
28
- <StyledListItem key={index}>{`- ${item}`}</StyledListItem>
29
- ))}
30
- </ul>
31
- )}
32
- </StyledShowWrapper>
33
- </ThemeProvider>
34
- );
35
- };
36
-
37
- export default StringListShow;
1
+ import React, { memo, useState, useEffect, useRef, FC } from "react";
2
+ import { ShowPropertyProps } from "adminjs";
3
+
4
+ import { ThemeProvider } from "styled-components";
5
+ import { theme } from "@adminjs/design-system";
6
+
7
+ import { StyledShowLabel, StyledShowWrapper, StyledListItem } from "./styles";
8
+ import { separator } from "./constants";
9
+
10
+ interface StringListShowPropsType extends ShowPropertyProps {
11
+ stringListSeparator?: string;
12
+ }
13
+
14
+ const StringListShow: FC<StringListShowPropsType> = ({
15
+ property,
16
+ record,
17
+ stringListSeparator = separator,
18
+ }) => {
19
+ return (
20
+ <ThemeProvider theme={theme}>
21
+ <StyledShowWrapper>
22
+ <StyledShowLabel>{property.path}</StyledShowLabel>
23
+ {record.params.facts && (
24
+ <ul>
25
+ {record.params.facts
26
+ .split(stringListSeparator)
27
+ .map((item: string, index: number) => (
28
+ <StyledListItem key={index}>{`- ${item}`}</StyledListItem>
29
+ ))}
30
+ </ul>
31
+ )}
32
+ </StyledShowWrapper>
33
+ </ThemeProvider>
34
+ );
35
+ };
36
+
37
+ export default StringListShow;
@@ -1 +1 @@
1
- export const separator = "|";
1
+ export const separator = "|";
@@ -1,2 +1,2 @@
1
- export * from "./StringList.js";
2
- export * from "./StringListShow.js";
1
+ export * from "./StringList.js";
2
+ export * from "./StringListShow.js";
@@ -1,41 +1,41 @@
1
- import { Box, Input } from "@adminjs/design-system";
2
- import { styled } from "@adminjs/design-system/styled-components";
3
-
4
- export const StyledWrapper = styled(Box)`
5
- display: flex;
6
- flex-direction: column;
7
- margin-bottom: 45px;
8
- `;
9
-
10
- export const StyledCustomInput = styled(Input)`
11
- width: 100%;
12
- margin-right: 10px;
13
- `;
14
-
15
- export const StyledInputWrapper = styled(Box)`
16
- display: flex;
17
- `;
18
-
19
- export const StyledListWrapper = styled(Box)`
20
- margin-bottom: 15px;
21
- `;
22
-
23
- export const StyledLabel = styled.div`
24
- font-size: 12px;
25
- margin-bottom: 8px;
26
- text-transform: capitalize;
27
- `;
28
-
29
- export const StyledShowLabel = styled(StyledLabel)`
30
- line-height: 16px;
31
- color: rgb(137, 138, 154);
32
- font-weight: 300;
33
- `;
34
-
35
- export const StyledShowWrapper = styled(Box)`
36
- margin-bottom: 35px;
37
- `;
38
-
39
- export const StyledListItem = styled.li`
40
- margin-bottom: 5px;
41
- `;
1
+ import { Box, Input } from "@adminjs/design-system";
2
+ import { styled } from "@adminjs/design-system/styled-components";
3
+
4
+ export const StyledWrapper = styled(Box)`
5
+ display: flex;
6
+ flex-direction: column;
7
+ margin-bottom: 45px;
8
+ `;
9
+
10
+ export const StyledCustomInput = styled(Input)`
11
+ width: 100%;
12
+ margin-right: 10px;
13
+ `;
14
+
15
+ export const StyledInputWrapper = styled(Box)`
16
+ display: flex;
17
+ `;
18
+
19
+ export const StyledListWrapper = styled(Box)`
20
+ margin-bottom: 15px;
21
+ `;
22
+
23
+ export const StyledLabel = styled.div`
24
+ font-size: 12px;
25
+ margin-bottom: 8px;
26
+ text-transform: capitalize;
27
+ `;
28
+
29
+ export const StyledShowLabel = styled(StyledLabel)`
30
+ line-height: 16px;
31
+ color: rgb(137, 138, 154);
32
+ font-weight: 300;
33
+ `;
34
+
35
+ export const StyledShowWrapper = styled(Box)`
36
+ margin-bottom: 35px;
37
+ `;
38
+
39
+ export const StyledListItem = styled.li`
40
+ margin-bottom: 5px;
41
+ `;
@@ -1,9 +1,10 @@
1
- export { default as ColorStatusEdit } from "./ColorStatus/ColorStatusEdit.jsx";
2
- export { default as ColorStatusShow } from "./ColorStatus/ColorStatusShow.js";
3
- export { default as ColorStatusList } from "./ColorStatus/ColorStatusList.js";
4
- export { default as CustomSlug } from "./CustomSlug/CustomSlug.js";
5
- export { default as Editor } from "./Editor/Editor.jsx";
6
- export { default as EditorList } from "./Editor/EditorList.jsx";
7
- export { default as EditorShow } from "./Editor/EditorShow.jsx";
8
- export { default as StringList } from "./StringList/StringList.js";
9
- export { default as StringListShow } from "./StringList/StringListShow.js";
1
+ export { default as ColorStatusEdit } from "./ColorStatus/ColorStatusEdit.jsx";
2
+ export { default as ColorStatusShow } from "./ColorStatus/ColorStatusShow.js";
3
+ export { default as ColorStatusList } from "./ColorStatus/ColorStatusList.js";
4
+ export { default as SlugEdit } from "./Slug/SlugEdit.js";
5
+ //export { default as Editor } from "./Editor/Editor.jsx";
6
+ //export { default as EditorList } from "./Editor/EditorList.jsx";
7
+ //export { default as EditorShow } from "./Editor/EditorShow.jsx";
8
+ export { default as StringList } from "./StringList/StringList.js";
9
+ export { default as StringListShow } from "./StringList/StringListShow.js";
10
+ export { default as SlugFeature} from "./Slug/SlugFeature.js"
package/dist/bundle.js DELETED
@@ -1,8 +0,0 @@
1
- import path from "path";
2
- import * as url from "url";
3
- const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
4
- const bundleComponent = (loader, componentName) => {
5
- const componentPath = path.join(__dirname, `./components/${componentName}`);
6
- return loader.add(componentName, componentPath);
7
- };
8
- export default bundleComponent;
@@ -1,29 +0,0 @@
1
- import React, { useEffect, useState, } from "react";
2
- import { ThemeProvider } from "styled-components";
3
- import { theme, Label } from "@adminjs/design-system";
4
- import { slugifyTitle } from "../../utils/index.js";
5
- import { StyledInputWrapper, StyledCustomInput, StyledGenerateButton, } from "./styles.js";
6
- const CustomSlug = ({ property, record, onChange }) => {
7
- const [inputValue, setInputValue] = useState(record.params.slug);
8
- useEffect(() => {
9
- onChange(property.path, inputValue);
10
- }, [inputValue]);
11
- return (<ThemeProvider theme={theme}>
12
- <Label htmlFor="customSlug">Slug</Label>
13
- <StyledInputWrapper>
14
- <StyledCustomInput id={property.path} name={property.path} value={inputValue} onChange={handleInput}/>
15
- <StyledGenerateButton variant="outlined" onClick={generateSlug}>
16
- Generate Slug
17
- </StyledGenerateButton>
18
- </StyledInputWrapper>
19
- </ThemeProvider>);
20
- function handleInput(e) {
21
- setInputValue(e.target.value);
22
- }
23
- function generateSlug(e) {
24
- e.preventDefault();
25
- const title = record.title;
26
- setInputValue(slugifyTitle(title));
27
- }
28
- };
29
- export default CustomSlug;
@@ -1 +0,0 @@
1
- export { default } from "./CustomSlug.js";
@@ -1,15 +0,0 @@
1
- // @ts-ignore
2
- import { styled } from "@adminjs/design-system/styled-components";
3
- // @ts-ignore
4
- import { Button, Box, Input } from "@adminjs/design-system";
5
- export const StyledInputWrapper = styled(Box) `
6
- display: flex;
7
- margin-bottom: 40px;
8
- `;
9
- export const StyledCustomInput = styled(Input) `
10
- width: 100%;
11
- margin-right: 10px;
12
- `;
13
- export const StyledGenerateButton = styled(Button) `
14
- white-space: nowrap;
15
- `;
@@ -1,11 +0,0 @@
1
- import Header from "@editorjs/header";
2
- import Paragraph from "@editorjs/paragraph";
3
- import List from "@editorjs/list";
4
- export const EDITOR_TOOLS = {
5
- paragraph: {
6
- class: Paragraph,
7
- inlineToolbar: true,
8
- },
9
- list: List,
10
- header: Header,
11
- };
@@ -1 +0,0 @@
1
- export { default } from "./Editor.jsx";
@@ -1,64 +0,0 @@
1
- import { Box } from "@adminjs/design-system";
2
- import { styled } from "@adminjs/design-system/styled-components";
3
- export const Label = styled.div `
4
- font-size: 12px;
5
- margin-bottom: 8px;
6
- `;
7
- export const EditorWrapper = styled(Box) `
8
- padding: 12px;
9
- border: 1px solid rgb(187, 195, 203);
10
- `;
11
- export const StyledEditor = styled.div `
12
- .cdx-block,
13
- .ce-header {
14
- padding-left: 58px;
15
- }
16
-
17
- .cdx-list {
18
- padding-left: 85px;
19
- }
20
-
21
- .ce-block__content {
22
- width: 100%;
23
- max-width: none;
24
- }
25
-
26
- .ce-toolbar__content {
27
- max-width: none;
28
- left: 0;
29
- }
30
-
31
- .ce-toolbar__actions {
32
- left: 0;
33
- }
34
-
35
- h1.ce-header {
36
- font-size: 22px;
37
- font-weight: bold;
38
- }
39
-
40
- h2.ce-header {
41
- font-size: 20px;
42
- font-weight: bold;
43
- }
44
-
45
- h3.ce-header {
46
- font-size: 18px;
47
- font-weight: bold;
48
- }
49
-
50
- h4.ce-header {
51
- font-size: 16px;
52
- font-weight: bold;
53
- }
54
-
55
- h5.ce-header {
56
- font-size: 15px;
57
- font-weight: bold;
58
- }
59
-
60
- h6.ce-header {
61
- font-size: 14px;
62
- font-weight: bold;
63
- }
64
- `;
@@ -1,43 +0,0 @@
1
- import React, { Fragment, useMemo, useState } from 'react';
2
- import { DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors, DragOverlay, defaultDropAnimationSideEffects, } from '@dnd-kit/core';
3
- import { SortableContext, arrayMove, sortableKeyboardCoordinates, verticalListSortingStrategy, } from '@dnd-kit/sortable';
4
- import { SortableItem } from './components/index.js';
5
- import { StyledListWrapper } from './styles.js';
6
- const dropAnimationConfig = {
7
- sideEffects: defaultDropAnimationSideEffects({
8
- styles: {
9
- active: {
10
- opacity: '0.4',
11
- },
12
- },
13
- }),
14
- };
15
- export function SortableList({ items, onChange, renderItem, }) {
16
- const [active, setActive] = useState(null);
17
- const activeItem = useMemo(() => items.find((item) => item.id === active?.id), [active, items]);
18
- const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
19
- coordinateGetter: sortableKeyboardCoordinates,
20
- }));
21
- return (<DndContext sensors={sensors} onDragStart={({ active }) => {
22
- setActive(active);
23
- }} onDragEnd={({ active, over }) => {
24
- if (over && active.id !== over?.id) {
25
- const activeIndex = items.findIndex(({ id }) => id === active.id);
26
- const overIndex = items.findIndex(({ id }) => id === over.id);
27
- onChange(arrayMove(items, activeIndex, overIndex));
28
- }
29
- setActive(null);
30
- }} onDragCancel={() => {
31
- setActive(null);
32
- }}>
33
- <SortableContext items={items} strategy={verticalListSortingStrategy}>
34
- <StyledListWrapper role="application">
35
- {items.map((item, index) => (<Fragment key={index}>{renderItem(item)}</Fragment>))}
36
- </StyledListWrapper>
37
- </SortableContext>
38
- <DragOverlay dropAnimation={dropAnimationConfig}>
39
- {activeItem ? renderItem(activeItem) : null}
40
- </DragOverlay>
41
- </DndContext>);
42
- }
43
- SortableList.Item = SortableItem;
@@ -1,10 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import { DragButton } from './styles.js';
3
- export const DragHandle = ({ context }) => {
4
- const { attributes, listeners, ref } = useContext(context);
5
- return (<DragButton {...attributes} {...listeners} ref={ref}>
6
- <svg viewBox="0 0 20 20" width="13">
7
- <path d="M7 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 2zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 14zm6-8a2 2 0 1 0-.001-4.001A2 2 0 0 0 13 6zm0 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 14z"></path>
8
- </svg>
9
- </DragButton>);
10
- };