@tscircuit/schematic-viewer 1.1.13 → 1.1.14
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.js +124 -52
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/package.json +1 -1
- package/src/lib/types/core.ts +1 -0
- package/src/lib/utils/collect-element-refs.ts +11 -2
- package/src/schematic-components/SVGPathComponent.tsx +85 -27
- package/src/schematic-components/SchematicPort.tsx +25 -2
package/dist/index.js
CHANGED
|
@@ -120,7 +120,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
120
120
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
121
121
|
}
|
|
122
122
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
123
|
-
var
|
|
123
|
+
var useState5 = React.useState, useEffect4 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
|
|
124
124
|
var didWarnOld18Alpha = false;
|
|
125
125
|
var didWarnUncachedGetSnapshot = false;
|
|
126
126
|
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
@@ -142,7 +142,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
var _useState =
|
|
145
|
+
var _useState = useState5({
|
|
146
146
|
inst: {
|
|
147
147
|
value,
|
|
148
148
|
getSnapshot
|
|
@@ -938,15 +938,19 @@ __export(src_exports, {
|
|
|
938
938
|
module.exports = __toCommonJS(src_exports);
|
|
939
939
|
|
|
940
940
|
// src/Schematic.tsx
|
|
941
|
-
var
|
|
941
|
+
var import_react6 = require("react");
|
|
942
942
|
var import_react_supergrid = require("react-supergrid");
|
|
943
943
|
var import_builder3 = require("@tscircuit/builder");
|
|
944
944
|
var import_react_fiber = require("@tscircuit/react-fiber");
|
|
945
945
|
|
|
946
946
|
// src/lib/utils/collect-element-refs.ts
|
|
947
947
|
var collectElementRefs = (elm, allElms) => {
|
|
948
|
+
const source_port = allElms.find(
|
|
949
|
+
(e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
|
|
950
|
+
);
|
|
951
|
+
const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
|
|
948
952
|
const source_component = allElms.find(
|
|
949
|
-
(e) => e.type === "source_component" && e.source_component_id ===
|
|
953
|
+
(e) => e.type === "source_component" && e.source_component_id === source_component_id
|
|
950
954
|
);
|
|
951
955
|
if ([
|
|
952
956
|
"schematic_component",
|
|
@@ -962,7 +966,9 @@ var collectElementRefs = (elm, allElms) => {
|
|
|
962
966
|
return {
|
|
963
967
|
schematic_children,
|
|
964
968
|
schematic: elm,
|
|
965
|
-
source: source_component
|
|
969
|
+
source: source_component,
|
|
970
|
+
source_component,
|
|
971
|
+
source_port
|
|
966
972
|
};
|
|
967
973
|
}
|
|
968
974
|
return null;
|
|
@@ -1257,8 +1263,16 @@ function getSVGPathBounds(ds) {
|
|
|
1257
1263
|
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
1258
1264
|
|
|
1259
1265
|
// src/schematic-components/SVGPathComponent.tsx
|
|
1266
|
+
var import_react2 = require("react");
|
|
1260
1267
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1261
|
-
var SVGPathComponent = ({
|
|
1268
|
+
var SVGPathComponent = ({
|
|
1269
|
+
size,
|
|
1270
|
+
center,
|
|
1271
|
+
rotation,
|
|
1272
|
+
paths,
|
|
1273
|
+
zIndex,
|
|
1274
|
+
hoverContent
|
|
1275
|
+
}) => {
|
|
1262
1276
|
const ct = useCameraTransform();
|
|
1263
1277
|
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
1264
1278
|
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
@@ -1267,37 +1281,86 @@ var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
|
1267
1281
|
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
1268
1282
|
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
1269
1283
|
const absoluteCenter = applyToPoint(ct, center);
|
|
1284
|
+
const actualAbsWidth = size.width * ct.a;
|
|
1285
|
+
const actualAbsHeight = size.height * ct.d;
|
|
1270
1286
|
const absoluteSize = {
|
|
1271
|
-
width: Math.max(1,
|
|
1272
|
-
height: Math.max(1,
|
|
1287
|
+
width: Math.max(1, actualAbsWidth),
|
|
1288
|
+
height: Math.max(1, actualAbsHeight)
|
|
1273
1289
|
};
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
+
const [hovering, setHovering] = (0, import_react2.useState)(false);
|
|
1291
|
+
const svgLeft = absoluteCenter.x - absoluteSize.width / 2;
|
|
1292
|
+
const svgTop = absoluteCenter.y - absoluteSize.height / 2;
|
|
1293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1294
|
+
hovering && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1296
|
+
"div",
|
|
1297
|
+
{
|
|
1298
|
+
style: {
|
|
1299
|
+
position: "absolute",
|
|
1300
|
+
left: svgLeft - 4,
|
|
1301
|
+
top: svgTop - 4,
|
|
1302
|
+
pointerEvents: "none",
|
|
1303
|
+
width: actualAbsWidth + 8,
|
|
1304
|
+
height: actualAbsHeight + 8,
|
|
1305
|
+
border: "1px red solid",
|
|
1306
|
+
zIndex: 1e3
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
),
|
|
1310
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1311
|
+
"div",
|
|
1290
1312
|
{
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1313
|
+
style: {
|
|
1314
|
+
position: "absolute",
|
|
1315
|
+
left: svgLeft + actualAbsWidth + 10,
|
|
1316
|
+
pointerEvents: "none",
|
|
1317
|
+
zIndex: 1e3,
|
|
1318
|
+
color: "red",
|
|
1319
|
+
top: svgTop,
|
|
1320
|
+
fontFamily: "monospace",
|
|
1321
|
+
fontSize: 14,
|
|
1322
|
+
textShadow: `-1px 1px 0 #fff,
|
|
1323
|
+
1px 1px 0 #fff,
|
|
1324
|
+
1px -1px 0 #fff,
|
|
1325
|
+
-1px -1px 0 #fff`
|
|
1326
|
+
},
|
|
1327
|
+
children: hoverContent
|
|
1328
|
+
}
|
|
1329
|
+
)
|
|
1330
|
+
] }),
|
|
1331
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1332
|
+
"svg",
|
|
1333
|
+
{
|
|
1334
|
+
onMouseOver: () => setHovering(Boolean(hoverContent)),
|
|
1335
|
+
onMouseOut: () => setHovering(false),
|
|
1336
|
+
style: {
|
|
1337
|
+
position: "absolute",
|
|
1338
|
+
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
1339
|
+
cursor: hovering ? "pointer" : void 0,
|
|
1340
|
+
zIndex,
|
|
1341
|
+
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
1342
|
+
left: svgLeft,
|
|
1343
|
+
top: svgTop
|
|
1344
|
+
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.5)" : "transparent",
|
|
1296
1345
|
},
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1346
|
+
overflow: "visible",
|
|
1347
|
+
width: absoluteSize.width,
|
|
1348
|
+
height: absoluteSize.height,
|
|
1349
|
+
viewBox: `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`,
|
|
1350
|
+
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1351
|
+
"path",
|
|
1352
|
+
{
|
|
1353
|
+
fill: p.fill ?? "none",
|
|
1354
|
+
strokeLinecap: "round",
|
|
1355
|
+
strokeWidth: 2 * (p.strokeWidth || 1),
|
|
1356
|
+
stroke: p.stroke || "red",
|
|
1357
|
+
d: p.d
|
|
1358
|
+
},
|
|
1359
|
+
i
|
|
1360
|
+
))
|
|
1361
|
+
}
|
|
1362
|
+
)
|
|
1363
|
+
] });
|
|
1301
1364
|
};
|
|
1302
1365
|
var SVGPathComponent_default = SVGPathComponent;
|
|
1303
1366
|
|
|
@@ -1343,7 +1406,7 @@ var SimpleCapacitor = ({
|
|
|
1343
1406
|
};
|
|
1344
1407
|
|
|
1345
1408
|
// src/lib/hooks/use-maybe-promise.ts
|
|
1346
|
-
var
|
|
1409
|
+
var import_react3 = require("react");
|
|
1347
1410
|
|
|
1348
1411
|
// src/schematic-components/ProjectComponent.tsx
|
|
1349
1412
|
var import_builder = require("@tscircuit/builder");
|
|
@@ -1365,13 +1428,22 @@ var directionToVec = (direction) => {
|
|
|
1365
1428
|
|
|
1366
1429
|
// src/schematic-components/SchematicPort.tsx
|
|
1367
1430
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1368
|
-
var SchematicPort = ({
|
|
1431
|
+
var SchematicPort = ({
|
|
1432
|
+
port: { source_port, source_component, schematic }
|
|
1433
|
+
}) => {
|
|
1434
|
+
const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
|
|
1369
1435
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1370
1436
|
SVGPathComponent,
|
|
1371
1437
|
{
|
|
1372
1438
|
rotation: 0,
|
|
1439
|
+
hoverContent: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1440
|
+
hoverName,
|
|
1441
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
|
|
1442
|
+
source_port?.pin_number && `Pin ${source_port.pin_number}`
|
|
1443
|
+
] }),
|
|
1373
1444
|
center: schematic.center,
|
|
1374
1445
|
size: { width: 0.2, height: 0.2 },
|
|
1446
|
+
zIndex: 10,
|
|
1375
1447
|
paths: [
|
|
1376
1448
|
{
|
|
1377
1449
|
stroke: "blue",
|
|
@@ -1390,7 +1462,7 @@ var SchematicPort = ({ port: { source, schematic } }) => {
|
|
|
1390
1462
|
var SchematicPort_default = SchematicPort;
|
|
1391
1463
|
|
|
1392
1464
|
// node_modules/react-use-measure/dist/web.js
|
|
1393
|
-
var
|
|
1465
|
+
var import_react4 = require("react");
|
|
1394
1466
|
var import_debounce = __toESM(require_debounce());
|
|
1395
1467
|
function useMeasure(_temp) {
|
|
1396
1468
|
let {
|
|
@@ -1408,7 +1480,7 @@ function useMeasure(_temp) {
|
|
|
1408
1480
|
if (!ResizeObserver) {
|
|
1409
1481
|
throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
|
|
1410
1482
|
}
|
|
1411
|
-
const [bounds, set] = (0,
|
|
1483
|
+
const [bounds, set] = (0, import_react4.useState)({
|
|
1412
1484
|
left: 0,
|
|
1413
1485
|
top: 0,
|
|
1414
1486
|
width: 0,
|
|
@@ -1418,7 +1490,7 @@ function useMeasure(_temp) {
|
|
|
1418
1490
|
x: 0,
|
|
1419
1491
|
y: 0
|
|
1420
1492
|
});
|
|
1421
|
-
const state = (0,
|
|
1493
|
+
const state = (0, import_react4.useRef)({
|
|
1422
1494
|
element: null,
|
|
1423
1495
|
scrollContainers: null,
|
|
1424
1496
|
resizeObserver: null,
|
|
@@ -1426,12 +1498,12 @@ function useMeasure(_temp) {
|
|
|
1426
1498
|
});
|
|
1427
1499
|
const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
|
|
1428
1500
|
const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
|
|
1429
|
-
const mounted = (0,
|
|
1430
|
-
(0,
|
|
1501
|
+
const mounted = (0, import_react4.useRef)(false);
|
|
1502
|
+
(0, import_react4.useEffect)(() => {
|
|
1431
1503
|
mounted.current = true;
|
|
1432
1504
|
return () => void (mounted.current = false);
|
|
1433
1505
|
});
|
|
1434
|
-
const [forceRefresh, resizeChange, scrollChange] = (0,
|
|
1506
|
+
const [forceRefresh, resizeChange, scrollChange] = (0, import_react4.useMemo)(() => {
|
|
1435
1507
|
const callback = () => {
|
|
1436
1508
|
if (!state.current.element)
|
|
1437
1509
|
return;
|
|
@@ -1497,22 +1569,22 @@ function useMeasure(_temp) {
|
|
|
1497
1569
|
};
|
|
1498
1570
|
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
1499
1571
|
useOnWindowResize(resizeChange);
|
|
1500
|
-
(0,
|
|
1572
|
+
(0, import_react4.useEffect)(() => {
|
|
1501
1573
|
removeListeners();
|
|
1502
1574
|
addListeners();
|
|
1503
1575
|
}, [scroll, scrollChange, resizeChange]);
|
|
1504
|
-
(0,
|
|
1576
|
+
(0, import_react4.useEffect)(() => removeListeners, []);
|
|
1505
1577
|
return [ref, bounds, forceRefresh];
|
|
1506
1578
|
}
|
|
1507
1579
|
function useOnWindowResize(onWindowResize) {
|
|
1508
|
-
(0,
|
|
1580
|
+
(0, import_react4.useEffect)(() => {
|
|
1509
1581
|
const cb = onWindowResize;
|
|
1510
1582
|
window.addEventListener("resize", cb);
|
|
1511
1583
|
return () => void window.removeEventListener("resize", cb);
|
|
1512
1584
|
}, [onWindowResize]);
|
|
1513
1585
|
}
|
|
1514
1586
|
function useOnWindowScroll(onScroll, enabled) {
|
|
1515
|
-
(0,
|
|
1587
|
+
(0, import_react4.useEffect)(() => {
|
|
1516
1588
|
if (enabled) {
|
|
1517
1589
|
const cb = onScroll;
|
|
1518
1590
|
window.addEventListener("scroll", cb, {
|
|
@@ -1930,14 +2002,14 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
|
1930
2002
|
var import_react_error_boundary = require("react-error-boundary");
|
|
1931
2003
|
|
|
1932
2004
|
// src/schematic-components/TableViewer.tsx
|
|
1933
|
-
var
|
|
2005
|
+
var import_react5 = require("react");
|
|
1934
2006
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1935
|
-
var LazyTableViewer = (0,
|
|
2007
|
+
var LazyTableViewer = (0, import_react5.lazy)(
|
|
1936
2008
|
() => import("@tscircuit/table-viewer").then((m) => ({
|
|
1937
2009
|
default: m.SoupTableViewer
|
|
1938
2010
|
}))
|
|
1939
2011
|
);
|
|
1940
|
-
var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2012
|
+
var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react5.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(LazyTableViewer, { ...params }) });
|
|
1941
2013
|
|
|
1942
2014
|
// src/Schematic.tsx
|
|
1943
2015
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
@@ -1958,8 +2030,8 @@ var Schematic = ({
|
|
|
1958
2030
|
showTable
|
|
1959
2031
|
}) => {
|
|
1960
2032
|
initialSoup = initialSoup ?? initialElements ?? [];
|
|
1961
|
-
const [elements, setElements] = (0,
|
|
1962
|
-
const [project, setProject] = (0,
|
|
2033
|
+
const [elements, setElements] = (0, import_react6.useState)(initialSoup ?? []);
|
|
2034
|
+
const [project, setProject] = (0, import_react6.useState)(null);
|
|
1963
2035
|
const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
|
|
1964
2036
|
const cameraTransform = useRenderContext((s) => s.camera_transform);
|
|
1965
2037
|
const [boundsRef, bounds] = useMeasure();
|
|
@@ -1969,7 +2041,7 @@ var Schematic = ({
|
|
|
1969
2041
|
}
|
|
1970
2042
|
// initialTransform: compose(scale(100, 100, 0, 0)),
|
|
1971
2043
|
});
|
|
1972
|
-
const setElementsAndCamera = (0,
|
|
2044
|
+
const setElementsAndCamera = (0, import_react6.useCallback)(
|
|
1973
2045
|
(elements2) => {
|
|
1974
2046
|
const elmBounds = ref.current.getBoundingClientRect();
|
|
1975
2047
|
const { center, width, height } = elements2.some(
|
|
@@ -1995,7 +2067,7 @@ var Schematic = ({
|
|
|
1995
2067
|
},
|
|
1996
2068
|
[setElements, setTransform]
|
|
1997
2069
|
);
|
|
1998
|
-
(0,
|
|
2070
|
+
(0, import_react6.useEffect)(() => {
|
|
1999
2071
|
if (initialSoup.length > 0) {
|
|
2000
2072
|
setElementsAndCamera(initialSoup);
|
|
2001
2073
|
return;
|