@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.
- package/lib/index.cjs.js +1 -1
- package/lib/index.es.js +215 -220
- package/lib/server.cjs.js +140 -157
- package/lib/server.es.js +140 -157
- package/lib/services/main.machine.d.ts +994 -14
- package/lib/services/main.machine.d.ts.map +1 -1
- package/lib/ui/components/FlowChart.context.d.ts +994 -14
- package/lib/ui/components/FlowChart.context.d.ts.map +1 -1
- package/lib/ui/components/NodesBoard.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/services/main.machine.ts +148 -41
- package/src/ui/components/FlowChart.context.ts +2 -131
- package/src/ui/components/FlowChart.tsx +10 -10
- package/src/ui/components/NodeComponent.tsx +8 -8
- package/src/ui/components/NodesBoard.tsx +32 -49
|
@@ -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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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={!
|
|
311
|
+
<Show when={!selectedId()}>
|
|
329
312
|
<DragOverlay children='' />
|
|
330
313
|
</Show>
|
|
331
314
|
</DragDropProvider>
|