@sanity/assist 1.0.6 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -23,6 +23,8 @@ export interface FieldRef {
23
23
  icon: ComponentType
24
24
  }
25
25
 
26
+ const maxDepth = 4
27
+
26
28
  export function getTypeIcon(schemaType: SchemaType) {
27
29
  let t: SchemaType | undefined = schemaType
28
30
 
@@ -57,7 +59,14 @@ export function getFieldRefsWithDocument(schemaType: ObjectSchemaType): FieldRef
57
59
  ]
58
60
  }
59
61
 
60
- export function getFieldRefs(schemaType: ObjectSchemaType, parent?: FieldRef): FieldRef[] {
62
+ export function getFieldRefs(
63
+ schemaType: ObjectSchemaType,
64
+ parent?: FieldRef,
65
+ depth = 0
66
+ ): FieldRef[] {
67
+ if (depth >= maxDepth) {
68
+ return []
69
+ }
61
70
  return schemaType.fields
62
71
  .filter((f) => !f.name.startsWith('_'))
63
72
  .flatMap((field) => {
@@ -70,7 +79,8 @@ export function getFieldRefs(schemaType: ObjectSchemaType, parent?: FieldRef): F
70
79
  schemaType: field.type,
71
80
  icon: getTypeIcon(field.type),
72
81
  }
73
- const fields = field.type.jsonType === 'object' ? getFieldRefs(field.type, fieldRef) : []
82
+ const fields =
83
+ field.type.jsonType === 'object' ? getFieldRefs(field.type, fieldRef, depth + 1) : []
74
84
 
75
85
  if (!isAssistSupported(field.type)) {
76
86
  return fields
@@ -110,13 +110,12 @@ export function AlphaMigration() {
110
110
  toast.push({
111
111
  title: `Converted instructions to new format.`,
112
112
  status: 'success',
113
- description: 'Pending feature name',
114
113
  closable: true,
115
114
  })
116
115
  } catch (e: any) {
117
116
  console.error(e)
118
117
  toast.push({
119
- title: `An error occured`,
118
+ title: `An error occurred`,
120
119
  status: 'error',
121
120
  closable: true,
122
121
  })