@tscircuit/props 0.0.88 → 0.0.89
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 +311 -275
- package/dist/index.js +78 -80
- package/dist/index.js.map +1 -1
- package/lib/common/layout.ts +3 -2
- package/lib/components/board.ts +11 -28
- package/lib/components/group.ts +15 -1
- package/lib/components/netalias.ts +3 -3
- package/lib/typecheck.ts +44 -2
- package/package.json +1 -1
package/lib/components/group.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import type { LayoutBuilder, ManualEditFile } from "@tscircuit/layout"
|
|
2
2
|
import { length } from "circuit-json"
|
|
3
3
|
import type { Distance } from "lib/common/distance"
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type CommonLayoutProps,
|
|
6
|
+
commonLayoutProps,
|
|
7
|
+
type SupplierPartNumbers,
|
|
8
|
+
} from "lib/common/layout"
|
|
5
9
|
import { expectTypesMatch } from "lib/typecheck"
|
|
6
10
|
import { z } from "zod"
|
|
11
|
+
import type { AnySourceComponent } from "circuit-json"
|
|
7
12
|
|
|
8
13
|
export interface BaseGroupProps extends CommonLayoutProps {
|
|
9
14
|
name?: string
|
|
10
15
|
children?: any
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
export type PartsEngine = {
|
|
19
|
+
findPart: (
|
|
20
|
+
sourceComponent: AnySourceComponent,
|
|
21
|
+
) => Promise<SupplierPartNumbers> | SupplierPartNumbers
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
export interface SubcircuitGroupProps extends BaseGroupProps {
|
|
14
25
|
subcircuit: true
|
|
15
26
|
layout?: LayoutBuilder
|
|
@@ -23,6 +34,8 @@ export interface SubcircuitGroupProps extends BaseGroupProps {
|
|
|
23
34
|
* sophisticated layout options/modes and will be enabled by default.
|
|
24
35
|
*/
|
|
25
36
|
schAutoLayoutEnabled?: boolean
|
|
37
|
+
|
|
38
|
+
partsEngine?: PartsEngine
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
export type GroupProps = SubcircuitGroupProps | BaseGroupProps
|
|
@@ -39,6 +52,7 @@ export const subcircuitGroupProps = baseGroupProps.extend({
|
|
|
39
52
|
schAutoLayoutEnabled: z.boolean().optional(),
|
|
40
53
|
routingDisabled: z.boolean().optional(),
|
|
41
54
|
defaultTraceWidth: length.optional(),
|
|
55
|
+
partsEngine: z.custom<PartsEngine>((v) => "findPart" in v).optional(),
|
|
42
56
|
})
|
|
43
57
|
|
|
44
58
|
export const groupProps = z.union([baseGroupProps, subcircuitGroupProps])
|
|
@@ -4,8 +4,8 @@ import { distance } from "lib/common/distance"
|
|
|
4
4
|
|
|
5
5
|
export interface NetAliasProps {
|
|
6
6
|
net?: string
|
|
7
|
-
schX?: number
|
|
8
|
-
schY?: number
|
|
7
|
+
schX?: number | string
|
|
8
|
+
schY?: number | string
|
|
9
9
|
anchorSide?: "left" | "up" | "right" | "down"
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -16,5 +16,5 @@ export const netAliasProps = z.object({
|
|
|
16
16
|
anchorSide: z.enum(["left", "up", "right", "down"]).optional(),
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
type InferredNetAliasProps = z.
|
|
19
|
+
type InferredNetAliasProps = z.input<typeof netAliasProps>
|
|
20
20
|
expectTypesMatch<NetAliasProps, InferredNetAliasProps>(true)
|
package/lib/typecheck.ts
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
import type { TypeEqual } from "ts-expect"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
type IsNever<T> = [T] extends [never] ? true : false
|
|
4
|
+
|
|
5
|
+
export const expectTypesMatch = <
|
|
6
|
+
const T1,
|
|
7
|
+
const T2,
|
|
8
|
+
T3 = Exclude<keyof T1, keyof T2>,
|
|
9
|
+
T4 = Exclude<keyof T2, keyof T1>,
|
|
10
|
+
>(
|
|
11
|
+
shouldBe: IsNever<T3> extends true
|
|
12
|
+
? IsNever<T4> extends true
|
|
13
|
+
? TypeEqual<T1, T2>
|
|
14
|
+
: `extra props ${T4 extends string ? T4 : ""}`
|
|
15
|
+
: `missing props ${T3 extends string ? T3 : ""}`,
|
|
5
16
|
): void => {}
|
|
17
|
+
|
|
18
|
+
// ------ TESTS -------
|
|
19
|
+
|
|
20
|
+
expectTypesMatch<
|
|
21
|
+
{
|
|
22
|
+
a: number
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
a: number
|
|
26
|
+
b: number
|
|
27
|
+
}
|
|
28
|
+
>("extra props b")
|
|
29
|
+
|
|
30
|
+
expectTypesMatch<
|
|
31
|
+
{
|
|
32
|
+
a: number
|
|
33
|
+
b: number
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
a: number
|
|
37
|
+
}
|
|
38
|
+
>("missing props b")
|
|
39
|
+
|
|
40
|
+
expectTypesMatch<
|
|
41
|
+
{
|
|
42
|
+
a: number
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
a: number
|
|
46
|
+
}
|
|
47
|
+
>(true)
|