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