seat-editor 1.2.21 → 1.2.23
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/app/only-view/page.d.ts +2 -2
- package/dist/app/only-view/page.js +39 -15
- package/dist/features/view/index.js +14 -8
- package/package.json +1 -1
- package/dist/app/layout.jsx +0 -27
- package/dist/app/new-board/page.jsx +0 -12
- package/dist/app/old-board/page.jsx +0 -515
- package/dist/app/only-view/page.jsx +0 -19
- package/dist/app/page.jsx +0 -13
- package/dist/components/button-tools/index.jsx +0 -17
- package/dist/components/form-tools/label.jsx +0 -44
- package/dist/components/form-tools/shape.jsx +0 -43
- package/dist/components/input/number-indicator.jsx +0 -36
- package/dist/components/layer/index.jsx +0 -254
- package/dist/components/lib/index.jsx +0 -33
- package/dist/components/modal-preview/index.jsx +0 -11
- package/dist/features/board/index.jsx +0 -310
- package/dist/features/navbar/index.jsx +0 -5
- package/dist/features/package/index.jsx +0 -46
- package/dist/features/panel/index.jsx +0 -86
- package/dist/features/panel/select-tool.jsx +0 -45
- package/dist/features/panel/square-circle-tool.jsx +0 -10
- package/dist/features/panel/table-seat-circle.jsx +0 -31
- package/dist/features/panel/text-tool.jsx +0 -22
- package/dist/features/panel/upload-tool.jsx +0 -133
- package/dist/features/side-tool/index.jsx +0 -211
- package/dist/features/view/index.jsx +0 -157
- package/dist/provider/antd-provider.jsx +0 -30
- package/dist/provider/redux-provider.jsx +0 -6
- package/dist/provider/store-provider.jsx +0 -8
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import Board from "../board";
|
|
4
|
-
import SideTool from "../side-tool";
|
|
5
|
-
import ControlPanels from "../panel";
|
|
6
|
-
import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
|
|
7
|
-
const TableEditor = (props) => {
|
|
8
|
-
const { componentProps, extraComponentProps, onCurrentStateChange } = props;
|
|
9
|
-
const { components, extraComponents } = useAppSelector((state) => state.board);
|
|
10
|
-
const dispatch = useAppDispatch();
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
onCurrentStateChange &&
|
|
13
|
-
onCurrentStateChange({
|
|
14
|
-
components,
|
|
15
|
-
extraComponents,
|
|
16
|
-
});
|
|
17
|
-
}, [components, extraComponents]);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
|
|
20
|
-
dispatch({
|
|
21
|
-
type: "board/setNewComponents",
|
|
22
|
-
payload: componentProps,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
|
|
26
|
-
dispatch({
|
|
27
|
-
type: "board/setNewExtraComponent",
|
|
28
|
-
payload: extraComponentProps,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
if (props === null || props === void 0 ? void 0 : props.defaultBackground) {
|
|
32
|
-
dispatch({
|
|
33
|
-
type: "board/setBackgroundColor",
|
|
34
|
-
payload: props === null || props === void 0 ? void 0 : props.defaultBackground,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}, [componentProps, extraComponentProps, props === null || props === void 0 ? void 0 : props.defaultBackground]);
|
|
38
|
-
return (<>
|
|
39
|
-
<div className="w-full h-screen flex relative">
|
|
40
|
-
<SideTool />
|
|
41
|
-
<Board onSelectComponent={props.onSelectComponent}/>
|
|
42
|
-
<ControlPanels action={props.action} responseMapping={props.responseMapping}/>
|
|
43
|
-
</div>
|
|
44
|
-
</>);
|
|
45
|
-
};
|
|
46
|
-
export default TableEditor;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
|
|
4
|
-
import { Form, Drawer, Input } from "antd";
|
|
5
|
-
import SelectToolForm from "./select-tool";
|
|
6
|
-
import SquareToolForm from "./square-circle-tool";
|
|
7
|
-
import SeatCircle from "./table-seat-circle";
|
|
8
|
-
import UploadTool from "./upload-tool";
|
|
9
|
-
const ControlPanels = (props) => {
|
|
10
|
-
const { action, responseMapping } = props;
|
|
11
|
-
const dispatch = useAppDispatch();
|
|
12
|
-
const tool = useAppSelector((state) => state.tool);
|
|
13
|
-
const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
|
|
14
|
-
const { show } = useAppSelector((state) => state.panel);
|
|
15
|
-
const [open, setOpen] = useState(false);
|
|
16
|
-
const [form] = Form.useForm();
|
|
17
|
-
let values = Form.useWatch([], form);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (selectedComponent) {
|
|
20
|
-
const isDifferentId = (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) !== (values === null || values === void 0 ? void 0 : values.id) || !(values === null || values === void 0 ? void 0 : values.id);
|
|
21
|
-
const isSameIdAndSameDimensions = (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) === (values === null || values === void 0 ? void 0 : values.id) &&
|
|
22
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.height) === (values === null || values === void 0 ? void 0 : values.height) &&
|
|
23
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.width) === (values === null || values === void 0 ? void 0 : values.width) &&
|
|
24
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.x) === (values === null || values === void 0 ? void 0 : values.x) &&
|
|
25
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.y) === (values === null || values === void 0 ? void 0 : values.y);
|
|
26
|
-
if (show && (isDifferentId || isSameIdAndSameDimensions)) {
|
|
27
|
-
setOpen(true);
|
|
28
|
-
}
|
|
29
|
-
form.setFieldsValue(selectedComponent);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
setOpen(false);
|
|
33
|
-
}
|
|
34
|
-
}, [selectedComponent]);
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (tool.active === "background" || tool.active === "image-table") {
|
|
37
|
-
setOpen(true);
|
|
38
|
-
}
|
|
39
|
-
}, [tool]);
|
|
40
|
-
const handleChangeComponent = (values, allValues) => {
|
|
41
|
-
dispatch({
|
|
42
|
-
type: "board/updateComponent",
|
|
43
|
-
payload: Object.assign(Object.assign({}, (selectedComponent || {})), allValues),
|
|
44
|
-
});
|
|
45
|
-
dispatch({
|
|
46
|
-
type: "panel/updateSelectedComponent",
|
|
47
|
-
payload: Object.assign(Object.assign({}, (selectedComponent || {})), allValues),
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const renderFormPanel = () => {
|
|
51
|
-
switch (tool.active) {
|
|
52
|
-
case "select":
|
|
53
|
-
return <SelectToolForm />;
|
|
54
|
-
case "square":
|
|
55
|
-
case "circle":
|
|
56
|
-
return <SquareToolForm />;
|
|
57
|
-
case "table-seat-circle":
|
|
58
|
-
return <SeatCircle />;
|
|
59
|
-
case "image-table":
|
|
60
|
-
return (<UploadTool name={tool.active} type="component" action={action} responseMapping={responseMapping}/>);
|
|
61
|
-
case "background":
|
|
62
|
-
return (<UploadTool name={tool.active} type="background" action={action} responseMapping={responseMapping}/>);
|
|
63
|
-
default:
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const handleClose = () => {
|
|
68
|
-
setOpen(false);
|
|
69
|
-
dispatch({
|
|
70
|
-
type: "panel/setShow",
|
|
71
|
-
payload: false,
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
// if(!show) return null
|
|
75
|
-
return (<Drawer open={show} onClose={handleClose} title="Panel">
|
|
76
|
-
<div className="bg-white h-full max-h-screen overflow-y-auto w-[300px]">
|
|
77
|
-
<Form layout="vertical" form={form} name="table" onFinish={(values) => { }} onValuesChange={handleChangeComponent} initialValues={{ labels: [{}] }}>
|
|
78
|
-
<Form.Item name="id" hidden>
|
|
79
|
-
<Input />
|
|
80
|
-
</Form.Item>
|
|
81
|
-
{renderFormPanel()}
|
|
82
|
-
</Form>
|
|
83
|
-
</div>
|
|
84
|
-
</Drawer>);
|
|
85
|
-
};
|
|
86
|
-
export default ControlPanels;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useAppSelector } from "../../hooks/use-redux";
|
|
3
|
-
import SquareToolForm from "./square-circle-tool";
|
|
4
|
-
import SeatCircle from "./table-seat-circle";
|
|
5
|
-
import UploadTool from "./upload-tool";
|
|
6
|
-
import TextTool from "./text-tool";
|
|
7
|
-
const SelectToolForm = ({ title = "Title" }) => {
|
|
8
|
-
const components = useAppSelector((state) => state.board.components);
|
|
9
|
-
const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
|
|
10
|
-
const SummaryComponents = () => {
|
|
11
|
-
const countByShape = components === null || components === void 0 ? void 0 : components.reduce((acc, item) => {
|
|
12
|
-
acc[item.shape] = (acc[item.shape] || 0) + 1;
|
|
13
|
-
return acc;
|
|
14
|
-
}, {});
|
|
15
|
-
return (<div className="flex flex-col">
|
|
16
|
-
<h1 className="heading-s">{title}</h1>
|
|
17
|
-
<div className="flex flex-col gap-2 mt-5">
|
|
18
|
-
{Object.entries(countByShape).map(([shape, count]) => (<div key={shape}>
|
|
19
|
-
<span className="font-bold">{shape}:</span> {count}
|
|
20
|
-
</div>))}
|
|
21
|
-
</div>
|
|
22
|
-
</div>);
|
|
23
|
-
};
|
|
24
|
-
const renderComponent = () => {
|
|
25
|
-
switch (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) {
|
|
26
|
-
case "square":
|
|
27
|
-
case "circle":
|
|
28
|
-
return <SquareToolForm />;
|
|
29
|
-
case "table-seat-circle":
|
|
30
|
-
return <SeatCircle />;
|
|
31
|
-
case "image-table":
|
|
32
|
-
case "background":
|
|
33
|
-
return <UploadTool name={selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.name}/>;
|
|
34
|
-
case "text":
|
|
35
|
-
return <TextTool />;
|
|
36
|
-
default:
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return (<div className="flex flex-col gap-2">
|
|
41
|
-
<SummaryComponents />
|
|
42
|
-
{renderComponent()}
|
|
43
|
-
</div>);
|
|
44
|
-
};
|
|
45
|
-
export default SelectToolForm;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import SectionLabel from "../../components/form-tools/label";
|
|
3
|
-
import SectionShape from "../../components/form-tools/shape";
|
|
4
|
-
const SquareToolForm = () => {
|
|
5
|
-
return (<>
|
|
6
|
-
<SectionShape />
|
|
7
|
-
<SectionLabel />
|
|
8
|
-
</>);
|
|
9
|
-
};
|
|
10
|
-
export default SquareToolForm;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ColorPicker, Flex, Form, InputNumber } from "antd";
|
|
3
|
-
import SectionLabel from "../../components/form-tools/label";
|
|
4
|
-
import SectionShape from "../../components/form-tools/shape";
|
|
5
|
-
const SeatCircle = () => {
|
|
6
|
-
return (<>
|
|
7
|
-
<div className="py-2">
|
|
8
|
-
<h1 className="heading-s"> Round table</h1>
|
|
9
|
-
<Flex>
|
|
10
|
-
<Form.Item name="seatCount" label="Seat Count" className="w-full">
|
|
11
|
-
<InputNumber />
|
|
12
|
-
</Form.Item>
|
|
13
|
-
<Form.Item name="openSpace" label="Open Space" className="w-full">
|
|
14
|
-
<InputNumber max={1} min={0} step={0.1}/>
|
|
15
|
-
</Form.Item>
|
|
16
|
-
|
|
17
|
-
</Flex>
|
|
18
|
-
<Flex gap={2}>
|
|
19
|
-
<Form.Item label="Seat Fill" name={"seatFill"} getValueFromEvent={(color) => color.toHexString()} className="w-full ">
|
|
20
|
-
<ColorPicker allowClear format="hex" defaultFormat="hex"/>
|
|
21
|
-
</Form.Item>
|
|
22
|
-
<Form.Item label="Table Fill" name={"fill"} getValueFromEvent={(color) => color.toHexString()} className="w-full ">
|
|
23
|
-
<ColorPicker allowClear format="hex" defaultFormat="hex"/>
|
|
24
|
-
</Form.Item>
|
|
25
|
-
</Flex>
|
|
26
|
-
<SectionShape />
|
|
27
|
-
<SectionLabel />
|
|
28
|
-
</div>
|
|
29
|
-
</>);
|
|
30
|
-
};
|
|
31
|
-
export default SeatCircle;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { ColorPicker, Form, Input, InputNumber } from "antd";
|
|
3
|
-
const TextTool = () => {
|
|
4
|
-
return (<div className="py-2">
|
|
5
|
-
<Form.Item name="text" label="Text">
|
|
6
|
-
<Input />
|
|
7
|
-
</Form.Item>
|
|
8
|
-
<Form.Item name={"fontColor"} label="Color" getValueFromEvent={(color) => color.toHexString()}>
|
|
9
|
-
<ColorPicker allowClear format="hex" defaultFormat="hex"/>
|
|
10
|
-
</Form.Item>
|
|
11
|
-
<Form.Item name={"x"} label="X">
|
|
12
|
-
<InputNumber />
|
|
13
|
-
</Form.Item>
|
|
14
|
-
<Form.Item name={"y"} label="Y">
|
|
15
|
-
<InputNumber />
|
|
16
|
-
</Form.Item>
|
|
17
|
-
<Form.Item name={"fontSize"} label="Size">
|
|
18
|
-
<InputNumber suffix="px"/>
|
|
19
|
-
</Form.Item>
|
|
20
|
-
</div>);
|
|
21
|
-
};
|
|
22
|
-
export default TextTool;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
import { Upload, message } from "antd";
|
|
12
|
-
import { InboxOutlined } from "@ant-design/icons";
|
|
13
|
-
import { useAppDispatch } from "../../hooks/use-redux";
|
|
14
|
-
import SectionLabel from "../../components/form-tools/label";
|
|
15
|
-
import SectionShape from "../../components/form-tools/shape";
|
|
16
|
-
const { Dragger } = Upload;
|
|
17
|
-
// const actionResponseBased = {
|
|
18
|
-
// status: 200,
|
|
19
|
-
// message: "Upload successful",
|
|
20
|
-
// data: {
|
|
21
|
-
// id: "12345",
|
|
22
|
-
// url: "https://example.com/image.png",
|
|
23
|
-
// },
|
|
24
|
-
// };
|
|
25
|
-
const UploadTool = ({ name, type, action, responseMapping, }) => {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
const dispatch = useAppDispatch();
|
|
28
|
-
const widthWorkspace = ((_a = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0;
|
|
29
|
-
const heightWorkspace = ((_b = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
|
|
30
|
-
const props = {
|
|
31
|
-
name: "file",
|
|
32
|
-
multiple: false,
|
|
33
|
-
maxCount: 1,
|
|
34
|
-
showUploadList: false,
|
|
35
|
-
onChange: (info) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
|
-
const { status } = info.file;
|
|
38
|
-
if (status !== "uploading" && info.file.originFileObj) {
|
|
39
|
-
const file = info.file.originFileObj;
|
|
40
|
-
const img = new window.Image();
|
|
41
|
-
let srcFromResponse = "";
|
|
42
|
-
try {
|
|
43
|
-
// ⬇️ IF ada custom action (upload ke server)
|
|
44
|
-
if (action && responseMapping) {
|
|
45
|
-
const res = yield action(file);
|
|
46
|
-
const isSuccess = (res === null || res === void 0 ? void 0 : res[responseMapping.status]) === 200;
|
|
47
|
-
if (isSuccess) {
|
|
48
|
-
srcFromResponse =
|
|
49
|
-
(_a = res === null || res === void 0 ? void 0 : res[responseMapping.data]) === null || _a === void 0 ? void 0 : _a[responseMapping.src];
|
|
50
|
-
img.onload = () => {
|
|
51
|
-
const scaleX = widthWorkspace / img.width;
|
|
52
|
-
const scaleY = heightWorkspace / img.height;
|
|
53
|
-
const scale = Math.min(1, scaleX, scaleY);
|
|
54
|
-
const width = img.width * scale;
|
|
55
|
-
const height = img.height * scale;
|
|
56
|
-
dispatch({
|
|
57
|
-
type: type === "component"
|
|
58
|
-
? "board/addComponent"
|
|
59
|
-
: "board/setExtraComponent",
|
|
60
|
-
payload: {
|
|
61
|
-
id: new Date().getTime(),
|
|
62
|
-
x: 0,
|
|
63
|
-
y: 0,
|
|
64
|
-
width,
|
|
65
|
-
height,
|
|
66
|
-
rotation: 0,
|
|
67
|
-
shape: name,
|
|
68
|
-
src: srcFromResponse,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
message.success(`${info.file.name} uploaded successfully.`);
|
|
72
|
-
};
|
|
73
|
-
// Set img src AFTER onload
|
|
74
|
-
img.src = srcFromResponse;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
message.error((res === null || res === void 0 ? void 0 : res[responseMapping.message]) || "Upload failed");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// ⬇️ IF local upload
|
|
81
|
-
else {
|
|
82
|
-
img.onload = () => {
|
|
83
|
-
const scaleX = widthWorkspace / img.width;
|
|
84
|
-
const scaleY = heightWorkspace / img.height;
|
|
85
|
-
const scale = Math.min(1, scaleX, scaleY);
|
|
86
|
-
const width = img.width * scale;
|
|
87
|
-
const height = img.height * scale;
|
|
88
|
-
dispatch({
|
|
89
|
-
type: type === "component"
|
|
90
|
-
? "board/addComponent"
|
|
91
|
-
: "board/setExtraComponent",
|
|
92
|
-
payload: {
|
|
93
|
-
id: new Date().getTime(),
|
|
94
|
-
x: 0,
|
|
95
|
-
y: 0,
|
|
96
|
-
width,
|
|
97
|
-
height,
|
|
98
|
-
rotation: 0,
|
|
99
|
-
shape: name,
|
|
100
|
-
src: img.src,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
message.success(`${info.file.name} uploaded successfully.`);
|
|
104
|
-
};
|
|
105
|
-
// Set img src AFTER onload
|
|
106
|
-
img.src = URL.createObjectURL(file);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
console.error("Upload error:", e);
|
|
111
|
-
message.error("Upload failed, please try again.");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}),
|
|
115
|
-
};
|
|
116
|
-
return (<>
|
|
117
|
-
<Dragger {...props}>
|
|
118
|
-
<p className="ant-upload-drag-icon">
|
|
119
|
-
<InboxOutlined />
|
|
120
|
-
</p>
|
|
121
|
-
<p className="ant-upload-text">
|
|
122
|
-
Click or drag file to this area to upload
|
|
123
|
-
</p>
|
|
124
|
-
<p className="ant-upload-hint">
|
|
125
|
-
Support for a single or bulk upload. Strictly prohibited from
|
|
126
|
-
uploading company data or other banned files.
|
|
127
|
-
</p>
|
|
128
|
-
</Dragger>
|
|
129
|
-
<SectionShape />
|
|
130
|
-
<SectionLabel />
|
|
131
|
-
</>);
|
|
132
|
-
};
|
|
133
|
-
export default UploadTool;
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Circle, CopyPlus, Eye, EyeOff, Image, Layers2, MousePointer, PaintBucket, Ratio, SquareMousePointer, Trash, Type, Upload, } from "lucide-react";
|
|
3
|
-
import ButtonTools from "../../components/button-tools";
|
|
4
|
-
import { Divider, ColorPicker, Button, } from "antd";
|
|
5
|
-
import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
|
|
6
|
-
import { useState } from "react";
|
|
7
|
-
const SideTool = () => {
|
|
8
|
-
const [color, setColor] = useState("#000000");
|
|
9
|
-
const dispatch = useAppDispatch();
|
|
10
|
-
const { active } = useAppSelector((state) => state.tool);
|
|
11
|
-
const { selectedComponent } = useAppSelector((state) => state.panel);
|
|
12
|
-
const { components } = useAppSelector((state) => state.board);
|
|
13
|
-
const [preview, setPreview] = useState(false);
|
|
14
|
-
const tools = [
|
|
15
|
-
{
|
|
16
|
-
id: "select",
|
|
17
|
-
name: "Select Tool",
|
|
18
|
-
icon: <MousePointer />,
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
const actionsTools = [
|
|
22
|
-
// {
|
|
23
|
-
// id: "table-split",
|
|
24
|
-
// name: "Table Split",
|
|
25
|
-
// icon: <TableCellsSplit />,
|
|
26
|
-
// },
|
|
27
|
-
{
|
|
28
|
-
id: "square",
|
|
29
|
-
name: "Square",
|
|
30
|
-
icon: <SquareMousePointer />,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "circle",
|
|
34
|
-
name: "Circle",
|
|
35
|
-
icon: <Circle />,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "table-seat-circle",
|
|
39
|
-
name: "Table Seat Circle",
|
|
40
|
-
icon: <Ratio />,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: "image-table",
|
|
44
|
-
name: "Image Table",
|
|
45
|
-
icon: <Upload />,
|
|
46
|
-
},
|
|
47
|
-
// {
|
|
48
|
-
// id: "table-seat-square",
|
|
49
|
-
// name: "Table Seat Square",
|
|
50
|
-
// icon: <Dock />,
|
|
51
|
-
// },
|
|
52
|
-
// {
|
|
53
|
-
// id: "diamond",
|
|
54
|
-
// name: "Diamond",
|
|
55
|
-
// icon: <Diamond />,
|
|
56
|
-
// },
|
|
57
|
-
];
|
|
58
|
-
const controlTools = [
|
|
59
|
-
{
|
|
60
|
-
id: "background",
|
|
61
|
-
name: "Background",
|
|
62
|
-
icon: <Image />,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "text",
|
|
66
|
-
name: "Text",
|
|
67
|
-
icon: <Type />,
|
|
68
|
-
},
|
|
69
|
-
// {
|
|
70
|
-
// id: "background-color",
|
|
71
|
-
// name: "Background Color",
|
|
72
|
-
// icon: <PaintBucket/>
|
|
73
|
-
// }
|
|
74
|
-
];
|
|
75
|
-
const hanldeSelectTool = (id) => {
|
|
76
|
-
if (id === "background" || id === "text" || id === "image-table") {
|
|
77
|
-
dispatch({
|
|
78
|
-
type: "panel/setShow",
|
|
79
|
-
payload: true
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
dispatch({
|
|
83
|
-
type: "tool/setActiveTool",
|
|
84
|
-
payload: id,
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
const handleChangeColorBackground = (color) => {
|
|
88
|
-
setColor(color.toHexString());
|
|
89
|
-
dispatch({
|
|
90
|
-
type: "board/setBackgroundColor",
|
|
91
|
-
payload: color.toHexString(),
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
const handleOpenModalPreview = () => {
|
|
95
|
-
dispatch({
|
|
96
|
-
type: "tool/setTooglePreview",
|
|
97
|
-
payload: true,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
const handleRemoveComponent = () => {
|
|
101
|
-
dispatch({
|
|
102
|
-
type: "board/removeComponent",
|
|
103
|
-
payload: selectedComponent,
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
const handleDuplicateComponent = () => {
|
|
107
|
-
const newComponent = Object.assign(Object.assign({}, selectedComponent), { x: selectedComponent.x + 20, y: selectedComponent.y + 20, id: Date.now() });
|
|
108
|
-
dispatch({
|
|
109
|
-
type: "board/addComponent",
|
|
110
|
-
payload: newComponent
|
|
111
|
-
});
|
|
112
|
-
dispatch({
|
|
113
|
-
type: "panel/setSelectedComponent",
|
|
114
|
-
payload: newComponent
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
function swapOneStepById(arr, id, direction) {
|
|
118
|
-
const index = arr.findIndex(item => (item === null || item === void 0 ? void 0 : item.id) === id);
|
|
119
|
-
if (index === -1)
|
|
120
|
-
return arr; // id tidak ditemukan
|
|
121
|
-
const newArr = [...arr];
|
|
122
|
-
if (direction === 'left' && index > 0) {
|
|
123
|
-
[newArr[index - 1], newArr[index]] = [newArr[index], newArr[index - 1]];
|
|
124
|
-
}
|
|
125
|
-
if (direction === 'right' && index < arr.length - 1) {
|
|
126
|
-
[newArr[index + 1], newArr[index]] = [newArr[index], newArr[index + 1]];
|
|
127
|
-
}
|
|
128
|
-
return newArr;
|
|
129
|
-
}
|
|
130
|
-
const handleOverride = () => {
|
|
131
|
-
const newArr = swapOneStepById(components, selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id, 'right');
|
|
132
|
-
dispatch({
|
|
133
|
-
type: "board/setNewComponents",
|
|
134
|
-
payload: newArr
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
return (<div className="h-screen left-0 flex flex-col items-center border-r-2 border-gray-300 bg-white px-2 pt-4">
|
|
138
|
-
{tools === null || tools === void 0 ? void 0 : tools.map((tool) => (<ButtonTools key={tool.id} buttonProps={{
|
|
139
|
-
icon: tool.icon,
|
|
140
|
-
type: "text",
|
|
141
|
-
name: tool.name,
|
|
142
|
-
onClick: () => hanldeSelectTool(tool.id),
|
|
143
|
-
style: active === tool.id ? { color: "red" } : {},
|
|
144
|
-
}} popoverProps={{
|
|
145
|
-
content: <div>{tool.name}</div>,
|
|
146
|
-
trigger: "hover",
|
|
147
|
-
placement: "right",
|
|
148
|
-
}} items={[]}/>))}
|
|
149
|
-
<ButtonTools buttonProps={{
|
|
150
|
-
icon: <CopyPlus />,
|
|
151
|
-
type: "text",
|
|
152
|
-
name: "duplicate",
|
|
153
|
-
onClick: () => handleDuplicateComponent(),
|
|
154
|
-
}} items={[]} popoverProps={{
|
|
155
|
-
content: <div>Duplicate</div>,
|
|
156
|
-
trigger: "hover",
|
|
157
|
-
placement: "right",
|
|
158
|
-
}}/>
|
|
159
|
-
<ButtonTools buttonProps={{
|
|
160
|
-
onClick: () => handleRemoveComponent(),
|
|
161
|
-
icon: <Trash />,
|
|
162
|
-
type: "text",
|
|
163
|
-
name: "trash",
|
|
164
|
-
}} items={[]} popoverProps={{
|
|
165
|
-
content: <div>Trash</div>,
|
|
166
|
-
trigger: "hover",
|
|
167
|
-
placement: "right",
|
|
168
|
-
}}/>
|
|
169
|
-
<ButtonTools buttonProps={{
|
|
170
|
-
onClick: () => handleOverride(),
|
|
171
|
-
icon: <Layers2 />,
|
|
172
|
-
type: "text",
|
|
173
|
-
name: "override",
|
|
174
|
-
}} items={[]} popoverProps={{
|
|
175
|
-
content: <div>Override</div>,
|
|
176
|
-
trigger: "hover",
|
|
177
|
-
placement: "right",
|
|
178
|
-
}}/>
|
|
179
|
-
|
|
180
|
-
<Divider />
|
|
181
|
-
{actionsTools === null || actionsTools === void 0 ? void 0 : actionsTools.map((tool) => (<ButtonTools key={tool.id} buttonProps={{
|
|
182
|
-
icon: tool.icon,
|
|
183
|
-
type: "text",
|
|
184
|
-
name: tool.name,
|
|
185
|
-
onClick: () => hanldeSelectTool(tool.id),
|
|
186
|
-
style: active === tool.id ? { color: "red" } : {},
|
|
187
|
-
}} popoverProps={{
|
|
188
|
-
content: <div>{tool.name}</div>,
|
|
189
|
-
trigger: "hover",
|
|
190
|
-
placement: "right",
|
|
191
|
-
}} items={[]}/>))}
|
|
192
|
-
|
|
193
|
-
<Divider />
|
|
194
|
-
{controlTools === null || controlTools === void 0 ? void 0 : controlTools.map((tool) => (<ButtonTools key={tool.id} buttonProps={{
|
|
195
|
-
icon: tool.icon,
|
|
196
|
-
type: "text",
|
|
197
|
-
name: tool.name,
|
|
198
|
-
onClick: () => hanldeSelectTool(tool.id),
|
|
199
|
-
style: active === tool.id ? { color: "red" } : {},
|
|
200
|
-
}} popoverProps={{
|
|
201
|
-
content: <div>{tool.name}</div>,
|
|
202
|
-
trigger: "hover",
|
|
203
|
-
placement: "right",
|
|
204
|
-
}} items={[]}/>))}
|
|
205
|
-
<ColorPicker value={color} onChange={handleChangeColorBackground}>
|
|
206
|
-
<Button icon={<PaintBucket />} type="text" name="Background Color" onClick={() => hanldeSelectTool("background-color")} style={active === "background-color" ? { color: "red" } : {}}/>
|
|
207
|
-
</ColorPicker>
|
|
208
|
-
<Button icon={preview ? <EyeOff /> : <Eye />} type="text" name="Preview" onClick={handleOpenModalPreview} style={active === "preview" ? { color: "red" } : {}}/>
|
|
209
|
-
</div>);
|
|
210
|
-
};
|
|
211
|
-
export default SideTool;
|