@tscircuit/schematic-viewer 2.0.101 → 2.0.103

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.d.ts CHANGED
@@ -24,6 +24,14 @@ declare const useSchematicViewerController: () => {
24
24
  focusSchematicComponent: (schematicComponentId: string) => void;
25
25
  };
26
26
 
27
+ /** Stable identity for hosts to locate the component on their PCB. */
28
+ interface ViewPcbComponentEvent {
29
+ source_component_id: string;
30
+ schematic_component_id: string;
31
+ pcb_component_id: string;
32
+ refdes: string;
33
+ }
34
+
27
35
  interface Props$1 {
28
36
  circuitJson: CircuitJson;
29
37
  containerStyle?: React.CSSProperties;
@@ -51,8 +59,10 @@ interface Props$1 {
51
59
  searchEnabled?: boolean;
52
60
  /** Connect the controller returned by useSchematicViewerController. */
53
61
  controller?: SchematicViewerController;
62
+ /** Omit when the host has no enabled PCB view. */
63
+ onViewPcbComponent?: (event: ViewPcbComponentEvent) => void;
54
64
  }
55
- declare const SchematicViewer: ({ circuitJson, containerStyle, debugGrid, debug, clickToInteractEnabled, colorOverrides, disableGroups, netHoverHighlightEnabled, onSchematicComponentClicked, showSchematicPorts, onSchematicPortClicked, onSchematicSheetChange, searchEnabled, controller, css, className, }: Props$1) => react.JSX.Element;
65
+ declare const SchematicViewer: ({ circuitJson, containerStyle, debugGrid, debug, clickToInteractEnabled, colorOverrides, disableGroups, netHoverHighlightEnabled, onSchematicComponentClicked, showSchematicPorts, onSchematicPortClicked, onSchematicSheetChange, searchEnabled, controller, onViewPcbComponent, css, className, }: Props$1) => react.JSX.Element;
56
66
 
57
67
  interface BoundingBoxBounds {
58
68
  minX: number;
@@ -88,4 +98,4 @@ interface Props {
88
98
  }
89
99
  declare const AnalogSimulationViewer: ({ circuitJson: inputCircuitJson, containerStyle, colorOverrides, width, height, className, hideSchematic, onSimulationChange, acSweepView, }: Props) => react.JSX.Element;
90
100
 
91
- export { AnalogSimulationViewer, MouseTracker, SchematicViewer, type SchematicViewerController, useMouseEventsOverBoundingBox, useSchematicViewerController };
101
+ export { AnalogSimulationViewer, MouseTracker, SchematicViewer, type SchematicViewerController, type ViewPcbComponentEvent, useMouseEventsOverBoundingBox, useSchematicViewerController };
package/dist/index.js CHANGED
@@ -1604,6 +1604,45 @@ var getFootprintPreviewUrl = (footprintPreviewCircuitJson, viewBox) => {
1604
1604
  return url.toString();
1605
1605
  };
1606
1606
 
1607
+ // lib/utils/get-pcb-component-at-element.ts
1608
+ var getSchematicComponentAtElement = (target, circuitJson) => {
1609
+ const componentId = target?.closest("[data-schematic-component-id]")?.getAttribute("data-schematic-component-id");
1610
+ const textId = target?.closest("[data-schematic-text-id]")?.getAttribute("data-schematic-text-id");
1611
+ const portId = target?.closest("[data-schematic-port-id]")?.getAttribute("data-schematic-port-id");
1612
+ if (!componentId && !textId && !portId) return;
1613
+ const text = circuitJson.find(
1614
+ (element) => element.type === "schematic_text" && element.schematic_text_id === textId
1615
+ );
1616
+ const port = circuitJson.find(
1617
+ (element) => element.type === "schematic_port" && !!portId && (element.schematic_port_id === portId || element.source_port_id === portId)
1618
+ );
1619
+ const schematicComponentId = componentId ?? (text?.type === "schematic_text" ? text.schematic_component_id : void 0) ?? (port?.type === "schematic_port" ? port.schematic_component_id : void 0);
1620
+ if (!schematicComponentId) return;
1621
+ const schematicComponent = circuitJson.find(
1622
+ (element) => element.type === "schematic_component" && element.schematic_component_id === schematicComponentId
1623
+ );
1624
+ if (schematicComponent?.type !== "schematic_component") return;
1625
+ return schematicComponent;
1626
+ };
1627
+ var getPcbComponentAtElement = (target, circuitJson) => {
1628
+ const schematicComponent = getSchematicComponentAtElement(target, circuitJson);
1629
+ if (!schematicComponent) return;
1630
+ const sourceComponent = circuitJson.find(
1631
+ (element) => element.type === "source_component" && element.source_component_id === schematicComponent.source_component_id
1632
+ );
1633
+ const pcbComponent = circuitJson.find(
1634
+ (element) => element.type === "pcb_component" && element.source_component_id === schematicComponent.source_component_id
1635
+ );
1636
+ if (sourceComponent?.type !== "source_component" || pcbComponent?.type !== "pcb_component")
1637
+ return;
1638
+ return {
1639
+ source_component_id: sourceComponent.source_component_id,
1640
+ schematic_component_id: schematicComponent.schematic_component_id,
1641
+ pcb_component_id: pcbComponent.pcb_component_id,
1642
+ refdes: sourceComponent.name
1643
+ };
1644
+ };
1645
+
1607
1646
  // lib/components/MouseTracker.tsx
1608
1647
  import {
1609
1648
  createContext,
@@ -3245,7 +3284,7 @@ import { useMemo as useMemo5 } from "react";
3245
3284
  // package.json
3246
3285
  var package_default = {
3247
3286
  name: "@tscircuit/schematic-viewer",
3248
- version: "2.0.100",
3287
+ version: "2.0.102",
3249
3288
  repository: {
3250
3289
  type: "git",
3251
3290
  url: "https://github.com/tscircuit/schematic-viewer"
@@ -3281,7 +3320,7 @@ var package_default = {
3281
3320
  tscircuit: "^0.0.2460",
3282
3321
  tsup: "^8.3.5",
3283
3322
  vite: "^6.0.3",
3284
- "@tscircuit/circuit-json-schematic-placement-analysis": "https://jscdn.tscircuit.com/@tscircuit/circuit-json-schematic-placement-analysis/0.0.11.tgz"
3323
+ "@tscircuit/circuit-json-schematic-placement-analysis": "https://jscdn.tscircuit.com/@tscircuit/circuit-json-schematic-placement-analysis/0.0.46.tgz"
3285
3324
  },
3286
3325
  peerDependencies: {
3287
3326
  typescript: "^5.0.0",
@@ -3301,7 +3340,7 @@ var package_default = {
3301
3340
  };
3302
3341
 
3303
3342
  // lib/components/ViewMenu.tsx
3304
- import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
3343
+ import { Fragment as Fragment7, jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
3305
3344
  var FONT_FAMILY2 = 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
3306
3345
  var contentStyles2 = {
3307
3346
  backgroundColor: "#262626",
@@ -3366,6 +3405,9 @@ var CheckIcon2 = () => /* @__PURE__ */ jsx11(
3366
3405
  }
3367
3406
  );
3368
3407
  var ViewMenu = ({
3408
+ isComponentMenu = false,
3409
+ pcbComponent,
3410
+ onViewPcbComponent,
3369
3411
  netLocations = [],
3370
3412
  onSelectNetLocation,
3371
3413
  circuitJson,
@@ -3416,6 +3458,7 @@ var ViewMenu = ({
3416
3458
  return false;
3417
3459
  }
3418
3460
  }, [circuitJsonKey]);
3461
+ if (isComponentMenu && (!pcbComponent || !onViewPcbComponent)) return null;
3419
3462
  return /* @__PURE__ */ jsx11(
3420
3463
  "div",
3421
3464
  {
@@ -3439,7 +3482,22 @@ var ViewMenu = ({
3439
3482
  avoidCollisions: true,
3440
3483
  children: [
3441
3484
  /* @__PURE__ */ jsx11("style", { children: HIGHLIGHT_CSS }),
3442
- netLocations.length > 0 && /* @__PURE__ */ jsxs9(DropdownMenu2.Sub, { children: [
3485
+ pcbComponent && onViewPcbComponent && /* @__PURE__ */ jsx11(Fragment7, { children: /* @__PURE__ */ jsxs9(
3486
+ DropdownMenu2.Item,
3487
+ {
3488
+ className: "sv-vm-item",
3489
+ style: itemStyles2,
3490
+ onSelect: () => {
3491
+ onOpenChange(false);
3492
+ onViewPcbComponent(pcbComponent);
3493
+ },
3494
+ children: [
3495
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: "\u2197" }),
3496
+ /* @__PURE__ */ jsx11("span", { children: "Show on PCB" })
3497
+ ]
3498
+ }
3499
+ ) }),
3500
+ !isComponentMenu && netLocations.length > 0 && /* @__PURE__ */ jsxs9(DropdownMenu2.Sub, { children: [
3443
3501
  /* @__PURE__ */ jsxs9(
3444
3502
  DropdownMenu2.SubTrigger,
3445
3503
  {
@@ -3473,103 +3531,105 @@ var ViewMenu = ({
3473
3531
  }
3474
3532
  ) })
3475
3533
  ] }),
3476
- /* @__PURE__ */ jsxs9(
3477
- DropdownMenu2.Item,
3478
- {
3479
- className: "sv-vm-item",
3480
- style: itemStyles2,
3481
- disabled: !hasPorts,
3482
- title: hasPorts ? void 0 : "No ports found in this schematic",
3483
- onSelect: (event) => event.preventDefault(),
3484
- onPointerDown: (event) => {
3485
- event.preventDefault();
3486
- if (hasPorts) onTogglePorts(!showPorts);
3487
- },
3488
- children: [
3489
- /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showPorts && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3490
- /* @__PURE__ */ jsx11("span", { children: "Show Schematic Ports" })
3491
- ]
3492
- }
3493
- ),
3494
- /* @__PURE__ */ jsxs9(
3495
- DropdownMenu2.Item,
3496
- {
3497
- className: "sv-vm-item",
3498
- style: itemStyles2,
3499
- disabled: !hasGroups,
3500
- title: hasGroups ? void 0 : "No groups found in this schematic",
3501
- onSelect: (event) => event.preventDefault(),
3502
- onPointerDown: (event) => {
3503
- event.preventDefault();
3504
- if (hasGroups) onToggleGroups(!showGroups);
3505
- },
3506
- children: [
3507
- /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showGroups && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3508
- /* @__PURE__ */ jsx11("span", { children: "View Schematic Groups" })
3509
- ]
3510
- }
3511
- ),
3512
- /* @__PURE__ */ jsxs9(
3513
- DropdownMenu2.Item,
3514
- {
3515
- className: "sv-vm-item",
3516
- style: itemStyles2,
3517
- onSelect: (event) => event.preventDefault(),
3518
- onPointerDown: (event) => {
3519
- event.preventDefault();
3520
- onToggleGrid(!showGrid);
3521
- },
3522
- children: [
3523
- /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showGrid && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3524
- /* @__PURE__ */ jsx11("span", { children: "Show Grid" })
3525
- ]
3526
- }
3527
- ),
3528
- /* @__PURE__ */ jsxs9(
3529
- DropdownMenu2.CheckboxItem,
3530
- {
3531
- className: "sv-vm-item",
3532
- style: itemStyles2,
3533
- checked: showWarnings,
3534
- onCheckedChange: onToggleWarnings,
3535
- onSelect: (event) => event.preventDefault(),
3536
- children: [
3537
- /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: /* @__PURE__ */ jsx11(DropdownMenu2.ItemIndicator, { children: /* @__PURE__ */ jsx11(CheckIcon2, {}) }) }),
3538
- /* @__PURE__ */ jsx11("span", { children: "Show Warnings" })
3539
- ]
3540
- }
3541
- ),
3542
- /* @__PURE__ */ jsx11(DropdownMenu2.Separator, { style: separatorStyles }),
3543
- /* @__PURE__ */ jsxs9(
3544
- DropdownMenu2.Item,
3545
- {
3546
- className: "sv-vm-item",
3547
- style: itemStyles2,
3548
- onSelect: onRunStyleAnalysis,
3549
- children: [
3550
- /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2 }),
3551
- /* @__PURE__ */ jsx11("span", { children: "Run Style Analysis" })
3552
- ]
3553
- }
3554
- ),
3555
- /* @__PURE__ */ jsx11(DropdownMenu2.Separator, { style: separatorStyles }),
3556
- /* @__PURE__ */ jsxs9(
3557
- "div",
3558
- {
3559
- style: {
3560
- padding: "4px 8px 4px 32px",
3561
- fontSize: 11,
3562
- opacity: 0.35,
3563
- color: "#a1a1aa",
3564
- letterSpacing: "0.2px",
3565
- fontFamily: FONT_FAMILY2
3566
- },
3567
- children: [
3568
- "@tscircuit/schematic-viewer@",
3569
- String(package_default?.version)
3570
- ]
3571
- }
3572
- )
3534
+ !isComponentMenu && /* @__PURE__ */ jsxs9(Fragment7, { children: [
3535
+ /* @__PURE__ */ jsxs9(
3536
+ DropdownMenu2.Item,
3537
+ {
3538
+ className: "sv-vm-item",
3539
+ style: itemStyles2,
3540
+ disabled: !hasPorts,
3541
+ title: hasPorts ? void 0 : "No ports found in this schematic",
3542
+ onSelect: (event) => event.preventDefault(),
3543
+ onPointerDown: (event) => {
3544
+ event.preventDefault();
3545
+ if (hasPorts) onTogglePorts(!showPorts);
3546
+ },
3547
+ children: [
3548
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showPorts && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3549
+ /* @__PURE__ */ jsx11("span", { children: "Show Schematic Ports" })
3550
+ ]
3551
+ }
3552
+ ),
3553
+ /* @__PURE__ */ jsxs9(
3554
+ DropdownMenu2.Item,
3555
+ {
3556
+ className: "sv-vm-item",
3557
+ style: itemStyles2,
3558
+ disabled: !hasGroups,
3559
+ title: hasGroups ? void 0 : "No groups found in this schematic",
3560
+ onSelect: (event) => event.preventDefault(),
3561
+ onPointerDown: (event) => {
3562
+ event.preventDefault();
3563
+ if (hasGroups) onToggleGroups(!showGroups);
3564
+ },
3565
+ children: [
3566
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showGroups && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3567
+ /* @__PURE__ */ jsx11("span", { children: "View Schematic Groups" })
3568
+ ]
3569
+ }
3570
+ ),
3571
+ /* @__PURE__ */ jsxs9(
3572
+ DropdownMenu2.Item,
3573
+ {
3574
+ className: "sv-vm-item",
3575
+ style: itemStyles2,
3576
+ onSelect: (event) => event.preventDefault(),
3577
+ onPointerDown: (event) => {
3578
+ event.preventDefault();
3579
+ onToggleGrid(!showGrid);
3580
+ },
3581
+ children: [
3582
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: showGrid && /* @__PURE__ */ jsx11(CheckIcon2, {}) }),
3583
+ /* @__PURE__ */ jsx11("span", { children: "Show Grid" })
3584
+ ]
3585
+ }
3586
+ ),
3587
+ /* @__PURE__ */ jsxs9(
3588
+ DropdownMenu2.CheckboxItem,
3589
+ {
3590
+ className: "sv-vm-item",
3591
+ style: itemStyles2,
3592
+ checked: showWarnings,
3593
+ onCheckedChange: onToggleWarnings,
3594
+ onSelect: (event) => event.preventDefault(),
3595
+ children: [
3596
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2, children: /* @__PURE__ */ jsx11(DropdownMenu2.ItemIndicator, { children: /* @__PURE__ */ jsx11(CheckIcon2, {}) }) }),
3597
+ /* @__PURE__ */ jsx11("span", { children: "Show Warnings" })
3598
+ ]
3599
+ }
3600
+ ),
3601
+ /* @__PURE__ */ jsx11(DropdownMenu2.Separator, { style: separatorStyles }),
3602
+ /* @__PURE__ */ jsxs9(
3603
+ DropdownMenu2.Item,
3604
+ {
3605
+ className: "sv-vm-item",
3606
+ style: itemStyles2,
3607
+ onSelect: onRunStyleAnalysis,
3608
+ children: [
3609
+ /* @__PURE__ */ jsx11("span", { style: iconSlotStyles2 }),
3610
+ /* @__PURE__ */ jsx11("span", { children: "Run Style Analysis" })
3611
+ ]
3612
+ }
3613
+ ),
3614
+ /* @__PURE__ */ jsx11(DropdownMenu2.Separator, { style: separatorStyles }),
3615
+ /* @__PURE__ */ jsxs9(
3616
+ "div",
3617
+ {
3618
+ style: {
3619
+ padding: "4px 8px 4px 32px",
3620
+ fontSize: 11,
3621
+ opacity: 0.35,
3622
+ color: "#a1a1aa",
3623
+ letterSpacing: "0.2px",
3624
+ fontFamily: FONT_FAMILY2
3625
+ },
3626
+ children: [
3627
+ "@tscircuit/schematic-viewer@",
3628
+ String(package_default?.version)
3629
+ ]
3630
+ }
3631
+ )
3632
+ ] })
3573
3633
  ]
3574
3634
  }
3575
3635
  ) })
@@ -3595,6 +3655,7 @@ var SchematicViewer = ({
3595
3655
  onSchematicSheetChange,
3596
3656
  searchEnabled = true,
3597
3657
  controller,
3658
+ onViewPcbComponent,
3598
3659
  css,
3599
3660
  className
3600
3661
  }) => {
@@ -4035,6 +4096,9 @@ var SchematicViewer = ({
4035
4096
  menuVisible && /* @__PURE__ */ jsx12(
4036
4097
  ViewMenu,
4037
4098
  {
4099
+ isComponentMenu: !!getSchematicComponentAtElement(menuTarget, circuitJson),
4100
+ pcbComponent: getPcbComponentAtElement(menuTarget, circuitJson),
4101
+ onViewPcbComponent,
4038
4102
  circuitJson,
4039
4103
  circuitJsonKey,
4040
4104
  netLocations: (() => {
@@ -4191,7 +4255,7 @@ var getAnalogSimulationBackgroundColor = (simulationSvg, colorOverrides) => getR
4191
4255
  // lib/components/AnalogSimulationSelector.tsx
4192
4256
  import * as DropdownMenu3 from "@radix-ui/react-dropdown-menu";
4193
4257
  import { useState as useState11 } from "react";
4194
- import { Fragment as Fragment7, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
4258
+ import { Fragment as Fragment8, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
4195
4259
  var FONT_FAMILY3 = 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
4196
4260
  var contentStyles3 = {
4197
4261
  backgroundColor: "#ffffff",
@@ -4296,7 +4360,7 @@ var AnalogSimulationSelector = ({
4296
4360
  ({ simulation }) => simulation.simulation_experiment_id === selectedSimulationExperimentId
4297
4361
  );
4298
4362
  const selectedLabel = selectedSimulation?.label ?? "Select simulation";
4299
- return /* @__PURE__ */ jsxs11(Fragment7, { children: [
4363
+ return /* @__PURE__ */ jsxs11(Fragment8, { children: [
4300
4364
  /* @__PURE__ */ jsx13("style", { children: MENU_CSS2 }),
4301
4365
  /* @__PURE__ */ jsxs11(DropdownMenu3.Root, { open, onOpenChange: setOpen, modal: false, children: [
4302
4366
  /* @__PURE__ */ jsx13(DropdownMenu3.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs11(