@carlonicora/nextjs-jsonapi 1.99.0 → 1.100.0

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.
@@ -6460,6 +6460,14 @@ import * as dagre from "dagre";
6460
6460
  var DEFAULT_RANKDIR = "LR";
6461
6461
  var DEFAULT_NODESEP = 50;
6462
6462
  var DEFAULT_RANKSEP = 120;
6463
+ var MIN_NODESEP = 20;
6464
+ var MAX_NODESEP = 400;
6465
+ var MIN_RANKSEP = 40;
6466
+ var MAX_RANKSEP = 600;
6467
+ var MIN_FACTOR = 0.25;
6468
+ var MAX_FACTOR = 4;
6469
+ var DEFAULT_TOLERANCE = 0.05;
6470
+ var DEFAULT_MAX_ITERATIONS = 4;
6463
6471
  var TITLE_PX_PER_CHAR_16 = 8;
6464
6472
  var NAME_PX_PER_CHAR_12 = 6.5;
6465
6473
  var NAME_PX_PER_CHAR_16_BOLD = 8;
@@ -6479,8 +6487,11 @@ function linkEndpointId(end) {
6479
6487
  return typeof end === "string" ? end : end.id;
6480
6488
  }
6481
6489
  __name(linkEndpointId, "linkEndpointId");
