@xyflow/system 0.0.13 → 0.0.14

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.
@@ -5,4 +5,5 @@ export * from './xydrag';
5
5
  export * from './xyhandle';
6
6
  export * from './xyminimap';
7
7
  export * from './xypanzoom';
8
+ export * from './xyresizer';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/esm/index.js CHANGED
@@ -2173,4 +2173,221 @@ function XYPanZoom({ domNode, minZoom, maxZoom, translateExtent, viewport, onPan
2173
2173
  };
2174
2174
  }
2175
2175
 
2176
- export { ConnectionLineType, ConnectionMode, MarkerType, PanOnScrollMode, Position, SelectionMode, XYDrag, XYHandle, XYMinimap, XYPanZoom, addEdgeBase, adoptUserProvidedNodes, areConnectionMapsEqual, boxToRect, calcAutoPan, calcNextPosition, clamp, clampPosition, createMarkerIds, devWarn, elementSelectionKeys, errorMessages, fitView, getBezierEdgeCenter, getBezierPath, getBoundsOfBoxes, getBoundsOfRects, getConnectedEdgesBase, getDimensions, getEdgeCenter, getEdgePosition, getElementsToRemove, getElevatedEdgeZIndex, getEventPosition, getHandleBounds, getHostForElement, getIncomersBase, getMarkerId, getNodePositionWithOrigin, getNodeToolbarTransform, getNodesBounds, getNodesInside, getOutgoersBase, getOverlappingArea, getPointerPosition, getPositionWithOrigin, getSmoothStepPath, getStraightPath, getViewportForBounds, handleConnectionChange, infiniteExtent, internalsSymbol, isEdgeBase, isEdgeVisible, isInputDOMNode, isMacOs, isMouseEvent, isNodeBase, isNumeric, isRectObject, nodeToBox, nodeToRect, panBy, pointToRendererPoint, rectToBox, rendererPointToPoint, snapPosition, updateAbsolutePositions, updateConnectionLookup, updateEdgeBase, updateNodeDimensions };
2176
+ var ResizeControlVariant;
2177
+ (function (ResizeControlVariant) {
2178
+ ResizeControlVariant["Line"] = "line";
2179
+ ResizeControlVariant["Handle"] = "handle";
2180
+ })(ResizeControlVariant || (ResizeControlVariant = {}));
2181
+ const XY_RESIZER_HANDLE_POSITIONS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
2182
+ const XY_RESIZER_LINE_POSITIONS = ['top', 'right', 'bottom', 'left'];
2183
+
2184
+ /**
2185
+ * Get all connecting edges for a given set of nodes
2186
+ * @param width - new width of the node
2187
+ * @param prevWidth - previous width of the node
2188
+ * @param height - new height of the node
2189
+ * @param prevHeight - previous height of the node
2190
+ * @param affectsX - whether to invert the resize direction for the x axis
2191
+ * @param affectsY - whether to invert the resize direction for the y axis
2192
+ * @returns array of two numbers representing the direction of the resize for each axis, 0 = no change, 1 = increase, -1 = decrease
2193
+ */
2194
+ function getResizeDirection({ width, prevWidth, height, prevHeight, affectsX, affectsY, }) {
2195
+ const deltaWidth = width - prevWidth;
2196
+ const deltaHeight = height - prevHeight;
2197
+ const direction = [deltaWidth > 0 ? 1 : deltaWidth < 0 ? -1 : 0, deltaHeight > 0 ? 1 : deltaHeight < 0 ? -1 : 0];
2198
+ if (deltaWidth && affectsX) {
2199
+ direction[0] = direction[0] * -1;
2200
+ }
2201
+ if (deltaHeight && affectsY) {
2202
+ direction[1] = direction[1] * -1;
2203
+ }
2204
+ return direction;
2205
+ }
2206
+ /**
2207
+ * Parses the control position that is being dragged to dimensions that are being resized
2208
+ * @param controlPosition - position of the control that is being dragged
2209
+ * @returns isHorizontal, isVertical, affectsX, affectsY,
2210
+ */
2211
+ function getControlDirection(controlPosition) {
2212
+ const isHorizontal = controlPosition.includes('right') || controlPosition.includes('left');
2213
+ const isVertical = controlPosition.includes('bottom') || controlPosition.includes('top');
2214
+ const affectsX = controlPosition.includes('left');
2215
+ const affectsY = controlPosition.includes('top');
2216
+ return {
2217
+ isHorizontal,
2218
+ isVertical,
2219
+ affectsX,
2220
+ affectsY,
2221
+ };
2222
+ }
2223
+ /**
2224
+ * Calculates new width & height of node after resize based on pointer position
2225
+ * @param startValues - starting values of resize
2226
+ * @param controlDirection - dimensions affected by the resize
2227
+ * @param pointerPosition - the current pointer position corrected for snapping
2228
+ * @param boundaries - minimum and maximum dimensions of the node
2229
+ * @param keepAspectRatio - prevent changes of asprect ratio
2230
+ * @returns width: new width of node, height: new height of node
2231
+ */
2232
+ function getDimensionsAfterResize(startValues, controlDirection, pointerPosition, boundaries, keepAspectRatio) {
2233
+ const { isHorizontal, isVertical, affectsX, affectsY } = controlDirection;
2234
+ const { xSnapped, ySnapped } = pointerPosition;
2235
+ const { minWidth, maxWidth, minHeight, maxHeight } = boundaries;
2236
+ const { pointerX: startX, pointerY: startY, width: startWidth, height: startHeight, aspectRatio } = startValues;
2237
+ const distX = Math.floor(isHorizontal ? xSnapped - startX : 0);
2238
+ const distY = Math.floor(isVertical ? ySnapped - startY : 0);
2239
+ let width = clamp(startWidth + (affectsX ? -distX : distX), minWidth, maxWidth);
2240
+ let height = clamp(startHeight + (affectsY ? -distY : distY), minHeight, maxHeight);
2241
+ if (keepAspectRatio) {
2242
+ const nextAspectRatio = width / height;
2243
+ const isDiagonal = isHorizontal && isVertical;
2244
+ const isOnlyHorizontal = isHorizontal && !isVertical;
2245
+ const isOnlyVertical = isVertical && !isHorizontal;
2246
+ width = (nextAspectRatio <= aspectRatio && isDiagonal) || isOnlyVertical ? height * aspectRatio : width;
2247
+ height = (nextAspectRatio > aspectRatio && isDiagonal) || isOnlyHorizontal ? width / aspectRatio : height;
2248
+ if (width >= maxWidth) {
2249
+ width = maxWidth;
2250
+ height = maxWidth / aspectRatio;
2251
+ }
2252
+ else if (width <= minWidth) {
2253
+ width = minWidth;
2254
+ height = minWidth / aspectRatio;
2255
+ }
2256
+ if (height >= maxHeight) {
2257
+ height = maxHeight;
2258
+ width = maxHeight * aspectRatio;
2259
+ }
2260
+ else if (height <= minHeight) {
2261
+ height = minHeight;
2262
+ width = minHeight * aspectRatio;
2263
+ }
2264
+ }
2265
+ return {
2266
+ width,
2267
+ height,
2268
+ };
2269
+ }
2270
+ /**
2271
+ * Determines new x & y position of node after resize based on new width & height
2272
+ * @param startValues - starting values of resize
2273
+ * @param controlDirection - dimensions affected by the resize
2274
+ * @param width - new width of node
2275
+ * @param height - new height of node
2276
+ * @returns x: new x position of node, y: new y position of node
2277
+ */
2278
+ function getPositionAfterResize(startValues, controlDirection, width, height) {
2279
+ return {
2280
+ x: controlDirection.affectsX ? startValues.x - (width - startValues.width) : startValues.x,
2281
+ y: controlDirection.affectsY ? startValues.y - (height - startValues.height) : startValues.y,
2282
+ };
2283
+ }
2284
+
2285
+ const initPrevValues = { width: 0, height: 0, x: 0, y: 0 };
2286
+ const initStartValues = {
2287
+ ...initPrevValues,
2288
+ pointerX: 0,
2289
+ pointerY: 0,
2290
+ aspectRatio: 1,
2291
+ };
2292
+ const initChange = {
2293
+ x: 0,
2294
+ y: 0,
2295
+ width: 0,
2296
+ height: 0,
2297
+ isXPosChange: false,
2298
+ isYPosChange: false,
2299
+ isWidthChange: false,
2300
+ isHeightChange: false,
2301
+ };
2302
+ function XYResizer({ domNode, nodeId, getStoreItems, onChange }) {
2303
+ const selection = select(domNode);
2304
+ function update({ controlPosition, boundaries, keepAspectRatio, onResizeStart, onResize, onResizeEnd, shouldResize, }) {
2305
+ let prevValues = { ...initPrevValues };
2306
+ let startValues = { ...initStartValues };
2307
+ const controlDirection = getControlDirection(controlPosition);
2308
+ const dragHandler = drag()
2309
+ .on('start', (event) => {
2310
+ const { nodeLookup, transform, snapGrid, snapToGrid } = getStoreItems();
2311
+ const node = nodeLookup.get(nodeId);
2312
+ const { xSnapped, ySnapped } = getPointerPosition(event.sourceEvent, { transform, snapGrid, snapToGrid });
2313
+ prevValues = {
2314
+ width: node?.computed?.width ?? 0,
2315
+ height: node?.computed?.height ?? 0,
2316
+ x: node?.position.x ?? 0,
2317
+ y: node?.position.y ?? 0,
2318
+ };
2319
+ startValues = {
2320
+ ...prevValues,
2321
+ pointerX: xSnapped,
2322
+ pointerY: ySnapped,
2323
+ aspectRatio: prevValues.width / prevValues.height,
2324
+ };
2325
+ onResizeStart?.(event, { ...prevValues });
2326
+ })
2327
+ .on('drag', (event) => {
2328
+ const { nodeLookup, transform, snapGrid, snapToGrid } = getStoreItems();
2329
+ const pointerPosition = getPointerPosition(event.sourceEvent, { transform, snapGrid, snapToGrid });
2330
+ const node = nodeLookup.get(nodeId);
2331
+ if (node) {
2332
+ const change = { ...initChange };
2333
+ const { x: prevX, y: prevY, width: prevWidth, height: prevHeight } = prevValues;
2334
+ const { width, height } = getDimensionsAfterResize(startValues, controlDirection, pointerPosition, boundaries, keepAspectRatio);
2335
+ const isWidthChange = width !== prevWidth;
2336
+ const isHeightChange = height !== prevHeight;
2337
+ if (controlDirection.affectsX || controlDirection.affectsY) {
2338
+ const { x, y } = getPositionAfterResize(startValues, controlDirection, width, height);
2339
+ // only transform the node if the width or height changes
2340
+ const isXPosChange = x !== prevX && isWidthChange;
2341
+ const isYPosChange = y !== prevY && isHeightChange;
2342
+ if (isXPosChange || isYPosChange) {
2343
+ change.isXPosChange = isXPosChange;
2344
+ change.isYPosChange = isYPosChange;
2345
+ change.x = isXPosChange ? x : prevX;
2346
+ change.y = isYPosChange ? y : prevY;
2347
+ prevValues.x = change.x;
2348
+ prevValues.y = change.y;
2349
+ }
2350
+ }
2351
+ if (isWidthChange || isHeightChange) {
2352
+ change.isWidthChange = isWidthChange;
2353
+ change.isHeightChange = isHeightChange;
2354
+ change.width = width;
2355
+ change.height = height;
2356
+ prevValues.width = width;
2357
+ prevValues.height = height;
2358
+ }
2359
+ if (!change.isXPosChange && !change.isYPosChange && !isWidthChange && !isHeightChange) {
2360
+ return;
2361
+ }
2362
+ const direction = getResizeDirection({
2363
+ width: prevValues.width,
2364
+ prevWidth,
2365
+ height: prevValues.height,
2366
+ prevHeight,
2367
+ affectsX: controlDirection.affectsX,
2368
+ affectsY: controlDirection.affectsY,
2369
+ });
2370
+ const nextValues = { ...prevValues, direction };
2371
+ const callResize = shouldResize?.(event, nextValues);
2372
+ if (callResize === false) {
2373
+ return;
2374
+ }
2375
+ onResize?.(event, nextValues);
2376
+ onChange(change);
2377
+ }
2378
+ })
2379
+ .on('end', (event) => {
2380
+ onResizeEnd?.(event, { ...prevValues });
2381
+ });
2382
+ selection.call(dragHandler);
2383
+ }
2384
+ function destroy() {
2385
+ selection.on('.drag', null);
2386
+ }
2387
+ return {
2388
+ update,
2389
+ destroy,
2390
+ };
2391
+ }
2392
+
2393
+ export { ConnectionLineType, ConnectionMode, MarkerType, PanOnScrollMode, Position, ResizeControlVariant, SelectionMode, XYDrag, XYHandle, XYMinimap, XYPanZoom, XYResizer, XY_RESIZER_HANDLE_POSITIONS, XY_RESIZER_LINE_POSITIONS, addEdgeBase, adoptUserProvidedNodes, areConnectionMapsEqual, boxToRect, calcAutoPan, calcNextPosition, clamp, clampPosition, createMarkerIds, devWarn, elementSelectionKeys, errorMessages, fitView, getBezierEdgeCenter, getBezierPath, getBoundsOfBoxes, getBoundsOfRects, getConnectedEdgesBase, getDimensions, getEdgeCenter, getEdgePosition, getElementsToRemove, getElevatedEdgeZIndex, getEventPosition, getHandleBounds, getHostForElement, getIncomersBase, getMarkerId, getNodePositionWithOrigin, getNodeToolbarTransform, getNodesBounds, getNodesInside, getOutgoersBase, getOverlappingArea, getPointerPosition, getPositionWithOrigin, getSmoothStepPath, getStraightPath, getViewportForBounds, handleConnectionChange, infiniteExtent, internalsSymbol, isEdgeBase, isEdgeVisible, isInputDOMNode, isMacOs, isMouseEvent, isNodeBase, isNumeric, isRectObject, nodeToBox, nodeToRect, panBy, pointToRendererPoint, rectToBox, rendererPointToPoint, snapPosition, updateAbsolutePositions, updateConnectionLookup, updateEdgeBase, updateNodeDimensions };
@@ -2173,4 +2173,221 @@ function XYPanZoom({ domNode, minZoom, maxZoom, translateExtent, viewport, onPan
2173
2173
  };
2174
2174
  }
