@tscircuit/core 0.0.34 → 0.0.36

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
@@ -534,6 +534,10 @@ declare class Port extends PrimitiveComponent<typeof portProps> {
534
534
  doInitialSourceParentAttachment(): void;
535
535
  doInitialPcbPortRender(): void;
536
536
  doInitialSchematicPortRender(): void;
537
+ _setPositionFromLayout(newCenter: {
538
+ x: number;
539
+ y: number;
540
+ }): void;
537
541
  }
538
542
 
539
543
  type ReactSubtree = {
@@ -3441,6 +3445,7 @@ declare class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
3441
3445
  declare const edgeSpecifiers: readonly ["leftedge", "rightedge", "topedge", "bottomedge", "center"];
3442
3446
  type EdgeSpecifier = (typeof edgeSpecifiers)[number];
3443
3447
  declare class Constraint extends PrimitiveComponent<typeof constraintProps> {
3448
+ componentName: string;
3444
3449
  get config(): {
3445
3450
  zodProps: z.ZodUnion<[z.ZodObject<{
3446
3451
  pcb: z.ZodOptional<z.ZodLiteral<true>>;
package/dist/index.js CHANGED
@@ -213,8 +213,8 @@ var PrimitiveComponent = class extends Renderable {
213
213
  );
214
214
  if (!this.componentName) {
215
215
  this.componentName = this.constructor.name;
216
- this.lowercaseComponentName = this.componentName.toLowerCase();
217
216
  }
217
+ this.lowercaseComponentName = this.componentName.toLowerCase();
218
218
  }
219
219
  setProps(props) {
220
220
  const newProps = this.config.zodProps.parse({
@@ -681,6 +681,9 @@ var Footprint = class extends PrimitiveComponent {
681
681
  x: -(bounds.right + bounds.left) / 2,
682
682
  y: -(bounds.top + bounds.bottom) / 2
683
683
  };
684
+ const containerPos = this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();
685
+ globalOffset.x += containerPos.x;
686
+ globalOffset.y += containerPos.y;
684
687
  for (const { component, selector } of involvedComponents) {
685
688
  const kvx = getKVar(`${selector}_x`);
686
689
  const kvy = getKVar(`${selector}_y`);
@@ -869,6 +872,12 @@ var Port = class extends PrimitiveComponent {
869
872
  });
870
873
  this.schematic_port_id = schematic_port.schematic_port_id;
871
874
  }
875
+ _setPositionFromLayout(newCenter) {
876
+ const { db } = this.root;
877
+ db.schematic_port.update(this.schematic_port_id, {
878
+ center: newCenter
879
+ });
880
+ }
872
881
  };
873
882
 
874
883
  // lib/components/base-components/NormalComponent.ts
@@ -2982,6 +2991,7 @@ var edgeSpecifiers = [
2982
2991
  "center"
2983
2992
  ];
2984
2993
  var Constraint2 = class extends PrimitiveComponent {
2994
+ componentName = "Constraint";
2985
2995
  get config() {
2986
2996
  return {
2987
2997
  zodProps: constraintProps
@@ -3002,9 +3012,9 @@ var Constraint2 = class extends PrimitiveComponent {
3002
3012
  }
3003
3013
  _getAllReferencedComponents() {
3004
3014
  const componentsWithSelectors = [];
3005
- const subcircuit = this.getSubcircuit();
3015
+ const container = this.getPrimitiveContainer();
3006
3016
  function addComponentFromSelector(selector) {
3007
- const component = subcircuit.selectOne(selector);
3017
+ const component = container.selectOne(selector);
3008
3018
  if (component) {
3009
3019
  const maybeEdge = selector.split(" ").pop();
3010
3020
  const edge = edgeSpecifiers.includes(maybeEdge) ? maybeEdge : void 0;
@@ -92,8 +92,8 @@ export abstract class PrimitiveComponent<
92
92
  ) as z.infer<ZodProps>
93
93
  if (!this.componentName) {
94
94
  this.componentName = this.constructor.name
95
- this.lowercaseComponentName = this.componentName.toLowerCase()
96
95
  }
96
+ this.lowercaseComponentName = this.componentName.toLowerCase()
97
97
  }
98
98
 
99
99
  setProps(props: Partial<z.input<ZodProps>>) {
@@ -13,6 +13,8 @@ const edgeSpecifiers = [
13
13
  export type EdgeSpecifier = (typeof edgeSpecifiers)[number]
14
14
 
15
15
  export class Constraint extends PrimitiveComponent<typeof constraintProps> {
16
+ componentName = "Constraint"
17
+
16
18
  get config() {
17
19
  return {
18
20
  zodProps: constraintProps,
@@ -49,12 +51,12 @@ export class Constraint extends PrimitiveComponent<typeof constraintProps> {
49
51
  edge: EdgeSpecifier | undefined
50
52
  }> = []
51
53
 
52
- const subcircuit = this.getSubcircuit()
54
+ const container = this.getPrimitiveContainer()!
53
55
 
54
56
  function addComponentFromSelector(selector: string) {
55
57
  // TODO this selector has to be modified in case it contains a leftedge,
56
58
  // center/topedge/rightedge indicator
57
- const component = subcircuit.selectOne(selector)
59
+ const component = container.selectOne(selector)
58
60
  if (component) {
59
61
  const maybeEdge = selector.split(" ").pop() as EdgeSpecifier
60
62
  const edge = edgeSpecifiers.includes(maybeEdge) ? maybeEdge : undefined
@@ -220,6 +220,12 @@ export class Footprint extends PrimitiveComponent<typeof footprintProps> {
220
220
  y: -(bounds.top + bounds.bottom) / 2,
221
221
  }
222
222
 
223
+ const containerPos =
224
+ this.getPrimitiveContainer()!._getGlobalPcbPositionBeforeLayout()
225
+
226
+ globalOffset.x += containerPos.x
227
+ globalOffset.y += containerPos.y
228
+
223
229
  // 4. Update the component positions
224
230
  for (const { component, selector } of involvedComponents) {
225
231
  const kvx = getKVar(`${selector}_x`)
@@ -205,4 +205,12 @@ export class Port extends PrimitiveComponent<typeof portProps> {
205
205
 
206
206
  this.schematic_port_id = schematic_port.schematic_port_id
207
207
  }
208
+
209
+ _setPositionFromLayout(newCenter: { x: number; y: number }): void {
210
+ const { db } = this.root!
211
+
212
+ db.schematic_port.update(this.schematic_port_id!, {
213
+ center: newCenter,
214
+ })
215
+ }
208
216
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/core",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.0.34",
5
+ "version": "0.0.36",
6
6
  "types": "dist/index.d.ts",
7
7
  "main": "dist/index.js",
8
8
  "files": [