@rulab/adminjs-components 0.1.0-alpha.2 → 0.1.0-alpha.3
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/dist/components/ColorStatus/ColorStatusEdit.d.ts +5 -0
- package/dist/components/ColorStatus/ColorStatusEdit.js +58 -0
- package/dist/components/ColorStatus/ColorStatusList.d.ts +4 -0
- package/dist/components/ColorStatus/ColorStatusList.js +7 -0
- package/dist/components/ColorStatus/ColorStatusShow.d.ts +4 -0
- package/dist/components/ColorStatus/ColorStatusShow.js +9 -0
- package/dist/components/ColorStatus/index.d.ts +3 -0
- package/dist/components/ColorStatus/index.js +3 -0
- package/dist/components/ColorStatus/styles.d.ts +5 -0
- package/dist/components/ColorStatus/styles.js +25 -0
- package/dist/components/ColorStatus/types.d.ts +5 -0
- package/dist/components/ColorStatus/types.js +1 -0
- package/dist/components/Editor/Editor.d.ts +11 -0
- package/dist/components/Editor/Editor.js +33 -0
- package/dist/components/Editor/EditorList.d.ts +9 -0
- package/dist/components/Editor/EditorList.js +10 -0
- package/dist/components/Editor/EditorShow.d.ts +9 -0
- package/dist/components/Editor/EditorShow.js +10 -0
- package/dist/components/Editor/config.d.ts +29 -0
- package/dist/components/Editor/config.js +34 -0
- package/dist/components/Editor/index.d.ts +3 -0
- package/dist/components/Editor/index.js +3 -0
- package/dist/components/Editor/styles.d.ts +6 -0
- package/dist/components/Editor/styles.js +145 -0
- package/dist/components/Slug/SlugEdit.d.ts +5 -0
- package/dist/components/Slug/SlugEdit.js +27 -0
- package/dist/components/Slug/SlugFeature.d.ts +7 -0
- package/dist/components/Slug/SlugFeature.js +21 -0
- package/dist/components/Slug/index.d.ts +1 -0
- package/dist/components/Slug/index.js +1 -0
- package/dist/components/Slug/styles.d.ts +4 -0
- package/dist/components/Slug/styles.js +20 -0
- package/dist/components/StringList/SortableList/SortableList.d.ts +18 -0
- package/dist/components/StringList/SortableList/SortableList.js +37 -0
- package/dist/components/StringList/SortableList/components/SortableItem/DragHandle.d.ts +7 -0
- package/dist/components/StringList/SortableList/components/SortableItem/DragHandle.js +8 -0
- package/dist/components/StringList/SortableList/components/SortableItem/SortableItem.d.ts +8 -0
- package/dist/components/StringList/SortableList/components/SortableItem/SortableItem.js +28 -0
- package/dist/components/StringList/SortableList/components/SortableItem/styles.d.ts +2 -0
- package/dist/components/StringList/SortableList/components/SortableItem/styles.js +20 -0
- package/dist/components/StringList/SortableList/components/SortableItem/types.d.ts +6 -0
- package/dist/components/StringList/SortableList/components/SortableItem/types.js +1 -0
- package/dist/components/StringList/SortableList/components/index.d.ts +2 -0
- package/dist/components/StringList/SortableList/components/index.js +2 -0
- package/dist/components/StringList/SortableList/index.d.ts +1 -0
- package/dist/components/StringList/SortableList/index.js +1 -0
- package/dist/components/StringList/SortableList/styles.d.ts +1 -0
- package/dist/components/StringList/SortableList/styles.js +8 -0
- package/dist/components/StringList/StringList.d.ts +8 -0
- package/dist/components/StringList/StringList.js +60 -0
- package/dist/components/StringList/StringListShow.d.ts +7 -0
- package/dist/components/StringList/StringListShow.js +14 -0
- package/dist/components/StringList/constants.d.ts +1 -0
- package/dist/components/StringList/constants.js +1 -0
- package/dist/components/StringList/index.d.ts +2 -0
- package/dist/components/StringList/index.js +2 -0
- package/dist/components/StringList/styles.d.ts +8 -0
- package/dist/components/StringList/styles.js +33 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.js +10 -0
- package/dist/index.d.ts +2 -33
- package/dist/index.js +1 -5
- package/dist/utils/bundle-component.d.ts +2 -0
- package/dist/utils/bundle-component.js +13 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/parseHtml.d.ts +1 -0
- package/dist/utils/parseHtml.js +37 -0
- package/dist/utils/slugifyImport.d.ts +3 -0
- package/dist/utils/slugifyImport.js +3 -0
- package/dist/utils/slugifyTitle.d.ts +1 -0
- package/dist/utils/slugifyTitle.js +10 -0
- package/package.json +2 -2
- package/src/components/ColorStatus/ColorStatusEdit.d.ts +5 -0
- package/src/components/ColorStatus/ColorStatusEdit.js +58 -0
- package/src/components/ColorStatus/ColorStatusList.d.ts +4 -0
- package/src/components/ColorStatus/ColorStatusList.js +7 -0
- package/src/components/ColorStatus/ColorStatusShow.d.ts +4 -0
- package/src/components/ColorStatus/ColorStatusShow.js +9 -0
- package/src/components/ColorStatus/index.d.ts +3 -0
- package/src/components/ColorStatus/index.js +3 -0
- package/src/components/ColorStatus/styles.d.ts +5 -0
- package/src/components/ColorStatus/styles.js +25 -0
- package/src/components/ColorStatus/types.d.ts +5 -0
- package/src/components/ColorStatus/types.js +1 -0
- package/src/components/Editor/Editor.d.ts +8 -0
- package/src/components/Editor/Editor.js +36 -0
- package/src/components/Editor/EditorList.d.ts +6 -0
- package/src/components/Editor/EditorList.js +11 -0
- package/src/components/Editor/EditorShow.d.ts +6 -0
- package/src/components/Editor/EditorShow.js +13 -0
- package/src/components/Editor/config.d.ts +29 -0
- package/src/components/Editor/config.js +34 -0
- package/src/components/Editor/index.d.ts +3 -0
- package/src/components/Editor/index.js +3 -0
- package/src/components/Editor/styles.d.ts +6 -0
- package/src/components/Editor/styles.js +145 -0
- package/src/components/Slug/SlugEdit.d.ts +5 -0
- package/src/components/Slug/SlugEdit.js +27 -0
- package/src/components/Slug/SlugFeature.d.ts +7 -0
- package/src/components/Slug/SlugFeature.js +21 -0
- package/src/components/Slug/SlugFeature.ts +1 -1
- package/src/components/Slug/index.d.ts +1 -0
- package/src/components/Slug/index.js +1 -0
- package/src/components/Slug/styles.d.ts +4 -0
- package/src/components/Slug/styles.js +20 -0
- package/src/components/StringList/SortableList/SortableList.d.ts +18 -0
- package/src/components/StringList/SortableList/SortableList.js +37 -0
- package/src/components/StringList/SortableList/components/SortableItem/DragHandle.d.ts +7 -0
- package/src/components/StringList/SortableList/components/SortableItem/DragHandle.js +8 -0
- package/src/components/StringList/SortableList/components/SortableItem/SortableItem.d.ts +8 -0
- package/src/components/StringList/SortableList/components/SortableItem/SortableItem.js +28 -0
- package/src/components/StringList/SortableList/components/SortableItem/styles.d.ts +2 -0
- package/src/components/StringList/SortableList/components/SortableItem/styles.js +20 -0
- package/src/components/StringList/SortableList/components/SortableItem/types.d.ts +6 -0
- package/src/components/StringList/SortableList/components/SortableItem/types.js +1 -0
- package/src/components/StringList/SortableList/components/index.d.ts +2 -0
- package/src/components/StringList/SortableList/components/index.js +2 -0
- package/src/components/StringList/SortableList/index.d.ts +1 -0
- package/src/components/StringList/SortableList/index.js +1 -0
- package/src/components/StringList/SortableList/styles.d.ts +1 -0
- package/src/components/StringList/SortableList/styles.js +8 -0
- package/src/components/StringList/StringList.d.ts +8 -0
- package/src/components/StringList/StringList.js +60 -0
- package/src/components/StringList/StringListShow.d.ts +7 -0
- package/src/components/StringList/StringListShow.js +14 -0
- package/src/components/StringList/constants.d.ts +1 -0
- package/src/components/StringList/constants.js +1 -0
- package/src/components/StringList/index.d.ts +2 -0
- package/src/components/StringList/index.js +2 -0
- package/src/components/StringList/styles.d.ts +8 -0
- package/src/components/StringList/styles.js +33 -0
- package/src/components/index.d.ts +7 -0
- package/src/components/index.js +10 -0
- package/dist/index.cjs +0 -32
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -33
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import Select from "react-select";
|
|
3
|
+
import chroma from "chroma-js";
|
|
4
|
+
import { ColorStatusWrapper, Label } from "./styles";
|
|
5
|
+
const dot = (color = "transparent") => ({
|
|
6
|
+
alignItems: "center",
|
|
7
|
+
display: "flex",
|
|
8
|
+
":before": {
|
|
9
|
+
backgroundColor: color,
|
|
10
|
+
borderRadius: 10,
|
|
11
|
+
content: '" "',
|
|
12
|
+
display: "block",
|
|
13
|
+
marginRight: 8,
|
|
14
|
+
height: 10,
|
|
15
|
+
width: 10,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const colorStyles = {
|
|
19
|
+
control: (styles) => ({ ...styles, backgroundColor: "white" }),
|
|
20
|
+
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
|
|
21
|
+
const color = chroma(data.color);
|
|
22
|
+
return {
|
|
23
|
+
...styles,
|
|
24
|
+
backgroundColor: isSelected
|
|
25
|
+
? data.color
|
|
26
|
+
: isFocused
|
|
27
|
+
? color.alpha(0.1).css()
|
|
28
|
+
: undefined,
|
|
29
|
+
color: isSelected
|
|
30
|
+
? chroma.contrast(color, "white") > 2
|
|
31
|
+
? "white"
|
|
32
|
+
: "black"
|
|
33
|
+
: data.color,
|
|
34
|
+
":active": {
|
|
35
|
+
...styles[":active"],
|
|
36
|
+
backgroundColor: isSelected ? data.color : color.alpha(0.3).css(),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
input: (styles) => ({ ...styles, ...dot() }),
|
|
41
|
+
placeholder: (styles) => ({ ...styles, ...dot("#ccc") }),
|
|
42
|
+
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
|
|
43
|
+
};
|
|
44
|
+
const ColorStatus = ({ property, record, onChange }) => {
|
|
45
|
+
const availableValues = property.availableValues;
|
|
46
|
+
const currentOption = availableValues.find((item) => item.value === record.params[property.path]);
|
|
47
|
+
const [selectOption, setCurrentOption] = useState(currentOption);
|
|
48
|
+
const handleSelectChange = (option) => {
|
|
49
|
+
setCurrentOption(option);
|
|
50
|
+
};
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
onChange(property.path, selectOption?.value);
|
|
53
|
+
}, [selectOption]);
|
|
54
|
+
return (React.createElement(ColorStatusWrapper, null,
|
|
55
|
+
React.createElement(Label, null, property.path),
|
|
56
|
+
React.createElement(Select, { className: "basic-single", classNamePrefix: "select", defaultValue: selectOption ?? availableValues[0], onChange: handleSelectChange, isClearable: true, name: "color", options: availableValues, styles: colorStyles })));
|
|
57
|
+
};
|
|
58
|
+
export default ColorStatus;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ColorStatusBadge } from "./styles";
|
|
3
|
+
const ColorStatusList = ({ property, record }) => {
|
|
4
|
+
const currentOption = property.availableValues?.find((item) => item.value === record.params[property.path]);
|
|
5
|
+
return (React.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path]));
|
|
6
|
+
};
|
|
7
|
+
export default ColorStatusList;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ColorStatusBadgeWrapper, ColorStatusBadge, ShowLabel } from "./styles";
|
|
3
|
+
const ColorStatusShow = ({ property, record }) => {
|
|
4
|
+
const currentOption = property.availableValues?.find((item) => item.value === record.params[property.path]);
|
|
5
|
+
return (React.createElement(ColorStatusBadgeWrapper, null,
|
|
6
|
+
React.createElement(ShowLabel, null, property.path),
|
|
7
|
+
React.createElement(ColorStatusBadge, { color: currentOption.color }, record.params[property.path])));
|
|
8
|
+
};
|
|
9
|
+
export default ColorStatusShow;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { styled } from "@adminjs/design-system/styled-components";
|
|
2
|
+
export const ColorStatusWrapper = styled.div `
|
|
3
|
+
margin-bottom: 24px;
|
|
4
|
+
`;
|
|
5
|
+
export const Label = styled.div `
|
|
6
|
+
font-size: 12px;
|
|
7
|
+
margin-bottom: 8px;
|
|
8
|
+
`;
|
|
9
|
+
export const ShowLabel = styled.div `
|
|
10
|
+
font-size: 12px;
|
|
11
|
+
margin-bottom: 8px;
|
|
12
|
+
color: rgb(137, 138, 154);
|
|
13
|
+
`;
|
|
14
|
+
export const ColorStatusBadgeWrapper = styled.div `
|
|
15
|
+
margin-bottom: 20px;
|
|
16
|
+
`;
|
|
17
|
+
export const ColorStatusBadge = styled.div `
|
|
18
|
+
background-color: ${(props) => props.color};
|
|
19
|
+
width: fit-content;
|
|
20
|
+
padding: 5px 10px;
|
|
21
|
+
border-radius: 20px;
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
color: white;
|
|
24
|
+
white-space: nowrap;
|
|
25
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Editor;
|
|
2
|
+
declare function Editor({ property, record, onChangeAdmin, editorId }: {
|
|
3
|
+
property: any;
|
|
4
|
+
record: any;
|
|
5
|
+
onChangeAdmin: any;
|
|
6
|
+
editorId: any;
|
|
7
|
+
}): React.FunctionComponentElement<{
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
theme: import("styled-components").DefaultTheme | ((outerTheme?: import("styled-components").DefaultTheme | undefined) => import("styled-components").DefaultTheme);
|
|
10
|
+
}>;
|
|
11
|
+
import React from "react";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { memo, useState, useEffect, useRef } from "react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import EditorJS from "@editorjs/editorjs";
|
|
4
|
+
import { theme } from "@adminjs/design-system";
|
|
5
|
+
import { StyledLabel, StyledEditor, StyledEditorWrapper } from "./styles";
|
|
6
|
+
import { EDITOR_TOOLS } from "./config";
|
|
7
|
+
const Editor = ({ property, record, onChangeAdmin, editorId }) => {
|
|
8
|
+
const [jsonData, setJsonData] = useState();
|
|
9
|
+
const isSavedData = Boolean(record.params[property.path]);
|
|
10
|
+
const ref = useRef();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
onChangeAdmin(property.path, jsonData);
|
|
13
|
+
}, [jsonData]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!ref.current) {
|
|
16
|
+
const editor = new EditorJS({
|
|
17
|
+
holder: editorId,
|
|
18
|
+
tools: EDITOR_TOOLS,
|
|
19
|
+
data: isSavedData ? JSON.parse(record.params[property.path]) : "",
|
|
20
|
+
async onChange(api, event) {
|
|
21
|
+
const data = await api.saver.save();
|
|
22
|
+
setJsonData(JSON.stringify(data));
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
ref.current = editor;
|
|
26
|
+
}
|
|
27
|
+
return () => {
|
|
28
|
+
ref?.current?.destroy?.();
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
return (React.createElement(ThemeProvider, { theme: theme }, React.createElement(StyledLabel, null, property.path), React.createElement(StyledEditorWrapper, null, React.createElement(StyledEditor, { id: editorId }))));
|
|
32
|
+
};
|
|
33
|
+
export default Editor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default EditorList;
|
|
2
|
+
declare function EditorList({ property, record }: {
|
|
3
|
+
property: any;
|
|
4
|
+
record: any;
|
|
5
|
+
}): React.FunctionComponentElement<{
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
theme: import("styled-components").DefaultTheme | ((outerTheme?: import("styled-components").DefaultTheme | undefined) => import("styled-components").DefaultTheme);
|
|
8
|
+
}>;
|
|
9
|
+
import React from "react";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { theme } from "@adminjs/design-system";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { parseHtml } from "../../utils/parseHtml";
|
|
5
|
+
import { StyledEditorViewWrapper } from "./styles";
|
|
6
|
+
const EditorList = ({ property, record }) => {
|
|
7
|
+
const htmlContent = parseHtml(record.params[property.path]);
|
|
8
|
+
return (React.createElement(ThemeProvider, { theme: theme }, React.createElement(StyledEditorViewWrapper, null, htmlContent && (React.createElement("div", { dangerouslySetInnerHTML: { __html: htmlContent } })))));
|
|
9
|
+
};
|
|
10
|
+
export default EditorList;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default EditorShow;
|
|
2
|
+
declare function EditorShow({ property, record }: {
|
|
3
|
+
property: any;
|
|
4
|
+
record: any;
|
|
5
|
+
}): React.FunctionComponentElement<{
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
theme: import("styled-components").DefaultTheme | ((outerTheme?: import("styled-components").DefaultTheme | undefined) => import("styled-components").DefaultTheme);
|
|
8
|
+
}>;
|
|
9
|
+
import React from "react";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import { theme } from "@adminjs/design-system";
|
|
4
|
+
import { parseHtml } from "../../utils/parseHtml";
|
|
5
|
+
import { StyledEditorShowWrapper, StyledShowLabel } from "./styles";
|
|
6
|
+
const EditorShow = ({ property, record }) => {
|
|
7
|
+
const htmlContent = parseHtml(record.params[property.path]);
|
|
8
|
+
return (React.createElement(ThemeProvider, { theme: theme }, React.createElement(StyledEditorShowWrapper, null, React.createElement(StyledShowLabel, null, property.path), htmlContent && (React.createElement("div", { dangerouslySetInnerHTML: { __html: htmlContent } })))));
|
|
9
|
+
};
|
|
10
|
+
export default EditorShow;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Quote from "@editorjs/quote";
|
|
2
|
+
import Table from "@editorjs/table";
|
|
3
|
+
export declare const EDITOR_TOOLS: {
|
|
4
|
+
paragraph: {
|
|
5
|
+
class: any;
|
|
6
|
+
inlineToolbar: boolean;
|
|
7
|
+
};
|
|
8
|
+
list: {
|
|
9
|
+
class: any;
|
|
10
|
+
inlineToolbar: boolean;
|
|
11
|
+
};
|
|
12
|
+
header: {
|
|
13
|
+
class: any;
|
|
14
|
+
config: {
|
|
15
|
+
placeholder: string;
|
|
16
|
+
levels: number[];
|
|
17
|
+
defaultLevel: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
table: {
|
|
21
|
+
class: typeof Table;
|
|
22
|
+
inlineToolbar: boolean;
|
|
23
|
+
};
|
|
24
|
+
quote: {
|
|
25
|
+
class: typeof Quote;
|
|
26
|
+
inlineToolbar: boolean;
|
|
27
|
+
};
|
|
28
|
+
audioPlayer: any;
|
|
29
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Header from "@editorjs/header";
|
|
2
|
+
import List from "@editorjs/list";
|
|
3
|
+
import Paragraph from "@editorjs/paragraph";
|
|
4
|
+
import Quote from "@editorjs/quote";
|
|
5
|
+
import Table from "@editorjs/table";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import AudioPlayer from "editorjs-audio-player";
|
|
8
|
+
export const EDITOR_TOOLS = {
|
|
9
|
+
paragraph: {
|
|
10
|
+
class: Paragraph,
|
|
11
|
+
inlineToolbar: true,
|
|
12
|
+
},
|
|
13
|
+
list: {
|
|
14
|
+
class: List,
|
|
15
|
+
inlineToolbar: true,
|
|
16
|
+
},
|
|
17
|
+
header: {
|
|
18
|
+
class: Header,
|
|
19
|
+
config: {
|
|
20
|
+
placeholder: "Enter a header",
|
|
21
|
+
levels: [2, 3, 4],
|
|
22
|
+
defaultLevel: 2,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
table: {
|
|
26
|
+
class: Table,
|
|
27
|
+
inlineToolbar: true,
|
|
28
|
+
},
|
|
29
|
+
quote: {
|
|
30
|
+
class: Quote,
|
|
31
|
+
inlineToolbar: true,
|
|
32
|
+
},
|
|
33
|
+
audioPlayer: AudioPlayer,
|
|
34
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const StyledLabel: any;
|
|
2
|
+
export declare const StyledShowLabel: any;
|
|
3
|
+
export declare const StyledEditorWrapper: any;
|
|
4
|
+
export declare const StyledEditorViewWrapper: any;
|
|
5
|
+
export declare const StyledEditorShowWrapper: any;
|
|
6
|
+
export declare const StyledEditor: any;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Box } from "@adminjs/design-system";
|
|
2
|
+
import { styled } from "@adminjs/design-system/styled-components";
|
|
3
|
+
export const StyledLabel = styled.div `
|
|
4
|
+
font-size: 12px;
|
|
5
|
+
margin-bottom: 8px;
|
|
6
|
+
text-transform: capitalize;
|
|
7
|
+
`;
|
|
8
|
+
export const StyledShowLabel = styled(StyledLabel) `
|
|
9
|
+
color: rgb(137, 138, 154);
|
|
10
|
+
font-weight: 300;
|
|
11
|
+
`;
|
|
12
|
+
export const StyledEditorWrapper = styled(Box) `
|
|
13
|
+
padding: 12px;
|
|
14
|
+
margin-bottom: 24px;
|
|
15
|
+
border: 1px solid rgb(187, 195, 203);
|
|
16
|
+
`;
|
|
17
|
+
export const StyledEditorViewWrapper = styled(Box) `
|
|
18
|
+
h1,
|
|
19
|
+
h2,
|
|
20
|
+
h3 {
|
|
21
|
+
margin-bottom: 5px;
|
|
22
|
+
font-weight: bold;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
h1 {
|
|
26
|
+
font-size: 18px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
h2 {
|
|
30
|
+
font-size: 16px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h3 {
|
|
34
|
+
font-size: 14px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
p {
|
|
38
|
+
margin-bottom: 8px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ol,
|
|
42
|
+
ul {
|
|
43
|
+
margin-left: 20px;
|
|
44
|
+
margin-bottom: 8px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ol {
|
|
48
|
+
list-style: auto;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
ul {
|
|
52
|
+
list-style: inherit;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
table,
|
|
56
|
+
audio {
|
|
57
|
+
margin: 16px 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
table,
|
|
61
|
+
th,
|
|
62
|
+
td {
|
|
63
|
+
border: 1px solid;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
th {
|
|
67
|
+
font-weight: bold;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
th,
|
|
71
|
+
td {
|
|
72
|
+
padding: 4px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
blockquote {
|
|
76
|
+
display: block;
|
|
77
|
+
padding: 5px 8px;
|
|
78
|
+
width: fit-content;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
background-color: #e6e6e6;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
export const StyledEditorShowWrapper = styled(StyledEditorViewWrapper) `
|
|
84
|
+
margin-bottom: 24px;
|
|
85
|
+
`;
|
|
86
|
+
export const StyledEditor = styled.div `
|
|
87
|
+
audio,
|
|
88
|
+
.cdx-block,
|
|
89
|
+
.ce-header {
|
|
90
|
+
padding-left: 58px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
input {
|
|
94
|
+
margin-left: 58px;
|
|
95
|
+
width: auto;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.cdx-list {
|
|
99
|
+
padding-left: 85px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.ce-block__content {
|
|
103
|
+
width: 100%;
|
|
104
|
+
max-width: none;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.ce-toolbar__content {
|
|
108
|
+
max-width: none;
|
|
109
|
+
left: 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.ce-toolbar__actions {
|
|
113
|
+
left: 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
h1.ce-header {
|
|
117
|
+
font-size: 22px;
|
|
118
|
+
font-weight: bold;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
h2.ce-header {
|
|
122
|
+
font-size: 20px;
|
|
123
|
+
font-weight: bold;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
h3.ce-header {
|
|
127
|
+
font-size: 18px;
|
|
128
|
+
font-weight: bold;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
h4.ce-header {
|
|
132
|
+
font-size: 16px;
|
|
133
|
+
font-weight: bold;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
h5.ce-header {
|
|
137
|
+
font-size: 15px;
|
|
138
|
+
font-weight: bold;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
h6.ce-header {
|
|
142
|
+
font-size: 14px;
|
|
143
|
+
font-weight: bold;
|
|
144
|
+
}
|
|
145
|
+
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useEffect, useState, } from "react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import { theme } from "@adminjs/design-system";
|
|
4
|
+
import { slugifyTitle } from "../../utils";
|
|
5
|
+
import { StyledCustomInput, StyledGenerateButton, StyledInputWrapper, StyledLabel, } from "./styles.js";
|
|
6
|
+
const SlugEdit = ({ property, record, resource, onChange, }) => {
|
|
7
|
+
const [inputValue, setInputValue] = useState(record.params.slug);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
onChange(property.path, inputValue);
|
|
10
|
+
}, [inputValue]);
|
|
11
|
+
return (React.createElement(ThemeProvider, { theme: theme },
|
|
12
|
+
React.createElement(StyledLabel, { htmlFor: "customSlug" }, property.path),
|
|
13
|
+
React.createElement(StyledInputWrapper, null,
|
|
14
|
+
React.createElement(StyledCustomInput, { id: property.path, name: property.path, value: inputValue, onChange: handleInput }),
|
|
15
|
+
React.createElement(StyledGenerateButton, { variant: "outlined", onClick: generateSlug }, "Generate Slug"))));
|
|
16
|
+
function handleInput(e) {
|
|
17
|
+
setInputValue(e.target.value);
|
|
18
|
+
}
|
|
19
|
+
function generateSlug(e) {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
const slugSource = record.params[property.props.sourceField ?? resource.titleProperty.name];
|
|
22
|
+
if (slugSource) {
|
|
23
|
+
setInputValue(slugifyTitle(slugSource));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export default SlugEdit;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildFeature } from "adminjs";
|
|
2
|
+
import { bundleComponent } from "../../utils/bundle-component";
|
|
3
|
+
const COMPONENT_NAME = 'Slug';
|
|
4
|
+
const SlugFeature = (config) => {
|
|
5
|
+
const { componentLoader, key } = config;
|
|
6
|
+
const slugFeature = () => {
|
|
7
|
+
const editComponent = bundleComponent(componentLoader, COMPONENT_NAME, 'SlugEdit.js');
|
|
8
|
+
return buildFeature({
|
|
9
|
+
properties: {
|
|
10
|
+
[key]: {
|
|
11
|
+
isVisible: { show: false, edit: true, list: false, filter: false },
|
|
12
|
+
components: {
|
|
13
|
+
edit: editComponent,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return slugFeature();
|
|
20
|
+
};
|
|
21
|
+
export default SlugFeature;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SlugFeature.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SlugFeature.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { styled } from "@adminjs/design-system/styled-components";
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { Box, Button, 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
|
+
`;
|
|
16
|
+
export const StyledLabel = styled.div `
|
|
17
|
+
font-size: 12px;
|
|
18
|
+
margin-bottom: 8px;
|
|
19
|
+
text-transform: capitalize;
|
|
20
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { SortableItem } from "./components/index.js";
|
|
4
|
+
import type { UniqueIdentifier } from "@dnd-kit/core";
|
|
5
|
+
interface BaseItem {
|
|
6
|
+
id: UniqueIdentifier;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
interface Props<T extends BaseItem> {
|
|
10
|
+
items: T[];
|
|
11
|
+
onChange(items: T[]): void;
|
|
12
|
+
renderItem(item: T): ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare function SortableList<T extends BaseItem>({ items, onChange, renderItem, }: Props<T>): React.JSX.Element;
|
|
15
|
+
export declare namespace SortableList {
|
|
16
|
+
var Item: typeof SortableItem;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
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 (React.createElement(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
|
+
React.createElement(SortableContext, { items: items, strategy: verticalListSortingStrategy },
|
|
34
|
+
React.createElement(StyledListWrapper, { role: "application" }, items.map((item, index) => (React.createElement(Fragment, { key: index }, renderItem(item)))))),
|
|
35
|
+
React.createElement(DragOverlay, { dropAnimation: dropAnimationConfig }, activeItem ? renderItem(activeItem) : null)));
|
|
36
|
+
}
|
|
37
|
+
SortableList.Item = SortableItem;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import { StyledDragButton } from "./styles.js";
|
|
3
|
+
export const DragHandle = ({ context }) => {
|
|
4
|
+
const { attributes, listeners, ref } = useContext(context);
|
|
5
|
+
return (React.createElement(StyledDragButton, { ...attributes, ...listeners, ref: ref },
|
|
6
|
+
React.createElement("svg", { viewBox: "0 0 20 20", width: "13" },
|
|
7
|
+
React.createElement("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" }))));
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
interface SortableItemPropsType {
|
|
4
|
+
id: string;
|
|
5
|
+
onDelete: (e: ChangeEvent<HTMLInputElement>, id: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function SortableItem({ children, id, onDelete, }: PropsWithChildren<SortableItemPropsType>): React.JSX.Element;
|
|
8
|
+
export {};
|