2175
2175
 
2176
- export { ConnectionLineType, ConnectionMode, MarkerType, PanOnScrollMode, Position, SelectionMode, XYDrag, XYHandle, XYMinimap, XYPanZoom, addEdgeBase, adoptUserProvidedNodes, areConnectionMapsEqual, boxToRect, calcAutoPan, calcNextPosition, clamp, clampPosition, createMarkerIds, devWarn, elementSelectionKeys, errorMessages, fitView, getBezierEdgeCenter, getBezierPath, getBoundsOfBoxes, getBoundsOfRects, getConnectedEdgesBase, getDimensions, getEdgeCenter, getEdgePosition, getElementsToRemove, getElevatedEdgeZIndex, getEventPosition, getHandleBounds, getHostForElement, getIncomersBase, getMarkerId, getNodePositionWithOrigin, getNodeToolbarTransform, getNodesBounds, getNodesInside, getOutgoersBase, getOverlappingArea, getPointerPosition, getPositionWithOrigin, getSmoothStepPath, getStraightPath, getViewportForBounds, handleConnectionChange, infiniteExtent, internalsSymbol, isEdgeBase, isEdgeVisible, isInputDOMNode, isMacOs, isMouseEvent, isNodeBase, isNumeric, isRectObject, nodeToBox, nodeToRect, panBy, pointToRendererPoint, rectToBox, rendererPointToPoint, snapPosition, updateAbsolutePositions, updateConnectionLookup, updateEdgeBase, updateNodeDimensions };
2176
+ var ResizeControlVariant;
2177
+ (function (ResizeControlVariant) {
2178
+ ResizeControlVariant["Line"] = "line";
2179
+ ResizeControlVariant["Handle"] = "handle";
2180
+ })(ResizeControlVariant || (ResizeControlVariant = {}));
2181
+ const XY_RESIZER_HANDLE_POSITIONS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
2182
+ const XY_RESIZER_LINE_POSITIONS = ['top', 'right', 'bottom', 'left'];
2183
+
2184
+ /**
2185
+ * Get all connecting edges for a given set of nodes
2186
+ * @param width - new width of the node
2187
+ * @param prevWidth - previous width of the node
2188
+ * @param height - new height of the node
2189
+ * @param prevHeight - previous height of the node
2190
+ * @param affectsX - whether to invert the resize direction for the x axis
2191
+ * @param affectsY - whether to invert the resize direction for the y axis
2192
+ * @returns array of two numbers representing the direction of the resize for each axis, 0 = no change, 1 = increase, -1 = decrease
2193
+ */
2194
+ function getResizeDirection({ width, prevWidth, height, prevHeight, affectsX, affectsY, }) {
2195
+ const deltaWidth = width - prevWidth;
2196
+ const deltaHeight = height - prevHeight;
2197
+ const direction = [deltaWidth > 0 ? 1 : deltaWidth < 0 ? -1 : 0, deltaHeight > 0 ? 1 : deltaHeight < 0 ? -1 : 0];
2198
+ if (deltaWidth && affectsX) {
2199
+ direction[0] = direction[0] * -1;
2200
+ }
2201
+ if (deltaHeight && affectsY) {
2202
+ direction[1] = direction[1] * -1;
2203
+ }
2204
+ return direction;
2205
+ }
2206
+ /**
2207
+ * Parses the control position that is being dragged to dimensions that are being resized
2208
+ * @param controlPosition - position of the control that is being dragged
2209
+ * @returns isHorizontal, isVertical, affectsX, affectsY,
2210
+ */
2211
+ function getControlDirection(controlPosition) {
2212
+ const isHorizontal = controlPosition.includes('right') || controlPosition.includes('left');
2213
+ const isVertical = controlPosition.includes('bottom') || controlPosition.includes('top');
2214
+ const affectsX = controlPosition.includes('left');
2215
+ const affectsY = controlPosition.includes('top');
2216
+ return {
2217
+ isHorizontal,
2218
+ isVertical,
2219
+ affectsX,
2220
+ affectsY,
2221
+ };
2222
+ }
2223
+ /**
2224
+ * Calculates new width & height of node after resize based on pointer position
2225
+ * @param startValues - starting values of resize
2226
+ * @param controlDirection - dimensions affected by the resize
2227
+ * @param pointerPosition - the current pointer position corrected for snapping
2228
+ * @param boundaries - minimum and maximum dimensions of the node
2229
+ * @param keepAspectRatio - prevent changes of asprect ratio
2230
+ * @returns width: new width of node, height: new height of node
2231
+ */
2232
+ function getDimensionsAfterResize(startValues, controlDirection, pointerPosition, boundaries, keepAspectRatio) {
2233
+ const { isHorizontal, isVertical, affectsX, affectsY } = controlDirection;
2234
+ const { xSnapped, ySnapped } = pointerPosition;
2235
+ const { minWidth, maxWidth, minHeight, maxHeight } = boundaries;
2236
+ const { pointerX: startX, pointerY: startY, width: startWidth, height: startHeight, aspectRatio } = startValues;
2237
+ const distX = Math.floor(isHorizontal ? xSnapped - startX : 0);
2238
+ const distY = Math.floor(isVertical ? ySnapped - startY : 0);
2239
+ let width = clamp(startWidth + (affectsX ? -distX : distX), minWidth, maxWidth);
2240
+ let height = clamp(startHeight + (affectsY ? -distY : distY), minHeight, maxHeight);
2241
+ if (keepAspectRatio) {
2242
+ const nextAspectRatio = width / height;
2243
+ const isDiagonal = isHorizontal && isVertical;
2244
+ const isOnlyHorizontal = isHorizontal && !isVertical;
2245
+ const isOnlyVertical = isVertical && !isHorizontal;
2246
+ width = (nextAspectRatio <= aspectRatio && isDiagonal) || isOnlyVertical ? height * aspectRatio : width;
2247
+ height = (nextAspectRatio > aspectRatio && isDiagonal) || isOnlyHorizontal ? width / aspectRatio : height;
2248
+ if (width >= maxWidth) {
2249
+ width = maxWidth;
2250
+ height = maxWidth / aspectRatio;
2251
+ }
2252
+ else if (width <= minWidth) {
2253
+ width = minWidth;
2254
+ height = minWidth / aspectRatio;
2255
+ }
2256
+ if (height >= maxHeight) {
2257
+ height = maxHeight;
2258
+ width = maxHeight * aspectRatio;
2259
+ }
2260
+ else if (height <= minHeight) {
2261
+ height = minHeight;
2262
+ width = minHeight * aspectRatio;
2263
+ }
2264
+ }
2265
+ return {
2266
+ width,
2267
+ height,
2268
+ };
2269
+ }
2270
+ /**
2271
+ * Determines new x & y position of node after resize based on new width & height
2272
+ * @param startValues - starting values of resize
2273
+ * @param controlDirection - dimensions affected by the resize
2274
+ * @param width - new width of node
2275
+ * @param height - new height of node
2276
+ * @returns x: new x position of node, y: new y position of node
2277
+ */
2278
+ function getPositionAfterResize(startValues, controlDirection, width, height) {
2279
+ return {
2280
+ x: controlDirection.affectsX ? startValues.x - (width - startValues.width) : startValues.x,
2281
+ y: controlDirection.affectsY ? startValues.y - (height - startValues.height) : startValues.y,
2282
+ };
2283
+ }
2284
+
2285
+ const initPrevValues = { width: 0, height: 0, x: 0, y: 0 };
2286
+ const initStartValues = {
2287
+ ...initPrevValues,
2288
+ pointerX: 0,
2289
+ pointerY: 0,
2290
+ aspectRatio: 1,
2291
+ };
2292
+ const initChange = {
2293
+ x: 0,
2294
+ y: 0,
2295
+ width: 0,
2296
+ height: 0,
2297
+ isXPosChange: false,
2298
+ isYPosChange: false,
2299
+ isWidthChange: false,
2300
+ isHeightChange: false,
2301
+ };
2302
+ function XYResizer({ domNode, nodeId, getStoreItems, onChange }) {
2303
+ const selection = select(domNode);
2304
+ function update({ controlPosition, boundaries, keepAspectRatio, onResizeStart, onResize, onResizeEnd, shouldResize, }) {
2305
+ let prevValues = { ...initPrevValues };
2306
+ let startValues = { ...initStartValues };
2307
+ const controlDirection = getControlDirection(controlPosition);
2308
+ const dragHandler = drag()
2309
+ .on('start', (event) => {
2310
+ const { nodeLookup, transform, snapGrid, snapToGrid } = getStoreItems();
2311
+ const node = nodeLookup.get(nodeId);
2312
+ const { xSnapped, ySnapped } = getPointerPosition(event.sourceEvent, { transform, snapGrid, snapToGrid });
2313
+ prevValues = {
2314
+ width: node?.computed?.width ?? 0,
2315
+ height: node?.computed?.height ?? 0,
2316
+ x: node?.position.x ?? 0,
2317
+ y: node?.position.y ?? 0,
2318
+ };
2319
+ startValues = {
2320
+ ...prevValues,
2321
+ pointerX: xSnapped,
2322
+ pointerY: ySnapped,
2323
+ aspectRatio: prevValues.width / prevValues.height,
2324
+ };
2325
+ onResizeStart?.(event, { ...prevValues });
2326
+ })
2327
+ .on('drag', (event) => {
2328
+ const { nodeLookup, transform, snapGrid, snapToGrid } = getStoreItems();
2329
+ const pointerPosition = getPointerPosition(event.sourceEvent, { transform, snapGrid, snapToGrid });
2330
+ const node = nodeLookup.get(nodeId);
2331
+ if (node) {
2332
+ const change = { ...initChange };
2333
+ const { x: prevX, y: prevY, width: prevWidth, height: prevHeight } = prevValues;
2334
+ const { width, height } = getDimensionsAfterResize(startValues, controlDirection, pointerPosition, boundaries, keepAspectRatio);
2335
+ const isWidthChange = width !== prevWidth;
2336
+ const isHeightChange = height !== prevHeight;
2337
+ if (controlDirection.affectsX || controlDirection.affectsY) {
2338
+ const { x, y } = getPositionAfterResize(startValues, controlDirection, width, height);
2339
+ // only transform the node if the width or height changes
2340
+ const isXPosChange = x !== prevX && isWidthChange;
2341
+ const isYPosChange = y !== prevY && isHeightChange;
2342
+ if (isXPosChange || isYPosChange) {
2343
+ change.isXPosChange = isXPosChange;
2344
+ change.isYPosChange = isYPosChange;
2345
+ change.x = isXPosChange ? x : prevX;
2346
+ change.y = isYPosChange ? y : prevY;
2347
+ prevValues.x = change.x;
2348
+ prevValues.y = change.y;
2349
+ }
2350
+ }
2351
+ if (isWidthChange || isHeightChange) {
2352
+ change.isWidthChange = isWidthChange;
2353
+ change.isHeightChange = isHeightChange;
2354
+ change.width = width;
2355
+ change.height = height;
2356
+ prevValues.width = width;
2357
+ prevValues.height = height;
2358
+ }
2359
+ if (!change.isXPosChange && !change.isYPosChange && !isWidthChange && !isHeightChange) {
2360
+ return;
2361
+ }
2362
+ const direction = getResizeDirection({
2363
+ width: prevValues.width,
2364
+ prevWidth,
2365
+ height: prevValues.height,
2366
+ prevHeight,
2367
+ affectsX: controlDirection.affectsX,
2368
+ affectsY: controlDirection.affectsY,
2369
+ });
2370
+ const nextValues = { ...prevValues, direction };
2371
+ const callResize = shouldResize?.(event, nextValues);
2372
+ if (callResize === false) {
2373
+ return;
2374
+ }
2375
+ onResize?.(event, nextValues);
2376
+ onChange(change);
2377
+ }
2378
+ })
2379
+ .on('end', (event) => {
2380
+ onResizeEnd?.(event, { ...prevValues });
2381
+ });
2382
+ selection.call(dragHandler);
2383
+ }
2384
+ function destroy() {
2385
+ selection.on('.drag', null);
2386
+ }
2387
+ return {
2388
+ update,
2389
+ destroy,
2390
+ };
2391
+ }
2392
+
2393
+ export { ConnectionLineType, ConnectionMode, MarkerType, PanOnScrollMode, Position, ResizeControlVariant, SelectionMode, XYDrag, XYHandle, XYMinimap, XYPanZoom, XYResizer, XY_RESIZER_HANDLE_POSITIONS, XY_RESIZER_LINE_POSITIONS, addEdgeBase, adoptUserProvidedNodes, areConnectionMapsEqual, boxToRect, calcAutoPan, calcNextPosition, clamp, clampPosition, createMarkerIds, devWarn, elementSelectionKeys, errorMessages, fitView, getBezierEdgeCenter, getBezierPath, getBoundsOfBoxes, getBoundsOfRects, getConnectedEdgesBase, getDimensions, getEdgeCenter, getEdgePosition, getElementsToRemove, getElevatedEdgeZIndex, getEventPosition, getHandleBounds, getHostForElement, getIncomersBase, getMarkerId, getNodePositionWithOrigin, getNodeToolbarTransform, getNodesBounds, getNodesInside, getOutgoersBase, getOverlappingArea, getPointerPosition, getPositionWithOrigin, getSmoothStepPath, getStraightPath, getViewportForBounds, handleConnectionChange, infiniteExtent, internalsSymbol, isEdgeBase, isEdgeVisible, isInputDOMNode, isMacOs, isMouseEvent, isNodeBase, isNumeric, isRectObject, nodeToBox, nodeToRect, panBy, pointToRendererPoint, rectToBox, rendererPointToPoint, snapPosition, updateAbsolutePositions, updateConnectionLookup, updateEdgeBase, updateNodeDimensions };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/types/utils.ts"],"names":[],"mappings":"AAEA,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAE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AAM,CAAC,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { NodeLookup, Transform } from '../types';
2
+ import type { OnResize, OnResizeEnd, OnResizeStart, ShouldResize, ControlPosition } from './types';
3
+ declare const initChange: {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ isXPosChange: boolean;
9
+ isYPosChange: boolean;
10
+ isWidthChange: boolean;
11
+ isHeightChange: boolean;
12
+ };
13
+ export type XYResizerChange = typeof initChange;
14
+ type XYResizerParams = {
15
+ domNode: HTMLDivElement;
16
+ nodeId: string;
17
+ getStoreItems: () => {
18
+ nodeLookup: NodeLookup;
19
+ transform: Transform;
20
+ snapGrid?: [number, number];
21
+ snapToGrid: boolean;
22
+ };
23
+ onChange: (changes: XYResizerChange) => void;
24
+ onEnd?: () => void;
25
+ };
26
+ type XYResizerUpdateParams = {
27
+ controlPosition: ControlPosition;
28
+ boundaries: {
29
+ minWidth: number;
30
+ minHeight: number;
31
+ maxWidth: number;
32
+ maxHeight: number;
33
+ };
34
+ keepAspectRatio: boolean;
35
+ onResizeStart: OnResizeStart | undefined;
36
+ onResize: OnResize | undefined;
37
+ onResizeEnd: OnResizeEnd | undefined;
38
+ shouldResize: ShouldResize | undefined;
39
+ };
40
+ export type XYResizerInstance = {
41
+ update: (params: XYResizerUpdateParams) => void;
42
+ destroy: () => void;
43
+ };
44
+ export declare function XYResizer({ domNode, nodeId, getStoreItems, onChange }: XYResizerParams): XYResizerInstance;
45
+ export {};
46
+ //# sourceMappingURL=XYResizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XYResizer.d.ts","sourceRoot":"","sources":["../../src/xyresizer/XYResizer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC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AAE,EAAE,eAAe,GAAG,iBAAiB,CA6H1G"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './XYResizer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/xyresizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { D3DragEvent, SubjectPosition } from 'd3-drag';
2
+ export type XYResizerParams = {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ };
8
+ export type XYResizerParamsWithDirection = XYResizerParams & {
9
+ direction: number[];
10
+ };
11
+ export type ControlLinePosition = 'top' | 'bottom' | 'left' | 'right';
12
+ export type ControlPosition = ControlLinePosition | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
13
+ export declare enum ResizeControlVariant {
14
+ Line = "line",
15
+ Handle = "handle"
16
+ }
17
+ export declare const XY_RESIZER_HANDLE_POSITIONS: ControlPosition[];
18
+ export declare const XY_RESIZER_LINE_POSITIONS: ControlLinePosition[];
19
+ type OnResizeHandler<Params = XYResizerParams, Result = void> = (event: ResizeDragEvent, params: Params) => Result;
20
+ export type ResizeDragEvent = D3DragEvent<HTMLDivElement, null, SubjectPosition>;
21
+ export type ShouldResize = OnResizeHandler<XYResizerParamsWithDirection, boolean>;
22
+ export type OnResizeStart = OnResizeHandler;
23
+ export type OnResize = OnResizeHandler<XYResizerParamsWithDirection>;
24
+ export type OnResizeEnd = OnResizeHandler;
25
+ export {};
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/xyresizer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,eAAe,GAAG;IAC3D,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEtE,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,CAAC;AAE9G,oBAAY,oBAAoB;IAC9B,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,2BAA2B,EAAE,eAAe,EAA6D,CAAC;AACvH,eAAO,MAAM,yBAAyB,EAAE,mBAAmB,EAAuC,CAAC;AAEnG,KAAK,eAAe,CAAC,MAAM,GAAG,eAAe,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AACnH,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,cAAc,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;AAEjF,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;AAClF,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,4BAA4B,CAAC,CAAC;AACrE,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { getPointerPosition } from '../utils';
2
+ import { ControlPosition } from './types';
3
+ type GetResizeDirectionParams = {
4
+ width: number;
5
+ prevWidth: number;
6
+ height: number;
7
+ prevHeight: number;
8
+ affectsX: boolean;
9
+ affectsY: boolean;
10
+ };
11
+ /**
12
+ * Get all connecting edges for a given set of nodes
13
+ * @param width - new width of the node
14
+ * @param prevWidth - previous width of the node
15
+ * @param height - new height of the node
16
+ * @param prevHeight - previous height of the node
17
+ * @param affectsX - whether to invert the resize direction for the x axis
18
+ * @param affectsY - whether to invert the resize direction for the y axis
19
+ * @returns array of two numbers representing the direction of the resize for each axis, 0 = no change, 1 = increase, -1 = decrease
20
+ */
21
+ export declare function getResizeDirection({ width, prevWidth, height, prevHeight, affectsX, affectsY, }: GetResizeDirectionParams): number[];
22
+ /**
23
+ * Parses the control position that is being dragged to dimensions that are being resized
24
+ * @param controlPosition - position of the control that is being dragged
25
+ * @returns isHorizontal, isVertical, affectsX, affectsY,
26
+ */
27
+ export declare function getControlDirection(controlPosition: ControlPosition): {
28
+ isHorizontal: boolean;
29
+ isVertical: boolean;
30
+ affectsX: boolean;
31
+ affectsY: boolean;
32
+ };
33
+ type PrevValues = {
34
+ width: number;
35
+ height: number;
36
+ x: number;
37
+ y: number;
38
+ };
39
+ type StartValues = PrevValues & {
40
+ pointerX: number;
41
+ pointerY: number;
42
+ aspectRatio: number;
43
+ };
44
+ /**
45
+ * Calculates new width & height of node after resize based on pointer position
46
+ * @param startValues - starting values of resize
47
+ * @param controlDirection - dimensions affected by the resize
48
+ * @param pointerPosition - the current pointer position corrected for snapping
49
+ * @param boundaries - minimum and maximum dimensions of the node
50
+ * @param keepAspectRatio - prevent changes of asprect ratio
51
+ * @returns width: new width of node, height: new height of node
52
+ */
53
+ export declare function getDimensionsAfterResize(startValues: StartValues, controlDirection: ReturnType<typeof getControlDirection>, pointerPosition: ReturnType<typeof getPointerPosition>, boundaries: {
54
+ minWidth: number;
55
+ maxWidth: number;
56
+ minHeight: number;
57
+ maxHeight: number;
58
+ }, keepAspectRatio: boolean): {
59
+ width: number;
60
+ height: number;
61
+ };
62
+ /**
63
+ * Determines new x & y position of node after resize based on new width & height
64
+ * @param startValues - starting values of resize
65
+ * @param controlDirection - dimensions affected by the resize
66
+ * @param width - new width of node
67
+ * @param height - new height of node
68
+ * @returns x: new x position of node, y: new y position of node
69
+ */
70
+ export declare function getPositionAfterResize(startValues: StartValues, controlDirection: ReturnType<typeof getControlDirection>, width: number, height: number): {
71
+ x: number;
72
+ y: number;
73
+ };
74
+ export {};
75
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/xyresizer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,SAAS,EACT,MAAM,EACN,UAAU,EACV,QAAQ,EACR,QAAQ,GACT,EAAE,wBAAwB,YAc1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,eAAe;;;;;EAYnE;AAED,KAAK,UAAU,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,KAAK,WAAW,GAAG,UAAU,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,EACxD,eAAe,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EACtD,UAAU,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EACxF,eAAe,EAAE,OAAO;;;EA2CzB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,EACxD,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;;;EAMf"}
@@ -5,4 +5,5 @@ export * from './xydrag';
5
5
  export * from './xyhandle';
6
6
  export * from './xyminimap';
7
7
  export * from './xypanzoom';
8
+ export * from './xyresizer';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}