@aiready/components 0.14.3 → 0.14.5
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/charts/ForceDirectedGraph.js.map +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/hooks/useForceSimulation.js +46 -23
- package/dist/hooks/useForceSimulation.js.map +1 -1
- package/dist/index.js +46 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/charts/force-directed/useGraphInteractions.ts +2 -2
- package/src/charts/force-directed/useImperativeHandle.ts +1 -1
- package/src/components/__tests__/badge.test.tsx +38 -0
- package/src/components/__tests__/button.test.tsx +54 -0
- package/src/components/__tests__/card.test.tsx +56 -17
- package/src/components/__tests__/checkbox.test.tsx +28 -58
- package/src/components/__tests__/container.test.tsx +44 -51
- package/src/components/__tests__/grid.test.tsx +27 -134
- package/src/components/__tests__/input.test.tsx +35 -20
- package/src/components/__tests__/label.test.tsx +29 -35
- package/src/components/__tests__/modal.test.tsx +43 -72
- package/src/components/__tests__/select.test.tsx +51 -84
- package/src/components/__tests__/separator.test.tsx +23 -56
- package/src/components/__tests__/switch.test.tsx +28 -68
- package/src/components/__tests__/textarea.test.tsx +29 -77
- package/src/hooks/useForceSimulation.ts +85 -36
package/dist/index.js
CHANGED
|
@@ -2165,10 +2165,15 @@ function useForceSimulation(initialNodes, initialLinks, options) {
|
|
|
2165
2165
|
try {
|
|
2166
2166
|
seedCircularPositions(nodesCopy, width, height);
|
|
2167
2167
|
} catch (error) {
|
|
2168
|
-
console.warn(
|
|
2168
|
+
console.warn(
|
|
2169
|
+
"AIReady: Position seeding failed, using random fallback:",
|
|
2170
|
+
error
|
|
2171
|
+
);
|
|
2169
2172
|
seedRandomPositions(nodesCopy, width, height);
|
|
2170
2173
|
}
|
|
2171
|
-
const simulation = d32.forceSimulation(
|
|
2174
|
+
const simulation = d32.forceSimulation(
|
|
2175
|
+
nodesCopy
|
|
2176
|
+
);
|
|
2172
2177
|
applySimulationForces(simulation, linksCopy);
|
|
2173
2178
|
configureSimulationParameters(simulation);
|
|
2174
2179
|
simulationRef.current = simulation;
|
|
@@ -2198,10 +2203,19 @@ function useForceSimulation(initialNodes, initialLinks, options) {
|
|
|
2198
2203
|
const applySimulationForces = (simulation, linksCopy) => {
|
|
2199
2204
|
try {
|
|
2200
2205
|
const linkForce = d32.forceLink(linksCopy).id((d) => d.id).distance((d) => d.distance ?? linkDistance).strength(linkStrength);
|
|
2201
|
-
simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d32.forceManyBody().strength(chargeStrength)).force(
|
|
2206
|
+
simulation.force(FORCE_NAMES.LINK, linkForce).force(FORCE_NAMES.CHARGE, d32.forceManyBody().strength(chargeStrength)).force(
|
|
2207
|
+
FORCE_NAMES.CENTER,
|
|
2208
|
+
d32.forceCenter(width / 2, height / 2).strength(centerStrength)
|
|
2209
|
+
).force(
|
|
2202
2210
|
FORCE_NAMES.COLLISION,
|
|
2203
2211
|
d32.forceCollide().radius((d) => (d.size ?? 10) + collisionRadius).strength(collisionStrength)
|
|
2204
|
-
).force(
|
|
2212
|
+
).force(
|
|
2213
|
+
FORCE_NAMES.X,
|
|
2214
|
+
d32.forceX(width / 2).strength(Math.max(0.02, centerStrength * 0.5))
|
|
2215
|
+
).force(
|
|
2216
|
+
FORCE_NAMES.Y,
|
|
2217
|
+
d32.forceY(height / 2).strength(Math.max(0.02, centerStrength * 0.5))
|
|
2218
|
+
);
|
|
2205
2219
|
} catch (error) {
|
|
2206
2220
|
console.warn("AIReady: Failed to configure simulation forces:", error);
|
|
2207
2221
|
}
|
|
@@ -2215,7 +2229,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
|
|
|
2215
2229
|
}
|
|
2216
2230
|
if (maxSimulationTimeMs > 0) {
|
|
2217
2231
|
stopTimeoutRef.current = setTimeout(() => {
|
|
2218
|
-
safelyStopSimulation(simulation, nodesCopy, {
|
|
2232
|
+
safelyStopSimulation(simulation, nodesCopy, {
|
|
2233
|
+
stabilize: stabilizeOnStop
|
|
2234
|
+
});
|
|
2219
2235
|
updateStateAfterStop(nodesCopy, linksCopy, 0);
|
|
2220
2236
|
}, maxSimulationTimeMs);
|
|
2221
2237
|
}
|
|
@@ -2237,7 +2253,9 @@ function useForceSimulation(initialNodes, initialLinks, options) {
|
|
|
2237
2253
|
}
|
|
2238
2254
|
const currentAlpha = simulation.alpha();
|
|
2239
2255
|
if (currentAlpha <= alphaMin) {
|
|
2240
|
-
safelyStopSimulation(simulation, nodesCopy, {
|
|
2256
|
+
safelyStopSimulation(simulation, nodesCopy, {
|
|
2257
|
+
stabilize: stabilizeOnStop
|
|
2258
|
+
});
|
|
2241
2259
|
updateStateAfterStop(nodesCopy, linksCopy, currentAlpha);
|
|
2242
2260
|
return;
|
|
2243
2261
|
}
|
|
@@ -2289,24 +2307,29 @@ function useForceSimulation(initialNodes, initialLinks, options) {
|
|
|
2289
2307
|
setIsRunning(false);
|
|
2290
2308
|
}
|
|
2291
2309
|
}, []);
|
|
2292
|
-
const setForcesEnabled = useCallback(
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2310
|
+
const setForcesEnabled = useCallback(
|
|
2311
|
+
(enabled) => {
|
|
2312
|
+
const sim = simulationRef.current;
|
|
2313
|
+
if (!sim || forcesEnabledRef.current === enabled) return;
|
|
2314
|
+
forcesEnabledRef.current = enabled;
|
|
2315
|
+
try {
|
|
2316
|
+
const charge = sim.force(
|
|
2317
|
+
FORCE_NAMES.CHARGE
|
|
2318
|
+
);
|
|
2319
|
+
if (charge) {
|
|
2320
|
+
charge.strength(enabled ? originalForcesRef.current.charge : 0);
|
|
2321
|
+
}
|
|
2322
|
+
const link = sim.force(FORCE_NAMES.LINK);
|
|
2323
|
+
if (link) {
|
|
2324
|
+
link.strength(enabled ? originalForcesRef.current.link : 0);
|
|
2325
|
+
}
|
|
2326
|
+
sim.alpha(warmAlpha).restart();
|
|
2327
|
+
} catch (error) {
|
|
2328
|
+
console.warn("AIReady: Failed to toggle simulation forces:", error);
|
|
2304
2329
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
}
|
|
2309
|
-
}, [warmAlpha]);
|
|
2330
|
+
},
|
|
2331
|
+
[warmAlpha]
|
|
2332
|
+
);
|
|
2310
2333
|
return {
|
|
2311
2334
|
nodes,
|
|
2312
2335
|
links,
|