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