@tscircuit/schematic-viewer 1.1.12 → 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 -54
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/package.json +1 -1
- package/src/Schematic.tsx +0 -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,16 +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
|
-
var builder1 = __toESM(require("@tscircuit/builder"));
|
|
945
944
|
var import_react_fiber = require("@tscircuit/react-fiber");
|
|
946
945
|
|
|
947
946
|
// src/lib/utils/collect-element-refs.ts
|
|
948
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;
|
|
949
952
|
const source_component = allElms.find(
|
|
950
|
-
(e) => e.type === "source_component" && e.source_component_id ===
|
|
953
|
+
(e) => e.type === "source_component" && e.source_component_id === source_component_id
|
|
951
954
|
);
|
|
952
955
|
if ([
|
|
953
956
|
"schematic_component",
|
|
@@ -963,7 +966,9 @@ var collectElementRefs = (elm, allElms) => {
|
|
|
963
966
|
return {
|
|
964
967
|
schematic_children,
|
|
965
968
|
schematic: elm,
|
|
966
|
-
source: source_component
|
|
969
|
+
source: source_component,
|
|
970
|
+
source_component,
|
|
971
|
+
source_port
|
|
967
972
|
};
|
|
968
973
|
}
|
|
969
974
|
return null;
|
|
@@ -1258,8 +1263,16 @@ function getSVGPathBounds(ds) {
|
|
|
1258
1263
|
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
1259
1264
|
|
|
1260
1265
|
// src/schematic-components/SVGPathComponent.tsx
|
|
1266
|
+
var import_react2 = require("react");
|
|
1261
1267
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1262
|
-
var SVGPathComponent = ({
|
|
1268
|
+
var SVGPathComponent = ({
|
|
1269
|
+
size,
|
|
1270
|
+
center,
|
|
1271
|
+
rotation,
|
|
1272
|
+
paths,
|
|
1273
|
+
zIndex,
|
|
1274
|
+
hoverContent
|
|
1275
|
+
}) => {
|
|
1263
1276
|
const ct = useCameraTransform();
|
|
1264
1277
|
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
1265
1278
|
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
@@ -1268,37 +1281,86 @@ var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
|
1268
1281
|
pathBounds.height = Math.max(pathBounds.height, 1);
|
|
1269
1282
|
pathBounds.width = Math.max(pathBounds.width, 1);
|
|
1270
1283
|
const absoluteCenter = applyToPoint(ct, center);
|
|
1284
|
+
const actualAbsWidth = size.width * ct.a;
|
|
1285
|
+
const actualAbsHeight = size.height * ct.d;
|
|
1271
1286
|
const absoluteSize = {
|
|
1272
|
-
width: Math.max(1,
|
|
1273
|
-
height: Math.max(1,
|
|
1287
|
+
width: Math.max(1, actualAbsWidth),
|
|
1288
|
+
height: Math.max(1, actualAbsHeight)
|
|
1274
1289
|
};
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
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",
|
|
1291
1312
|
{
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
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",
|
|
1297
1345
|
},
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
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
|
+
] });
|
|
1302
1364
|
};
|
|
1303
1365
|
var SVGPathComponent_default = SVGPathComponent;
|
|
1304
1366
|
|
|
@@ -1344,7 +1406,7 @@ var SimpleCapacitor = ({
|
|
|
1344
1406
|
};
|
|
1345
1407
|
|
|
1346
1408
|
// src/lib/hooks/use-maybe-promise.ts
|
|
1347
|
-
var
|
|
1409
|
+
var import_react3 = require("react");
|
|
1348
1410
|
|
|
1349
1411
|
// src/schematic-components/ProjectComponent.tsx
|
|
1350
1412
|
var import_builder = require("@tscircuit/builder");
|
|
@@ -1366,13 +1428,22 @@ var directionToVec = (direction) => {
|
|
|
1366
1428
|
|
|
1367
1429
|
// src/schematic-components/SchematicPort.tsx
|
|
1368
1430
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1369
|
-
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}`;
|
|
1370
1435
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1371
1436
|
SVGPathComponent,
|
|
1372
1437
|
{
|
|
1373
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
|
+
] }),
|
|
1374
1444
|
center: schematic.center,
|
|
1375
1445
|
size: { width: 0.2, height: 0.2 },
|
|
1446
|
+
zIndex: 10,
|
|
1376
1447
|
paths: [
|
|
1377
1448
|
{
|
|
1378
1449
|
stroke: "blue",
|
|
@@ -1391,7 +1462,7 @@ var SchematicPort = ({ port: { source, schematic } }) => {
|
|
|
1391
1462
|
var SchematicPort_default = SchematicPort;
|
|
1392
1463
|
|
|
1393
1464
|
// node_modules/react-use-measure/dist/web.js
|
|
1394
|
-
var
|
|
1465
|
+
var import_react4 = require("react");
|
|
1395
1466
|
var import_debounce = __toESM(require_debounce());
|
|
1396
1467
|
function useMeasure(_temp) {
|
|
1397
1468
|
let {
|
|
@@ -1409,7 +1480,7 @@ function useMeasure(_temp) {
|
|
|
1409
1480
|
if (!ResizeObserver) {
|
|
1410
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");
|
|
1411
1482
|
}
|
|
1412
|
-
const [bounds, set] = (0,
|
|
1483
|
+
const [bounds, set] = (0, import_react4.useState)({
|
|
1413
1484
|
left: 0,
|
|
1414
1485
|
top: 0,
|
|
1415
1486
|
width: 0,
|
|
@@ -1419,7 +1490,7 @@ function useMeasure(_temp) {
|
|
|
1419
1490
|
x: 0,
|
|
1420
1491
|
y: 0
|
|
1421
1492
|
});
|
|
1422
|
-
const state = (0,
|
|
1493
|
+
const state = (0, import_react4.useRef)({
|
|
1423
1494
|
element: null,
|
|
1424
1495
|
scrollContainers: null,
|
|
1425
1496
|
resizeObserver: null,
|
|
@@ -1427,12 +1498,12 @@ function useMeasure(_temp) {
|
|
|
1427
1498
|
});
|
|
1428
1499
|
const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
|
|
1429
1500
|
const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
|
|
1430
|
-
const mounted = (0,
|
|
1431
|
-
(0,
|
|
1501
|
+
const mounted = (0, import_react4.useRef)(false);
|
|
1502
|
+
(0, import_react4.useEffect)(() => {
|
|
1432
1503
|
mounted.current = true;
|
|
1433
1504
|
return () => void (mounted.current = false);
|
|
1434
1505
|
});
|
|
1435
|
-
const [forceRefresh, resizeChange, scrollChange] = (0,
|
|
1506
|
+
const [forceRefresh, resizeChange, scrollChange] = (0, import_react4.useMemo)(() => {
|
|
1436
1507
|
const callback = () => {
|
|
1437
1508
|
if (!state.current.element)
|
|
1438
1509
|
return;
|
|
@@ -1498,22 +1569,22 @@ function useMeasure(_temp) {
|
|
|
1498
1569
|
};
|
|
1499
1570
|
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
1500
1571
|
useOnWindowResize(resizeChange);
|
|
1501
|
-
(0,
|
|
1572
|
+
(0, import_react4.useEffect)(() => {
|
|
1502
1573
|
removeListeners();
|
|
1503
1574
|
addListeners();
|
|
1504
1575
|
}, [scroll, scrollChange, resizeChange]);
|
|
1505
|
-
(0,
|
|
1576
|
+
(0, import_react4.useEffect)(() => removeListeners, []);
|
|
1506
1577
|
return [ref, bounds, forceRefresh];
|
|
1507
1578
|
}
|
|
1508
1579
|
function useOnWindowResize(onWindowResize) {
|
|
1509
|
-
(0,
|
|
1580
|
+
(0, import_react4.useEffect)(() => {
|
|
1510
1581
|
const cb = onWindowResize;
|
|
1511
1582
|
window.addEventListener("resize", cb);
|
|
1512
1583
|
return () => void window.removeEventListener("resize", cb);
|
|
1513
1584
|
}, [onWindowResize]);
|
|
1514
1585
|
}
|
|
1515
1586
|
function useOnWindowScroll(onScroll, enabled) {
|
|
1516
|
-
(0,
|
|
1587
|
+
(0, import_react4.useEffect)(() => {
|
|
1517
1588
|
if (enabled) {
|
|
1518
1589
|
const cb = onScroll;
|
|
1519
1590
|
window.addEventListener("scroll", cb, {
|
|
@@ -1931,14 +2002,14 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
|
1931
2002
|
var import_react_error_boundary = require("react-error-boundary");
|
|
1932
2003
|
|
|
1933
2004
|
// src/schematic-components/TableViewer.tsx
|
|
1934
|
-
var
|
|
2005
|
+
var import_react5 = require("react");
|
|
1935
2006
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
1936
|
-
var LazyTableViewer = (0,
|
|
2007
|
+
var LazyTableViewer = (0, import_react5.lazy)(
|
|
1937
2008
|
() => import("@tscircuit/table-viewer").then((m) => ({
|
|
1938
2009
|
default: m.SoupTableViewer
|
|
1939
2010
|
}))
|
|
1940
2011
|
);
|
|
1941
|
-
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 }) });
|
|
1942
2013
|
|
|
1943
2014
|
// src/Schematic.tsx
|
|
1944
2015
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
@@ -1959,8 +2030,8 @@ var Schematic = ({
|
|
|
1959
2030
|
showTable
|
|
1960
2031
|
}) => {
|
|
1961
2032
|
initialSoup = initialSoup ?? initialElements ?? [];
|
|
1962
|
-
const [elements, setElements] = (0,
|
|
1963
|
-
const [project, setProject] = (0,
|
|
2033
|
+
const [elements, setElements] = (0, import_react6.useState)(initialSoup ?? []);
|
|
2034
|
+
const [project, setProject] = (0, import_react6.useState)(null);
|
|
1964
2035
|
const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
|
|
1965
2036
|
const cameraTransform = useRenderContext((s) => s.camera_transform);
|
|
1966
2037
|
const [boundsRef, bounds] = useMeasure();
|
|
@@ -1970,8 +2041,7 @@ var Schematic = ({
|
|
|
1970
2041
|
}
|
|
1971
2042
|
// initialTransform: compose(scale(100, 100, 0, 0)),
|
|
1972
2043
|
});
|
|
1973
|
-
|
|
1974
|
-
const setElementsAndCamera = (0, import_react5.useCallback)(
|
|
2044
|
+
const setElementsAndCamera = (0, import_react6.useCallback)(
|
|
1975
2045
|
(elements2) => {
|
|
1976
2046
|
const elmBounds = ref.current.getBoundingClientRect();
|
|
1977
2047
|
const { center, width, height } = elements2.some(
|
|
@@ -1997,7 +2067,7 @@ var Schematic = ({
|
|
|
1997
2067
|
},
|
|
1998
2068
|
[setElements, setTransform]
|
|
1999
2069
|
);
|
|
2000
|
-
(0,
|
|
2070
|
+
(0, import_react6.useEffect)(() => {
|
|
2001
2071
|
if (initialSoup.length > 0) {
|
|
2002
2072
|
setElementsAndCamera(initialSoup);
|
|
2003
2073
|
return;
|