@flowgram.ai/free-auto-layout-plugin 0.2.16 → 0.2.18

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.mts CHANGED
@@ -140,12 +140,18 @@ declare namespace dagreLib {
140
140
  export { reversePointsForReversedEdges };
141
141
  }
142
142
 
143
+ /**
144
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
145
+ * SPDX-License-Identifier: MIT
146
+ */
147
+
143
148
  declare class LayoutStore {
144
149
  readonly config: LayoutConfig;
145
150
  private indexMap;
146
151
  private init;
147
152
  private store;
148
153
  private container;
154
+ options: LayoutOptions;
149
155
  constructor(config: LayoutConfig);
150
156
  get initialized(): boolean;
151
157
  getNode(id?: string): LayoutNode | undefined;
@@ -153,7 +159,7 @@ declare class LayoutStore {
153
159
  getEdge(id: string): LayoutEdge | undefined;
154
160
  get nodes(): LayoutNode[];
155
161
  get edges(): LayoutEdge[];
156
- create(params: LayoutParams): void;
162
+ create(params: LayoutParams, options: LayoutOptions): void;
157
163
  /** 创建布局数据 */
158
164
  private createStore;
159
165
  /** 创建节点布局数据 */
@@ -166,8 +172,17 @@ declare class LayoutStore {
166
172
  private createIndexMap;
167
173
  /** 节点排序 */
168
174
  private sortNodes;
175
+ /** 记录运行选项 */
176
+ private setOptions;
177
+ /** 设置跟随节点配置 */
178
+ private setFollowNode;
169
179
  }
170
180
 
181
+ /**
182
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
183
+ * SPDX-License-Identifier: MIT
184
+ */
185
+
171
186
  interface LayoutNode {
172
187
  id: string;
173
188
  /** 节点索引 */
@@ -222,6 +237,7 @@ interface LayoutParams {
222
237
  }
223
238
  interface LayoutOptions {
224
239
  getFollowNode?: GetFollowNode;
240
+ enableAnimation: boolean;
225
241
  }
226
242
  interface LayoutConfig {
227
243
  /** Direction for rank nodes. Can be TB, BT, LR, or RL, where T = top, B = bottom, L = left, and R = right. */
@@ -251,30 +267,49 @@ type GetFollowNode = (node: LayoutNode, context: {
251
267
  followTo?: string;
252
268
  } | undefined;
253
269
 
270
+ /**
271
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
272
+ * SPDX-License-Identifier: MIT
273
+ */
274
+
254
275
  interface AutoLayoutOptions {
255
276
  layoutConfig?: Partial<LayoutConfig>;
256
277
  }
257
278
 
258
279
  declare const createFreeAutoLayoutPlugin: _flowgram_ai_core.PluginCreator<AutoLayoutOptions>;
259
280
 
281
+ /**
282
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
283
+ * SPDX-License-Identifier: MIT
284
+ */
285
+
260
286
  declare class Layout {
261
287
  private readonly _store;
262
288
  private readonly _layout;
263
289
  private readonly _position;
264
290
  constructor(config: LayoutConfig);
265
- init(params: LayoutParams, options?: LayoutOptions): void;
291
+ init(params: LayoutParams, options: LayoutOptions): void;
266
292
  layout(): void;
267
293
  position(): Promise<void>;
268
- setFollowNode(getFollowNode?: GetFollowNode): void;
269
294
  }
270
295
 
296
+ /**
297
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
298
+ * SPDX-License-Identifier: MIT
299
+ */
300
+
271
301
  declare const DefaultLayoutConfig: LayoutConfig;
272
302
 
303
+ /**
304
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
305
+ * SPDX-License-Identifier: MIT
306
+ */
307
+
273
308
  declare class AutoLayoutService {
274
309
  private readonly document;
275
310
  private layoutConfig;
276
311
  init(options: AutoLayoutOptions): void;
277
- layout(options?: LayoutOptions): Promise<void>;
312
+ layout(options?: Partial<LayoutOptions>): Promise<void>;
278
313
  private layoutNode;
279
314
  private getNodesAllLines;
280
315
  }
package/dist/index.d.ts CHANGED
@@ -140,12 +140,18 @@ declare namespace dagreLib {
140
140
  export { reversePointsForReversedEdges };
141
141
  }
142
142
 
143
+ /**
144
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
145
+ * SPDX-License-Identifier: MIT
146
+ */
147
+
143
148
  declare class LayoutStore {
144
149
  readonly config: LayoutConfig;
145
150
  private indexMap;
146
151
  private init;
147
152
  private store;
148
153
  private container;
154
+ options: LayoutOptions;
149
155
  constructor(config: LayoutConfig);
150
156
  get initialized(): boolean;
151
157
  getNode(id?: string): LayoutNode | undefined;
@@ -153,7 +159,7 @@ declare class LayoutStore {
153
159
  getEdge(id: string): LayoutEdge | undefined;
154
160
  get nodes(): LayoutNode[];
155
161
  get edges(): LayoutEdge[];
156
- create(params: LayoutParams): void;
162
+ create(params: LayoutParams, options: LayoutOptions): void;
157
163
  /** 创建布局数据 */
158
164
  private createStore;
159
165
  /** 创建节点布局数据 */
@@ -166,8 +172,17 @@ declare class LayoutStore {
166
172
  private createIndexMap;
167
173
  /** 节点排序 */
168
174
  private sortNodes;
175
+ /** 记录运行选项 */
176
+ private setOptions;
177
+ /** 设置跟随节点配置 */
178
+ private setFollowNode;
169
179
  }
170
180
 
181
+ /**
182
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
183
+ * SPDX-License-Identifier: MIT
184
+ */
185
+
171
186
  interface LayoutNode {
172
187
  id: string;
173
188
  /** 节点索引 */
@@ -222,6 +237,7 @@ interface LayoutParams {
222
237
  }
223
238
  interface LayoutOptions {
224
239
  getFollowNode?: GetFollowNode;
240
+ enableAnimation: boolean;
225
241
  }
226
242
  interface LayoutConfig {
227
243
  /** Direction for rank nodes. Can be TB, BT, LR, or RL, where T = top, B = bottom, L = left, and R = right. */
@@ -251,30 +267,49 @@ type GetFollowNode = (node: LayoutNode, context: {
251
267
  followTo?: string;
252
268
  } | undefined;
253
269
 
270
+ /**
271
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
272
+ * SPDX-License-Identifier: MIT
273
+ */
274
+
254
275
  interface AutoLayoutOptions {
255
276
  layoutConfig?: Partial<LayoutConfig>;
256
277
  }
257
278
 
258
279
  declare const createFreeAutoLayoutPlugin: _flowgram_ai_core.PluginCreator<AutoLayoutOptions>;
259
280
 
281
+ /**
282
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
283
+ * SPDX-License-Identifier: MIT
284
+ */
285
+
260
286
  declare class Layout {
261
287
  private readonly _store;
262
288
  private readonly _layout;
263
289
  private readonly _position;
264
290
  constructor(config: LayoutConfig);
265
- init(params: LayoutParams, options?: LayoutOptions): void;
291
+ init(params: LayoutParams, options: LayoutOptions): void;
266
292
  layout(): void;
267
293
  position(): Promise<void>;
268
- setFollowNode(getFollowNode?: GetFollowNode): void;
269
294
  }
270
295
 
296
+ /**
297
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
298
+ * SPDX-License-Identifier: MIT
299
+ */
300
+
271
301
  declare const DefaultLayoutConfig: LayoutConfig;
272
302
 
303
+ /**
304
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
305
+ * SPDX-License-Identifier: MIT
306
+ */
307
+
273
308
  declare class AutoLayoutService {
274
309
  private readonly document;
275
310
  private layoutConfig;
276
311
  init(options: AutoLayoutOptions): void;
277
- layout(options?: LayoutOptions): Promise<void>;
312
+ layout(options?: Partial<LayoutOptions>): Promise<void>;
278
313
  private layoutNode;
279
314
  private getNodesAllLines;
280
315
  }
package/dist/index.js CHANGED
@@ -2111,6 +2111,23 @@ var import_core2 = require("@flowgram.ai/core");
2111
2111
  var import_inversify = require("inversify");
2112
2112
  var import_free_layout_core2 = require("@flowgram.ai/free-layout-core");
2113
2113
 
2114
+ // src/layout/constant.ts
2115
+ var DefaultLayoutConfig = {
2116
+ rankdir: "LR",
2117
+ align: void 0,
2118
+ nodesep: 100,
2119
+ edgesep: 10,
2120
+ ranksep: 100,
2121
+ marginx: 0,
2122
+ marginy: 0,
2123
+ acyclicer: void 0,
2124
+ ranker: "network-simplex"
2125
+ };
2126
+ var DefaultLayoutOptions = {
2127
+ getFollowNode: void 0,
2128
+ enableAnimation: false
2129
+ };
2130
+
2114
2131
  // src/layout/store.ts
2115
2132
  var import_free_layout_core = require("@flowgram.ai/free-layout-core");
2116
2133
  var import_document = require("@flowgram.ai/document");
@@ -2141,9 +2158,10 @@ var LayoutStore = class {
2141
2158
  get edges() {
2142
2159
  return Array.from(this.store.edges.values());
2143
2160
  }
2144
- create(params) {
2161
+ create(params, options) {
2145
2162
  this.store = this.createStore(params);
2146
2163
  this.indexMap = this.createIndexMap();
2164
+ this.setOptions(options);
2147
2165
  this.init = true;
2148
2166
  }
2149
2167
  /** 创建布局数据 */
@@ -2333,6 +2351,27 @@ var LayoutStore = class {
2333
2351
  }, []);
2334
2352
  return uniqueNodeIds;
2335
2353
  }
2354
+ /** 记录运行选项 */
2355
+ setOptions(options) {
2356
+ this.options = options;
2357
+ this.setFollowNode(options.getFollowNode);
2358
+ }
2359
+ /** 设置跟随节点配置 */
2360
+ setFollowNode(getFollowNode) {
2361
+ if (!getFollowNode) return;
2362
+ const context = { store: this };
2363
+ this.nodes.forEach((node) => {
2364
+ const followTo = getFollowNode(node, context)?.followTo;
2365
+ if (!followTo) return;
2366
+ const followToNode = this.getNode(followTo);
2367
+ if (!followToNode) return;
2368
+ if (!followToNode.followedBy) {
2369
+ followToNode.followedBy = [];
2370
+ }
2371
+ followToNode.followedBy.push(node.id);
2372
+ node.followTo = followTo;
2373
+ });
2374
+ }
2336
2375
  };
2337
2376
 
2338
2377
  // src/layout/position.ts
@@ -2342,6 +2381,17 @@ var LayoutPosition = class {
2342
2381
  this.store = store;
2343
2382
  }
2344
2383
  async position() {
2384
+ if (this.store.options.enableAnimation) {
2385
+ return this.positionWithAnimation();
2386
+ }
2387
+ return this.positionDirectly();
2388
+ }
2389
+ positionDirectly() {
2390
+ this.store.nodes.forEach((layoutNode) => {
2391
+ this.updateNodePosition({ layoutNode, step: 100 });
2392
+ });
2393
+ }
2394
+ async positionWithAnimation() {
2345
2395
  return new Promise((resolve) => {
2346
2396
  (0, import_core.startTween)({
2347
2397
  from: { d: 0 },
@@ -2556,9 +2606,8 @@ var Layout = class {
2556
2606
  this._layout = new DagreLayout(this._store);
2557
2607
  this._position = new LayoutPosition(this._store);
2558
2608
  }
2559
- init(params, options = {}) {
2560
- this._store.create(params);
2561
- this.setFollowNode(options.getFollowNode);
2609
+ init(params, options) {
2610
+ this._store.create(params, options);
2562
2611
  }
2563
2612
  layout() {
2564
2613
  if (!this._store.initialized) {
@@ -2572,34 +2621,6 @@ var Layout = class {
2572
2621
  }
2573
2622
  return await this._position.position();
2574
2623
  }
2575
- setFollowNode(getFollowNode) {
2576
- if (!getFollowNode) return;
2577
- const context = { store: this._store };
2578
- this._store.nodes.forEach((node) => {
2579
- const followTo = getFollowNode(node, context)?.followTo;
2580
- if (!followTo) return;
2581
- const followToNode = this._store.getNode(followTo);
2582
- if (!followToNode) return;
2583
- if (!followToNode.followedBy) {
2584
- followToNode.followedBy = [];
2585
- }
2586
- followToNode.followedBy.push(node.id);
2587
- node.followTo = followTo;
2588
- });
2589
- }
2590
- };
2591
-
2592
- // src/layout/constant.ts
2593
- var DefaultLayoutConfig = {
2594
- rankdir: "LR",
2595
- align: void 0,
2596
- nodesep: 100,
2597
- edgesep: 10,
2598
- ranksep: 100,
2599
- marginx: 0,
2600
- marginy: 0,
2601
- acyclicer: void 0,
2602
- ranker: "network-simplex"
2603
2624
  };
2604
2625
 
2605
2626
  // src/services.ts
@@ -2614,7 +2635,10 @@ var AutoLayoutService = class {
2614
2635
  };
2615
2636
  }
2616
2637
  async layout(options = {}) {
2617
- await this.layoutNode(this.document.root, options);
2638
+ await this.layoutNode(this.document.root, {
2639
+ ...DefaultLayoutOptions,
2640
+ ...options
2641
+ });
2618
2642
  }
2619
2643
  async layoutNode(node, options) {
2620
2644
  const nodes = node.blocks;