@aiready/components 0.14.3 → 0.14.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/components",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"description": "Unified shared components library (UI, charts, hooks, utilities) for AIReady",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"framer-motion": "^12.35.0",
|
|
129
129
|
"lucide-react": "^0.577.0",
|
|
130
130
|
"tailwind-merge": "^3.0.0",
|
|
131
|
-
"@aiready/core": "0.24.
|
|
131
|
+
"@aiready/core": "0.24.5"
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
134
134
|
"@testing-library/jest-dom": "^6.6.5",
|
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
seedCircularPositions,
|
|
11
11
|
safelyStopSimulation,
|
|
12
12
|
} from './simulation-helpers';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
SIMULATION_DEFAULTS,
|
|
15
|
+
FORCE_NAMES,
|
|
16
|
+
EVENT_NAMES,
|
|
17
|
+
} from './simulation-constants';
|
|
14
18
|
import type {
|
|
15
19
|
SimulationNode,
|
|
16
20
|
SimulationLink,
|
|
@@ -62,7 +66,10 @@ export function useForceSimulation(
|
|
|
62
66
|
const [isRunning, setIsRunning] = useState(false);
|
|
63
67
|
const [alpha, setAlpha] = useState(1);
|
|
64
68
|
|
|
65
|
-
const simulationRef = useRef<d3.Simulation<
|
|
69
|
+
const simulationRef = useRef<d3.Simulation<
|
|
70
|
+
SimulationNode,
|
|
71
|
+
SimulationLink
|
|
72
|
+
> | null>(null);
|
|
66
73
|
const stopTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
67
74
|
const forcesEnabledRef = useRef(true);
|
|
68
75
|
const originalForcesRef = useRef({
|
|
@@ -74,8 +81,14 @@ export function useForceSimulation(
|
|
|
74
81
|
const nodesKey = initialNodes.map((n) => n.id).join('|');
|
|
75
82
|
const linksKey = initialLinks
|
|
76
83
|
.map((l) => {
|
|
77
|
-
const sourceId =
|
|
78
|
-
|
|
84
|
+
const sourceId =
|
|
85
|
+
typeof l.source === 'string'
|
|
86
|
+
? l.source
|
|
87
|
+
: (l.source as SimulationNode)?.id;
|
|
88
|
+
const targetId =
|
|
89
|
+
typeof l.target === 'string'
|
|
90
|
+
? l.target
|
|
91
|
+
: (l.target as SimulationNode)?.id;
|
|
79
92
|
const linkType = (l as any).type || '';
|
|
80
93
|
return `${sourceId}->${targetId}:${linkType}`;
|
|
81
94
|
})
|
|
@@ -91,11 +104,16 @@ export function useForceSimulation(
|
|
|
91
104
|
try {
|
|
92
105
|
seedCircularPositions(nodesCopy, width, height);
|
|
93
106
|
} catch (error) {
|
|
94
|
-
console.warn(
|
|
107
|
+
console.warn(
|
|
108
|
+
'AIReady: Position seeding failed, using random fallback:',
|
|
109
|
+
error
|
|
110
|
+
);
|
|
95
111
|
seedRandomPositions(nodesCopy, width, height);
|
|
96
112
|
}
|
|
97
113
|
|
|
98
|
-
const simulation = d3.forceSimulation<SimulationNode, SimulationLink>(
|
|
114
|
+
const simulation = d3.forceSimulation<SimulationNode, SimulationLink>(
|
|
115
|
+
nodesCopy
|
|
116
|
+
);
|
|
99
117
|
applySimulationForces(simulation, linksCopy);
|
|
100
118
|
configureSimulationParameters(simulation);
|
|
101
119
|
|
|
@@ -144,13 +162,25 @@ export function useForceSimulation(
|
|
|
144
162
|
simulation
|
|
145
163
|
.force(FORCE_NAMES.LINK, linkForce)
|
|
146
164
|
.force(FORCE_NAMES.CHARGE, d3.forceManyBody().strength(chargeStrength))
|
|
147
|
-
.force(
|
|
165
|
+
.force(
|
|
166
|
+
FORCE_NAMES.CENTER,
|
|
167
|
+
d3.forceCenter(width / 2, height / 2).strength(centerStrength)
|
|
168
|
+
)
|
|
148
169
|
.force(
|
|
149
170
|
FORCE_NAMES.COLLISION,
|
|
150
|
-
d3
|
|
171
|
+
d3
|
|
172
|
+
.forceCollide<SimulationNode>()
|
|
173
|
+
.radius((d) => (d.size ?? 10) + collisionRadius)
|
|
174
|
+
.strength(collisionStrength)
|
|
175
|
+
)
|
|
176
|
+
.force(
|
|
177
|
+
FORCE_NAMES.X,
|
|
178
|
+
d3.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))
|
|
151
179
|
)
|
|
152
|
-
.force(
|
|
153
|
-
|
|
180
|
+
.force(
|
|
181
|
+
FORCE_NAMES.Y,
|
|
182
|
+
d3.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5))
|
|
183
|
+
);
|
|
154
184
|
} catch (error) {
|
|
155
185
|
console.warn('AIReady: Failed to configure simulation forces:', error);
|
|
156
186
|
}
|
|
@@ -159,7 +189,9 @@ export function useForceSimulation(
|
|
|
159
189
|
/**
|
|
160
190
|
* Configures simulation decay and heat parameters
|
|
161
191
|
*/
|
|
162
|
-
const configureSimulationParameters = (
|
|
192
|
+
const configureSimulationParameters = (
|
|
193
|
+
simulation: d3.Simulation<SimulationNode, SimulationLink>
|
|
194
|
+
) => {
|
|
163
195
|
simulation
|
|
164
196
|
.alphaDecay(alphaDecay)
|
|
165
197
|
.velocityDecay(velocityDecay)
|
|
@@ -182,7 +214,9 @@ export function useForceSimulation(
|
|
|
182
214
|
|
|
183
215
|
if (maxSimulationTimeMs > 0) {
|
|
184
216
|
stopTimeoutRef.current = setTimeout(() => {
|
|
185
|
-
safelyStopSimulation(simulation, nodesCopy, {
|
|
217
|
+
safelyStopSimulation(simulation, nodesCopy, {
|
|
218
|
+
stabilize: stabilizeOnStop,
|
|
219
|
+
});
|
|
186
220
|
updateStateAfterStop(nodesCopy, linksCopy, 0);
|
|
187
221
|
}, maxSimulationTimeMs);
|
|
188
222
|
}
|
|
@@ -222,7 +256,9 @@ export function useForceSimulation(
|
|
|
222
256
|
|
|
223
257
|
const currentAlpha = simulation.alpha();
|
|
224
258
|
if (currentAlpha <= alphaMin) {
|
|
225
|
-
safelyStopSimulation(simulation, nodesCopy, {
|
|
259
|
+
safelyStopSimulation(simulation, nodesCopy, {
|
|
260
|
+
stabilize: stabilizeOnStop,
|
|
261
|
+
});
|
|
226
262
|
updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);
|
|
227
263
|
return;
|
|
228
264
|
}
|
|
@@ -244,7 +280,10 @@ export function useForceSimulation(
|
|
|
244
280
|
rafState: { rafId: number | null; lastUpdate: number }
|
|
245
281
|
) => {
|
|
246
282
|
const now = Date.now();
|
|
247
|
-
if (
|
|
283
|
+
if (
|
|
284
|
+
rafState.rafId === null &&
|
|
285
|
+
now - rafState.lastUpdate >= tickThrottleMs
|
|
286
|
+
) {
|
|
248
287
|
rafState.rafId = requestAnimationFrame(() => {
|
|
249
288
|
rafState.rafId = null;
|
|
250
289
|
rafState.lastUpdate = Date.now();
|
|
@@ -305,28 +344,36 @@ export function useForceSimulation(
|
|
|
305
344
|
/**
|
|
306
345
|
* Enable or disable simulation forces
|
|
307
346
|
*/
|
|
308
|
-
const setForcesEnabled = useCallback(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
347
|
+
const setForcesEnabled = useCallback(
|
|
348
|
+
(enabled: boolean) => {
|
|
349
|
+
const sim = simulationRef.current;
|
|
350
|
+
if (!sim || forcesEnabledRef.current === enabled) return;
|
|
351
|
+
|
|
352
|
+
forcesEnabledRef.current = enabled;
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
const charge = sim.force(
|
|
356
|
+
FORCE_NAMES.CHARGE
|
|
357
|
+
) as d3.ForceManyBody<SimulationNode> | null;
|
|
358
|
+
if (charge) {
|
|
359
|
+
charge.strength(enabled ? originalForcesRef.current.charge : 0);
|
|
360
|
+
}
|
|
313
361
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
362
|
+
const link = sim.force(FORCE_NAMES.LINK) as d3.ForceLink<
|
|
363
|
+
SimulationNode,
|
|
364
|
+
SimulationLink
|
|
365
|
+
> | null;
|
|
366
|
+
if (link) {
|
|
367
|
+
link.strength(enabled ? originalForcesRef.current.link : 0);
|
|
368
|
+
}
|
|
319
369
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
370
|
+
sim.alpha(warmAlpha).restart();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.warn('AIReady: Failed to toggle simulation forces:', error);
|
|
323
373
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
console.warn('AIReady: Failed to toggle simulation forces:', error);
|
|
328
|
-
}
|
|
329
|
-
}, [warmAlpha]);
|
|
374
|
+
},
|
|
375
|
+
[warmAlpha]
|
|
376
|
+
);
|
|
330
377
|
|
|
331
378
|
return {
|
|
332
379
|
nodes,
|
|
@@ -342,7 +389,9 @@ export function useForceSimulation(
|
|
|
342
389
|
/**
|
|
343
390
|
* Hook for creating a draggable force simulation
|
|
344
391
|
*/
|
|
345
|
-
export function useDrag(
|
|
392
|
+
export function useDrag(
|
|
393
|
+
simulation: d3.Simulation<SimulationNode, any> | null | undefined
|
|
394
|
+
) {
|
|
346
395
|
const handleDragStart = useCallback(
|
|
347
396
|
(event: any, node: SimulationNode) => {
|
|
348
397
|
if (!simulation) return;
|