seat-editor 3.2.2 → 3.2.3

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.
@@ -1,38 +1,27 @@
1
1
  "use client";
2
2
  import { useEffect, useState } from "react";
3
3
  import SeatEditor from "../../features/package";
4
- import { extraComponent } from "../constant";
5
4
  import { data4 } from "../constant";
6
5
  import { dummyImage } from "../only-view/page";
7
6
  export default function NewBoard() {
8
7
  const [initialValue, setInitialValue] = useState([]);
9
- const [extraComponents, setExtraComponents] = useState(dummyImage);
8
+ const [extraComponents, setExtraComponents] = useState([]);
10
9
  const [backgroundColor, setBackgroundColor] = useState("#000000");
11
10
  const [viewOnly, setViewOnly] = useState(true);
12
11
  useEffect(() => {
13
12
  setInitialValue(data4);
14
- setExtraComponents(extraComponent);
13
+ setExtraComponents(dummyImage);
15
14
  }, []);
16
15
  return (<>
17
16
  <div className="w-full h-screen flex flex-col relative justify-center">
18
17
  <div className="w-full h-[1000px] bg-white border-r border-gray-200">
19
- {/* <LayerView
20
- componentProps={initialValue}
21
- mappingKey="properties"
22
- extraComponentProps={[]}
23
- defaultBackground="#ffffff"
24
- // dragOnly={true}
25
- statusKey="status"
26
-
27
- /> */}
18
+
28
19
  </div>
29
- {/* <button className="bg-blue-500 text-white px-4 py-2 rounded"
30
- onClick={() => setViewOnly(!viewOnly)}
31
- >
32
- {viewOnly ? "Edit Mode" : "View Mode"}
33
- </button> */}
20
+ <button className="bg-blue-500 text-white px-4 py-2 rounded" onClick={() => setViewOnly(!viewOnly)}>
21
+ {viewOnly ? "Edit Mode ddd" : "View Mode"}
22
+ </button>
34
23
  <div className="flex-1 h-full">
35
- <SeatEditor componentProps={initialValue} viewOnly={false} dragOnly={viewOnly} deleteAutorized={{
24
+ <SeatEditor componentProps={initialValue} viewOnly={viewOnly} dragOnly={true} deleteAutorized={{
36
25
  component: true,
37
26
  extraComponent: true,
38
27
  }}
@@ -228,7 +228,9 @@ const TouchScrollDetect = () => {
228
228
  icon: <UserIcon />,
229
229
  key: "user",
230
230
  },
231
- ]}/>
231
+ ]} viewStyles={{
232
+ paddingTop: 200,
233
+ }}/>
232
234
  </div>
233
235
  </div>
234
236
  </div>);
@@ -111,7 +111,7 @@ const Layers = ({ components, selectedTable, iconTags, eventMatchTable, onHighli
111
111
  }
112
112
  return null;
113
113
  });
114
- return <g key={`group-${tagIndex}`}>{elements}</g>;
114
+ return <g key={`group-${tagIndex}`} pointerEvents="none">{elements}</g>;
115
115
  });
116
116
  };