6482
- function computeLayeredLayout(nodes, links, opts) {
6483
- if (nodes.length === 0) return /* @__PURE__ */ new Map();
6490
+ function clamp(value, min, max) {
6491
+ return Math.min(Math.max(value, min), max);
6492
+ }
6493
+ __name(clamp, "clamp");
6494
+ function runDagreOnce(nodes, links, opts) {
6484
6495
  const rankdir = opts.rankdir ?? DEFAULT_RANKDIR;
6485
6496
  const nodesep = opts.nodesep ?? DEFAULT_NODESEP;
6486
6497
  const ranksep = opts.ranksep ?? DEFAULT_RANKSEP;
@@ -6508,15 +6519,70 @@ function computeLayeredLayout(nodes, links, opts) {
6508
6519
  return null;
6509
6520
  }
6510
6521
  const positions = /* @__PURE__ */ new Map();
6522
+ let xMin = Infinity;
6523
+ let xMax = -Infinity;
6524
+ let yMin = Infinity;
6525
+ let yMax = -Infinity;
6511
6526
  for (const node of nodes) {
6512
6527
  const laid = g.node(node.id);
6513
6528
  if (laid && Number.isFinite(laid.x) && Number.isFinite(laid.y)) {
6514
6529
  positions.set(node.id, { x: laid.x, y: laid.y });
6530
+ const halfW = (laid.width ?? opts.minNodeWidth) / 2;
6531
+ const halfH = (laid.height ?? opts.minNodeHeight) / 2;
6532
+ xMin = Math.min(xMin, laid.x - halfW);
6533
+ xMax = Math.max(xMax, laid.x + halfW);
6534
+ yMin = Math.min(yMin, laid.y - halfH);
6535
+ yMax = Math.max(yMax, laid.y + halfH);
6515
6536
  }
6516
6537
  }
6517
- return positions;
6538
+ const bbox = positions.size === 0 ? { width: 0, height: 0 } : { width: Math.max(0, xMax - xMin), height: Math.max(0, yMax - yMin) };
6539
+ return { positions, bbox };
6540
+ }
6541
+ __name(runDagreOnce, "runDagreOnce");
6542
+ function computeLayeredLayout(nodes, links, opts) {
6543
+ if (nodes.length === 0) return /* @__PURE__ */ new Map();
6544
+ const result = runDagreOnce(nodes, links, opts);
6545
+ return result ? result.positions : null;
6518
6546
  }
6519
6547
  __name(computeLayeredLayout, "computeLayeredLayout");
6548
+ function fitLayeredLayoutToAspectRatio(nodes, links, opts) {
6549
+ if (nodes.length === 0) return /* @__PURE__ */ new Map();
6550
+ if (!Number.isFinite(opts.targetAspectRatio) || opts.targetAspectRatio <= 0) {
6551
+ return computeLayeredLayout(nodes, links, opts);
6552
+ }
6553
+ const maxIterations = opts.maxIterations ?? DEFAULT_MAX_ITERATIONS;
6554
+ const tolerance = opts.tolerance ?? DEFAULT_TOLERANCE;
6555
+ const rankdir = opts.rankdir ?? DEFAULT_RANKDIR;
6556
+ const isHorizontalFlow = rankdir === "LR" || rankdir === "RL";
6557
+ let nodesep = opts.nodesep ?? DEFAULT_NODESEP;
6558
+ let ranksep = opts.ranksep ?? DEFAULT_RANKSEP;
6559
+ let best = null;
6560
+ for (let i = 0; i < maxIterations; i++) {
6561
+ const result = runDagreOnce(nodes, links, {
6562
+ ...opts,
6563
+ nodesep,
6564
+ ranksep
6565
+ });
6566
+ if (!result) return best ? best.positions : null;
6567
+ best = result;
6568
+ if (result.positions.size <= 1) return result.positions;
6569
+ const { width, height } = result.bbox;
6570
+ if (width === 0 || height === 0) return result.positions;
6571
+ const currentAspect = width / height;
6572
+ const ratio = opts.targetAspectRatio / currentAspect;
6573
+ if (Math.abs(ratio - 1) < tolerance) return result.positions;
6574
+ const factor = clamp(Math.sqrt(ratio), MIN_FACTOR, MAX_FACTOR);
6575
+ if (isHorizontalFlow) {
6576
+ ranksep = clamp(ranksep * factor, MIN_RANKSEP, MAX_RANKSEP);
6577
+ nodesep = clamp(nodesep / factor, MIN_NODESEP, MAX_NODESEP);
6578
+ } else {
6579
+ ranksep = clamp(ranksep / factor, MIN_RANKSEP, MAX_RANKSEP);
6580
+ nodesep = clamp(nodesep * factor, MIN_NODESEP, MAX_NODESEP);
6581
+ }
6582
+ }
6583
+ return best ? best.positions : null;
6584
+ }
6585
+ __name(fitLayeredLayoutToAspectRatio, "fitLayeredLayoutToAspectRatio");
6520
6586
 
6521
6587
  // src/hooks/useCustomD3Graph.tsx
6522
6588
  import { jsx as jsx49 } from "react/jsx-runtime";
@@ -6653,7 +6719,15 @@ function useCustomD3Graph(nodes, links, onNodeClick, visibleNodeIds, options, lo
6653
6719
  let layeredPositionsApplied = false;
6654
6720
  if (layoutMode === "layered") {
6655
6721
  const layeredOpts = options?.layered ?? {};
6656
- const positions = computeLayeredLayout(visibleNodes, visibleLinks, {
6722
+ const useFit = layeredOpts.fitContainer === true && width > 0 && height > 0;
6723
+ const positions = useFit ? fitLayeredLayoutToAspectRatio(visibleNodes, visibleLinks, {
6724
+ rankdir: layeredOpts.rankdir ?? "LR",
6725
+ nodesep: layeredOpts.nodesep,
6726
+ ranksep: layeredOpts.ranksep,
6727
+ minNodeWidth: nodeRadius * 2,
6728
+ minNodeHeight: nodeRadius * 2,
6729
+ targetAspectRatio: width / height
6730
+ }) : computeLayeredLayout(visibleNodes, visibleLinks, {
6657
6731
  rankdir: layeredOpts.rankdir ?? "LR",
6658
6732
  nodesep: layeredOpts.nodesep,
6659
6733
  ranksep: layeredOpts.ranksep,
@@ -6963,6 +7037,7 @@ function useCustomD3Graph(nodes, links, onNodeClick, visibleNodeIds, options, lo
6963
7037
  options?.layered?.rankdir,
6964
7038
  options?.layered?.nodesep,
6965
7039
  options?.layered?.ranksep,
7040
+ options?.layered?.fitContainer,
6966
7041
  loadingNodeIds,
6967
7042
  onNodeClick
6968
7043
  ]);
@@ -9400,7 +9475,7 @@ import { useRef as useRef15 } from "react";
9400
9475
  import dynamic from "next/dynamic";
9401
9476
  import React14 from "react";
9402
9477
  import { jsx as jsx73 } from "react/jsx-runtime";
9403
- var BlockNoteEditor = dynamic(() => import("./BlockNoteEditor-IBV3KBQM.mjs"), {
9478
+ var BlockNoteEditor = dynamic(() => import("./BlockNoteEditor-QH3NPFYN.mjs"), {
9404
9479
  ssr: false
9405
9480
  });
9406
9481
  var BlockNoteEditorContainer = React14.memo(/* @__PURE__ */ __name(function EditorContainer(props) {
@@ -21815,6 +21890,7 @@ export {
21815
21890
  registerTableGenerator,
21816
21891
  useTableGenerator,
21817
21892
  computeLayeredLayout,
21893
+ fitLayeredLayoutToAspectRatio,
21818
21894
  useCustomD3Graph,
21819
21895
  SocketContext,
21820
21896
  SocketProvider,
@@ -22314,4 +22390,4 @@ export {
22314
22390
  useOAuthClients,
22315
22391
  useOAuthClient
22316
22392
  };
22317
- //# sourceMappingURL=chunk-CDNVUON3.mjs.map
22393
+ //# sourceMappingURL=chunk-S34H33HJ.mjs.map