seat-editor 1.4.21 → 1.4.22
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/features/package/index.js +7 -2
- package/dist/features/view/index.js +1 -1
- package/package.json +1 -1
- package/dist/app/layout.jsx +0 -27
- package/dist/app/new-board/page.jsx +0 -53
- package/dist/app/old-board/page.jsx +0 -510
- package/dist/app/only-view/page.jsx +0 -40
- 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 -66
- package/dist/components/input/number-indicator.jsx +0 -36
- package/dist/components/joystick/index.jsx +0 -49
- package/dist/components/layer/index.jsx +0 -361
- package/dist/components/lib/index.jsx +0 -33
- package/dist/components/modal-preview/index.jsx +0 -11
- package/dist/features/board/index.jsx +0 -654
- package/dist/features/navbar/index.jsx +0 -5
- package/dist/features/package/index.jsx +0 -107
- package/dist/features/panel/index.jsx +0 -105
- package/dist/features/panel/select-tool.jsx +0 -53
- 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 -177
- package/dist/features/side-tool/index.jsx +0 -261
- package/dist/features/view/index.jsx +0 -220
- package/dist/provider/antd-provider.jsx +0 -46
- package/dist/provider/redux-provider.jsx +0 -6
- package/dist/provider/store-provider.jsx +0 -10
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useState } 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
|
-
import { isEqual } from "lodash";
|
|
8
|
-
const TableEditor = (props) => {
|
|
9
|
-
const [initialValue, setInitialValue] = useState(null);
|
|
10
|
-
const { componentProps, extraComponentProps, onCurrentStateChange, dragOnly, mappingKey, } = props;
|
|
11
|
-
const { components, extraComponents } = useAppSelector((state) => state.board);
|
|
12
|
-
const dispatch = useAppDispatch();
|
|
13
|
-
const onUpdateCurrentState = () => {
|
|
14
|
-
let matchInitialValueWithComponents = initialValue === null || initialValue === void 0 ? void 0 : initialValue.map((item) => {
|
|
15
|
-
if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
|
|
16
|
-
let findComponent = components === null || components === void 0 ? void 0 : components.find((c) => { var _a; return c.id === ((_a = item === null || item === void 0 ? void 0 : item[mappingKey]) === null || _a === void 0 ? void 0 : _a.id); });
|
|
17
|
-
if (findComponent) {
|
|
18
|
-
return Object.assign(Object.assign({}, item), { [mappingKey]: Object.assign({}, findComponent) });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
let findComponent = components === null || components === void 0 ? void 0 : components.find((c) => c.id === (item === null || item === void 0 ? void 0 : item.id));
|
|
23
|
-
if (findComponent) {
|
|
24
|
-
return Object.assign(Object.assign({}, item), findComponent);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
onCurrentStateChange({
|
|
29
|
-
components: matchInitialValueWithComponents !== null && matchInitialValueWithComponents !== void 0 ? matchInitialValueWithComponents : [],
|
|
30
|
-
extraComponents,
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
onCurrentStateChange && onUpdateCurrentState();
|
|
35
|
-
}, [components, initialValue, extraComponents]);
|
|
36
|
-
// if (!isEqual(componentsProps, componentsState)) {
|
|
37
|
-
// isSyncingFromRedux.current = true;
|
|
38
|
-
// setComponentsState(componentsProps);
|
|
39
|
-
// }
|
|
40
|
-
// if (!isEqual(extraComponentsProps, extraComponentsState)) {
|
|
41
|
-
// isSyncingFromRedux.current = true;
|
|
42
|
-
// setExtraComponentsState(extraComponentsProps);
|
|
43
|
-
// }
|
|
44
|
-
// if (!isEqual(selectedComponentProps, selectedComponent)) {
|
|
45
|
-
// isSyncingFromRedux.current = true;
|
|
46
|
-
// setSelectedComponent(selectedComponentProps);
|
|
47
|
-
// }
|
|
48
|
-
// useEffect(() => {
|
|
49
|
-
// if (componentProps && componentProps.length > 0) {
|
|
50
|
-
// let hasMappingKeyEveryComponent = componentProps.every(
|
|
51
|
-
// (item) => mappingKey && item[mappingKey]
|
|
52
|
-
// );
|
|
53
|
-
// if(componentProps
|
|
54
|
-
// setInitialValue(componentProps);
|
|
55
|
-
// }
|
|
56
|
-
// }
|
|
57
|
-
// , [componentProps]);
|
|
58
|
-
const convertComponentProps = () => {
|
|
59
|
-
let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
|
|
60
|
-
if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
|
|
61
|
-
return Object.assign({}, item[mappingKey]);
|
|
62
|
-
}
|
|
63
|
-
return item;
|
|
64
|
-
});
|
|
65
|
-
return mappingData;
|
|
66
|
-
};
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!isEqual(components, convertComponentProps())) {
|
|
69
|
-
let mappingData = componentProps === null || componentProps === void 0 ? void 0 : componentProps.map((item) => {
|
|
70
|
-
if (mappingKey && (item === null || item === void 0 ? void 0 : item[props.mappingKey])) {
|
|
71
|
-
return Object.assign({}, item[props.mappingKey]);
|
|
72
|
-
}
|
|
73
|
-
return item;
|
|
74
|
-
});
|
|
75
|
-
if (mappingKey) {
|
|
76
|
-
setInitialValue(componentProps);
|
|
77
|
-
}
|
|
78
|
-
dispatch({
|
|
79
|
-
type: "board/setNewComponents",
|
|
80
|
-
payload: mappingData,
|
|
81
|
-
});
|
|
82
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
83
|
-
}
|
|
84
|
-
if (!isEqual(extraComponents, extraComponentProps)) {
|
|
85
|
-
dispatch({
|
|
86
|
-
type: "board/setNewExtraComponents",
|
|
87
|
-
payload: extraComponentProps,
|
|
88
|
-
});
|
|
89
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
90
|
-
}
|
|
91
|
-
if (props === null || props === void 0 ? void 0 : props.defaultBackground) {
|
|
92
|
-
dispatch({
|
|
93
|
-
type: "board/setBackgroundColor",
|
|
94
|
-
payload: props === null || props === void 0 ? void 0 : props.defaultBackground,
|
|
95
|
-
});
|
|
96
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
97
|
-
}
|
|
98
|
-
}, [componentProps, extraComponentProps, props === null || props === void 0 ? void 0 : props.defaultBackground]);
|
|
99
|
-
return (<>
|
|
100
|
-
<div className="w-full h-screen flex relative">
|
|
101
|
-
<SideTool dragOnly={dragOnly}/>
|
|
102
|
-
<Board onSelectComponent={props.onSelectComponent}/>
|
|
103
|
-
<ControlPanels action={props.action} responseMapping={props.responseMapping}/>
|
|
104
|
-
</div>
|
|
105
|
-
</>);
|
|
106
|
-
};
|
|
107
|
-
export default TableEditor;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
import { useEffect, useState } from "react";
|
|
14
|
-
import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
|
|
15
|
-
import { Form, Drawer, Input } from "antd";
|
|
16
|
-
import SelectToolForm from "./select-tool";
|
|
17
|
-
import SquareToolForm from "./square-circle-tool";
|
|
18
|
-
import SeatCircle from "./table-seat-circle";
|
|
19
|
-
import UploadTool from "./upload-tool";
|
|
20
|
-
const ControlPanels = (props) => {
|
|
21
|
-
const { action, responseMapping } = props;
|
|
22
|
-
const dispatch = useAppDispatch();
|
|
23
|
-
const theme = useAppSelector((state) => state.theme);
|
|
24
|
-
const tool = useAppSelector((state) => state.tool);
|
|
25
|
-
const selectedComponent = useAppSelector((state) => state.panel.selectedComponent);
|
|
26
|
-
const { show } = useAppSelector((state) => state.panel);
|
|
27
|
-
const [open, setOpen] = useState(false);
|
|
28
|
-
const [form] = Form.useForm();
|
|
29
|
-
let values = Form.useWatch([], form);
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (selectedComponent) {
|
|
32
|
-
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);
|
|
33
|
-
const isSameIdAndSameDimensions = (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.id) === (values === null || values === void 0 ? void 0 : values.id) &&
|
|
34
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.height) === (values === null || values === void 0 ? void 0 : values.height) &&
|
|
35
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.width) === (values === null || values === void 0 ? void 0 : values.width) &&
|
|
36
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.x) === (values === null || values === void 0 ? void 0 : values.x) &&
|
|
37
|
-
(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.y) === (values === null || values === void 0 ? void 0 : values.y);
|
|
38
|
-
if (show && (isDifferentId || isSameIdAndSameDimensions)) {
|
|
39
|
-
setOpen(true);
|
|
40
|
-
}
|
|
41
|
-
form.setFieldsValue(selectedComponent);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
setOpen(false);
|
|
45
|
-
}
|
|
46
|
-
}, [selectedComponent]);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (tool.active === "background" || tool.active === "image-table") {
|
|
49
|
-
setOpen(true);
|
|
50
|
-
}
|
|
51
|
-
}, [tool]);
|
|
52
|
-
const createShape = (shape, ...props) => {
|
|
53
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
54
|
-
return (Object.assign(Object.assign({}, props === null || props === void 0 ? void 0 : props[0]), { shape, fill: (_b = (_a = props === null || props === void 0 ? void 0 : props[0]) === null || _a === void 0 ? void 0 : _a.fill) !== null && _b !== void 0 ? _b : theme === null || theme === void 0 ? void 0 : theme.primaryColor, seatCount: shape === "table-seat-circle" ? (_d = (_c = props === null || props === void 0 ? void 0 : props[0]) === null || _c === void 0 ? void 0 : _c.seatCount) !== null && _d !== void 0 ? _d : 6 : 0, openSpace: shape === "table-seat-circle" ? (_f = (_e = props === null || props === void 0 ? void 0 : props[0]) === null || _e === void 0 ? void 0 : _e.openSpace) !== null && _f !== void 0 ? _f : 0 : undefined, seatFill: shape === "table-seat-circle" ? (_h = (_g = props === null || props === void 0 ? void 0 : props[0]) === null || _g === void 0 ? void 0 : _g.seatFill) !== null && _h !== void 0 ? _h : "#DADADA" : undefined, text: shape === "text" ? "Text" : "", fontColor: shape === "text" ? (_k = (_j = props === null || props === void 0 ? void 0 : props[0]) === null || _j === void 0 ? void 0 : _j.fontColor) !== null && _k !== void 0 ? _k : "#DADADA" : undefined }));
|
|
55
|
-
};
|
|
56
|
-
const handleChangeComponent = (values, allValues) => {
|
|
57
|
-
const { shape } = allValues, restProps = __rest(allValues, ["shape"]);
|
|
58
|
-
const newValues = createShape(shape, restProps);
|
|
59
|
-
dispatch({
|
|
60
|
-
type: "board/updateComponent",
|
|
61
|
-
payload: Object.assign(Object.assign({}, (selectedComponent || {})), newValues),
|
|
62
|
-
});
|
|
63
|
-
dispatch({
|
|
64
|
-
type: "panel/updateSelectedComponent",
|
|
65
|
-
payload: Object.assign(Object.assign({}, (selectedComponent || {})), newValues),
|
|
66
|
-
});
|
|
67
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
68
|
-
};
|
|
69
|
-
const renderFormPanel = () => {
|
|
70
|
-
switch (tool.active) {
|
|
71
|
-
case "select":
|
|
72
|
-
return <SelectToolForm />;
|
|
73
|
-
case "square":
|
|
74
|
-
case "circle":
|
|
75
|
-
return <SquareToolForm />;
|
|
76
|
-
case "table-seat-circle":
|
|
77
|
-
return <SeatCircle />;
|
|
78
|
-
case "image-table":
|
|
79
|
-
return (<UploadTool name={tool.active} type="component" action={action} responseMapping={responseMapping}/>);
|
|
80
|
-
case "background":
|
|
81
|
-
return (<UploadTool name={tool.active} type="background" action={action} responseMapping={responseMapping}/>);
|
|
82
|
-
default:
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const handleClose = () => {
|
|
87
|
-
setOpen(false);
|
|
88
|
-
dispatch({
|
|
89
|
-
type: "panel/setShow",
|
|
90
|
-
payload: false,
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
// if(!show) return null
|
|
94
|
-
return (<Drawer open={show} onClose={handleClose} title="Panel">
|
|
95
|
-
<div className="bg-white h-full max-h-screen overflow-y-auto w-full">
|
|
96
|
-
<Form layout="vertical" form={form} name="table" onFinish={(values) => { }} onValuesChange={handleChangeComponent} initialValues={{ labels: [{}] }}>
|
|
97
|
-
<Form.Item name="id" hidden>
|
|
98
|
-
<Input />
|
|
99
|
-
</Form.Item>
|
|
100
|
-
{renderFormPanel()}
|
|
101
|
-
</Form>
|
|
102
|
-
</div>
|
|
103
|
-
</Drawer>);
|
|
104
|
-
};
|
|
105
|
-
export default ControlPanels;
|
|
@@ -1,53 +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 extraComponents = useAppSelector((state) => state.board.extraComponents);
|
|
11
|
-
const SummaryComponents = () => {
|
|
12
|
-
const countByShape = components === null || components === void 0 ? void 0 : components.reduce((acc, item) => {
|
|
13
|
-
acc[item.shape] = (acc[item.shape] || 0) + 1;
|
|
14
|
-
return acc;
|
|
15
|
-
}, {});
|
|
16
|
-
const extraCountByShape = extraComponents === null || extraComponents === void 0 ? void 0 : extraComponents.reduce((acc, item) => {
|
|
17
|
-
acc[item.shape] = (acc[item.shape] || 0) + 1;
|
|
18
|
-
return acc;
|
|
19
|
-
}, {});
|
|
20
|
-
const variableFormatToString = (variable) => {
|
|
21
|
-
return variable.replace(/-/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
|
|
22
|
-
};
|
|
23
|
-
return (<div className="flex flex-col">
|
|
24
|
-
<h1 className="heading-s">{title}</h1>
|
|
25
|
-
<div className="flex flex-col gap-2 mt-5">
|
|
26
|
-
{Object.entries(countByShape).map(([shape, count]) => (<div key={shape}>
|
|
27
|
-
<span className="font-bold">{variableFormatToString(shape)}:</span> {count}
|
|
28
|
-
</div>))}
|
|
29
|
-
</div>
|
|
30
|
-
</div>);
|
|
31
|
-
};
|
|
32
|
-
const renderComponent = () => {
|
|
33
|
-
switch (selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) {
|
|
34
|
-
case "square":
|
|
35
|
-
case "circle":
|
|
36
|
-
return <SquareToolForm />;
|
|
37
|
-
case "table-seat-circle":
|
|
38
|
-
return <SeatCircle />;
|
|
39
|
-
case "image-table":
|
|
40
|
-
case "background":
|
|
41
|
-
return <UploadTool name={selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape} defaultValue={selectedComponent} type={(selectedComponent === null || selectedComponent === void 0 ? void 0 : selectedComponent.shape) === "background" ? "background" : "component"}/>;
|
|
42
|
-
case "text":
|
|
43
|
-
return <TextTool />;
|
|
44
|
-
default:
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
return (<div className="flex flex-col gap-2">
|
|
49
|
-
<SummaryComponents />
|
|
50
|
-
{renderComponent()}
|
|
51
|
-
</div>);
|
|
52
|
-
};
|
|
53
|
-
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,177 +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 { useState, useEffect } from "react";
|
|
12
|
-
import { Upload, message, Image, Button } from "antd";
|
|
13
|
-
import { InboxOutlined } from "@ant-design/icons";
|
|
14
|
-
import { useAppDispatch } from "../../hooks/use-redux";
|
|
15
|
-
import SectionLabel from "../../components/form-tools/label";
|
|
16
|
-
import SectionShape from "../../components/form-tools/shape";
|
|
17
|
-
const { Dragger } = Upload;
|
|
18
|
-
// const actionResponseBased = {
|
|
19
|
-
// status: 200,
|
|
20
|
-
// message: "Upload successful",
|
|
21
|
-
// data: {
|
|
22
|
-
// id: "12345",
|
|
23
|
-
// url: "https://example.com/image.png",
|
|
24
|
-
// },
|
|
25
|
-
// };
|
|
26
|
-
const UploadTool = ({ name, type, action, responseMapping, defaultValue, }) => {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
const [defaultSrc, setDefaultSrc] = useState(null);
|
|
29
|
-
const [isEdit, setIsEdit] = useState(false);
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (defaultValue) {
|
|
32
|
-
setDefaultSrc(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.src);
|
|
33
|
-
setIsEdit(true);
|
|
34
|
-
}
|
|
35
|
-
}, [defaultValue]);
|
|
36
|
-
const dispatch = useAppDispatch();
|
|
37
|
-
const widthWorkspace = ((_a = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0;
|
|
38
|
-
const heightWorkspace = ((_b = document === null || document === void 0 ? void 0 : document.getElementById("workspace")) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
|
|
39
|
-
const defaultFormatValue = (width, height, src, id) => ({
|
|
40
|
-
id: id || new Date().getTime(),
|
|
41
|
-
x: 0,
|
|
42
|
-
y: 0,
|
|
43
|
-
width,
|
|
44
|
-
height,
|
|
45
|
-
rotation: 0,
|
|
46
|
-
shape: name,
|
|
47
|
-
src,
|
|
48
|
-
});
|
|
49
|
-
const props = {
|
|
50
|
-
name: "file",
|
|
51
|
-
multiple: true,
|
|
52
|
-
maxCount: 1,
|
|
53
|
-
showUploadList: false,
|
|
54
|
-
onChange: (info) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
var _a;
|
|
56
|
-
const { status } = info.file;
|
|
57
|
-
if (status !== "uploading" && info.file.originFileObj) {
|
|
58
|
-
const file = info.file.originFileObj;
|
|
59
|
-
const img = new window.Image();
|
|
60
|
-
let srcFromResponse = "";
|
|
61
|
-
try {
|
|
62
|
-
// ⬇️ IF ada custom action (upload ke server)
|
|
63
|
-
if (action && responseMapping) {
|
|
64
|
-
const res = yield action(file);
|
|
65
|
-
const isSuccess = (res === null || res === void 0 ? void 0 : res[responseMapping.status]) === 200;
|
|
66
|
-
if (isSuccess) {
|
|
67
|
-
srcFromResponse =
|
|
68
|
-
(_a = res === null || res === void 0 ? void 0 : res[responseMapping.data]) === null || _a === void 0 ? void 0 : _a[responseMapping.src];
|
|
69
|
-
img.onload = () => {
|
|
70
|
-
const scaleX = widthWorkspace / img.width;
|
|
71
|
-
const scaleY = heightWorkspace / img.height;
|
|
72
|
-
const scale = Math.min(1, scaleX, scaleY);
|
|
73
|
-
const width = img.width * scale;
|
|
74
|
-
const height = img.height * scale;
|
|
75
|
-
if (isEdit) {
|
|
76
|
-
dispatch({
|
|
77
|
-
type: type === "component"
|
|
78
|
-
? "board/updateComponent"
|
|
79
|
-
: "board/updateExtraComponent",
|
|
80
|
-
payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse, defaultValue.id)),
|
|
81
|
-
});
|
|
82
|
-
dispatch({
|
|
83
|
-
type: "panel/setSelectedComponent",
|
|
84
|
-
payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse, defaultValue.id)),
|
|
85
|
-
});
|
|
86
|
-
setDefaultSrc(srcFromResponse);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
dispatch({
|
|
90
|
-
type: type === "component"
|
|
91
|
-
? "board/addComponent"
|
|
92
|
-
: "board/setExtraComponent",
|
|
93
|
-
payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse)),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
97
|
-
message.success(`${info.file.name} uploaded successfully.`);
|
|
98
|
-
};
|
|
99
|
-
// Set img src AFTER onload
|
|
100
|
-
img.src = srcFromResponse;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
message.error((res === null || res === void 0 ? void 0 : res[responseMapping.message]) || "Upload failed");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// ⬇️ IF local upload
|
|
107
|
-
else {
|
|
108
|
-
img.onload = () => {
|
|
109
|
-
const scaleX = widthWorkspace / img.width;
|
|
110
|
-
const scaleY = heightWorkspace / img.height;
|
|
111
|
-
const scale = Math.min(1, scaleX, scaleY);
|
|
112
|
-
const width = img.width * scale;
|
|
113
|
-
const height = img.height * scale;
|
|
114
|
-
if (isEdit) {
|
|
115
|
-
dispatch({
|
|
116
|
-
type: type === "component"
|
|
117
|
-
? "board/updateComponent"
|
|
118
|
-
: "board/updateExtraComponent",
|
|
119
|
-
payload: Object.assign({}, defaultFormatValue(width, height, img.src, defaultValue.id)),
|
|
120
|
-
});
|
|
121
|
-
dispatch({
|
|
122
|
-
type: "panel/setSelectedComponent",
|
|
123
|
-
payload: Object.assign({}, defaultFormatValue(width, height, srcFromResponse, defaultValue.id)),
|
|
124
|
-
});
|
|
125
|
-
setDefaultSrc(img.src);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
dispatch({
|
|
129
|
-
type: type === "component"
|
|
130
|
-
? "board/addComponent"
|
|
131
|
-
: "board/setExtraComponent",
|
|
132
|
-
payload: Object.assign({}, defaultFormatValue(width, height, img.src)),
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
dispatch({ type: "board/setFlagChange", payload: true });
|
|
136
|
-
message.success(`${info.file.name} uploaded successfully.`);
|
|
137
|
-
};
|
|
138
|
-
// Set img src AFTER onload
|
|
139
|
-
img.src = URL.createObjectURL(file);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (e) {
|
|
143
|
-
console.error("Upload error:", e);
|
|
144
|
-
message.error("Upload failed, please try again.");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}),
|
|
148
|
-
};
|
|
149
|
-
const handleDelete = () => {
|
|
150
|
-
setDefaultSrc(null);
|
|
151
|
-
};
|
|
152
|
-
return (<>
|
|
153
|
-
{defaultSrc ? (<>
|
|
154
|
-
<div className="w-full flex flex-col items-center gap-2 max-h-[200px] overflow-y-auto">
|
|
155
|
-
<Image src={defaultSrc}/>
|
|
156
|
-
</div>
|
|
157
|
-
<Button type="primary" onClick={handleDelete}>
|
|
158
|
-
Edit
|
|
159
|
-
</Button>
|
|
160
|
-
</>) : (<Dragger {...props}>
|
|
161
|
-
<p className="ant-upload-drag-icon">
|
|
162
|
-
<InboxOutlined />
|
|
163
|
-
</p>
|
|
164
|
-
<p className="ant-upload-text">
|
|
165
|
-
Click or drag file to this area to upload
|
|
166
|
-
</p>
|
|
167
|
-
<p className="ant-upload-hint">
|
|
168
|
-
Support for a single or bulk upload. Strictly prohibited from
|
|
169
|
-
uploading company data or other banned files.
|
|
170
|
-
</p>
|
|
171
|
-
</Dragger>)}
|
|
172
|
-
|
|
173
|
-
<SectionShape />
|
|
174
|
-
<SectionLabel />
|
|
175
|
-
</>);
|
|
176
|
-
};
|
|
177
|
-
export default UploadTool;
|