117
117
  let commonProps = {
@@ -243,12 +243,12 @@ const Layers = ({ components, selectedTable, iconTags, eventMatchTable, onHighli
243
243
  {...omit(item, ["x", "y", "label", "points"])} {...commonProps}/>
244
244
 
245
245
  {renderTags(tags)}
246
- {!iconTags && (<g transform={`rotate(${-rotation}, ${width / 2}, ${height / 2})`}>
246
+ {!iconTags && (<g transform={`rotate(${-rotation}, ${width / 2}, ${height / 2})`} pointerEvents="none">
247
247
  {labels === null || labels === void 0 ? void 0 : labels.map((_, index) => {
248
248
  var _a, _b, _c, _d, _e, _f, _g;
249
249
  const cx = width / 2 + ((_a = _ === null || _ === void 0 ? void 0 : _.x) !== null && _a !== void 0 ? _a : 0);
250
250
  const cy = height / 2 + ((_b = _ === null || _ === void 0 ? void 0 : _.y) !== null && _b !== void 0 ? _b : 0);
251
- return (<text {...omit(commonProps, [
251
+ return (<text pointerEvents="none" {...omit(commonProps, [
252
252
  "opacity",
253
253
  "stroke",
254
254
  "strokeWidth",
@@ -146,10 +146,17 @@ const BoardTemplate = ({ refs }) => {
146
146
  }
147
147
  if ((extraComponentsProps === null || extraComponentsProps === void 0 ? void 0 : extraComponentsProps.length) < 1 &&
148
148
  ["background", "text"].includes((_g = componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps[0]) === null || _g === void 0 ? void 0 : _g.shape)) {
149
- minX = minX - minX * 0.5;
150
- minY = minY - minY * 0.5;
149
+ minX = minX;
150
+ minY = minY;
151
+ }
152
+ const hasBoundingBox = extraComponentsProps === null || extraComponentsProps === void 0 ? void 0 : extraComponentsProps.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"); });
153
+ if (hasBoundingBox) {
154
+ const findBoundingBox = extraComponentsProps.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"); });
155
+ minX = findBoundingBox.x;
156
+ minY = findBoundingBox.y;
151
157
  }
152
158
  if ((minX !== Infinity || minY !== Infinity) && !activeTool) {
159
+ console.log("minX", minX, "minY", minY, "maxX", maxX, "maxY", maxY, "Haduhhh");
153
160
  (_h = transformRef.current) === null || _h === void 0 ? void 0 : _h.setTransform(-minX, -minY, scale);
154
161
  setHasInitialzed(true);
155
162
  }
@@ -174,6 +181,10 @@ const BoardTemplate = ({ refs }) => {
174
181
  }, 1000));
175
182
  // Redux → Local
176
183
  useEffect(() => {
184
+ console.log({
185
+ flagChange,
186
+ updateBy
187
+ }, "haduuhhh");
177
188
  if (flagChange && updateBy === "global") {
178
189
  if (!isEqual(selectedComponentProps, selectedComponent)) {
179
190
  isSyncingFromRedux.current = true;
@@ -369,7 +380,6 @@ const BoardTemplate = ({ refs }) => {
369
380
  }
370
381
  //move tanpa ada selection single element dan bisa move juga ketika ada selection box
371
382
  //JIKA PUNYA SELECTION TAPI DOWN DI ELEMENT LAIN
372
- const downInMatchSelectionBox = downInSelectionBox && (hitPoint === null || hitPoint === void 0 ? void 0 : hitPoint.nodeName) !== "svg" && isInSelectionTarget;
373
383
  if (downInSelectionBox) {
374
384
  hadSelectionRef.current = true;
375
385
  }
@@ -407,17 +417,17 @@ const BoardTemplate = ({ refs }) => {
407
417
  !downOutSelectionBox &&
408
418
  isInSelectionTarget &&
409
419
  !isSingleSelection &&
410
- !isInTargetElement;
411
- const downAtResizePositionAndHasSelectionBox = downAtResizePosition && hadSelectionBox && !isRotateSelectionBox;
420
+ !isInTargetElement && !isInitialCreateBoundingBox;
421
+ const downAtResizePositionAndHasSelectionBox = downAtResizePosition && hadSelectionBox && !isRotateSelectionBox && !isInitialCreateBoundingBox;
412
422
  const isMightResizeElement = !isEmpty(selectedComponent) &&
413
423
  downAtResizePosition &&
414
424
  downAtResizePosition &&
415
- !hadSelectionBox;
425
+ !hadSelectionBox && !isInitialCreateBoundingBox;
416
426
  const isMightMove = activeId &&
417
427
  !targetPointPolygon &&
418
428
  isInTargetElement &&
419
- !isMightResizeElement;
420
- const isMightMoveOneElementSelection = isSingleSelection && !isMightResizeElement;
429
+ !isMightResizeElement && !isInitialCreateBoundingBox;
430
+ const isMightMoveOneElementSelection = isSingleSelection && !isMightResizeElement && !isInitialCreateBoundingBox;
421
431
  if (downOutResizePositionAndInSelectionBox) {
422
432
  onMoveSelectionBoxRef.current = true;
423
433
  }
@@ -34,6 +34,12 @@ export interface TableEditorProps {
34
34
  extraComponent: boolean;
35
35
  };
36
36
  refs?: React.RefObject<RefsType>;
37
+ viewStyles?: {
38
+ paddingTop?: number;
39
+ paddingLeft?: number;
40
+ paddingRight?: number;
41
+ paddingBottom?: number;
42
+ };
37
43
  }
38
44
  declare const TableEditor: (props: TableEditorProps) => import("react").JSX.Element;
39
45
  export default TableEditor;
@@ -8,7 +8,7 @@ import { isEqual } from "lodash";
8
8
  import LayerView from "../view-only";
9
9
  const TableEditor = (props) => {
10
10
  const [initialValue, setInitialValue] = useState(null);
11
- const { componentProps, extraComponentProps, onCurrentStateChange, dragOnly, mappingKey, viewOnly, deleteAutorized, refs } = props;
11
+ const { componentProps, extraComponentProps, onCurrentStateChange, dragOnly, mappingKey, viewOnly, deleteAutorized, refs, } = props;
12
12
  const { components, extraComponents, backgroundColor } = useAppSelector((state) => state.board);
13
13
  const dispatch = useAppDispatch();
14
14
  const refsBoard = useRef(null);
@@ -17,7 +17,7 @@ const TableEditor = (props) => {
17
17
  return ({
18
18
  svgRef: (_a = refsBoard === null || refsBoard === void 0 ? void 0 : refsBoard.current) === null || _a === void 0 ? void 0 : _a.svgRef,
19
19
  transformRef: (_b = refsBoard === null || refsBoard === void 0 ? void 0 : refsBoard.current) === null || _b === void 0 ? void 0 : _b.transformRef,
20
- containerRef: (_c = refsBoard === null || refsBoard === void 0 ? void 0 : refsBoard.current) === null || _c === void 0 ? void 0 : _c.containerRef
20
+ containerRef: (_c = refsBoard === null || refsBoard === void 0 ? void 0 : refsBoard.current) === null || _c === void 0 ? void 0 : _c.containerRef,
21
21
  });
22
22
  });
23
23
  useEffect(() => {
@@ -27,6 +27,13 @@ const TableEditor = (props) => {
27
27
  payload: null,
28
28
  });
29
29
  }
30
+ dispatch({
31
+ type: "tool/setActiveTool",
32
+ payload: ""
33
+ });
34
+ if (viewOnly) {
35
+ dispatch({ type: "board/setFlagChange", payload: true });
36
+ }
30
37
  }, [viewOnly]);
31
38
  const onUpdateCurrentState = () => {
32
39
  let matchInitialValueWithComponents = initialValue === null || initialValue === void 0 ? void 0 : initialValue.map((item) => {
@@ -58,7 +65,8 @@ const TableEditor = (props) => {
58
65
  };
59
66
  useEffect(() => {
60
67
  if (!isEqual(components, convertComponentProps()) ||
61
- !isEqual(extraComponents, extraComponentProps) || !isEqual(backgroundColor, props === null || props === void 0 ? void 0 : props.defaultBackground)) {
68
+ !isEqual(extraComponents, extraComponentProps) ||
69
+ !isEqual(backgroundColor, props === null || props === void 0 ? void 0 : props.defaultBackground)) {
62
70
  onCurrentStateChange && onUpdateCurrentState();
63
71
  }
64
72
  }, [components, extraComponents, backgroundColor]);
@@ -105,18 +113,13 @@ const TableEditor = (props) => {
105
113
  }, [componentProps, extraComponentProps, props === null || props === void 0 ? void 0 : props.defaultBackground]);
106
114
  return (<>
107
115
  <div className="w-full h-screen flex relative">
108
- <div className="w-full h-full flex relative" style={{
109
- display: !viewOnly ? "none" : "flex",
110
- }}>
111
- <LayerView statusKey="status"/>
112
- </div>
113
- <div className="w-full h-full flex relative" style={{
114
- display: viewOnly ? "none" : "flex",
115
- }}>
116
- <SideTool dragOnly={dragOnly} deleteAutorized={deleteAutorized}/>
117
- <Board refs={refsBoard}/>
118
- <ControlPanels action={props.action} responseMapping={props.responseMapping}/>
119
- </div>
116
+ {viewOnly ? (<div className="w-full h-full flex relative">
117
+ <LayerView statusKey="status"/>
118
+ </div>) : (<div key={`${viewOnly}`} className="w-full h-full flex relative">
119
+ <SideTool dragOnly={dragOnly} deleteAutorized={deleteAutorized}/>
120
+ <Board key={`${viewOnly}`} refs={refsBoard}/>
121
+ <ControlPanels action={props.action} responseMapping={props.responseMapping}/>
122
+ </div>)}
120
123
  </div>
121
124
  </>);
122
125
  };
@@ -71,8 +71,10 @@ export interface LayerViewProps<TMeta = undefined> {
71
71
  onSwitch?: (e: MouseEvent, component: TypeActionProps<TMeta>) => void;
72
72
  refs?: React.ForwardedRef<RefLayerView>;
73
73
  viewStyles?: {
74
- paddingX?: number;
75
- paddingY?: number;
74
+ paddingTop?: number;
75
+ paddingLeft?: number;
76
+ paddingRight?: number;
77
+ paddingBottom?: number;
76
78
  };
77
79
  }
78
80
  declare const LayerView: <TMeta>(props: LayerViewProps<TMeta>) => React.JSX.Element;
@@ -163,10 +163,12 @@ const LayerView = (props) => {
163
163
  minY = minY;
164
164
  }
165
165
  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"); });
166
- const paddingY = maxY * (((_h = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _h === void 0 ? void 0 : _h.paddingY) || 0) +
167
- minY * (((_j = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _j === void 0 ? void 0 : _j.paddingY) || 0);
168
- const paddingX = maxX * (((_k = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _k === void 0 ? void 0 : _k.paddingX) || 0) +
169
- minX * (((_l = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _l === void 0 ? void 0 : _l.paddingX) || 0);
166
+ // const paddingY =
167
+ // maxY * (props?.viewStyles?.paddingY || 0) +
168
+ // minY * (props?.viewStyles?.paddingY || 0);
169
+ // const paddingX =
170
+ // maxX * (props?.viewStyles?.paddingX || 0) +
171
+ // minX * (props?.viewStyles?.paddingX || 0);
170
172
  if (hasBoundingBox) {
171
173
  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"); });
172
174
  hasBoundingBoxRef.current = true;
@@ -177,11 +179,17 @@ const LayerView = (props) => {
177
179
  height: findBoundingBox.height,
178
180
  };
179
181
  }
182
+ // return {
183
+ // minX: minX - paddingX - (minX - paddingX) * 0.5,
184
+ // minY: minY - paddingY * 2,
185
+ // width: maxX + paddingX * 2,
186
+ // height: maxY + paddingY + (maxY + paddingY) * 0.5,
187
+ // };
180
188
  return {
181
- minX: minX - paddingX - (minX - paddingX) * 0.5,
182
- minY: minY - paddingY * 2,
183
- width: maxX + paddingX * 2,
184
- height: maxY + paddingY + (maxY + paddingY) * 0.5,
189
+ minX: minX - ((_h = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _h === void 0 ? void 0 : _h.paddingTop),
190
+ minY: minY - ((_j = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _j === void 0 ? void 0 : _j.paddingLeft),
191
+ width: maxX + ((_k = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _k === void 0 ? void 0 : _k.paddingRight),
192
+ height: maxY + ((_l = props === null || props === void 0 ? void 0 : props.viewStyles) === null || _l === void 0 ? void 0 : _l.paddingBottom),
185
193
  };
186
194
  }, [componentsEditor, extraComponentsEditor]);
187
195
  const renderElements = (elementEditor, mappingKey, tableMatchKey) => {
@@ -538,11 +546,11 @@ const LayerView = (props) => {
538
546
  touchAction: "none",
539
547
  userSelect: "none",
540
548
  }} {...props.svgProps}>
541
- <defs>
542
- <clipPath id="contentCrop">
543
- <rect x={boundingBox.minX} y={boundingBox.minY} width={boundingBox.width} height={boundingBox.height}/>
544
- </clipPath>
545
- </defs>
549
+ {hasBoundingBox && (<defs>
550
+ <clipPath id="contentCrop">
551
+ <rect x={boundingBox.minX} y={boundingBox.minY} width={boundingBox.width} height={boundingBox.height}/>
552
+ </clipPath>
553
+ </defs>)}
546
554
  <g id="main-layer" clip-path="url(#contentCrop)">
547
555
  <Layers components={[
548
556
  ...extraComponentsEditor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seat-editor",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",