@principal-ai/subsystems-react 0.56.21 → 0.56.23
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/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts +12 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.d.ts.map +1 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js +4 -0
- package/dist/stories/Canvases/Aggregate/aggregateViewLargeFixture.js.map +1 -0
- package/dist/subsystem/C4Graph.d.ts +2 -69
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +8 -154
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +1 -47
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +6 -141
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/ContainersPanel.d.ts +33 -0
- package/dist/subsystem/ContainersPanel.d.ts.map +1 -0
- package/dist/subsystem/ContainersPanel.js +116 -0
- package/dist/subsystem/ContainersPanel.js.map +1 -0
- package/dist/subsystem/SubsystemAggregateGraph.d.ts +14 -0
- package/dist/subsystem/SubsystemAggregateGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemAggregateGraph.js +116 -69
- package/dist/subsystem/SubsystemAggregateGraph.js.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts +18 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +143 -21
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/dist/subsystem/containerCard.d.ts +132 -0
- package/dist/subsystem/containerCard.d.ts.map +1 -0
- package/dist/subsystem/containerCard.js +167 -0
- package/dist/subsystem/containerCard.js.map +1 -0
- package/dist/subsystem/graphChrome.d.ts +11 -8
- package/dist/subsystem/graphChrome.d.ts.map +1 -1
- package/dist/subsystem/graphChrome.js +11 -9
- package/dist/subsystem/graphChrome.js.map +1 -1
- package/dist/subsystem/graphMorph.d.ts +142 -0
- package/dist/subsystem/graphMorph.d.ts.map +1 -0
- package/dist/subsystem/graphMorph.js +177 -0
- package/dist/subsystem/graphMorph.js.map +1 -0
- package/dist/subsystem/model.d.ts +89 -0
- package/dist/subsystem/model.d.ts.map +1 -1
- package/dist/subsystem/model.js +224 -15
- package/dist/subsystem/model.js.map +1 -1
- package/dist/subsystem/nodes.d.ts +9 -3
- package/dist/subsystem/nodes.d.ts.map +1 -1
- package/dist/subsystem/nodes.js +134 -82
- package/dist/subsystem/nodes.js.map +1 -1
- package/dist/utils/elkLayout.d.ts +11 -0
- package/dist/utils/elkLayout.d.ts.map +1 -1
- package/dist/utils/elkLayout.js +4 -3
- package/dist/utils/elkLayout.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/stories/Canvases/Aggregate/AggregateFrameGraph.stories.tsx +140 -2
- package/src/stories/Canvases/Aggregate/aggregateViewLargeFixture.ts +14 -0
- package/src/stories/Canvases/Subsystem/ContainerFrames.stories.tsx +132 -0
- package/src/subsystem/C4Graph.tsx +20 -180
- package/src/subsystem/C4NodeCard.tsx +34 -202
- package/src/subsystem/ContainersPanel.tsx +239 -0
- package/src/subsystem/SubsystemAggregateGraph.tsx +146 -78
- package/src/subsystem/SubsystemComponentGraph.tsx +222 -25
- package/src/subsystem/containerCard.tsx +264 -0
- package/src/subsystem/graphChrome.tsx +11 -9
- package/src/subsystem/graphMorph.tsx +212 -0
- package/src/subsystem/model.collapse.test.ts +128 -0
- package/src/subsystem/model.ts +306 -16
- package/src/subsystem/nodes.group.test.tsx +125 -16
- package/src/subsystem/nodes.tsx +201 -91
- package/src/utils/elkLayout.ts +16 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregateViewLargeFixture.js","sourceRoot":"","sources":["../../../../src/stories/Canvases/Aggregate/aggregateViewLargeFixture.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,oBAAoB,GAAyB,IAAI,CAAC,KAAK,CAAC,w5nHAAw5nH,CAAC,CAAC;AAE/9nH,MAAM,CAAC,MAAM,mBAAmB,GAAyB,IAAI,CAAC,KAAK,CAAC,gu8HAAgu8H,CAAC,CAAC;AAEty8H,MAAM,CAAC,MAAM,kBAAkB,GAAmB,IAAI,CAAC,KAAK,CAAC,8vLAA8vL,CAAC,CAAC"}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
import type { ReactNode } from 'react';
|
|
14
14
|
import type { CompoundGroupDef, ElkLayoutResult } from '../utils/elkLayout';
|
|
15
15
|
import { type C4Group } from './c4';
|
|
16
|
+
export { absoluteRectOf, shouldRefitCamera } from './graphMorph';
|
|
17
|
+
export type { FlowRect, FrameGrow } from './graphMorph';
|
|
16
18
|
import type { C4Edge, C4Model, C4TrailRef } from './c4';
|
|
17
19
|
import type { SubsystemComponent, SubsystemTrail } from './model';
|
|
18
20
|
/**
|
|
@@ -172,75 +174,6 @@ export interface C4GraphProps {
|
|
|
172
174
|
}
|
|
173
175
|
/** Containers frame their contents; an overview also includes outside actors/systems. */
|
|
174
176
|
export declare function c4CameraNodeIds(model: C4Model, targetIds?: string | readonly string[] | null): string[];
|
|
175
|
-
/** Flow-space rect of a box node or a frame, for the drill-down morph. */
|
|
176
|
-
export interface FlowRect {
|
|
177
|
-
x: number;
|
|
178
|
-
y: number;
|
|
179
|
-
width: number;
|
|
180
|
-
height: number;
|
|
181
|
-
}
|
|
182
|
-
/** A frame's growth for the drill-down morph: its flow rect before → after. */
|
|
183
|
-
export interface FrameGrow {
|
|
184
|
-
from: FlowRect;
|
|
185
|
-
to: FlowRect;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* A node's rect in **absolute** flow space, walking the parent chain.
|
|
189
|
-
*
|
|
190
|
-
* `groupBounds` is already absolute; a leaf's `position` is relative to its
|
|
191
|
-
* parent, so each ancestor's origin is added in turn.
|
|
192
|
-
*
|
|
193
|
-
* The FLIP needs absolute rects, not parent-relative ones. React Flow places a
|
|
194
|
-
* node at its new absolute position (parent origin + relative position) and
|
|
195
|
-
* moves children along with the parent's *wrapper* — while our FLIP transform
|
|
196
|
-
* lives on the node's inner div, which the children do not inherit. So a node's
|
|
197
|
-
* own transform must cover its full absolute delta; rebasing it to the parent
|
|
198
|
-
* would leave it short by exactly the parent's movement (the "subtle drift"
|
|
199
|
-
* before a leaving box disappears).
|
|
200
|
-
*/
|
|
201
|
-
export declare function absoluteRectOf(layout: {
|
|
202
|
-
nodes: ReadonlyArray<{
|
|
203
|
-
id: string;
|
|
204
|
-
position: {
|
|
205
|
-
x: number;
|
|
206
|
-
y: number;
|
|
207
|
-
};
|
|
208
|
-
parentId?: string;
|
|
209
|
-
width?: number | null;
|
|
210
|
-
height?: number | null;
|
|
211
|
-
}>;
|
|
212
|
-
groupBounds: Map<string, {
|
|
213
|
-
x: number;
|
|
214
|
-
y: number;
|
|
215
|
-
width: number;
|
|
216
|
-
height: number;
|
|
217
|
-
}>;
|
|
218
|
-
}, id: string): FlowRect | null;
|
|
219
|
-
/**
|
|
220
|
-
* Whether committing a layout should also move the camera.
|
|
221
|
-
*
|
|
222
|
-
* A morph — a commit that has rects to FLIP from — must not. Every element
|
|
223
|
-
* already on screen is sliding from the rect the reader last saw it at, and that
|
|
224
|
-
* anchoring *is* the morph; a viewport move on top of it makes each card's
|
|
225
|
-
* on-screen path the sum of two independent animations, so nothing lands where
|
|
226
|
-
* the FLIP said it would. `CAMERA_MS` also outlasts `MORPH_MS`, so the camera
|
|
227
|
-
* would still be drifting for 100ms after the cards had settled — which is what
|
|
228
|
-
* reads as the cards "still moving".
|
|
229
|
-
*
|
|
230
|
-
* A commit with no `grows` is a genuine change: the first paint, a new system, a
|
|
231
|
-
* different element set, or the grid fallback after an ELK failure. There is no
|
|
232
|
-
* continuity to preserve there and the content may genuinely not be on screen, so
|
|
233
|
-
* fit.
|
|
234
|
-
*
|
|
235
|
-
* An *empty* map fits for the same reason — no element is anchoring, so there is
|
|
236
|
-
* nothing a camera move could contradict. Testing the size rather than the
|
|
237
|
-
* identity keeps that total over the whole input domain instead of leaning on a
|
|
238
|
-
* caller convention (`growsFor` happens to hand back `null` rather than an empty
|
|
239
|
-
* map, but nothing forces it to).
|
|
240
|
-
*
|
|
241
|
-
* @param grows the rects to animate from, exactly as `injectGrow` received them.
|
|
242
|
-
*/
|
|
243
|
-
export declare function shouldRefitCamera(grows: Map<string, FrameGrow> | null): boolean;
|
|
244
177
|
/**
|
|
245
178
|
* Whether a card shows its description line.
|
|
246
179
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"C4Graph.d.ts","sourceRoot":"","sources":["../../src/subsystem/C4Graph.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,OAAO,CAAC;AAiBrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"C4Graph.d.ts","sourceRoot":"","sources":["../../src/subsystem/C4Graph.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,OAAO,CAAC;AAiBrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AA6BnE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGxD,OAAO,KAA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
21
21
|
import { C4NodeCard, COMPONENT_FOOTER_PAD, COMPONENT_HEADER_PAD, COMPONENT_W, NODE_H, NODE_W, OPEN_FOOTER_PAD, OPEN_HEADER_PAD, OPEN_SIDE_PAD, nodeSize, nodeStyle, } from './C4NodeCard';
|
|
22
22
|
import { TechMark, technologyBrand } from './techIcons';
|
|
23
|
+
import { absoluteRectOf, diffLayoutRects, FADE_MS, MORPH_MS, shouldRefitCamera, useFade, useFlip, useMorphStyle, } from './graphMorph';
|
|
24
|
+
// The morph vocabulary moved to `graphMorph` so the component graph can share
|
|
25
|
+
// it; re-exported here for callers written against this module.
|
|
26
|
+
export { absoluteRectOf, shouldRefitCamera } from './graphMorph';
|
|
23
27
|
import { GRAPH_CANVAS_CLASS, GRAPH_NAV_PROPS, GraphChrome, GraphLayerStyle } from './graphChrome';
|
|
24
28
|
import { openContainerSet, openStateKey } from './c4';
|
|
25
29
|
import { EDGE_DIM_ALPHA, hexWithAlpha, SubsystemCallbacksProvider, SubsystemComponentNode, SubsystemEdge, } from './nodes';
|
|
@@ -347,20 +351,8 @@ function C4GroupView(props) {
|
|
|
347
351
|
*/
|
|
348
352
|
const SubsystemNode = SubsystemComponentNode;
|
|
349
353
|
function C4SubsystemNodeView(props) {
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
const sliding = flipping && (dx !== 0 || dy !== 0);
|
|
353
|
-
const fade = useFade(entering, leaving);
|
|
354
|
-
const transitions = [
|
|
355
|
-
...(fade.transition ? [fade.transition] : []),
|
|
356
|
-
...(sliding && placed ? [`transform ${MORPH_MS}ms ease-out ${moveDelayMs}ms`] : []),
|
|
357
|
-
];
|
|
358
|
-
return (_jsx("div", { style: {
|
|
359
|
-
transformOrigin: 'top left',
|
|
360
|
-
transform: sliding && !placed ? `translate(${dx}px, ${dy}px)` : 'none',
|
|
361
|
-
transition: transitions.length > 0 ? transitions.join(', ') : 'none',
|
|
362
|
-
opacity: fade.opacity,
|
|
363
|
-
}, children: _jsx(SubsystemNode, { ...props }) }));
|
|
354
|
+
const morph = useMorphStyle(props.data);
|
|
355
|
+
return (_jsx("div", { style: morph, children: _jsx(SubsystemNode, { ...props }) }));
|
|
364
356
|
}
|
|
365
357
|
const nodeTypes = {
|
|
366
358
|
'c4-node': C4NodeView,
|
|
@@ -374,16 +366,8 @@ const edgeTypes = {
|
|
|
374
366
|
'c4-edge': C4EdgeView,
|
|
375
367
|
'subsystem-edge': SubsystemEdge,
|
|
376
368
|
};
|
|
377
|
-
/**
|
|
378
|
-
const MORPH_MS = 420;
|
|
369
|
+
/** Camera re-frame duration, in ms. The morph's own clocks live in `graphMorph`. */
|
|
379
370
|
const CAMERA_MS = 520;
|
|
380
|
-
/**
|
|
381
|
-
* How long cards arriving or leaving take to fade, in ms. The morph is
|
|
382
|
-
* sequenced: the fade runs first, and the surviving cards wait it out before
|
|
383
|
-
* they move and grow (`moveDelayMs` below). So the reveal clock is
|
|
384
|
-
* `FADE_MS + MORPH_MS`, not just `MORPH_MS`.
|
|
385
|
-
*/
|
|
386
|
-
const FADE_MS = 200;
|
|
387
371
|
/**
|
|
388
372
|
* When to re-frame the camera after a drill-down: the sequenced morph (fade,
|
|
389
373
|
* then move), plus a beat.
|
|
@@ -421,62 +405,6 @@ export function c4CameraNodeIds(model, targetIds) {
|
|
|
421
405
|
.map((node) => node.id),
|
|
422
406
|
];
|
|
423
407
|
}
|
|
424
|
-
/**
|
|
425
|
-
* A node's rect in **absolute** flow space, walking the parent chain.
|
|
426
|
-
*
|
|
427
|
-
* `groupBounds` is already absolute; a leaf's `position` is relative to its
|
|
428
|
-
* parent, so each ancestor's origin is added in turn.
|
|
429
|
-
*
|
|
430
|
-
* The FLIP needs absolute rects, not parent-relative ones. React Flow places a
|
|
431
|
-
* node at its new absolute position (parent origin + relative position) and
|
|
432
|
-
* moves children along with the parent's *wrapper* — while our FLIP transform
|
|
433
|
-
* lives on the node's inner div, which the children do not inherit. So a node's
|
|
434
|
-
* own transform must cover its full absolute delta; rebasing it to the parent
|
|
435
|
-
* would leave it short by exactly the parent's movement (the "subtle drift"
|
|
436
|
-
* before a leaving box disappears).
|
|
437
|
-
*/
|
|
438
|
-
export function absoluteRectOf(layout, id) {
|
|
439
|
-
const frame = layout.groupBounds.get(id);
|
|
440
|
-
if (frame)
|
|
441
|
-
return { x: frame.x, y: frame.y, width: frame.width, height: frame.height };
|
|
442
|
-
const node = layout.nodes.find((n) => n.id === id);
|
|
443
|
-
if (!node)
|
|
444
|
-
return null;
|
|
445
|
-
const origin = node.parentId ? absoluteRectOf(layout, node.parentId) : null;
|
|
446
|
-
return {
|
|
447
|
-
x: (origin?.x ?? 0) + node.position.x,
|
|
448
|
-
y: (origin?.y ?? 0) + node.position.y,
|
|
449
|
-
width: node.width ?? 0,
|
|
450
|
-
height: node.height ?? 0,
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Whether committing a layout should also move the camera.
|
|
455
|
-
*
|
|
456
|
-
* A morph — a commit that has rects to FLIP from — must not. Every element
|
|
457
|
-
* already on screen is sliding from the rect the reader last saw it at, and that
|
|
458
|
-
* anchoring *is* the morph; a viewport move on top of it makes each card's
|
|
459
|
-
* on-screen path the sum of two independent animations, so nothing lands where
|
|
460
|
-
* the FLIP said it would. `CAMERA_MS` also outlasts `MORPH_MS`, so the camera
|
|
461
|
-
* would still be drifting for 100ms after the cards had settled — which is what
|
|
462
|
-
* reads as the cards "still moving".
|
|
463
|
-
*
|
|
464
|
-
* A commit with no `grows` is a genuine change: the first paint, a new system, a
|
|
465
|
-
* different element set, or the grid fallback after an ELK failure. There is no
|
|
466
|
-
* continuity to preserve there and the content may genuinely not be on screen, so
|
|
467
|
-
* fit.
|
|
468
|
-
*
|
|
469
|
-
* An *empty* map fits for the same reason — no element is anchoring, so there is
|
|
470
|
-
* nothing a camera move could contradict. Testing the size rather than the
|
|
471
|
-
* identity keeps that total over the whole input domain instead of leaning on a
|
|
472
|
-
* caller convention (`growsFor` happens to hand back `null` rather than an empty
|
|
473
|
-
* map, but nothing forces it to).
|
|
474
|
-
*
|
|
475
|
-
* @param grows the rects to animate from, exactly as `injectGrow` received them.
|
|
476
|
-
*/
|
|
477
|
-
export function shouldRefitCamera(grows) {
|
|
478
|
-
return !grows || grows.size === 0;
|
|
479
|
-
}
|
|
480
408
|
/**
|
|
481
409
|
* Whether a card shows its description line.
|
|
482
410
|
*
|
|
@@ -620,59 +548,6 @@ export function c4GroupDefs(model, openIds, constructGraphByContainer) {
|
|
|
620
548
|
}
|
|
621
549
|
return { frames, groups };
|
|
622
550
|
}
|
|
623
|
-
/**
|
|
624
|
-
* FLIP between two absolute flow rects: render transformed back onto `from`,
|
|
625
|
-
* then release onto `to`.
|
|
626
|
-
*
|
|
627
|
-
* The step back **must** happen while rendering, not in an effect. An effect runs
|
|
628
|
-
* after the browser has already painted, so the element is painted at its new
|
|
629
|
-
* position for one frame and only then jumps back — a visible teleport, which is
|
|
630
|
-
* the exact thing this hook exists to remove. Adjusting state during render lets
|
|
631
|
-
* React apply the transform in the same commit, so the new position is never
|
|
632
|
-
* painted untransformed.
|
|
633
|
-
*
|
|
634
|
-
* The rects are keyed by value: `injectGrow` mints fresh objects each layout, so
|
|
635
|
-
* comparing identity would re-fire the whole morph on unrelated re-renders.
|
|
636
|
-
*/
|
|
637
|
-
function useFlip(from, to) {
|
|
638
|
-
const key = from && to ? `${from.x},${from.y},${to.x},${to.y}` : '';
|
|
639
|
-
const [lastKey, setLastKey] = useState(key);
|
|
640
|
-
const [placed, setPlaced] = useState(!key);
|
|
641
|
-
if (key !== lastKey) {
|
|
642
|
-
setLastKey(key);
|
|
643
|
-
setPlaced(false);
|
|
644
|
-
}
|
|
645
|
-
useEffect(() => {
|
|
646
|
-
if (!key)
|
|
647
|
-
return;
|
|
648
|
-
const raf = requestAnimationFrame(() => setPlaced(true));
|
|
649
|
-
return () => cancelAnimationFrame(raf);
|
|
650
|
-
}, [key]);
|
|
651
|
-
return {
|
|
652
|
-
flipping: key !== '',
|
|
653
|
-
placed,
|
|
654
|
-
dx: from && to ? from.x - to.x : 0,
|
|
655
|
-
dy: from && to ? from.y - to.y : 0,
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* Opacity for a card arriving or leaving the layout. An arriving card mounts
|
|
660
|
-
* hidden and fades in; a leaving card is kept (out of the new layout) for the
|
|
661
|
-
* morph, then fades out — a removal reads as a fade, not a pop.
|
|
662
|
-
*/
|
|
663
|
-
function useFade(entering, leaving) {
|
|
664
|
-
const animate = entering === true || leaving === true;
|
|
665
|
-
const [shown, setShown] = useState(entering !== true);
|
|
666
|
-
useEffect(() => {
|
|
667
|
-
if (!animate)
|
|
668
|
-
return;
|
|
669
|
-
const raf = requestAnimationFrame(() => setShown(leaving !== true));
|
|
670
|
-
return () => cancelAnimationFrame(raf);
|
|
671
|
-
}, [animate, entering, leaving]);
|
|
672
|
-
if (!animate)
|
|
673
|
-
return { opacity: 1, transition: undefined };
|
|
674
|
-
return { opacity: shown ? 1 : 0, transition: `opacity ${FADE_MS}ms ease` };
|
|
675
|
-
}
|
|
676
551
|
/**
|
|
677
552
|
* Whether a nested component is withheld while the diagram is mid-morph.
|
|
678
553
|
*
|
|
@@ -1299,28 +1174,7 @@ function Inner({ model, containerFocus, selectedNodeId, selectedEdgeId: controll
|
|
|
1299
1174
|
const prevLayout = layoutCache.current.get(prevCacheKey);
|
|
1300
1175
|
if (!prevLayout)
|
|
1301
1176
|
return null;
|
|
1302
|
-
|
|
1303
|
-
const cardIds = (l) => l.nodes.map((n) => n.id);
|
|
1304
|
-
const ids = new Set([
|
|
1305
|
-
...prevLayout.groupBounds.keys(),
|
|
1306
|
-
...next.groupBounds.keys(),
|
|
1307
|
-
...cardIds(prevLayout),
|
|
1308
|
-
...cardIds(next),
|
|
1309
|
-
]);
|
|
1310
|
-
for (const id of ids) {
|
|
1311
|
-
const fromRect = absoluteRectOf(prevLayout, id);
|
|
1312
|
-
const to = absoluteRectOf(next, id);
|
|
1313
|
-
if (!fromRect || !to)
|
|
1314
|
-
continue;
|
|
1315
|
-
if (fromRect.x === to.x &&
|
|
1316
|
-
fromRect.y === to.y &&
|
|
1317
|
-
fromRect.width === to.width &&
|
|
1318
|
-
fromRect.height === to.height) {
|
|
1319
|
-
continue;
|
|
1320
|
-
}
|
|
1321
|
-
grows.set(id, { from: fromRect, to });
|
|
1322
|
-
}
|
|
1323
|
-
return grows.size > 0 ? grows : null;
|
|
1177
|
+
return diffLayoutRects(prevLayout, next);
|
|
1324
1178
|
};
|
|
1325
1179
|
// Commit a new layout: keep the survivors gliding (FLIP), fade in cards the
|
|
1326
1180
|
// previous layout did not have, and hold the previous layout's orphans for
|