@tscircuit/props 0.0.169 → 0.0.171
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 +83 -1
- package/dist/index.js +194 -172
- package/dist/index.js.map +1 -1
- package/lib/common/connectionsProp.ts +12 -0
- package/lib/components/capacitor.ts +14 -0
- package/lib/components/chip.ts +1 -8
- package/lib/components/resistor.ts +8 -0
- package/lib/index.ts +1 -0
- package/lib/utility-types/connections-and-selectors.ts +77 -0
- package/package.json +1 -1
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { resistance } from "circuit-json"
|
|
2
|
+
import { createConnectionsProp } from "lib/common/connectionsProp"
|
|
2
3
|
import {
|
|
3
4
|
type CommonComponentProps,
|
|
4
5
|
commonComponentProps,
|
|
5
6
|
lrPins,
|
|
6
7
|
} from "lib/common/layout"
|
|
7
8
|
import { expectTypesMatch } from "lib/typecheck"
|
|
9
|
+
import type { Connections } from "lib/utility-types/connections-and-selectors"
|
|
8
10
|
import { z } from "zod"
|
|
9
11
|
|
|
12
|
+
export const resistorPinLabels = ["pin1", "pin2", "pos", "neg"] as const
|
|
13
|
+
export type ResistorPinLabels = (typeof resistorPinLabels)[number]
|
|
14
|
+
|
|
10
15
|
export interface ResistorProps extends CommonComponentProps {
|
|
11
16
|
resistance: number | string
|
|
12
17
|
pullupFor?: string
|
|
13
18
|
pullupTo?: string
|
|
14
19
|
pulldownFor?: string
|
|
15
20
|
pulldownTo?: string
|
|
21
|
+
connections?: Connections<ResistorPinLabels>
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export const resistorProps = commonComponentProps.extend({
|
|
@@ -23,6 +29,8 @@ export const resistorProps = commonComponentProps.extend({
|
|
|
23
29
|
|
|
24
30
|
pulldownFor: z.string().optional(),
|
|
25
31
|
pulldownTo: z.string().optional(),
|
|
32
|
+
|
|
33
|
+
connections: createConnectionsProp(resistorPinLabels).optional(),
|
|
26
34
|
})
|
|
27
35
|
export const resistorPins = lrPins
|
|
28
36
|
|
package/lib/index.ts
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export type ConnectionTarget = string
|
|
2
|
+
/**
|
|
3
|
+
* Defines a mapping of strings to connection paths e.g.
|
|
4
|
+
*
|
|
5
|
+
* const connections: Connections = {
|
|
6
|
+
* GND: ".U1 > .GND",
|
|
7
|
+
* VCC: ".U1 > .VCC",
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* Connections are used as both inputs and outputs. For example, you might
|
|
11
|
+
* receive connections when using `sel` to select a chip.
|
|
12
|
+
*
|
|
13
|
+
* const u1Connections = sel.U1(MyChip)
|
|
14
|
+
*
|
|
15
|
+
* You can also define a module with connections like this:
|
|
16
|
+
*
|
|
17
|
+
* export const MyModule = (props: { connections: { GND: string, VCC: string } }) => {
|
|
18
|
+
* return (
|
|
19
|
+
* <group>
|
|
20
|
+
* <capacitor name="C1" connections={{
|
|
21
|
+
* anode: props.connections.GND,
|
|
22
|
+
* cathode: props.connections.VCC,
|
|
23
|
+
* }} />
|
|
24
|
+
* </group>
|
|
25
|
+
* )
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export type Connections<PinLabel extends string = string> = Partial<
|
|
29
|
+
Record<
|
|
30
|
+
PinLabel,
|
|
31
|
+
ConnectionTarget | ConnectionTarget[] | readonly ConnectionTarget[]
|
|
32
|
+
>
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Defines a mapping of strings (usually chip names) to connections e.g.
|
|
37
|
+
*
|
|
38
|
+
* const selectors: Selectors = {
|
|
39
|
+
* U1: { GND: ".U1 > .GND", VCC: ".U1 > .VCC" },
|
|
40
|
+
* U2: {
|
|
41
|
+
* GND: ".U2 > .pin1",
|
|
42
|
+
* VCC: ".U2 > .pin2",
|
|
43
|
+
* CUSTOM_DATA_1: ".U2 > .pin3",
|
|
44
|
+
* CUSTOM_DATA_2: ".U2 > .pin4",
|
|
45
|
+
* },
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* A user can also use selectors to define the connections, this is helpful when
|
|
49
|
+
* there's multiple chips in the group.
|
|
50
|
+
*
|
|
51
|
+
* ```tsx
|
|
52
|
+
* const MyModule = (props: {
|
|
53
|
+
* selectors: {
|
|
54
|
+
* U1: { GND: string, VCC: string },
|
|
55
|
+
* R1: { GND: string, VCC: string }
|
|
56
|
+
* }
|
|
57
|
+
* }) => {
|
|
58
|
+
* return (
|
|
59
|
+
* <group>
|
|
60
|
+
* <resistor name="R1" connections={{
|
|
61
|
+
* pin1: props.selectors.R1.GND,
|
|
62
|
+
* pin2: props.selectors.R1.VCC,
|
|
63
|
+
* }} />
|
|
64
|
+
* <capacitor name="C1" connections={{
|
|
65
|
+
* anode: props.selectors.U1.GND,
|
|
66
|
+
* cathode: props.selectors.U1.VCC,
|
|
67
|
+
* }} />
|
|
68
|
+
* </group>
|
|
69
|
+
* )
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* These selectors can also be used with "sel":
|
|
74
|
+
*
|
|
75
|
+
* sel.M1(MyModule).U1.GND // ".M1 > .C1 > .anode"
|
|
76
|
+
*/
|
|
77
|
+
export type Selectors = Record<string, Connections>
|