@statelyai/flow 0.9.0 → 0.9.1
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/esm/index.d.ts +14 -0
- package/dist/esm/index.js +84 -0
- package/package.json +1 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -742,6 +742,10 @@ type EntityOrderOptions = {
|
|
|
742
742
|
type EdgePathOptions = {
|
|
743
743
|
graph?: FlowStoreContext['graph'];
|
|
744
744
|
};
|
|
745
|
+
type PaintZIndices = {
|
|
746
|
+
nodes: Map<string, number>;
|
|
747
|
+
edges: Map<string, number>;
|
|
748
|
+
};
|
|
745
749
|
/**
|
|
746
750
|
* Create the framework-agnostic derived-geometry and query layer for a store.
|
|
747
751
|
*
|
|
@@ -1513,6 +1517,16 @@ declare function createFlowEngine(store: FlowStore, initialOptions?: FlowEngineO
|
|
|
1513
1517
|
nodes: FlowNode[];
|
|
1514
1518
|
edges: FlowEdge[];
|
|
1515
1519
|
};
|
|
1520
|
+
/**
|
|
1521
|
+
* CSS z-indices for the visible entity set. Base values are spaced by 2.
|
|
1522
|
+
* When `elevateOnSelect` allows an entity kind, a selected entity is
|
|
1523
|
+
* raised just above its own depth/zIndex band while remaining below the
|
|
1524
|
+
* next band, so a selected parent never paints over its descendants.
|
|
1525
|
+
* Multiple selected entities in one band tie; the renderer's DOM order
|
|
1526
|
+
* resolves the tie and matches core's elevated order. The result is
|
|
1527
|
+
* memoized per store snapshot so callers can compare it by identity.
|
|
1528
|
+
*/
|
|
1529
|
+
getPaintZIndices: (options?: EntityOrderOptions) => PaintZIndices;
|
|
1516
1530
|
/**
|
|
1517
1531
|
* Renderable (visible, optionally viewport-culled) entities. Memoized per
|
|
1518
1532
|
* (store snapshot, cull/overscan) so several render layers can share one
|
package/dist/esm/index.js
CHANGED
|
@@ -3096,6 +3096,21 @@ function createEventObject(type, event) {
|
|
|
3096
3096
|
function isExplicitlyVisibleNode(node) {
|
|
3097
3097
|
return !node.hidden;
|
|
3098
3098
|
}
|
|
3099
|
+
/**
|
|
3100
|
+
* A collapsed group hides its descendants: they are not selectable and do not
|
|
3101
|
+
* contribute to any group's derived selection geometry. Mirrors the engine's
|
|
3102
|
+
* `isHiddenByCollapsedAncestor`.
|
|
3103
|
+
*/
|
|
3104
|
+
function isHiddenByCollapsedAncestor(ctx, nodeId) {
|
|
3105
|
+
if (ctx.collapsedNodeIds.size === 0) return false;
|
|
3106
|
+
const nodeIndex = indexNodes(ctx.graph.nodes);
|
|
3107
|
+
let parentId = nodeIndex.get(nodeId)?.parentId;
|
|
3108
|
+
while (parentId) {
|
|
3109
|
+
if (ctx.collapsedNodeIds.has(parentId)) return true;
|
|
3110
|
+
parentId = nodeIndex.get(parentId)?.parentId;
|
|
3111
|
+
}
|
|
3112
|
+
return false;
|
|
3113
|
+
}
|
|
3099
3114
|
function isDescendantOf(nodes, nodeId, ancestorId) {
|
|
3100
3115
|
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
3101
3116
|
let parentId = byId.get(nodeId)?.parentId;
|
|
@@ -3130,6 +3145,7 @@ function entitiesInBox(ctx, rect) {
|
|
|
3130
3145
|
const nodes = ctx.graph.nodes;
|
|
3131
3146
|
for (const node of nodes) {
|
|
3132
3147
|
if (!isExplicitlyVisibleNode(node)) continue;
|
|
3148
|
+
if (isHiddenByCollapsedAncestor(ctx, node.id)) continue;
|
|
3133
3149
|
if (test(rect, nodeSelectionBounds(ctx, node))) ids.add(node.id);
|
|
3134
3150
|
}
|
|
3135
3151
|
for (const edge of ctx.graph.edges) {
|
|
@@ -3169,6 +3185,7 @@ function groupGeometryForSelection(ctx, node, visiting) {
|
|
|
3169
3185
|
};
|
|
3170
3186
|
for (const child of ctx.graph.nodes) {
|
|
3171
3187
|
if (child.parentId !== node.id || !isExplicitlyVisibleNode(child)) continue;
|
|
3188
|
+
if (isHiddenByCollapsedAncestor(ctx, child.id)) continue;
|
|
3172
3189
|
addBounds(child.group && !nextVisiting.has(child.id) ? groupGeometryForSelection(ctx, child, nextVisiting).bounds : resolvedBounds(child));
|
|
3173
3190
|
}
|
|
3174
3191
|
const nodeIndex = indexNodes(ctx.graph.nodes);
|
|
@@ -5019,6 +5036,7 @@ function createFlowEngine(store, initialOptions = {}) {
|
|
|
5019
5036
|
let renderableCache = /* @__PURE__ */ new WeakMap();
|
|
5020
5037
|
let entityOrderCache = null;
|
|
5021
5038
|
let baseEntityOrderCache = null;
|
|
5039
|
+
let paintZIndicesCache = /* @__PURE__ */ new WeakMap();
|
|
5022
5040
|
let entityRankCache = null;
|
|
5023
5041
|
let renderableSpatialIndex = null;
|
|
5024
5042
|
let graphBoundsCache = null;
|
|
@@ -5085,6 +5103,7 @@ function createFlowEngine(store, initialOptions = {}) {
|
|
|
5085
5103
|
renderableCache = /* @__PURE__ */ new WeakMap();
|
|
5086
5104
|
entityOrderCache = null;
|
|
5087
5105
|
baseEntityOrderCache = null;
|
|
5106
|
+
paintZIndicesCache = /* @__PURE__ */ new WeakMap();
|
|
5088
5107
|
entityRankCache = null;
|
|
5089
5108
|
renderableSpatialIndex = null;
|
|
5090
5109
|
graphBoundsCache = null;
|
|
@@ -6385,6 +6404,61 @@ function createFlowEngine(store, initialOptions = {}) {
|
|
|
6385
6404
|
else baseEntityOrderCache = nextCache;
|
|
6386
6405
|
return value;
|
|
6387
6406
|
}
|
|
6407
|
+
function getPaintZIndicesFor(c, options = {}) {
|
|
6408
|
+
const elevateSelected = options.elevateSelected ?? true;
|
|
6409
|
+
const cacheKey = `${optionsVersion}:${elevateSelected}`;
|
|
6410
|
+
const snapshotCache = paintZIndicesCache.get(c);
|
|
6411
|
+
const cached = snapshotCache?.get(cacheKey);
|
|
6412
|
+
if (cached) return cached;
|
|
6413
|
+
const baseOrder = getEntityOrderFor(c, { elevateSelected: false });
|
|
6414
|
+
const depths = nodeDepths(c.graph.nodes);
|
|
6415
|
+
const visibleNodes = baseOrder.nodes.filter((node) => isNodeVisible(node, c));
|
|
6416
|
+
const visibleEdges = baseOrder.edges.filter((edge) => isEdgeVisible(edge, c.graph, c));
|
|
6417
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
6418
|
+
const edges = /* @__PURE__ */ new Map();
|
|
6419
|
+
for (let start = 0; start < visibleNodes.length;) {
|
|
6420
|
+
const first = visibleNodes[start];
|
|
6421
|
+
const depth = depths.get(first.id) ?? 0;
|
|
6422
|
+
const zIndex = first.zIndex ?? 0;
|
|
6423
|
+
let end = start + 1;
|
|
6424
|
+
while (end < visibleNodes.length) {
|
|
6425
|
+
const node = visibleNodes[end];
|
|
6426
|
+
if ((depths.get(node.id) ?? 0) !== depth || (node.zIndex ?? 0) !== zIndex) break;
|
|
6427
|
+
end++;
|
|
6428
|
+
}
|
|
6429
|
+
const elevatedZIndex = 2 * (end - 1) + 1;
|
|
6430
|
+
for (let index = start; index < end; index++) {
|
|
6431
|
+
const node = visibleNodes[index];
|
|
6432
|
+
nodes.set(node.id, elevateSelected && selectedBoostEnabled("node") && c.selection.has(node.id) ? elevatedZIndex : 2 * index);
|
|
6433
|
+
}
|
|
6434
|
+
start = end;
|
|
6435
|
+
}
|
|
6436
|
+
for (let start = 0; start < visibleEdges.length;) {
|
|
6437
|
+
const first = visibleEdges[start];
|
|
6438
|
+
const depth = Math.max(depths.get(first.sourceId) ?? 0, depths.get(first.targetId) ?? 0);
|
|
6439
|
+
const zIndex = first.zIndex ?? 0;
|
|
6440
|
+
let end = start + 1;
|
|
6441
|
+
while (end < visibleEdges.length) {
|
|
6442
|
+
const edge = visibleEdges[end];
|
|
6443
|
+
if (Math.max(depths.get(edge.sourceId) ?? 0, depths.get(edge.targetId) ?? 0) !== depth || (edge.zIndex ?? 0) !== zIndex) break;
|
|
6444
|
+
end++;
|
|
6445
|
+
}
|
|
6446
|
+
const elevatedZIndex = 2 * (end - 1) + 1;
|
|
6447
|
+
for (let index = start; index < end; index++) {
|
|
6448
|
+
const edge = visibleEdges[index];
|
|
6449
|
+
edges.set(edge.id, elevateSelected && selectedBoostEnabled("edge") && c.selection.has(edge.id) ? elevatedZIndex : 2 * index);
|
|
6450
|
+
}
|
|
6451
|
+
start = end;
|
|
6452
|
+
}
|
|
6453
|
+
const value = {
|
|
6454
|
+
nodes,
|
|
6455
|
+
edges
|
|
6456
|
+
};
|
|
6457
|
+
const nextSnapshotCache = snapshotCache ?? /* @__PURE__ */ new Map();
|
|
6458
|
+
nextSnapshotCache.set(cacheKey, value);
|
|
6459
|
+
if (!snapshotCache) paintZIndicesCache.set(c, nextSnapshotCache);
|
|
6460
|
+
return value;
|
|
6461
|
+
}
|
|
6388
6462
|
function getPublicVisualBounds(nodeOrId) {
|
|
6389
6463
|
const node = typeof nodeOrId === "string" ? getNode(nodeOrId) : nodeOrId;
|
|
6390
6464
|
if (!node) return {
|
|
@@ -6632,6 +6706,16 @@ function createFlowEngine(store, initialOptions = {}) {
|
|
|
6632
6706
|
/** Deterministic paint order. Later items should paint above earlier ones. */
|
|
6633
6707
|
getEntityOrder: (options = {}) => getEntityOrderFor(ctx(), options),
|
|
6634
6708
|
/**
|
|
6709
|
+
* CSS z-indices for the visible entity set. Base values are spaced by 2.
|
|
6710
|
+
* When `elevateOnSelect` allows an entity kind, a selected entity is
|
|
6711
|
+
* raised just above its own depth/zIndex band while remaining below the
|
|
6712
|
+
* next band, so a selected parent never paints over its descendants.
|
|
6713
|
+
* Multiple selected entities in one band tie; the renderer's DOM order
|
|
6714
|
+
* resolves the tie and matches core's elevated order. The result is
|
|
6715
|
+
* memoized per store snapshot so callers can compare it by identity.
|
|
6716
|
+
*/
|
|
6717
|
+
getPaintZIndices: (options = {}) => getPaintZIndicesFor(ctx(), options),
|
|
6718
|
+
/**
|
|
6635
6719
|
* Renderable (visible, optionally viewport-culled) entities. Memoized per
|
|
6636
6720
|
* (store snapshot, cull/overscan) so several render layers can share one
|
|
6637
6721
|
* computation per frame. Treat the result as read-only.
|