@tscircuit/props 0.0.669 → 0.0.670

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.
@@ -1,13 +1,21 @@
1
+ import { url } from "lib/common/url"
1
2
  import { expectTypesMatch } from "lib/typecheck"
2
3
  import { z } from "zod"
3
4
 
4
5
  export interface AssemblyDeviceProps {
5
6
  /** Product-level assembly identity. */
6
7
  name?: string
8
+ /** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
9
+ modelUrl?: string
7
10
  }
8
11
 
9
12
  export const assemblyDeviceProps = z.object({
10
13
  name: z.string().optional(),
14
+ modelUrl: url
15
+ .refine((value) => value.trim().length > 0, {
16
+ message: "modelUrl cannot be empty",
17
+ })
18
+ .optional(),
11
19
  })
12
20
 
13
21
  export type AssemblyDevicePropsInput = z.input<typeof assemblyDeviceProps>
@@ -1,3 +1,4 @@
1
+ import { url } from "lib/common/url"
1
2
  import { type Distance, distance } from "lib/common/distance"
2
3
  import { expectTypesMatch } from "lib/typecheck"
3
4
  import { z } from "zod"
@@ -5,6 +6,8 @@ import { z } from "zod"
5
6
  export interface AssemblyScreenProps {
6
7
  /** Stable product-level identity for the screen assembly. */
7
8
  name: string
9
+ /** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
10
+ modelUrl?: string
8
11
  /** Selector for the connector that the screen attaches to. */
9
12
  connectsTo: string
10
13
  /**
@@ -19,7 +22,7 @@ export interface AssemblyScreenProps {
19
22
  height?: Distance
20
23
  /**
21
24
  * Advanced modelprinter string used to render the screen assembly. Required
22
- * when `width` and `height` are omitted.
25
+ * when `width`, `height`, and `modelUrl` are omitted.
23
26
  */
24
27
  cadModel?: string
25
28
  }
@@ -37,12 +40,24 @@ const positiveDistance = (fieldName: "width" | "height") =>
37
40
  export const assemblyScreenProps = z
38
41
  .object({
39
42
  name: nonemptyString("name"),
43
+ modelUrl: url
44
+ .refine((value) => value.trim().length > 0, {
45
+ message: "modelUrl cannot be empty",
46
+ })
47
+ .optional(),
40
48
  connectsTo: nonemptyString("connectsTo"),
41
49
  width: positiveDistance("width").optional(),
42
50
  height: positiveDistance("height").optional(),
43
51
  cadModel: nonemptyString("cadModel").optional(),
44
52
  })
45
53
  .superRefine((screen, context) => {
54
+ if (screen.modelUrl !== undefined && screen.cadModel !== undefined) {
55
+ context.addIssue({
56
+ code: z.ZodIssueCode.custom,
57
+ message: "Provide either modelUrl or cadModel, not both",
58
+ path: ["modelUrl"],
59
+ })
60
+ }
46
61
  const hasWidth = screen.width !== undefined
47
62
  const hasHeight = screen.height !== undefined
48
63
 
@@ -55,10 +70,14 @@ export const assemblyScreenProps = z
55
70
  return
56
71
  }
57
72
 
58
- if (!hasWidth && screen.cadModel === undefined) {
73
+ if (
74
+ !hasWidth &&
75
+ screen.cadModel === undefined &&
76
+ screen.modelUrl === undefined
77
+ ) {
59
78
  context.addIssue({
60
79
  code: z.ZodIssueCode.custom,
61
- message: "provide either width and height or cadModel",
80
+ message: "provide width and height, cadModel, or modelUrl",
62
81
  path: [],
63
82
  })
64
83
  }
@@ -1,3 +1,4 @@
1
+ import { url } from "lib/common/url"
1
2
  import { type CadModelProp, cadModelProp } from "lib/common/cadModel"
2
3
  import { expectTypesMatch } from "lib/typecheck"
3
4
  import type { ReactNode } from "react"
@@ -6,6 +7,8 @@ import { z } from "zod"
6
7
  export interface AssemblySubassemblyProps {
7
8
  /** Stable identity used by selectors from other assembly elements. */
8
9
  name: string
10
+ /** Imported CAD model URL. Mutually exclusive with cadModel where supported. */
11
+ modelUrl?: string
9
12
  /** Human-facing alternate to the stable name. */
10
13
  displayName?: string
11
14
  /** Optional CAD geometry using the existing component cadModel formats. */
@@ -14,14 +17,28 @@ export interface AssemblySubassemblyProps {
14
17
  children?: ReactNode
15
18
  }
16
19
 
17
- export const assemblySubassemblyProps = z.object({
18
- name: z.string().refine((value) => value.trim().length > 0, {
19
- message: "name cannot be empty",
20
- }),
21
- displayName: z.string().optional(),
22
- cadModel: cadModelProp.optional(),
23
- children: z.custom<ReactNode>().optional(),
24
- })
20
+ export const assemblySubassemblyProps = z
21
+ .object({
22
+ name: z.string().refine((value) => value.trim().length > 0, {
23
+ message: "name cannot be empty",
24
+ }),
25
+ displayName: z.string().optional(),
26
+ modelUrl: url
27
+ .refine((value) => value.trim().length > 0, {
28
+ message: "modelUrl cannot be empty",
29
+ })
30
+ .optional(),
31
+ cadModel: cadModelProp.optional(),
32
+ children: z.custom<ReactNode>().optional(),
33
+ })
34
+ .refine(
35
+ (assembly) =>
36
+ assembly.modelUrl === undefined || assembly.cadModel === undefined,
37
+ {
38
+ message: "Provide either modelUrl or cadModel, not both",
39
+ path: ["modelUrl"],
40
+ },
41
+ )
25
42
 
26
43
  export type AssemblySubassemblyPropsInput = z.input<
27
44
  typeof assemblySubassemblyProps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/props",
3
- "version": "0.0.669",
3
+ "version": "0.0.670",
4
4
  "description": "Props for tscircuit builtin component types",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",