@bemedev/mind-flow 0.3.1 → 0.3.2

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.
@@ -34,7 +34,6 @@ export const NodesBoard: Component = () => {
34
34
  let containerRef: HTMLDivElement;
35
35
  const [isPanning, setIsPanning] = createSignal(false);
36
36
  const [transform, setTransform] = createSignal({ x: 0, y: 0 });
37
- const [id, setId] = createSignal<string | number>('');
38
37
  const [ref, setRef] = createSignal<HTMLDivElement | undefined>();
39
38
  let percentX = 0;
40
39
  let percentY = 0;
@@ -107,15 +106,6 @@ export const NodesBoard: Component = () => {
107
106
 
108
107
  const selectedId = createState(service, { selector: s => s.context?.selected });
109
108
 
110
- /**
111
- * Determines whether the given element ID matches the currently selected entity.
112
- *
113
- * @param id - The node or edge identifier to check.
114
- *
115
- * @returns `true` if the item is currently selected, otherwise `false`.
116
- */
117
- const selected = (id: string | number) => selectedId() === id;
118
-
119
109
  const nodeIds = createState(service, {
120
110
  selector: ({ context }) => {
121
111
  const list = toArray.typed(context.data?.nodes);
@@ -149,44 +139,38 @@ export const NodesBoard: Component = () => {
149
139
  >
150
140
  <DragDropProvider
151
141
  onDragMove={({ draggable: { transform: _transform, node, id } }) => {
152
- setId(id);
153
- if (selected(id)) {
154
- const grandParent = node.parentElement?.parentElement;
155
- const currentZoom = zoom();
156
- const minX = 0;
157
- const maxX = grandParent
158
- ? Math.max(0, grandParent.clientWidth / currentZoom - node.offsetWidth)
159
- : Infinity;
160
- const minY = 0;
161
- const maxY = grandParent
162
- ? Math.max(
163
- 0,
164
- grandParent.clientHeight / currentZoom - node.offsetHeight,
165
- )
166
- : Infinity;
167
-
168
- const targetX = node.offsetLeft + _transform.x / currentZoom;
169
- const targetY = node.offsetTop + _transform.y / currentZoom;
170
-
171
- const x = Math.min(Math.max(targetX, minX), maxX);
172
- const y = Math.min(Math.max(targetY, minY), maxY);
173
-
174
- const deltaX = x - node.offsetLeft;
175
- const deltaY = y - node.offsetTop;
176
-
177
- // Directly update the draggable node's CSS transform adjusted for zoom:
178
- node.style.setProperty(
179
- 'transform',
180
- `translate3d(${deltaX}px, ${deltaY}px, 0)`,
181
- );
182
-
183
- service.send({ type: 'MOVE_IMMEDIATE', payload: { id: `${id}`, x, y } });
184
- setTransform({ x: deltaX * currentZoom, y: deltaY * currentZoom });
185
- }
142
+ const grandParent = node.parentElement?.parentElement;
143
+ const currentZoom = zoom();
144
+ const minX = 0;
145
+ const maxX = grandParent
146
+ ? Math.max(0, grandParent.clientWidth / currentZoom - node.offsetWidth)
147
+ : Infinity;
148
+ const minY = 0;
149
+ const maxY = grandParent
150
+ ? Math.max(0, grandParent.clientHeight / currentZoom - node.offsetHeight)
151
+ : Infinity;
152
+
153
+ const targetX = node.offsetLeft + _transform.x / currentZoom;
154
+ const targetY = node.offsetTop + _transform.y / currentZoom;
155
+
156
+ const x = Math.min(Math.max(targetX, minX), maxX);
157
+ const y = Math.min(Math.max(targetY, minY), maxY);
158
+
159
+ const deltaX = x - node.offsetLeft;
160
+ const deltaY = y - node.offsetTop;
161
+
162
+ // Directly update the draggable node's CSS transform adjusted for zoom:
163
+ node.style.setProperty(
164
+ 'transform',
165
+ `translate3d(${deltaX}px, ${deltaY}px, 0)`,
166
+ );
167
+
168
+ service.send({ type: 'MOVE_IMMEDIATE', payload: { id: `${id}`, x, y } });
169
+ setTransform({ x: deltaX * currentZoom, y: deltaY * currentZoom });
186
170
  }}
187
171
 
188
172
  onDragEnd={({ draggable: { node, id } }) => {
189
- if (!selected(id)) return;
173
+ // if (!selected(id)) return;
190
174
 
191
175
  const grandParent = node.parentElement?.parentElement;
192
176
  const currentZoom = zoom();
@@ -227,11 +211,12 @@ export const NodesBoard: Component = () => {
227
211
  class='relative cursor-crosshair overflow-hidden'
228
212
  classList={{ 'cursor-grabbing': isPanning() }}
229
213
  style={{ height: cHeight(), width: cWidth() }}
230
- onScroll={() => {}}
214
+ // onScroll={() => {}}
231
215
 
232
216
  onMouseDown={e => {
233
217
  if (newEdge() || e.button !== 0) return;
234
218
  service.send('DESELECT');
219
+ setIsPanning(true);
235
220
 
236
221
  // #region Props
237
222
  const startX = e.clientX;
@@ -240,8 +225,6 @@ export const NodesBoard: Component = () => {
240
225
  const startScrollTop = containerRef.scrollTop;
241
226
  // #endregion
242
227
 
243
- setIsPanning(true);
244
-
245
228
  const handleMouseMove = (moveEvent: MouseEvent) => {
246
229
  const dx = moveEvent.clientX - startX;
247
230
  const dy = moveEvent.clientY - startY;
@@ -325,7 +308,7 @@ export const NodesBoard: Component = () => {
325
308
  </svg>
326
309
  </button>
327
310
  </div>
328
- <Show when={!id() || !selected(id())}>
311
+ <Show when={!selectedId()}>
329
312
  <DragOverlay children='' />
330
313
  </Show>
331
314
  </DragDropProvider>