@tscircuit/schematic-viewer 1.1.13 → 1.1.15
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 +121 -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 +82 -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,83 @@ 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
|
+
mixBlendMode: "difference",
|
|
1320
|
+
top: svgTop,
|
|
1321
|
+
fontFamily: "monospace",
|
|
1322
|
+
fontSize: 14
|
|
1323
|
+
},
|
|
1324
|
+
children: hoverContent
|
|
1325
|
+
}
|
|
1326
|
+
)
|
|
1327
|
+
] }),
|
|
1328
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1329
|
+
"svg",
|
|
1330
|
+
{
|
|
1331
|
+
onMouseOver: () => setHovering(Boolean(hoverContent)),
|
|
1332
|
+
onMouseOut: () => setHovering(false),
|
|
1333
|
+
style: {
|
|
1334
|
+
position: "absolute",
|
|
1335
|
+
// backgroundColor: hovering ? "rgba(0, 0, 255, 0.5)" : "transparent",
|
|
1336
|
+
cursor: hovering ? "pointer" : void 0,
|
|
1337
|
+
zIndex,
|
|
1338
|
+
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
1339
|
+
left: svgLeft,
|
|
1340
|
+
top: svgTop
|
|
1341
|
+
// backgroundColor: badRatio ? "rgba(255, 0, 0, 0.5)" : "transparent",
|
|
1296
1342
|
},
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1343
|
+
overflow: "visible",
|
|
1344
|
+
width: absoluteSize.width,
|
|
1345
|
+
height: absoluteSize.height,
|
|
1346
|
+
viewBox: `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`,
|
|
1347
|
+
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1348
|
+
"path",
|
|
1349
|
+
{
|
|
1350
|
+
fill: p.fill ?? "none",
|
|
1351
|
+
strokeLinecap: "round",
|
|
1352
|
+
strokeWidth: 2 * (p.strokeWidth || 1),
|
|
1353
|
+
stroke: p.stroke || "red",
|
|
1354
|
+
d: p.d
|
|
1355
|
+
},
|
|
1356
|
+
i
|
|
1357
|
+
))
|
|
1358
|
+
}
|
|
1359
|
+
)
|
|
1360
|
+
] });
|
|
1301
1361
|
};
|
|
1302
1362
|
var SVGPathComponent_default = SVGPathComponent;
|
|
1303
1363
|
|
|
@@ -1343,7 +1403,7 @@ var SimpleCapacitor = ({
|
|
|
1343
1403
|
};
|
|
1344
1404
|
|
|
1345
1405
|
// src/lib/hooks/use-maybe-promise.ts
|
|
1346
|
-
var
|
|
1406
|
+
var import_react3 = require("react");
|
|
1347
1407
|
|
|
1348
1408
|
// src/schematic-components/ProjectComponent.tsx
|
|
1349
1409
|
var import_builder = require("@tscircuit/builder");
|
|
@@ -1365,13 +1425,22 @@ var directionToVec = (direction) => {
|
|
|
1365
1425
|
|
|
1366
1426
|
// src/schematic-components/SchematicPort.tsx
|
|
1367
1427
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1368
|
-
var SchematicPort = ({
|
|
1428
|
+
var SchematicPort = ({
|
|
1429
|
+
port: { source_port, source_component, schematic }
|
|
1430
|
+
}) => {
|
|
1431
|
+
const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
|
|
1369
1432
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1370
1433
|
SVGPathComponent,
|
|
1371
1434
|
{
|
|
1372
1435
|
rotation: 0,
|
|
1436
|
+
hoverContent: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1437
|
+
hoverName,
|
|
1438
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
|
|
1439
|
+
source_port?.pin_number && `Pin ${source_port.pin_number}`
|
|
1440
|
+
] }),
|
|
1373
1441
|
center: schematic.center,
|
|
1374
1442
|
size: { width: 0.2, height: 0.2 },
|
|
1443
|
+
zIndex: 10,
|
|
1375
1444
|
paths: [
|
|
1376
1445
|
{
|
|
1377
1446
|
stroke: "blue",
|
|
@@ -1390,7 +1459,7 @@ var SchematicPort = ({ port: { source, schematic } }) => {
|
|
|
1390
1459
|
var SchematicPort_default = SchematicPort;
|
|
1391
1460
|
|
|
1392
1461
|
// node_modules/react-use-measure/dist/web.js
|
|
1393
|
-
var
|
|
1462
|
+
var import_react4 = require("react");
|
|
1394
1463
|
var import_debounce = __toESM(require_debounce());
|
|
1395
1464
|
function useMeasure(_temp) {
|
|
1396
1465
|
let {
|
|
@@ -1408,7 +1477,7 @@ function useMeasure(_temp) {
|
|
|
1408
1477
|
if (!ResizeObserver) {
|
|
1409
1478
|
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
1479
|
}
|
|
1411
|
-
const [bounds, set] = (0,
|
|
1480
|
+
const [bounds, set] = (0, import_react4.useState)({
|
|
1412
1481
|
left: 0,
|
|
1413
1482
|
top: 0,
|
|
1414
1483
|
width: 0,
|
|
@@ -1418,7 +1487,7 @@ function useMeasure(_temp) {
|
|
|
1418
1487
|
x: 0,
|
|
1419
1488
|
y: 0
|
|
1420
1489
|
});
|
|
1421
|
-
const state = (0,
|
|
1490
|
+
const state = (0, import_react4.useRef)({
|
|
1422
1491
|
element: null,
|
|
1423
1492
|
scrollContainers: null,
|
|
1424
1493
|
resizeObserver: null,
|
|
@@ -1426,12 +1495,12 @@ function useMeasure(_temp) {
|
|
|
1426
1495
|
});
|
|
1427
1496
|
const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
|
|
1428
1497
|
const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
|
|
1429
|
-
const mounted = (0,
|
|
1430
|
-
(0,
|
|
1498
|
+
const mounted = (0, import_react4.useRef)(false);
|
|
1499
|
+
(0, import_react4.useEffect)(() => {
|
|
1431
1500
|
mounted.current = true;
|
|
1432
1501
|
return () => void (mounted.current = false);
|
|
1433
1502
|
});
|
|
1434
|
-
const [forceRefresh, resizeChange, scrollChange] = (0,
|
|
1503
|
+
const [forceRefresh, resizeChange, scrollChange] = (0, import_react4.useMemo)(() => {
|
|
1435
1504
|
const callback = () => {
|
|
1436
1505
|
if (!state.current.element)
|
|
1437
1506
|
return;
|
|
@@ -1497,22 +1566,22 @@ function useMeasure(_temp) {
|
|
|
1497
1566
|
};
|
|
1498
1567
|
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
1499
1568
|
useOnWindowResize(resizeChange);
|
|
1500
|
-
(0,
|
|
1569
|
+
(0, import_react4.useEffect)(() => {
|
|
1501
1570
|
removeListeners();
|
|
1502
1571
|
addListeners();
|
|
1503
1572
|
}, [scroll, scrollChange, resizeChange]);
|
|
1504
|
-
(0,
|
|
1573
|
+
(0, import_react4.useEffect)(() => removeListeners, []);
|
|
1505
1574
|
return [ref, bounds, forceRefresh];
|
|
1506
1575
|
}
|
|
1507
1576
|
function useOnWindowResize(onWindowResize) {
|
|
1508
|
-
(0,
|
|
1577
|
+
(0, import_react4.useEffect)(() => {
|
|
1509
1578
|
const cb = onWindowResize;
|
|
1510
1579
|
window.addEventListener("resize", cb);
|
|
1511
1580
|
return () => void window.removeEventListener("resize", cb);
|
|
1512
1581
|
}, [onWindowResize]);
|
|
1513
1582
|
}
|
|
1514
1583
|
function useOnWindowScroll(onScroll, enabled) {
|
|
1515
|
-
(0,
|
|
1584
|
+
(0, import_react4.useEffect)(() => {
|
|
1516
1585
|
if (enabled) {
|
|
1517
1586
|
const cb = onScroll;
|
|
1518
1587
|
window.addEventListener("scroll", cb, {
|
|
@@ -1930,14 +1999,14 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
|
1930
1999
|
var import_react_error_boundary = require("react-error-boundary");
|
|
1931
2000
|
|
|
1932
2001
|
// src/schematic-components/TableViewer.tsx
|
|
1933
|
-
var
|
|
2002
|
+
var import_react5 = require("react");
|
|
1934
2003
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1935
|
-
var LazyTableViewer = (0,
|
|
2004
|
+
var LazyTableViewer = (0, import_react5.lazy)(
|
|
1936
2005
|
() => import("@tscircuit/table-viewer").then((m) => ({
|
|
1937
2006
|
default: m.SoupTableViewer
|
|
1938
2007
|
}))
|
|
1939
2008
|
);
|
|
1940
|
-
var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2009
|
+
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
2010
|
|
|
1942
2011
|
// src/Schematic.tsx
|
|
1943
2012
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
@@ -1958,8 +2027,8 @@ var Schematic = ({
|
|
|
1958
2027
|
showTable
|
|
1959
2028
|
}) => {
|
|
1960
2029
|
initialSoup = initialSoup ?? initialElements ?? [];
|
|
1961
|
-
const [elements, setElements] = (0,
|
|
1962
|
-
const [project, setProject] = (0,
|
|
2030
|
+
const [elements, setElements] = (0, import_react6.useState)(initialSoup ?? []);
|
|
2031
|
+
const [project, setProject] = (0, import_react6.useState)(null);
|
|
1963
2032
|
const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
|
|
1964
2033
|
const cameraTransform = useRenderContext((s) => s.camera_transform);
|
|
1965
2034
|
const [boundsRef, bounds] = useMeasure();
|
|
@@ -1969,7 +2038,7 @@ var Schematic = ({
|
|
|
1969
2038
|
}
|
|
1970
2039
|
// initialTransform: compose(scale(100, 100, 0, 0)),
|
|
1971
2040
|
});
|
|
1972
|
-
const setElementsAndCamera = (0,
|
|
2041
|
+
const setElementsAndCamera = (0, import_react6.useCallback)(
|
|
1973
2042
|
(elements2) => {
|
|
1974
2043
|
const elmBounds = ref.current.getBoundingClientRect();
|
|
1975
2044
|
const { center, width, height } = elements2.some(
|
|
@@ -1995,7 +2064,7 @@ var Schematic = ({
|
|
|
1995
2064
|
},
|
|
1996
2065
|
[setElements, setTransform]
|
|
1997
2066
|
);
|
|
1998
|
-
(0,
|
|
2067
|
+
(0, import_react6.useEffect)(() => {
|
|
1999
2068
|
if (initialSoup.length > 0) {
|
|
2000
2069
|
setElementsAndCamera(initialSoup);
|
|
2001
2070
|
return;
|