seat-editor 3.3.35 → 3.3.37
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/constant.d.ts +3 -0
- package/dist/app/constant.js +2 -0
- 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 +58 -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/chair.d.ts +1 -1
- package/dist/app/only-view/chair.js +2 -10
- package/dist/app/only-view/page.d.ts +1 -1
- package/dist/app/only-view/page.js +226 -0
- package/dist/app/only-view/user.d.ts +1 -1
- package/dist/app/only-view/user.js +2 -10
- package/dist/app/page.d.ts +1 -1
- package/dist/app/page.js +8 -0
- package/dist/app/test/page.d.ts +1 -2
- package/dist/app/test/page.js +43 -0
- package/dist/app/v2/page.d.ts +1 -1
- package/dist/app/v2/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 +21 -0
- package/dist/components/form-tools/shape.d.ts +1 -1
- package/dist/components/form-tools/shape.js +69 -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 +295 -0
- package/dist/components/layer-v2/index.d.ts +1 -1
- package/dist/components/layer-v2/index.js +282 -0
- package/dist/components/layer-v3/index.d.ts +1 -1
- package/dist/components/layer-v3/index.js +483 -0
- package/dist/components/layer-v4/index.d.ts +1 -1
- package/dist/components/layer-v4/index.js +924 -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 +666 -0
- package/dist/features/board-v2/index.d.ts +1 -2
- package/dist/features/board-v2/index.js +807 -0
- package/dist/features/board-v3/icons.js +16 -0
- package/dist/features/board-v3/index.d.ts +1 -1
- package/dist/features/board-v3/index.js +1587 -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 +166 -0
- package/dist/features/panel/index.d.ts +1 -1
- package/dist/features/panel/index.js +243 -0
- package/dist/features/panel/select-tool.d.ts +1 -1
- package/dist/features/panel/select-tool.js +57 -0
- package/dist/features/panel/selected-group.d.ts +1 -1
- package/dist/features/panel/selected-group.js +35 -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/table-seat-square.d.ts +1 -1
- package/dist/features/panel/table-seat-square.js +9 -0
- package/dist/features/panel/text-tool.d.ts +1 -1
- package/dist/features/panel/text-tool.js +22 -0
- package/dist/features/panel/upload-tool.d.ts +1 -1
- package/dist/features/panel/upload-tool.js +150 -0
- package/dist/features/side-tool/index.d.ts +1 -1
- package/dist/features/side-tool/index.js +365 -0
- package/dist/features/view-only/index.d.ts +1 -1
- package/dist/features/view-only/index.js +198 -0
- package/dist/features/view-only-2/index.d.ts +84 -14
- package/dist/features/view-only-2/index.js +558 -0
- package/dist/features/view-only-3/index.d.ts +1 -1
- package/dist/features/view-only-3/index.js +577 -0
- 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,558 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState, useImperativeHandle, } from "react";
|
|
4
|
+
import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
|
|
5
|
+
import Layers from "../../components/layer-v4";
|
|
6
|
+
import { getTranslate } from "../board-v3/utils";
|
|
7
|
+
import { Spin } from "antd";
|
|
8
|
+
const LayerView = (props) => {
|
|
9
|
+
const { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, statusKey, defaultBackground, defaultBoundingBox, iconTags, tooltipProps, onRightClick, allowTooltip = true, tableMatchKey, eventMatchTable, ghostAttributes, onDrop, onSwitch, refs, privilegedTags, disabled, loadingRender, } = props;
|
|
10
|
+
const widthTooltip = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.minWidth) || 168;
|
|
11
|
+
const tableGhost = useRef(null);
|
|
12
|
+
const hoverUnderghostId = useRef(null);
|
|
13
|
+
const transformRef = useRef(null);
|
|
14
|
+
const containerRef = useRef(null);
|
|
15
|
+
const svgRef = useRef(null);
|
|
16
|
+
const hasBoundingBoxRef = useRef(false);
|
|
17
|
+
const [tooltip, setTooltip] = useState({
|
|
18
|
+
x: 0,
|
|
19
|
+
y: 0,
|
|
20
|
+
visible: false,
|
|
21
|
+
});
|
|
22
|
+
const isDragging = useRef(false);
|
|
23
|
+
const [panningGroup, setPanningGroup] = useState(false);
|
|
24
|
+
const [scale, setScale] = useState(1);
|
|
25
|
+
const [selectedTable, setSelectedTable] = useState(null);
|
|
26
|
+
const { components: componentsEditor, extraComponents: extraComponentsEditor, boundingBox: boundingBoxProps, } = useAppSelector((state) => state.board);
|
|
27
|
+
const backgroundColor = useAppSelector((state) => state.board.backgroundColor);
|
|
28
|
+
const { loading } = useAppSelector((state) => state.panel);
|
|
29
|
+
useImperativeHandle(refs, () => ({
|
|
30
|
+
svgRef: svgRef === null || svgRef === void 0 ? void 0 : svgRef.current,
|
|
31
|
+
transformRef: transformRef === null || transformRef === void 0 ? void 0 : transformRef.current,
|
|
32
|
+
containerRef: containerRef === null || containerRef === void 0 ? void 0 : containerRef.current,
|
|
33
|
+
tableGhost: tableGhost === null || tableGhost === void 0 ? void 0 : tableGhost.current,
|
|
34
|
+
hoverUnderghost: originalData({
|
|
35
|
+
id: hoverUnderghostId === null || hoverUnderghostId === void 0 ? void 0 : hoverUnderghostId.current,
|
|
36
|
+
type: "find",
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
39
|
+
const dispatch = useAppDispatch();
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!loading && (loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state)) {
|
|
42
|
+
dispatch({ type: "panel/setLoading", payload: true });
|
|
43
|
+
}
|
|
44
|
+
// check in null
|
|
45
|
+
const isEmptyComponents = (componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) === 0;
|
|
46
|
+
const isEmptyExtraComponents = (extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) === 0;
|
|
47
|
+
// const isEmptyBoundingBox = boundingBox === null;
|
|
48
|
+
if (isEmptyComponents) {
|
|
49
|
+
dispatch({
|
|
50
|
+
type: "board/setNewComponents",
|
|
51
|
+
payload: [],
|
|
52
|
+
});
|
|
53
|
+
setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
|
|
54
|
+
}
|
|
55
|
+
if (isEmptyExtraComponents) {
|
|
56
|
+
dispatch({
|
|
57
|
+
type: "board/setNewExtraComponents",
|
|
58
|
+
payload: [],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
|
|
62
|
+
dispatch({
|
|
63
|
+
type: "board/setNewComponents",
|
|
64
|
+
payload: componentProps,
|
|
65
|
+
});
|
|
66
|
+
setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
|
|
67
|
+
}
|
|
68
|
+
if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
|
|
69
|
+
dispatch({
|
|
70
|
+
type: "board/setNewExtraComponents",
|
|
71
|
+
payload: extraComponentProps,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (defaultBackground) {
|
|
75
|
+
dispatch({
|
|
76
|
+
type: "board/setBackgroundColor",
|
|
77
|
+
payload: defaultBackground,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// if(boundingBoxProps) {
|
|
81
|
+
dispatch({
|
|
82
|
+
type: "board/setBoundingBox",
|
|
83
|
+
payload: defaultBoundingBox,
|
|
84
|
+
});
|
|
85
|
+
// }
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
dispatch({ type: "panel/setLoading", payload: false });
|
|
88
|
+
}, 1000);
|
|
89
|
+
}, [
|
|
90
|
+
componentProps,
|
|
91
|
+
extraComponentProps,
|
|
92
|
+
defaultBackground,
|
|
93
|
+
loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.state,
|
|
94
|
+
props === null || props === void 0 ? void 0 : props.viewOnly,
|
|
95
|
+
defaultBoundingBox,
|
|
96
|
+
]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
|
|
99
|
+
}, [privilegedTags]);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
onCurrentStateChange &&
|
|
102
|
+
onCurrentStateChange({
|
|
103
|
+
components: componentsEditor,
|
|
104
|
+
extraComponents: extraComponentsEditor,
|
|
105
|
+
background: backgroundColor,
|
|
106
|
+
boundingBox: boundingBoxProps,
|
|
107
|
+
});
|
|
108
|
+
}, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
|
|
109
|
+
const originalData = ({ id, type, dataParams, }) => {
|
|
110
|
+
let data;
|
|
111
|
+
if (type === "find") {
|
|
112
|
+
data = componentsEditor.find((item) => {
|
|
113
|
+
if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
|
|
114
|
+
return item[mappingKey].id == id;
|
|
115
|
+
}
|
|
116
|
+
return (item === null || item === void 0 ? void 0 : item.id) == id;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (type === "get" && dataParams) {
|
|
120
|
+
const mapped = mappingKey ? dataParams[mappingKey] : undefined;
|
|
121
|
+
data = mapped !== undefined ? mapped : dataParams;
|
|
122
|
+
}
|
|
123
|
+
return data;
|
|
124
|
+
};
|
|
125
|
+
const handleSelectComponent = (items, e) => {
|
|
126
|
+
const find = componentsEditor.find((item) => {
|
|
127
|
+
var _a;
|
|
128
|
+
if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
|
|
129
|
+
return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
|
|
130
|
+
}
|
|
131
|
+
return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
|
|
132
|
+
});
|
|
133
|
+
const rightClick = e.button === 2;
|
|
134
|
+
const click = e.button === 0;
|
|
135
|
+
onRightClick && rightClick && onRightClick(e, find);
|
|
136
|
+
onSelectComponent && !rightClick && onSelectComponent(find);
|
|
137
|
+
const seletedTable = mappingKey ? find[mappingKey] : find;
|
|
138
|
+
setSelectedTable(seletedTable);
|
|
139
|
+
};
|
|
140
|
+
const boundingBox = useMemo(() => {
|
|
141
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
142
|
+
if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
|
|
143
|
+
return { minX: 0, minY: 0, width: 500, height: 500 };
|
|
144
|
+
}
|
|
145
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
146
|
+
componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_, i) => {
|
|
147
|
+
let values = mappingKey ? _[mappingKey] : _;
|
|
148
|
+
if (!values)
|
|
149
|
+
return;
|
|
150
|
+
if (values === null || values === void 0 ? void 0 : values.shape) {
|
|
151
|
+
minX = Math.min(minX, values.x);
|
|
152
|
+
minY = Math.min(minY, values.y);
|
|
153
|
+
maxX = Math.max(maxX, values.x + values.width);
|
|
154
|
+
maxY = Math.max(maxY, values.y + values.height);
|
|
155
|
+
}
|
|
156
|
+
if (i === componentsEditor.length - 1 &&
|
|
157
|
+
(extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 0) {
|
|
158
|
+
minX = minX > 10 ? minX - 10 : minX;
|
|
159
|
+
minY = minY > 10 ? minY - 10 : minY;
|
|
160
|
+
maxX = maxX + 10;
|
|
161
|
+
maxY = maxY + 10;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
|
|
165
|
+
var _a, _b, _c, _d, _e;
|
|
166
|
+
if (values === null || values === void 0 ? void 0 : values.shape) {
|
|
167
|
+
minX = Math.min(minX, values.x);
|
|
168
|
+
minY = Math.min(minY, values.y);
|
|
169
|
+
maxX = Math.max(maxX, values.x + values.width);
|
|
170
|
+
maxY = Math.max(maxY, values.y + values.height);
|
|
171
|
+
}
|
|
172
|
+
if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("polygon")) {
|
|
173
|
+
minX = Math.min(minX, (_b = values === null || values === void 0 ? void 0 : values.points) === null || _b === void 0 ? void 0 : _b.reduce((min, point) => Math.min(min, point.x), Infinity));
|
|
174
|
+
minY = Math.min(minY, (_c = values === null || values === void 0 ? void 0 : values.points) === null || _c === void 0 ? void 0 : _c.reduce((min, point) => Math.min(min, point.y), Infinity));
|
|
175
|
+
maxX = Math.max(maxX, (_d = values === null || values === void 0 ? void 0 : values.points) === null || _d === void 0 ? void 0 : _d.reduce((max, point) => Math.max(max, point.x), -Infinity));
|
|
176
|
+
maxY = Math.max(maxY, (_e = values === null || values === void 0 ? void 0 : values.points) === null || _e === void 0 ? void 0 : _e.reduce((max, point) => Math.max(max, point.y), -Infinity));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
let backgroundHasOne = false;
|
|
180
|
+
if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 &&
|
|
181
|
+
((_b = (_a = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _a === void 0 ? void 0 : _a.shape) === null || _b === void 0 ? void 0 : _b.includes("background"))) {
|
|
182
|
+
backgroundHasOne = true;
|
|
183
|
+
// console.log({ backgroundHasOne },"shini")
|
|
184
|
+
minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
|
|
185
|
+
minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
|
|
186
|
+
maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
|
|
187
|
+
maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
|
|
188
|
+
}
|
|
189
|
+
const hasBoundingBox = boundingBoxProps;
|
|
190
|
+
// const paddingY =
|
|
191
|
+
// maxY * (props?.viewStyles?.paddingY || 0) +
|
|
192
|
+
// minY * (props?.viewStyles?.paddingY || 0);
|
|
193
|
+
// const paddingX =
|
|
194
|
+
// maxX * (props?.viewStyles?.paddingX || 0) +
|
|
195
|
+
// minX * (props?.viewStyles?.paddingX || 0);
|
|
196
|
+
if (hasBoundingBox) {
|
|
197
|
+
hasBoundingBoxRef.current = true;
|
|
198
|
+
return {
|
|
199
|
+
minX: boundingBoxProps.x,
|
|
200
|
+
minY: boundingBoxProps.y,
|
|
201
|
+
width: boundingBoxProps.width,
|
|
202
|
+
height: boundingBoxProps.height,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
// return {
|
|
206
|
+
// minX: minX - paddingX - (minX - paddingX) * 0.5,
|
|
207
|
+
// minY: minY - paddingY * 2,
|
|
208
|
+
// width: maxX + paddingX * 2,
|
|
209
|
+
// height: maxY + paddingY + (maxY + paddingY) * 0.5,
|
|
210
|
+
// };
|
|
211
|
+
// console.log(minX, minY, maxX, maxY,props?.viewStyles, "bounding box");
|
|
212
|
+
return {
|
|
213
|
+
minX: minX - (((_g = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _g === void 0 ? void 0 : _g.paddingLeft) || 0),
|
|
214
|
+
minY: minY - (((_h = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _h === void 0 ? void 0 : _h.paddingTop) || 0),
|
|
215
|
+
width: maxX + (((_j = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _j === void 0 ? void 0 : _j.paddingRight) || 0),
|
|
216
|
+
height: maxY + (((_k = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _k === void 0 ? void 0 : _k.paddingBottom) || 0),
|
|
217
|
+
};
|
|
218
|
+
}, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
|
|
219
|
+
const renderElements = (elementEditor, mappingKey, tableMatchKey) => {
|
|
220
|
+
return elementEditor.map((editorItem) => {
|
|
221
|
+
const isUsingMapping = mappingKey &&
|
|
222
|
+
typeof editorItem[mappingKey] === "object" &&
|
|
223
|
+
editorItem[mappingKey] !== null;
|
|
224
|
+
let finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
|
|
225
|
+
if (tableMatchKey) {
|
|
226
|
+
const tableMatch = tableMatchKey.find((item) => item.key == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[statusKey]));
|
|
227
|
+
finalProps = Object.assign(Object.assign(Object.assign({}, finalProps), tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.properties), { className: tableMatch === null || tableMatch === void 0 ? void 0 : tableMatch.className });
|
|
228
|
+
}
|
|
229
|
+
return finalProps;
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const [fingerCount, setFingerCount] = useState(0);
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const container = document.getElementById("workspace");
|
|
235
|
+
const handleTouchStart = (e) => {
|
|
236
|
+
const count = e.touches.length;
|
|
237
|
+
setFingerCount(count);
|
|
238
|
+
};
|
|
239
|
+
const handleTouchEnd = () => {
|
|
240
|
+
setFingerCount(0);
|
|
241
|
+
};
|
|
242
|
+
if (container) {
|
|
243
|
+
container.addEventListener("touchstart", handleTouchStart);
|
|
244
|
+
container.addEventListener("touchend", handleTouchEnd);
|
|
245
|
+
}
|
|
246
|
+
return () => {
|
|
247
|
+
if (container) {
|
|
248
|
+
container.removeEventListener("touchstart", handleTouchStart);
|
|
249
|
+
container.removeEventListener("touchend", handleTouchEnd);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}, []);
|
|
253
|
+
const handleTableEvent = (event, type) => {
|
|
254
|
+
var _a;
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
// cari elemen yg diklik
|
|
257
|
+
const elementTarget = event.target;
|
|
258
|
+
if (!elementTarget)
|
|
259
|
+
return;
|
|
260
|
+
// cari group data-id terdekat
|
|
261
|
+
const group = elementTarget.closest("g[data-id]");
|
|
262
|
+
if (!group)
|
|
263
|
+
return;
|
|
264
|
+
try {
|
|
265
|
+
const tableId = JSON.parse(group.getAttribute("data-id") || "{}");
|
|
266
|
+
const dragEvent = event;
|
|
267
|
+
const dataTransfer = JSON.parse(((_a = dragEvent.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData("application/json")) || "{}");
|
|
268
|
+
const data = {
|
|
269
|
+
targetTable: originalData({ id: tableId, type: "find" }),
|
|
270
|
+
sourceTable: originalData({ dataParams: dataTransfer, type: "get" }),
|
|
271
|
+
};
|
|
272
|
+
// drop from out layout editor
|
|
273
|
+
if (type === "drop") {
|
|
274
|
+
onDrop && onDrop(event, data);
|
|
275
|
+
}
|
|
276
|
+
// cari elemen bentuk (rect / circle / path)
|
|
277
|
+
const shape = group.querySelector("rect") ||
|
|
278
|
+
group.querySelector("circle") ||
|
|
279
|
+
group.querySelector("path");
|
|
280
|
+
if (!shape)
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
console.error("Invalid data-id JSON:", err);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const getSvgCoords = (e) => {
|
|
288
|
+
var _a;
|
|
289
|
+
const svg = svgRef.current;
|
|
290
|
+
const point = svg.createSVGPoint();
|
|
291
|
+
point.x = e.clientX;
|
|
292
|
+
point.y = e.clientY;
|
|
293
|
+
const transformed = point.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
|
|
294
|
+
return { x: transformed.x, y: transformed.y };
|
|
295
|
+
};
|
|
296
|
+
const handlePointerDown = (e) => {
|
|
297
|
+
var _a;
|
|
298
|
+
const svg = svgRef.current;
|
|
299
|
+
if (!e.isPrimary)
|
|
300
|
+
return;
|
|
301
|
+
if (!svg)
|
|
302
|
+
return;
|
|
303
|
+
isDragging.current = false;
|
|
304
|
+
let hasMoved = false;
|
|
305
|
+
const startX = e.clientX;
|
|
306
|
+
const startY = e.clientY;
|
|
307
|
+
const { x, y } = getSvgCoords(e);
|
|
308
|
+
const targetGroup = e.target.closest("g[data-id]");
|
|
309
|
+
if (!targetGroup) {
|
|
310
|
+
setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
setPanningGroup(true);
|
|
314
|
+
// clone element yang diklik
|
|
315
|
+
let ghost = targetGroup.cloneNode(true);
|
|
316
|
+
const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
|
|
317
|
+
const allowedDrag = (!(props === null || props === void 0 ? void 0 : props.dragTableBlockKey)
|
|
318
|
+
? true
|
|
319
|
+
: (_a = props === null || props === void 0 ? void 0 : props.dragTableBlockKey) === null || _a === void 0 ? void 0 : _a.some((_) => {
|
|
320
|
+
const dataRaw = originalData({ id: ghostId, type: "find" });
|
|
321
|
+
return _.value != (dataRaw === null || dataRaw === void 0 ? void 0 : dataRaw[_.key]);
|
|
322
|
+
})) && (!disabled);
|
|
323
|
+
if (ghostAttributes) {
|
|
324
|
+
Object.keys(ghostAttributes).forEach((key) => {
|
|
325
|
+
ghost.setAttribute(key, ghostAttributes[key]);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
ghost.setAttribute("opacity", "0.5");
|
|
329
|
+
ghost.setAttribute("pointer-events", "none");
|
|
330
|
+
ghost.setAttribute("stroke-width", "1");
|
|
331
|
+
svg.appendChild(ghost);
|
|
332
|
+
tableGhost.current = ghost;
|
|
333
|
+
const pt = svg.createSVGPoint();
|
|
334
|
+
pt.x = e.clientX;
|
|
335
|
+
pt.y = e.clientY;
|
|
336
|
+
const startBox = getTranslate(targetGroup);
|
|
337
|
+
const groupCTM = targetGroup.getCTM();
|
|
338
|
+
if (!groupCTM) {
|
|
339
|
+
setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const offset = {
|
|
343
|
+
x: x - startBox.x,
|
|
344
|
+
y: y - startBox.y,
|
|
345
|
+
};
|
|
346
|
+
const pointerMoveGhost = (ev) => {
|
|
347
|
+
var _a;
|
|
348
|
+
isDragging.current = true;
|
|
349
|
+
const p = svg.createSVGPoint();
|
|
350
|
+
p.x = ev.clientX;
|
|
351
|
+
p.y = ev.clientY;
|
|
352
|
+
const dx = ev.clientX - startX;
|
|
353
|
+
const dy = ev.clientY - startY;
|
|
354
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
355
|
+
onPanning(ev);
|
|
356
|
+
if (!hasMoved && distance > 0) {
|
|
357
|
+
// transformRef?.current?.instance
|
|
358
|
+
// only move ghost if the mouse has moved more than 5 pixels
|
|
359
|
+
hasMoved = true;
|
|
360
|
+
isDragging.current = true;
|
|
361
|
+
}
|
|
362
|
+
// ✅ DETEKSI ELEMEN YANG DILEWATI POINTER
|
|
363
|
+
ghost.style.display = "none";
|
|
364
|
+
const elemUnderPointer = document.elementFromPoint(ev.clientX, ev.clientY);
|
|
365
|
+
ghost.style.display = "";
|
|
366
|
+
const hoveredGroup = elemUnderPointer === null || elemUnderPointer === void 0 ? void 0 : elemUnderPointer.closest("g[data-id]");
|
|
367
|
+
const dataHoveredGhostId = JSON.parse((hoveredGroup === null || hoveredGroup === void 0 ? void 0 : hoveredGroup.getAttribute("data-id")) || "{}");
|
|
368
|
+
const dataGhostId = JSON.parse(ghost.getAttribute("data-id") || "{}");
|
|
369
|
+
if (dataHoveredGhostId !== dataGhostId) {
|
|
370
|
+
hoverUnderghostId.current = dataHoveredGhostId;
|
|
371
|
+
}
|
|
372
|
+
const posSVG = p.matrixTransform((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse());
|
|
373
|
+
// posisi awal ghost di bawah kursor tanpa matrix dulu
|
|
374
|
+
const newX = posSVG.x - offset.x;
|
|
375
|
+
const newY = posSVG.y - offset.y;
|
|
376
|
+
if (allowedDrag) {
|
|
377
|
+
ghost.setAttribute("transform", `translate(${newX}, ${newY})`);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
// tampilkan ghost di posisi awal
|
|
381
|
+
pointerMoveGhost(e.nativeEvent);
|
|
382
|
+
const pointerHandleUp = (e) => {
|
|
383
|
+
var _a;
|
|
384
|
+
if (!hasMoved) {
|
|
385
|
+
const dataId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
|
|
386
|
+
isDragging.current = false;
|
|
387
|
+
const dataGroupEmty = !dataId;
|
|
388
|
+
// TOOLTIP ACTION
|
|
389
|
+
const svgSize = svg.getBoundingClientRect();
|
|
390
|
+
const widthScreeen = svgSize.width;
|
|
391
|
+
const heightScreen = svgSize.height;
|
|
392
|
+
const clientX = e.clientX;
|
|
393
|
+
const clientY = e.clientY;
|
|
394
|
+
const relX = clientX - svgSize.left;
|
|
395
|
+
const relY = clientY - svgSize.top;
|
|
396
|
+
const centerX = widthScreeen / 2;
|
|
397
|
+
const centerY = heightScreen / 2;
|
|
398
|
+
let newX = 0;
|
|
399
|
+
let newY = 0;
|
|
400
|
+
if (relX > centerX) {
|
|
401
|
+
newX = relX - widthTooltip;
|
|
402
|
+
}
|
|
403
|
+
else if (relX < centerX) {
|
|
404
|
+
newX = relX;
|
|
405
|
+
}
|
|
406
|
+
else if (relX === centerX) {
|
|
407
|
+
newX = relX;
|
|
408
|
+
}
|
|
409
|
+
if (relY > centerY) {
|
|
410
|
+
newY = relY;
|
|
411
|
+
}
|
|
412
|
+
else if (relY < centerY) {
|
|
413
|
+
newY = relY;
|
|
414
|
+
}
|
|
415
|
+
else if (relY === centerY) {
|
|
416
|
+
newY = relY;
|
|
417
|
+
}
|
|
418
|
+
const rightClick = e.button === 2 && !dataGroupEmty && allowTooltip;
|
|
419
|
+
setTooltip({
|
|
420
|
+
x: newX / scale,
|
|
421
|
+
y: newY / scale,
|
|
422
|
+
visible: rightClick,
|
|
423
|
+
});
|
|
424
|
+
const findDayaById = originalData({ id: dataId, type: "find" });
|
|
425
|
+
handleSelectComponent(findDayaById, e);
|
|
426
|
+
}
|
|
427
|
+
if (isDragging.current && hasMoved && allowedDrag) {
|
|
428
|
+
// drag between group
|
|
429
|
+
const dataHoveredGhost = hoverUnderghostId.current;
|
|
430
|
+
hoverUnderghostId.current = null;
|
|
431
|
+
const sourceTable = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
|
|
432
|
+
const data = {
|
|
433
|
+
targetTable: originalData({ id: dataHoveredGhost, type: "find" }),
|
|
434
|
+
sourceTable: originalData({ id: sourceTable, type: "find" }),
|
|
435
|
+
};
|
|
436
|
+
const allowToSwitch = onSwitch && (data === null || data === void 0 ? void 0 : data.sourceTable) && (data === null || data === void 0 ? void 0 : data.targetTable);
|
|
437
|
+
allowToSwitch && onSwitch(e, data);
|
|
438
|
+
ghost.remove();
|
|
439
|
+
isDragging.current = false;
|
|
440
|
+
(_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
441
|
+
tableGhost.current = null;
|
|
442
|
+
}
|
|
443
|
+
setPanningGroup(false);
|
|
444
|
+
tableGhost.current = null;
|
|
445
|
+
isDragging.current = false;
|
|
446
|
+
window.removeEventListener("pointermove", pointerMoveGhost);
|
|
447
|
+
window.removeEventListener("pointerup", pointerHandleUp);
|
|
448
|
+
};
|
|
449
|
+
window.addEventListener("pointermove", pointerMoveGhost);
|
|
450
|
+
window.addEventListener("pointerup", pointerHandleUp);
|
|
451
|
+
};
|
|
452
|
+
const handleMouseUp = () => {
|
|
453
|
+
var _a;
|
|
454
|
+
// isDragging.current = false;
|
|
455
|
+
(_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
456
|
+
tableGhost.current = null;
|
|
457
|
+
};
|
|
458
|
+
useEffect(() => {
|
|
459
|
+
return () => {
|
|
460
|
+
var _a;
|
|
461
|
+
(_a = tableGhost.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
462
|
+
};
|
|
463
|
+
}, []);
|
|
464
|
+
const handlePan = (dx, dy) => {
|
|
465
|
+
var _a, _b;
|
|
466
|
+
const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
|
|
467
|
+
const setTransform = (_b = transformRef === null || transformRef === void 0 ? void 0 : transformRef.current) === null || _b === void 0 ? void 0 : _b.setTransform;
|
|
468
|
+
if (!instance)
|
|
469
|
+
return;
|
|
470
|
+
const bounds = instance.bounds;
|
|
471
|
+
const { positionX, positionY, scale } = instance.transformState;
|
|
472
|
+
let x = positionX + dx;
|
|
473
|
+
let y = positionY + dy;
|
|
474
|
+
if (x >= bounds.maxPositionX)
|
|
475
|
+
x = bounds.maxPositionX;
|
|
476
|
+
if (y >= bounds.maxPositionY)
|
|
477
|
+
y = bounds.maxPositionY;
|
|
478
|
+
if (y <= bounds.minPositionY)
|
|
479
|
+
y = bounds.minPositionY;
|
|
480
|
+
if (x <= bounds.minPositionX)
|
|
481
|
+
x = bounds.minPositionX;
|
|
482
|
+
setTransform(x, y, scale, 100, "linear");
|
|
483
|
+
};
|
|
484
|
+
// const instance = transformRef.current?.instance;
|
|
485
|
+
// console.log({ instance })
|
|
486
|
+
const getCoords = (e) => {
|
|
487
|
+
var _a;
|
|
488
|
+
const svg = svgRef.current;
|
|
489
|
+
const instance = (_a = transformRef.current) === null || _a === void 0 ? void 0 : _a.instance;
|
|
490
|
+
if (!svg || !instance)
|
|
491
|
+
return null;
|
|
492
|
+
const { positionX, positionY, scale } = instance.transformState;
|
|
493
|
+
let clientX, clientY;
|
|
494
|
+
if ("touches" in e && e.touches.length > 0) {
|
|
495
|
+
clientX = e.touches[0].clientX;
|
|
496
|
+
clientY = e.touches[0].clientY;
|
|
497
|
+
}
|
|
498
|
+
else if ("clientX" in e) {
|
|
499
|
+
clientX = e.clientX;
|
|
500
|
+
clientY = e.clientY;
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
const svgRect = svg.getBoundingClientRect();
|
|
506
|
+
// const viewBox = svg.viewBox.baseVal;
|
|
507
|
+
const xLeft = (clientX - svgRect.left + positionX) / scale;
|
|
508
|
+
const yTop = (clientY - svgRect.top + positionY) / scale;
|
|
509
|
+
const xRight = clientX - svgRect.left + positionX - svgRect.width / scale;
|
|
510
|
+
const yBottom = clientY - svgRect.top + positionY - svgRect.height / scale;
|
|
511
|
+
const minX = svgRect.left + positionX;
|
|
512
|
+
const minY = svgRect.top + positionY;
|
|
513
|
+
const maxX = svgRect.right;
|
|
514
|
+
const maxY = svgRect.bottom;
|
|
515
|
+
return [
|
|
516
|
+
xLeft,
|
|
517
|
+
yTop,
|
|
518
|
+
Math.abs(xRight),
|
|
519
|
+
Math.abs(yBottom),
|
|
520
|
+
minX,
|
|
521
|
+
minY,
|
|
522
|
+
maxX,
|
|
523
|
+
maxY,
|
|
524
|
+
];
|
|
525
|
+
};
|
|
526
|
+
const onPanning = (e) => {
|
|
527
|
+
const [xLeft, yTop, xRight, yBottom, minX, minY, maxX, maxY] = getCoords(e);
|
|
528
|
+
const edgeThreshold = 100;
|
|
529
|
+
const speedPanning = 50;
|
|
530
|
+
if (scale !== 1) {
|
|
531
|
+
if (xLeft < edgeThreshold)
|
|
532
|
+
handlePan(speedPanning, 0);
|
|
533
|
+
if (xRight < edgeThreshold)
|
|
534
|
+
handlePan(-speedPanning, 0);
|
|
535
|
+
if (yTop < edgeThreshold)
|
|
536
|
+
handlePan(0, speedPanning);
|
|
537
|
+
if (yBottom < edgeThreshold)
|
|
538
|
+
handlePan(0, -speedPanning);
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
const hasBoundingBox = hasBoundingBoxRef.current;
|
|
542
|
+
return (_jsxs("div", Object.assign({ className: "relative w-full h-full flex-1", ref: containerRef, style: {
|
|
543
|
+
overflow: "auto",
|
|
544
|
+
WebkitOverflowScrolling: "touch",
|
|
545
|
+
} }, props.containerProps, { children: [loading && (_jsx("div", { className: "absolute z-10 top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-opacity-50 bg-white w-full h-full flex items-center justify-center", children: (loadingRender === null || loadingRender === void 0 ? void 0 : loadingRender.element) || _jsx(Spin, {}) })), _jsxs("svg", Object.assign({ id: "workspace", onContextMenu: (e) => e.preventDefault(), onDrop: (e) => handleTableEvent(e, "drop"), onPointerDown: handlePointerDown, onPointerUp: handleMouseUp, ref: svgRef, width: "100%", height: "100%",
|
|
546
|
+
// scale={5}
|
|
547
|
+
overflow: "hidden", viewBox: `${boundingBox.minX} ${boundingBox.minY} ${boundingBox.width} ${boundingBox.height}`, className: "h-full", xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", style: {
|
|
548
|
+
background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
|
|
549
|
+
display: "block",
|
|
550
|
+
pointerEvents: disabled ? "none" : "all",
|
|
551
|
+
touchAction: "none",
|
|
552
|
+
userSelect: "none",
|
|
553
|
+
} }, props.svgProps, { children: [hasBoundingBox && (_jsx("defs", { children: _jsx("clipPath", { id: "contentCrop", children: _jsx("rect", { x: boundingBox.minX, y: boundingBox.minY, width: boundingBox.width, height: boundingBox.height }) }) })), _jsx("g", { id: "main-layer", "clip-path": "url(#contentCrop)", children: _jsx(Layers, { components: [
|
|
554
|
+
...extraComponentsEditor,
|
|
555
|
+
...renderElements(componentsEditor, mappingKey, tableMatchKey),
|
|
556
|
+
], selectedTable: selectedTable, iconTags: iconTags, eventMatchTable: eventMatchTable, privilegedTags: privilegedTags }) })] })), tooltip.visible && (_jsx("div", { className: `seat-editor tooltip-container ${tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.className}`, style: Object.assign({ top: tooltip.y, left: tooltip.x, transform: `scale(${1 / scale})`, transformOrigin: "top left", minWidth: widthTooltip + "px" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.style), children: tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.children }))] })));
|
|
557
|
+
};
|
|
558
|
+
export default LayerView;
|
|
@@ -85,5 +85,5 @@ export interface LayerViewProps<TMeta = undefined> {
|
|
|
85
85
|
defaultBoundingBox?: PropertiesProps;
|
|
86
86
|
viewOnly?: boolean;
|
|
87
87
|
}
|
|
88
|
-
declare const LayerView: <TMeta>(props: LayerViewProps<TMeta>) =>
|
|
88
|
+
declare const LayerView: <TMeta>(props: LayerViewProps<TMeta>) => import("react/jsx-runtime").JSX.Element;
|
|
89
89
|
export default LayerView;
|