irr-gh 0.1.33 → 0.1.34

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/irr-gh.js CHANGED
@@ -19039,6 +19039,10 @@ class UF {
19039
19039
  lastRenderTime = 0;
19040
19040
  RENDER_THROTTLE = 16;
19041
19041
  // ~60fps
19042
+ /** 待更新的 Group ID 集合,用于批量节流 */
19043
+ pendingGroups = /* @__PURE__ */ new Set();
19044
+ /** 待更新时是否同时更新位置(由首次调用决定) */
19045
+ pendingUpdatePosition = !1;
19042
19046
  /** nodeId → groupId[] 反向索引 */
19043
19047
  nodeToGroups = /* @__PURE__ */ new Map();
19044
19048
  /** groupId → expandedNodeSet 缓存 */
@@ -19087,7 +19091,7 @@ class UF {
19087
19091
  * 销毁控制器,解绑所有事件
19088
19092
  */
19089
19093
  destroy() {
19090
- this.renderTimer && (clearTimeout(this.renderTimer), this.renderTimer = null), this.unbindEvents(), this.graph = null, this.groups = [], this.edgesForCalc = [], this.nodeToGroups.clear(), this.groupExpandedNodes.clear();
19094
+ this.renderTimer && (clearTimeout(this.renderTimer), this.renderTimer = null), this.pendingGroups.clear(), this.unbindEvents(), this.graph = null, this.groups = [], this.edgesForCalc = [], this.nodeToGroups.clear(), this.groupExpandedNodes.clear();
19091
19095
  }
19092
19096
  /**
19093
19097
  * 构建反向索引和扩展节点集合缓存
@@ -19113,33 +19117,71 @@ class UF {
19113
19117
  */
19114
19118
  bindEvents() {
19115
19119
  this.graph && (this.dragHandler = (t) => {
19116
- const e = t?.target?.id;
19117
- e && this.nodeToGroups.has(e) && this.throttledUpdate(e, !1);
19120
+ const e = t?.target?.id, r = this.getEffectiveNodeIds(e);
19121
+ if (r.length === 0) return;
19122
+ const n = this.getGroupIdsForNodes(r);
19123
+ for (const i of n)
19124
+ this.throttledUpdateForGroup(i, !1);
19118
19125
  }, this.dragEndHandler = (t) => {
19119
- const e = t?.target?.id;
19120
- e && this.nodeToGroups.has(e) && this.updateAffectedGroups(e, !1);
19126
+ const e = t?.target?.id, r = this.getEffectiveNodeIds(e);
19127
+ if (r.length === 0) return;
19128
+ const n = this.getGroupIdsForNodes(r);
19129
+ for (const i of n)
19130
+ this.updateBufferNode(i, !1);
19121
19131
  }, this.graph.on("node:drag", this.dragHandler), this.graph.on("node:dragend", this.dragEndHandler));
19122
19132
  }
19123
19133
  /**
19124
- * 节流更新
19134
+ * 获取图内所有选中节点的 ID 列表
19135
+ */
19136
+ getSelectedNodeIds() {
19137
+ if (!this.graph) return [];
19138
+ try {
19139
+ return (this.graph.getElementDataByState?.("node", "selected") || []).map((e) => e.id);
19140
+ } catch {
19141
+ return [];
19142
+ }
19143
+ }
19144
+ /**
19145
+ * 获取应参与缓冲区更新的有效节点 ID 列表
19146
+ * = 选中节点 ∪ 直接拖拽节点(处理未选中直接拖拽的场景)
19147
+ */
19148
+ getEffectiveNodeIds(t) {
19149
+ const e = new Set(this.getSelectedNodeIds());
19150
+ return t && e.add(t), [...e];
19151
+ }
19152
+ /**
19153
+ * 根据节点 ID 列表,获取受影响的 Group ID 集合(去重)
19154
+ */
19155
+ getGroupIdsForNodes(t) {
19156
+ const e = /* @__PURE__ */ new Set();
19157
+ for (const r of t) {
19158
+ const n = this.nodeToGroups.get(r);
19159
+ if (n)
19160
+ for (const i of n)
19161
+ e.add(i);
19162
+ }
19163
+ return e;
19164
+ }
19165
+ /**
19166
+ * 对单个 Group 执行节流更新(批量收集,统一刷新)
19125
19167
  * @param updatePosition 是否同时更新 buffer 节点位置
19126
19168
  */
19127
- throttledUpdate(t, e) {
19169
+ throttledUpdateForGroup(t, e) {
19170
+ this.pendingGroups.add(t), this.pendingUpdatePosition = e;
19128
19171
  const r = Date.now(), n = r - this.lastRenderTime;
19129
- n >= this.RENDER_THROTTLE ? (this.lastRenderTime = r, this.updateAffectedGroups(t, e)) : (this.renderTimer && clearTimeout(this.renderTimer), this.renderTimer = window.setTimeout(() => {
19130
- this.lastRenderTime = Date.now(), this.updateAffectedGroups(t, e);
19172
+ n >= this.RENDER_THROTTLE ? (this.lastRenderTime = r, this.flushPendingGroups()) : (this.renderTimer && clearTimeout(this.renderTimer), this.renderTimer = window.setTimeout(() => {
19173
+ this.lastRenderTime = Date.now(), this.flushPendingGroups();
19131
19174
  }, this.RENDER_THROTTLE - n));
19132
19175
  }
19133
19176
  /**
19134
- * 更新被拖拽节点所影响的所有 Group 的 buffer-polygon 节点
19135
- * @param updatePosition 是否同时更新 buffer 节点位置
19177
+ * 批量执行所有待更新 Group 的 buffer 节点刷新
19136
19178
  */
19137
- updateAffectedGroups(t, e) {
19138
- if (!this.graph) return;
19139
- const r = this.nodeToGroups.get(t);
19140
- if (!(!r || r.length === 0))
19141
- for (const n of r)
19142
- this.updateBufferNode(n, e);
19179
+ flushPendingGroups() {
19180
+ if (this.pendingGroups.size === 0) return;
19181
+ const t = this.pendingUpdatePosition;
19182
+ for (const e of this.pendingGroups)
19183
+ this.updateBufferNode(e, t);
19184
+ this.pendingGroups.clear();
19143
19185
  }
19144
19186
  /**
19145
19187
  * 重新计算并更新单个 Group 的 buffer-polygon 节点