seat-editor 3.3.36 → 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.
@@ -274,8 +274,10 @@ export declare const test4: ({
274
274
  seatCount: number;
275
275
  uuid_table: string;
276
276
  gapTags: number;
277
+ status?: undefined;
277
278
  properties?: undefined;
278
279
  } | {
280
+ status: string;
279
281
  properties: {
280
282
  x: number;
281
283
  y: number;
@@ -288,6 +290,7 @@ export declare const test4: ({
288
290
  width: number;
289
291
  height: number;
290
292
  gapTags: number;
293
+ status: string;
291
294
  labels: {
292
295
  x: number;
293
296
  y: number;
@@ -3436,6 +3436,7 @@ export const test4 = [
3436
3436
  gapTags: 20,
3437
3437
  },
3438
3438
  {
3439
+ status: "hold",
3439
3440
  properties: {
3440
3441
  x: 400,
3441
3442
  y: 20,
@@ -3448,6 +3449,7 @@ export const test4 = [
3448
3449
  width: 100,
3449
3450
  height: 100,
3450
3451
  gapTags: 20, //gap antara tags secara vertical,
3452
+ status: "hold",
3451
3453
  labels: [
3452
3454
  {
3453
3455
  x: 0,
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import LayerView from "../../features/view-only-3";
4
4
  import { useState, useRef } from "react";
5
- // import { data4, test4, test1 } from "../constant";
5
+ import { data4 } from "../constant";
6
6
  import { ChairIcon } from "./chair";
7
7
  import { UserIcon } from "./user";
8
8
  import { Modal } from "antd";
@@ -165,7 +165,7 @@ const TouchScrollDetect = () => {
165
165
  return (_jsx(Modal, { open: open, onCancel: () => setOpen(false), width: 700, title: "Preview Board", centered: true, footer: null, children: _jsx("div", { className: "flex flex-col p-4 h-[500px] overflow-auto", children: _jsx(JsonView, { value: table }) }) }));
166
166
  };
167
167
  const testData = [];
168
- return (_jsxs("div", { className: "w-full h-screen border-2 border-black overflow-auto", id: "scroll-container", children: [renderModal(), _jsxs("div", { className: "flex", children: [_jsx("div", { className: "h-screen bg-gray-500 w-1/3", children: _jsx("div", { className: "p-4" }) }), _jsxs("div", { className: "h-screen w-2/3 relative", children: [_jsxs("div", { className: "absolute top-1 right-1 flex gap-4 z-[10]", children: [_jsx("button", { className: "p-4 bg-gray-400", onClick: () => handleZoomIn(), children: "+" }), _jsx("button", { className: "p-4 bg-gray-400", onClick: () => handleZoomOut(), children: "-" })] }), _jsx(LayerView, { refs: refLayer, statusKey: "is_hold", privilegedTags: [
168
+ return (_jsxs("div", { className: "w-full h-screen border-2 border-black overflow-auto", id: "scroll-container", children: [renderModal(), _jsxs("div", { className: "flex", children: [_jsx("div", { className: "h-screen bg-gray-500 w-1/3", children: _jsx("div", { className: "p-4", children: data4.map((item, index) => (_jsx(Card, Object.assign({}, item), index))) }) }), _jsxs("div", { className: "h-screen w-2/3 relative", children: [_jsxs("div", { className: "absolute top-1 right-1 flex gap-4 z-[10]", children: [_jsx("button", { className: "p-4 bg-gray-400", onClick: () => handleZoomIn(), children: "+" }), _jsx("button", { className: "p-4 bg-gray-400", onClick: () => handleZoomOut(), children: "-" })] }), _jsx(LayerView, { refs: refLayer, statusKey: "is_hold", privilegedTags: [
169
169
  {
170
170
  key: "table",
171
171
  items: ["text", "icon"],
@@ -176,7 +176,7 @@ const TouchScrollDetect = () => {
176
176
  },
177
177
  ], defaultBackground: "#000000", mappingKey: "properties", componentProps: testData === null || testData === void 0 ? void 0 : testData.map((item) => {
178
178
  return {
179
- properties: item === null || item === void 0 ? void 0 : item.properties,
179
+ properties: item,
180
180
  test: item === null || item === void 0 ? void 0 : item.test,
181
181
  };
182
182
  }), onDrop: (e, data) => handleDrop(e, data), onSwitch: (e, data) => handleSwitch(e, data), extraComponentProps: [], onSelectComponent: (component) => {
@@ -1,19 +1,89 @@
1
- export interface LayerViewProps {
2
- componentProps?: any[];
3
- extraComponentProps?: any[];
4
- onCurrentStateChange?: (state: any) => void;
5
- onSelectComponent?: (component: any) => void;
1
+ import React, { CSSProperties, SVGAttributes } from "react";
2
+ import { ReactZoomPanPinchRef, ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from "react-zoom-pan-pinch";
3
+ import { PropertiesProps } from "../../dto/table";
4
+ import { EventHandleType } from "../../dto/event-handler";
5
+ export type TableGhost = {
6
+ table: PropertiesProps;
7
+ event: EventHandleType;
8
+ };
9
+ export type TableMatchKey = {
10
+ key: string | number;
11
+ properties?: PropertiesProps;
12
+ className?: string;
13
+ };
14
+ export type TableMatchEvent = {
15
+ event: EventHandleType;
16
+ properties: PropertiesProps;
17
+ };
18
+ export type ComponentProps<T = undefined> = T extends undefined ? PropertiesProps : Omit<PropertiesProps, keyof T> & T;
19
+ export type OnCurrentStateChange<TMeta = undefined> = ({ components, extraComponents, background, boundingBox, }: {
20
+ components: ComponentProps<TMeta>[];
21
+ extraComponents: ComponentProps[];
22
+ background: string;
23
+ boundingBox: PropertiesProps | null;
24
+ }) => void;
25
+ export type TransformProps = React.ForwardRefExoticComponent<Omit<ReactZoomPanPinchProps, "ref"> & React.RefAttributes<ReactZoomPanPinchContentRef>>;
26
+ export type RefLayerView = {
27
+ svgRef: SVGSVGElement;
28
+ transformRef: ReactZoomPanPinchRef;
29
+ containerRef: HTMLDivElement;
30
+ tableGhost: SVGGElement;
31
+ hoverUnderghost: ComponentProps;
32
+ };
33
+ export type TypeActionProps<TMeta = undefined> = {
34
+ targetTable: ComponentProps<TMeta>;
35
+ sourceTable: ComponentProps<TMeta>;
36
+ };
37
+ export interface LayerViewProps<TMeta = undefined> {
38
+ componentProps?: ComponentProps<TMeta>[];
39
+ extraComponentProps?: ComponentProps[];
40
+ onCurrentStateChange?: OnCurrentStateChange;
41
+ onSelectComponent?: (component: ComponentProps<TMeta>) => void;
6
42
  mappingKey?: string;
7
- selectedTableColor?: string;
8
- colorMatchKey?: {
9
- color: string;
10
- key: string;
11
- }[];
43
+ tableMatchKey?: TableMatchKey[];
44
+ eventMatchTable?: TableMatchEvent[];
12
45
  statusKey: string;
13
46
  defaultBackground?: string;
14
- transformProps?: any;
15
- containerProps?: any;
16
- svgProps?: any;
47
+ transformProps?: ReactZoomPanPinchProps;
48
+ containerProps?: React.HTMLAttributes<HTMLDivElement>;
49
+ svgProps?: SVGAttributes<SVGSVGElement>;
50
+ ghostAttributes?: SVGAttributes<SVGGElement>;
51
+ iconTags?: {
52
+ icon: React.JSX.Element;
53
+ key: string;
54
+ }[];
55
+ privilegedTags?: {
56
+ key: string;
57
+ items: string[];
58
+ }[];
59
+ tooltipProps?: {
60
+ className?: string;
61
+ style?: CSSProperties;
62
+ minWidth?: number;
63
+ children: React.ReactNode;
64
+ };
65
+ dragTableBlockKey?: {
66
+ key: string;
67
+ value: string | number | null;
68
+ }[];
69
+ onRightClick?: (e: MouseEvent, component: ComponentProps<TMeta>) => void;
70
+ allowTooltip?: boolean;
71
+ onDrop?: (e: React.MouseEvent<SVGSVGElement>, component: TypeActionProps<TMeta>) => void;
72
+ onSwitch?: (e: MouseEvent, component: TypeActionProps<TMeta>) => void;
73
+ refs?: React.ForwardedRef<RefLayerView>;
74
+ viewStyles?: {
75
+ paddingTop?: number;
76
+ paddingLeft?: number;
77
+ paddingRight?: number;
78
+ paddingBottom?: number;
79
+ };
80
+ disabled?: boolean;
81
+ loadingRender?: {
82
+ state: boolean;
83
+ element: React.JSX.Element;
84
+ };
85
+ defaultBoundingBox?: PropertiesProps;
86
+ viewOnly?: boolean;
17
87
  }
18
- declare const LayerView: (props: LayerViewProps) => import("react/jsx-runtime").JSX.Element;
88
+ declare const LayerView: <TMeta>(props: LayerViewProps<TMeta>) => import("react/jsx-runtime").JSX.Element;
19
89
  export default LayerView;
@@ -1,24 +1,69 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useRef, useState, useImperativeHandle, } from "react";
4
4
  import { useAppDispatch, useAppSelector } from "../../hooks/use-redux";
5
- import Layers from "../../components/layer";
5
+ import Layers from "../../components/layer-v4";
6
+ import { getTranslate } from "../board-v3/utils";
7
+ import { Spin } from "antd";
6
8
  const LayerView = (props) => {
7
- const { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, selectedTableColor, colorMatchKey, statusKey, defaultBackground, } = 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);
8
13
  const transformRef = useRef(null);
9
14
  const containerRef = useRef(null);
10
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);
11
24
  const [scale, setScale] = useState(1);
12
25
  const [selectedTable, setSelectedTable] = useState(null);
13
- const { components: componentsEditor, extraComponents: extraComponentsEditor, } = useAppSelector((state) => state.board);
26
+ const { components: componentsEditor, extraComponents: extraComponentsEditor, boundingBox: boundingBoxProps, } = useAppSelector((state) => state.board);
14
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
+ }));
15
39
  const dispatch = useAppDispatch();
16
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
+ }
17
61
  if ((componentProps === null || componentProps === void 0 ? void 0 : componentProps.length) > 0) {
18
62
  dispatch({
19
63
  type: "board/setNewComponents",
20
64
  payload: componentProps,
21
65
  });
66
+ setTooltip(Object.assign(Object.assign({}, tooltip), { visible: false }));
22
67
  }
23
68
  if ((extraComponentProps === null || extraComponentProps === void 0 ? void 0 : extraComponentProps.length) > 0) {
24
69
  dispatch({
@@ -32,120 +77,154 @@ const LayerView = (props) => {
32
77
  payload: defaultBackground,
33
78
  });
34
79
  }
35
- }, [componentProps, extraComponentProps, defaultBackground]);
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]);
36
100
  useEffect(() => {
37
101
  onCurrentStateChange &&
38
102
  onCurrentStateChange({
39
103
  components: componentsEditor,
40
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;
41
117
  });
42
- }, [componentsEditor, extraComponentsEditor]);
43
- const handleSelectComponent = (items) => {
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) => {
44
126
  const find = componentsEditor.find((item) => {
127
+ var _a;
45
128
  if (mappingKey && (item === null || item === void 0 ? void 0 : item[mappingKey])) {
46
- return item[mappingKey].id === (items === null || items === void 0 ? void 0 : items.id);
129
+ return item[mappingKey].id == ((_a = items[mappingKey]) === null || _a === void 0 ? void 0 : _a.id);
47
130
  }
48
- return (item === null || item === void 0 ? void 0 : item.id) === (items === null || items === void 0 ? void 0 : items.id);
131
+ return (item === null || item === void 0 ? void 0 : item.id) == (items === null || items === void 0 ? void 0 : items.id);
49
132
  });
50
- onSelectComponent && onSelectComponent(find);
51
- setSelectedTable(find);
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);
52
139
  };
53
140
  const boundingBox = useMemo(() => {
54
- var _a, _b, _c, _d, _e, _f, _g;
141
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
55
142
  if (!componentsEditor && (componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.length) === 0) {
56
143
  return { minX: 0, minY: 0, width: 500, height: 500 };
57
144
  }
58
145
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
59
- componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_) => {
60
- var _a, _b, _c, _d;
146
+ componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor.forEach((_, i) => {
61
147
  let values = mappingKey ? _[mappingKey] : _;
62
148
  if (!values)
63
149
  return;
64
- if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("square")) {
65
- minX = Math.min(minX, values.x);
66
- minY = Math.min(minY, values.y);
67
- maxX = Math.max(maxX, values.x + values.width);
68
- maxY = Math.max(maxY, values.y + values.height);
69
- }
70
- if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("circle")) {
150
+ if (values === null || values === void 0 ? void 0 : values.shape) {
71
151
  minX = Math.min(minX, values.x);
72
152
  minY = Math.min(minY, values.y);
73
153
  maxX = Math.max(maxX, values.x + values.width);
74
154
  maxY = Math.max(maxY, values.y + values.height);
75
155
  }
76
- if ((_c = values === null || values === void 0 ? void 0 : values.shape) === null || _c === void 0 ? void 0 : _c.includes("table-seat-circle")) {
77
- minX = Math.min(minX, values.x);
78
- minY = Math.min(minY, values.y);
79
- maxX = Math.max(maxX, values.x + values.width);
80
- maxY = Math.max(maxY, values.y + values.height);
81
- }
82
- if ((_d = values === null || values === void 0 ? void 0 : values.shape) === null || _d === void 0 ? void 0 : _d.includes("image-table")) {
83
- minX = Math.min(minX, values.x);
84
- minY = Math.min(minY, values.y);
85
- maxX = Math.max(maxX, values.x + values.width);
86
- maxY = Math.max(maxY, values.y + values.height);
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;
87
162
  }
88
163
  });
89
164
  extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.forEach((values) => {
90
- var _a, _b;
91
- if ((_a = values === null || values === void 0 ? void 0 : values.shape) === null || _a === void 0 ? void 0 : _a.includes("background")) {
165
+ var _a, _b, _c, _d, _e;
166
+ if (values === null || values === void 0 ? void 0 : values.shape) {
92
167
  minX = Math.min(minX, values.x);
93
168
  minY = Math.min(minY, values.y);
94
169
  maxX = Math.max(maxX, values.x + values.width);
95
170
  maxY = Math.max(maxY, values.y + values.height);
96
171
  }
97
- if ((_b = values === null || values === void 0 ? void 0 : values.shape) === null || _b === void 0 ? void 0 : _b.includes("text")) {
98
- minX = Math.min(minX, values.x);
99
- minY = Math.min(minY, values.y);
100
- maxX = Math.max(maxX, values.x + values.width);
101
- maxY = Math.max(maxY, values.y + values.height);
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));
102
177
  }
103
178
  });
104
179
  let backgroundHasOne = false;
105
180
  if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) === 1 &&
106
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"))) {
107
182
  backgroundHasOne = true;
183
+ // console.log({ backgroundHasOne },"shini")
108
184
  minX = (_c = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _c === void 0 ? void 0 : _c.x;
109
185
  minY = (_d = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _d === void 0 ? void 0 : _d.y;
110
186
  maxX = (_e = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _e === void 0 ? void 0 : _e.width;
111
187
  maxY = (_f = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor[0]) === null || _f === void 0 ? void 0 : _f.height;
112
188
  }
113
- if ((extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.length) < 1 &&
114
- ["background", "text"].includes((_g = componentsEditor === null || componentsEditor === void 0 ? void 0 : componentsEditor[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
115
- minX = minX - minX * 0.5;
116
- minY = minY - minY * 0.5;
117
- }
118
- const hasBoundingBox = extraComponentsEditor === null || extraComponentsEditor === void 0 ? void 0 : extraComponentsEditor.some((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
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);
119
196
  if (hasBoundingBox) {
120
- const findBoundingBox = extraComponentsEditor.find((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.shape) === null || _a === void 0 ? void 0 : _a.includes("bounding-box"); });
197
+ hasBoundingBoxRef.current = true;
121
198
  return {
122
- minX: findBoundingBox.x,
123
- minY: findBoundingBox.y,
124
- width: findBoundingBox.width,
125
- height: findBoundingBox.height,
199
+ minX: boundingBoxProps.x,
200
+ minY: boundingBoxProps.y,
201
+ width: boundingBoxProps.width,
202
+ height: boundingBoxProps.height,
126
203
  };
127
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");
128
212
  return {
129
- minX: backgroundHasOne ? minX : minX - minX * 0.5,
130
- minY: backgroundHasOne ? minY : minY - minY * 0.5,
131
- width: maxX,
132
- height: maxY,
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),
133
217
  };
134
- }, [componentsEditor, extraComponentsEditor]);
135
- const renderElements = (elementEditor, mappingKey, colorMatchKey) => {
136
- return elementEditor.map((editorItem, i) => {
137
- var _a, _b, _c, _d;
218
+ }, [componentsEditor, extraComponentsEditor, boundingBoxProps]);
219
+ const renderElements = (elementEditor, mappingKey, tableMatchKey) => {
220
+ return elementEditor.map((editorItem) => {
138
221
  const isUsingMapping = mappingKey &&
139
222
  typeof editorItem[mappingKey] === "object" &&
140
223
  editorItem[mappingKey] !== null;
141
- const finalProps = isUsingMapping ? editorItem[mappingKey] : editorItem;
142
- if (colorMatchKey) {
143
- if (isUsingMapping) {
144
- return Object.assign(Object.assign({}, finalProps), { fill: (_b = (_a = colorMatchKey.find((item) => item.key == (editorItem === null || editorItem === void 0 ? void 0 : editorItem[statusKey]))) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : finalProps.fill });
145
- }
146
- else {
147
- 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 });
148
- }
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 });
149
228
  }
150
229
  return finalProps;
151
230
  });
@@ -171,17 +250,309 @@ const LayerView = (props) => {
171
250
  }
172
251
  };
173
252
  }, []);
174
- return (_jsx("div", Object.assign({ className: "relative w-full h-full flex-1", ref: containerRef }, props.containerProps, { children: _jsx("svg", Object.assign({}, props.svgProps, {
175
- // id="workspace"
176
- ref: svgRef, width: "100%", height: "100%", viewBox: `${boundingBox.minX} ${boundingBox.minY} ${boundingBox.width} ${boundingBox.height}`, className: "h-full", xmlns: "http://www.w3.org/2000/svg", preserveAspectRatio: "xMidYMid meet", style: {
177
- background: backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : defaultBackground,
178
- display: "block",
179
- pointerEvents: "auto",
180
- touchAction: "auto",
181
- // touchAction: "pan-y",
182
- }, children: _jsx(Layers, { mode: "view", components: [
183
- ...extraComponentsEditor,
184
- ...renderElements(componentsEditor, mappingKey, colorMatchKey),
185
- ], onClick: handleSelectComponent, selectedTable: selectedTable, selectedTableColor: selectedTableColor }) })) })));
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 }))] })));
186
557
  };
187
558
  export default LayerView;
@@ -7,7 +7,7 @@ import Layers from "../../components/layer-v4";
7
7
  import { getTranslate } from "../board-v3/utils";
8
8
  import { Spin } from "antd";
9
9
  const LayerView = (props) => {
10
- 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 { componentProps, extraComponentProps, onSelectComponent, onCurrentStateChange, mappingKey, statusKey, defaultBackground, defaultBoundingBox, iconTags, tooltipProps, onRightClick, allowTooltip = true, tableMatchKey, eventMatchTable, ghostAttributes, onDrop, onSwitch, refs, privilegedTags, disabled = true, loadingRender, } = props;
11
11
  const widthTooltip = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.minWidth) || 168;
12
12
  const tableGhost = useRef(null);
13
13
  const hoverUnderghostId = useRef(null);
@@ -315,12 +315,12 @@ const LayerView = (props) => {
315
315
  // clone element yang diklik
316
316
  let ghost = targetGroup.cloneNode(true);
317
317
  const ghostId = JSON.parse(targetGroup.getAttribute("data-id") || "{}");
318
- const allowedDrag = !(props === null || props === void 0 ? void 0 : props.dragTableBlockKey)
318
+ const allowedDrag = (!(props === null || props === void 0 ? void 0 : props.dragTableBlockKey)
319
319
  ? true
320
320
  : (_a = props === null || props === void 0 ? void 0 : props.dragTableBlockKey) === null || _a === void 0 ? void 0 : _a.some((_) => {
321
321
  const dataRaw = originalData({ id: ghostId, type: "find" });
322
- return _.value !== (dataRaw === null || dataRaw === void 0 ? void 0 : dataRaw[_.key]);
323
- });
322
+ return _.value != (dataRaw === null || dataRaw === void 0 ? void 0 : dataRaw[_.key]);
323
+ })) && (!disabled);
324
324
  if (ghostAttributes) {
325
325
  Object.keys(ghostAttributes).forEach((key) => {
326
326
  ghost.setAttribute(key, ghostAttributes[key]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.3.36",
3
+ "version": "3.3.37",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",