@sanity/assist 2.0.4-canary.0 → 2.0.5

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.
Files changed (91) hide show
  1. package/README.md +233 -214
  2. package/dist/index.esm.js +1769 -1769
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +1767 -1767
  5. package/dist/index.js.map +1 -1
  6. package/package.json +17 -18
  7. package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
  8. package/src/_lib/connector/ConnectToRegion.tsx +1 -0
  9. package/src/_lib/connector/ConnectorRegion.tsx +2 -1
  10. package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
  11. package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
  12. package/src/_lib/connector/index.ts +1 -1
  13. package/src/_lib/connector/mapConnectorToLine.ts +2 -2
  14. package/src/_lib/connector/useConnectorsStore.ts +2 -1
  15. package/src/_lib/connector/useRegionRects.ts +4 -3
  16. package/src/_lib/fixedListenQuery.ts +11 -11
  17. package/src/_lib/form/DocumentForm.tsx +4 -3
  18. package/src/_lib/form/helpers.ts +2 -1
  19. package/src/_lib/useListeningQuery.ts +4 -3
  20. package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
  21. package/src/assistConnectors/ConnectorPath.tsx +3 -2
  22. package/src/assistConnectors/draw/connectorPath.ts +13 -13
  23. package/src/assistDocument/AssistDocumentContext.tsx +3 -2
  24. package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
  25. package/src/assistDocument/AssistDocumentInput.tsx +9 -8
  26. package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
  27. package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
  28. package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
  29. package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
  30. package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
  31. package/src/assistDocument/components/helpers.ts +4 -4
  32. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +3 -2
  33. package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
  34. package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
  35. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
  36. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
  37. package/src/assistDocument/components/instruction/PromptInput.tsx +4 -3
  38. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
  39. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
  40. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +7 -6
  41. package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
  42. package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
  43. package/src/assistFormComponents/AssistField.tsx +9 -8
  44. package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
  45. package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
  46. package/src/assistFormComponents/AssistItem.tsx +3 -2
  47. package/src/assistFormComponents/validation/listItem.tsx +2 -2
  48. package/src/assistFormComponents/validation/validationList.tsx +3 -2
  49. package/src/assistInspector/AssistInspector.tsx +16 -15
  50. package/src/assistInspector/FieldAutocomplete.tsx +4 -3
  51. package/src/assistInspector/InstructionTaskHistoryButton.tsx +19 -18
  52. package/src/assistInspector/helpers.ts +10 -9
  53. package/src/assistInspector/index.ts +4 -3
  54. package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
  55. package/src/assistLayout/AssistLayout.tsx +5 -4
  56. package/src/assistLayout/RunInstructionProvider.tsx +18 -15
  57. package/src/components/FadeInContent.tsx +1 -1
  58. package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
  59. package/src/components/ImageContext.tsx +4 -3
  60. package/src/components/SafeValueInput.tsx +7 -6
  61. package/src/components/TimeAgo.tsx +1 -1
  62. package/src/fieldActions/assistFieldActions.tsx +31 -30
  63. package/src/fieldActions/generateCaptionActions.tsx +8 -7
  64. package/src/fieldActions/generateImageActions.tsx +6 -5
  65. package/src/helpers/assistSupported.ts +1 -0
  66. package/src/helpers/conditionalMembers.test.ts +2 -1
  67. package/src/helpers/conditionalMembers.ts +17 -14
  68. package/src/helpers/misc.ts +3 -2
  69. package/src/helpers/typeUtils.ts +1 -1
  70. package/src/helpers/useAssistSupported.ts +2 -1
  71. package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
  72. package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
  73. package/src/onboarding/InspectorOnboarding.tsx +3 -2
  74. package/src/onboarding/onboardingStore.ts +1 -1
  75. package/src/presence/AiFieldPresence.tsx +3 -1
  76. package/src/presence/AssistDocumentPresence.tsx +7 -6
  77. package/src/presence/useAssistPresence.ts +6 -3
  78. package/src/schemas/assistDocumentSchema.tsx +21 -20
  79. package/src/schemas/contextDocumentSchema.tsx +3 -2
  80. package/src/schemas/index.ts +2 -1
  81. package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
  82. package/src/schemas/serialize/serializeSchema.test.ts +3 -2
  83. package/src/schemas/serialize/serializeSchema.ts +15 -14
  84. package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
  85. package/src/translate/FieldTranslationProvider.tsx +33 -25
  86. package/src/translate/getLanguageParams.ts +3 -3
  87. package/src/translate/paths.test.ts +11 -4
  88. package/src/translate/paths.ts +12 -11
  89. package/src/translate/translateActions.tsx +12 -11
  90. package/src/translate/types.ts +2 -2
  91. package/src/useApiClient.ts +9 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "2.0.4-canary.0",
3
+ "version": "2.0.5",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -65,32 +65,31 @@
65
65
  "rxjs-exhaustmap-with-trailing": "^2.1.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@commitlint/cli": "^18.4.3",
69
- "@commitlint/config-conventional": "^18.4.3",
68
+ "@commitlint/cli": "^19.2.1",
69
+ "@commitlint/config-conventional": "^19.1.0",
70
70
  "@rollup/plugin-image": "^3.0.3",
71
71
  "@sanity/pkg-utils": "^2.4.10",
72
72
  "@sanity/plugin-kit": "^3.1.10",
73
73
  "@sanity/semantic-release-preset": "^4.1.7",
74
- "@types/react": "^18.2.37",
75
- "@types/styled-components": "^5.1.30",
76
- "@typescript-eslint/eslint-plugin": "^7.0.1",
77
- "@typescript-eslint/parser": "^7.0.1",
74
+ "@types/react": "^18.2.75",
75
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
76
+ "@typescript-eslint/parser": "^7.6.0",
78
77
  "date-fns": "^2.30.0",
79
- "eslint": "^8.56.0",
80
- "eslint-config-prettier": "^8.10.0",
81
- "eslint-config-sanity": "^6.0.0",
82
- "eslint-plugin-prettier": "^4.2.1",
83
- "eslint-plugin-react": "^7.33.2",
78
+ "eslint": "^8.57.0",
79
+ "eslint-config-prettier": "^9.1.0",
80
+ "eslint-config-sanity": "^7.1.2",
81
+ "eslint-plugin-prettier": "^5.1.3",
82
+ "eslint-plugin-react": "^7.34.1",
84
83
  "eslint-plugin-react-hooks": "^4.6.0",
85
- "npm-run-all": "^4.1.5",
84
+ "npm-run-all2": "^5.0.0",
86
85
  "react": "^18.2.0",
87
86
  "react-dom": "^18.2.0",
88
87
  "rimraf": "^5.0.5",
89
- "sanity": "^3.28.0",
90
- "semantic-release": "^23.0.2",
91
- "styled-components": "^6.1.1",
92
- "typescript": "^5.3.3",
93
- "vitest": "^1.2.1"
88
+ "sanity": "^3.36.4",
89
+ "semantic-release": "^23.0.7",
90
+ "styled-components": "^6.1.8",
91
+ "typescript": "5.4.2",
92
+ "vitest": "^1.4.0"
94
93
  },
95
94
  "peerDependencies": {
96
95
  "react": "^18",
@@ -1,10 +1,11 @@
1
1
  import {HTMLProps, useEffect, useState} from 'react'
2
- import {useConnectorsStore} from './useConnectorsStore'
3
- import {ConnectorRegionRects} from './types'
2
+
4
3
  import {ConnectorRegion} from './ConnectorRegion'
4
+ import {ConnectorRegionRects} from './types'
5
+ import {useConnectorsStore} from './useConnectorsStore'
5
6
 
6
7
  export function ConnectFromRegion(
7
- props: {_key: string; zIndex: number} & HTMLProps<HTMLDivElement>
8
+ props: {_key: string; zIndex: number} & HTMLProps<HTMLDivElement>,
8
9
  ) {
9
10
  const {children, _key: key, zIndex, ...restProps} = props
10
11
  const store = useConnectorsStore()
@@ -1,4 +1,5 @@
1
1
  import {HTMLProps, useEffect, useState} from 'react'
2
+
2
3
  import {ConnectorRegion} from './ConnectorRegion'
3
4
  import {ConnectorRegionRects} from './types'
4
5
  import {useConnectorsStore} from './useConnectorsStore'
@@ -1,11 +1,12 @@
1
1
  import {HTMLProps, useEffect} from 'react'
2
+
2
3
  import {ConnectorRegionRects} from './types'
3
4
  import {useRegionRects} from './useRegionRects'
4
5
 
5
6
  export function ConnectorRegion(
6
7
  props: {
7
8
  onRectsChange?: (rects: ConnectorRegionRects | null) => void
8
- } & HTMLProps<HTMLDivElement>
9
+ } & HTMLProps<HTMLDivElement>,
9
10
  ) {
10
11
  const {children, onRectsChange, ...restProps} = props
11
12
 
@@ -1,4 +1,5 @@
1
1
  import {ReactNode, useEffect, useMemo} from 'react'
2
+
2
3
  import {ConnectorsStore, createConnectorsStore} from './ConnectorsStore'
3
4
  import {ConnectorsStoreContext} from './ConnectorsStoreContext'
4
5
  import {Connector} from './types'
@@ -12,7 +13,7 @@ export function ConnectorsProvider(props: {
12
13
 
13
14
  useEffect(
14
15
  () => onConnectorsChange && store.connectors.subscribe(onConnectorsChange),
15
- [onConnectorsChange, store]
16
+ [onConnectorsChange, store],
16
17
  )
17
18
 
18
19
  return <ConnectorsStoreContext.Provider value={store}>{children}</ConnectorsStoreContext.Provider>
@@ -1,4 +1,5 @@
1
1
  import {createContext} from 'react'
2
+
2
3
  import {ConnectorsStore} from './ConnectorsStore'
3
4
 
4
5
  export const ConnectorsStoreContext = createContext<ConnectorsStore | null>(null)
@@ -1,9 +1,9 @@
1
1
  export * from './ConnectFromRegion'
2
- export * from './ConnectToRegion'
3
2
  export * from './ConnectorRegion'
4
3
  export * from './ConnectorsProvider'
5
4
  export * from './ConnectorsStore'
6
5
  export * from './ConnectorsStoreContext'
6
+ export * from './ConnectToRegion'
7
7
  export * from './mapConnectorToLine'
8
8
  export * from './types'
9
9
  export * from './useConnectorsStore'
@@ -9,7 +9,7 @@ import {
9
9
  function getConnectorLinePoint(
10
10
  options: ConnectorOptions,
11
11
  rect: Rect,
12
- bounds: Rect
12
+ bounds: Rect,
13
13
  ): ConnectorLinePoint {
14
14
  const centerY = rect.y + rect.h / 2
15
15
  const isAbove = rect.y + rect.h < bounds.y + options.arrow.marginY
@@ -30,7 +30,7 @@ function getConnectorLinePoint(
30
30
 
31
31
  export function mapConnectorToLine(
32
32
  options: ConnectorOptions,
33
- connector: {from: ConnectorRegionRects; to: ConnectorRegionRects}
33
+ connector: {from: ConnectorRegionRects; to: ConnectorRegionRects},
34
34
  ): ConnectorLine {
35
35
  const fromBounds: Rect = {
36
36
  y: connector.from.bounds.y + options.arrow.threshold,
@@ -1,6 +1,7 @@
1
1
  import {useContext} from 'react'
2
- import {ConnectorsStoreContext} from './ConnectorsStoreContext'
2
+
3
3
  import {ConnectorsStore} from './ConnectorsStore'
4
+ import {ConnectorsStoreContext} from './ConnectorsStoreContext'
4
5
 
5
6
  export function useConnectorsStore(): ConnectorsStore {
6
7
  const store = useContext(ConnectorsStoreContext)
@@ -1,6 +1,7 @@
1
1
  import {useEffect, useMemo, useRef, useState} from 'react'
2
- import {Rect, Scroll} from './types'
2
+
3
3
  import {hasOverflowScroll} from './helpers'
4
+ import {Rect, Scroll} from './types'
4
5
 
5
6
  export function useRegionRects() {
6
7
  const ref = useRef<HTMLDivElement>(null)
@@ -123,7 +124,7 @@ export function useRegionRects() {
123
124
  w: relativeBoundsRect.w,
124
125
  h: relativeBoundsRect.h,
125
126
  },
126
- [relativeBoundsRect, boundsScroll]
127
+ [relativeBoundsRect, boundsScroll],
127
128
  )
128
129
 
129
130
  const element: Rect | null = useMemo(
@@ -134,7 +135,7 @@ export function useRegionRects() {
134
135
  w: relativeElementRect.w,
135
136
  h: relativeElementRect.h,
136
137
  },
137
- [relativeElementRect, scroll]
138
+ [relativeElementRect, scroll],
138
139
  )
139
140
 
140
141
  return {bounds, element, ref}
@@ -19,21 +19,21 @@ const fetch = (
19
19
  client: SanityClient,
20
20
  query: string,
21
21
  params: ListenQueryParams,
22
- options: ListenQueryOptions
22
+ options: ListenQueryOptions,
23
23
  ) =>
24
24
  defer(() =>
25
25
  // getVersionedClient(options.apiVersion)
26
26
  client.observable.fetch(query, params, {
27
27
  tag: options.tag,
28
28
  filterResponse: true,
29
- })
29
+ }),
30
30
  )
31
31
 
32
32
  const listen = (
33
33
  client: SanityClient,
34
34
  query: string,
35
35
  params: ListenQueryParams,
36
- options: ListenQueryOptions
36
+ options: ListenQueryOptions,
37
37
  ) =>
38
38
  defer(() =>
39
39
  // getVersionedClient(options.apiVersion)
@@ -42,11 +42,11 @@ const listen = (
42
42
  includeResult: false,
43
43
  visibility: 'query',
44
44
  tag: options.tag,
45
- })
45
+ }),
46
46
  ) as Observable<ReconnectEvent | WelcomeEvent | MutationEvent>
47
47
 
48
48
  function isWelcomeEvent(
49
- event: MutationEvent | ReconnectEvent | WelcomeEvent
49
+ event: MutationEvent | ReconnectEvent | WelcomeEvent,
50
50
  ): event is WelcomeEvent {
51
51
  return event.type === 'welcome'
52
52
  }
@@ -56,7 +56,7 @@ export const listenQuery = (
56
56
  client: SanityClient,
57
57
  query: string | {fetch: string; listen: string},
58
58
  params: ListenQueryParams = {},
59
- options: ListenQueryOptions = {}
59
+ options: ListenQueryOptions = {},
60
60
  ) => {
61
61
  const fetchQuery = typeof query === 'string' ? query : query.fetch
62
62
  const listenerQuery = typeof query === 'string' ? query : query.listen
@@ -73,13 +73,13 @@ export const listenQuery = (
73
73
  new Error(
74
74
  ev.type === 'reconnect'
75
75
  ? 'Could not establish EventSource connection'
76
- : `Received unexpected type of first event "${ev.type}"`
77
- )
76
+ : `Received unexpected type of first event "${ev.type}"`,
77
+ ),
78
78
  )
79
79
  }
80
80
  return of(ev)
81
81
  }),
82
- share()
82
+ share(),
83
83
  )
84
84
 
85
85
  const [welcome$, mutationAndReconnect$] = partition(events$, isWelcomeEvent)
@@ -95,7 +95,7 @@ export const listenQuery = (
95
95
  welcome$.pipe(take(1)),
96
96
  mutationAndReconnect$.pipe(
97
97
  filter(isRelevantEvent),
98
- switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1000))))
99
- )
98
+ switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1000)))),
99
+ ),
100
100
  ).pipe(exhaustMapToWithTrailing(fetchOnce$))
101
101
  }
@@ -12,12 +12,13 @@ import {
12
12
  useDocumentStore,
13
13
  } from 'sanity'
14
14
  import {useDocumentPane} from 'sanity/desk'
15
+
15
16
  import {assistFormId} from './constants'
16
17
 
17
18
  const preventDefault = (ev: React.FormEvent) => ev.preventDefault()
18
19
 
19
20
  export function DocumentForm(
20
- props: Omit<BoxProps, 'as'> & Omit<HTMLProps<HTMLDivElement>, 'as' | 'onSubmit' | 'ref'>
21
+ props: Omit<BoxProps, 'as'> & Omit<HTMLProps<HTMLDivElement>, 'as' | 'onSubmit' | 'ref'>,
21
22
  ) {
22
23
  const {
23
24
  collapsedFieldSets,
@@ -61,7 +62,7 @@ export function DocumentForm(
61
62
  if (event.type === 'rebase') {
62
63
  patchChannel.publish(prepareRebaseEvent(event))
63
64
  }
64
- })
65
+ }),
65
66
  )
66
67
  .subscribe()
67
68
 
@@ -192,7 +193,7 @@ function prepareRebaseEvent(event: DocumentRebaseEvent): PatchMsg {
192
193
  type: 'rebase',
193
194
  snapshot: event.document,
194
195
  patches: fromMutationPatches('remote', remotePatches).concat(
195
- fromMutationPatches('local', localPatches)
196
+ fromMutationPatches('local', localPatches),
196
197
  ),
197
198
  }
198
199
  }
@@ -1,4 +1,5 @@
1
1
  import {isArraySchemaType, isObjectSchemaType, ObjectItem, SchemaType} from 'sanity'
2
+
2
3
  import {randomKey} from '../randomKey'
3
4
 
4
5
  export function createProtoValue(type: SchemaType): any {
@@ -23,7 +24,7 @@ export function createProtoValue(type: SchemaType): any {
23
24
  export function createProtoArrayValue<Item extends ObjectItem>(type: SchemaType): Item {
24
25
  if (!isObjectSchemaType(type)) {
25
26
  throw new Error(
26
- `Invalid item type: "${type.type}". Default array input can only contain objects (for now)`
27
+ `Invalid item type: "${type.type}". Default array input can only contain objects (for now)`,
27
28
  )
28
29
  }
29
30
 
@@ -1,7 +1,8 @@
1
1
  import {useEffect, useRef, useState} from 'react'
2
- import {catchError, distinctUntilChanged} from 'rxjs/operators'
3
2
  import isEqual from 'react-fast-compare'
3
+ import {catchError, distinctUntilChanged} from 'rxjs/operators'
4
4
  import {ListenQueryOptions, useClient} from 'sanity'
5
+
5
6
  import {listenQuery} from './fixedListenQuery'
6
7
 
7
8
  type Params = Record<string, string | number | boolean | string[]>
@@ -22,7 +23,7 @@ const DEFAULT_OPTIONS: ListenQueryOptions = {apiVersion: `v2022-05-09`}
22
23
  export function useListeningQuery<T>(
23
24
  query: string,
24
25
  params: Params = DEFAULT_PARAMS,
25
- options: ListenQueryOptions = DEFAULT_OPTIONS
26
+ options: ListenQueryOptions = DEFAULT_OPTIONS,
26
27
  ): ReturnShape<T> {
27
28
  const [loading, setLoading] = useState(true)
28
29
  const [error, setError] = useState(false)
@@ -43,7 +44,7 @@ export function useListeningQuery<T>(
43
44
  setData(null)
44
45
 
45
46
  return err
46
- })
47
+ }),
47
48
  )
48
49
  .subscribe((documents) => {
49
50
  setData((current) => (isEqual(current, documents) ? current : documents))
@@ -1,4 +1,5 @@
1
1
  import {Fragment, useEffect, useState} from 'react'
2
+
2
3
  import {Connector, ConnectorOptions} from '../_lib/connector'
3
4
  import {ConnectorPath} from './ConnectorPath'
4
5
 
@@ -1,5 +1,6 @@
1
1
  import {rgba, useTheme} from '@sanity/ui'
2
2
  import {useMemo} from 'react'
3
+
3
4
  import {ConnectorOptions, mapConnectorToLine, Rect} from '../_lib/connector'
4
5
  import {arrowPath} from './draw/arrowPath'
5
6
  import {drawConnectorPath} from './draw/connectorPath'
@@ -35,7 +36,7 @@ export function ConnectorPath(props: {
35
36
  options,
36
37
  line.from.x + options.arrow.marginX,
37
38
  line.from.bounds.y - options.arrow.threshold + options.arrow.marginY,
38
- -1
39
+ -1,
39
40
  )}
40
41
  stroke={theme.sanity.color.base.border}
41
42
  strokeWidth={strokeWidth}
@@ -51,7 +52,7 @@ export function ConnectorPath(props: {
51
52
  line.from.bounds.h +
52
53
  options.arrow.threshold -
53
54
  options.arrow.marginY,
54
- 1
55
+ 1,
55
56
  )}
56
57
  stroke={theme.sanity.color.base.border}
57
58
  strokeWidth={strokeWidth}
@@ -4,7 +4,7 @@ export function drawArrowPath(
4
4
  options: ConnectorOptions,
5
5
  x: number,
6
6
  y: number,
7
- dir: number
7
+ dir: number,
8
8
  ): string {
9
9
  return [
10
10
  `M ${x - options.arrow.size} ${y - options.arrow.size * dir} `,
@@ -54,19 +54,19 @@ export function drawConnectorPath(options: ConnectorOptions, line: ConnectorLine
54
54
  cmds.push(
55
55
  moveTo(
56
56
  fromX + options.arrow.marginX,
57
- fromY - options.arrow.threshold + options.arrow.marginY
57
+ fromY - options.arrow.threshold + options.arrow.marginY,
58
58
  ),
59
59
  lineTo(fromX + options.arrow.marginX, fromY - r0),
60
- quadCurve(fromX + options.arrow.marginX, fromY, fromX + options.arrow.marginX + r0, fromY)
60
+ quadCurve(fromX + options.arrow.marginX, fromY, fromX + options.arrow.marginX + r0, fromY),
61
61
  )
62
62
  } else if (from.isBelow) {
63
63
  cmds.push(
64
64
  moveTo(
65
65
  fromX + options.arrow.marginX,
66
- fromY + options.arrow.threshold - options.arrow.marginY
66
+ fromY + options.arrow.threshold - options.arrow.marginY,
67
67
  ),
68
68
  lineTo(fromX + options.arrow.marginX, fromY + r0),
69
- quadCurve(fromX + options.arrow.marginX, fromY, fromX + options.arrow.marginX + r0, fromY)
69
+ quadCurve(fromX + options.arrow.marginX, fromY, fromX + options.arrow.marginX + r0, fromY),
70
70
  )
71
71
  } else {
72
72
  cmds.push(moveTo(fromX, fromY))
@@ -82,13 +82,13 @@ export function drawConnectorPath(options: ConnectorOptions, line: ConnectorLine
82
82
  quadCurve(dividerX, toY, dividerX + r1, toY),
83
83
  lineTo(dividerX - cornerRadius, toY),
84
84
  quadCurve(dividerX, toY, dividerX, toY - cornerRadius),
85
- lineTo(dividerX, toY - options.arrow.threshold + options.arrow.marginY)
85
+ lineTo(dividerX, toY - options.arrow.threshold + options.arrow.marginY),
86
86
  )
87
87
  } else {
88
88
  cmds.push(
89
89
  lineTo(dividerX - cornerRadius, fromY),
90
90
  quadCurve(dividerX, fromY, dividerX, fromY - cornerRadius),
91
- lineTo(dividerX, toY - options.arrow.threshold + options.arrow.marginY)
91
+ lineTo(dividerX, toY - options.arrow.threshold + options.arrow.marginY),
92
92
  )
93
93
  }
94
94
  } else if (to.isBelow) {
@@ -100,24 +100,24 @@ export function drawConnectorPath(options: ConnectorOptions, line: ConnectorLine
100
100
  dividerX - options.arrow.marginX,
101
101
  fromY,
102
102
  dividerX - options.arrow.marginX,
103
- fromY - r1
103
+ fromY - r1,
104
104
  ),
105
105
  lineTo(dividerX - options.arrow.marginX, toY + r1),
106
106
  quadCurve(
107
107
  dividerX - options.arrow.marginX,
108
108
  toY,
109
109
  dividerX - options.arrow.marginX + r1,
110
- toY
110
+ toY,
111
111
  ),
112
112
  lineTo(dividerX - cornerRadius, toY),
113
113
  quadCurve(dividerX, toY, dividerX, toY + cornerRadius),
114
- lineTo(dividerX, toY + options.arrow.threshold - options.arrow.marginY)
114
+ lineTo(dividerX, toY + options.arrow.threshold - options.arrow.marginY),
115
115
  )
116
116
  } else {
117
117
  cmds.push(
118
118
  lineTo(dividerX - cornerRadius, fromY),
119
119
  quadCurve(dividerX, fromY, dividerX, fromY + cornerRadius),
120
- lineTo(dividerX, toY + options.arrow.threshold - options.arrow.marginY)
120
+ lineTo(dividerX, toY + options.arrow.threshold - options.arrow.marginY),
121
121
  )
122
122
  }
123
123
  } else if (fromY < toY) {
@@ -126,7 +126,7 @@ export function drawConnectorPath(options: ConnectorOptions, line: ConnectorLine
126
126
  quadCurve(dividerX, fromY, dividerX, fromY + r1),
127
127
  lineTo(dividerX, toY - r1),
128
128
  quadCurve(dividerX, toY, dividerX + r1, toY),
129
- lineTo(toX, toY)
129
+ lineTo(toX, toY),
130
130
  )
131
131
  } else {
132
132
  cmds.push(
@@ -134,7 +134,7 @@ export function drawConnectorPath(options: ConnectorOptions, line: ConnectorLine
134
134
  quadCurve(dividerX, fromY, dividerX, fromY - Math.min(r0, r1)),
135
135
  lineTo(dividerX, toY + r1),
136
136
  quadCurve(dividerX, toY, dividerX + r1, toY),
137
- lineTo(toX, toY)
137
+ lineTo(toX, toY),
138
138
  )
139
139
  }
140
140
 
@@ -1,5 +1,6 @@
1
- import {DocumentInspector, ObjectSchemaType, PatchEvent} from 'sanity'
2
1
  import {createContext, useContext} from 'react'
2
+ import {DocumentInspector, ObjectSchemaType, PatchEvent} from 'sanity'
3
+
3
4
  import {StudioAssistDocument} from '../types'
4
5
 
5
6
  export type AssistDocumentContextValue = (
@@ -19,7 +20,7 @@ export type AssistDocumentContextValue = (
19
20
  }
20
21
 
21
22
  export const AssistDocumentContext = createContext<AssistDocumentContextValue | undefined>(
22
- undefined
23
+ undefined,
23
24
  )
24
25
 
25
26
  export function useAssistDocumentContext(): AssistDocumentContextValue {
@@ -1,7 +1,8 @@
1
+ import {PropsWithChildren} from 'react'
1
2
  import {ObjectSchemaType} from 'sanity'
3
+
2
4
  import {AssistDocumentContext} from './AssistDocumentContext'
3
5
  import {useAssistDocumentContextValue} from './hooks/useAssistDocumentContextValue'
4
- import {PropsWithChildren} from 'react'
5
6
 
6
7
  export interface AIDocumentInputProps {
7
8
  documentId: string
@@ -1,15 +1,16 @@
1
- import {InputProps, ObjectInputProps, ObjectSchemaType} from 'sanity'
2
- import {AssistDocumentContextProvider} from './AssistDocumentContextProvider'
3
- import {FirstAssistedPathProvider} from '../onboarding/FirstAssistedPathProvider'
4
- import {useInstructionToaster} from './hooks/useInstructionToaster'
5
- import {isType} from '../helpers/typeUtils'
6
1
  import {useLayer} from '@sanity/ui'
2
+ import {useMemo} from 'react'
3
+ import {InputProps, ObjectInputProps, ObjectSchemaType} from 'sanity'
7
4
  import {useDocumentPane} from 'sanity/desk'
8
- import {usePathKey} from '../helpers/misc'
5
+
9
6
  import {ConnectFromRegion} from '../_lib/connector'
10
- import {assistDocumentTypeName} from '../types'
11
- import {useMemo} from 'react'
12
7
  import {assistFormId} from '../_lib/form/constants'
8
+ import {usePathKey} from '../helpers/misc'
9
+ import {isType} from '../helpers/typeUtils'
10
+ import {FirstAssistedPathProvider} from '../onboarding/FirstAssistedPathProvider'
11
+ import {assistDocumentTypeName} from '../types'
12
+ import {AssistDocumentContextProvider} from './AssistDocumentContextProvider'
13
+ import {useInstructionToaster} from './hooks/useInstructionToaster'
13
14
 
14
15
  export function AssistDocumentInputWrapper(props: InputProps) {
15
16
  if (!isType(props.schemaType, 'document') && props.id !== 'root' && props.id !== assistFormId) {
@@ -1,6 +1,7 @@
1
- import {useRunInstruction} from '../assistLayout/RunInstructionProvider'
2
1
  import {useCallback, useEffect, useState} from 'react'
3
2
  import {ObjectSchemaType, PatchEvent, SanityDocument, unset} from 'sanity'
3
+
4
+ import {useRunInstruction} from '../assistLayout/RunInstructionProvider'
4
5
  import {publicId} from '../helpers/ids'
5
6
 
6
7
  export interface DraftDelayedTaskArgs<T> {
@@ -13,7 +14,7 @@ export interface DraftDelayedTaskArgs<T> {
13
14
  export function isDocAssistable(
14
15
  documentSchemaType: ObjectSchemaType,
15
16
  published?: SanityDocument | null,
16
- draft?: SanityDocument | null
17
+ draft?: SanityDocument | null,
17
18
  ) {
18
19
  return !!(documentSchemaType.liveEdit ? published : draft)
19
20
  }
@@ -61,6 +62,6 @@ export function useDraftDelayedTask<T>(args: DraftDelayedTaskArgs<T>) {
61
62
  documentOnChange(PatchEvent.from([unset(['_force_document_creation'])]))
62
63
  setQueuedArgs(taskArgs)
63
64
  },
64
- [setQueuedArgs, documentOnChange]
65
+ [setQueuedArgs, documentOnChange],
65
66
  )
66
67
  }
@@ -1,13 +1,4 @@
1
- import {
2
- AssistDocument,
3
- AssistField,
4
- assistFieldTypeName,
5
- AssistInspectorRouteParams,
6
- documentRootKey,
7
- fieldPathParam,
8
- instructionParam,
9
- StudioInstruction,
10
- } from '../../types'
1
+ import {Card, Stack, Text} from '@sanity/ui'
11
2
  import {createContext, useContext, useEffect, useMemo, useRef} from 'react'
12
3
  import {
13
4
  FormCallbacksProvider,
@@ -27,12 +18,22 @@ import {
27
18
  useFormCallbacks,
28
19
  useSchema,
29
20
  } from 'sanity'
30
- import {BackToInstructionListLink} from './instruction/BackToInstructionsLink'
21
+
31
22
  import {useAiPaneRouter} from '../../assistInspector/helpers'
32
- import {SelectedFieldContextProvider, SelectedFieldContextValue} from './SelectedFieldContext'
33
- import {Card, Stack, Text} from '@sanity/ui'
34
- import {documentTypeFromAiDocumentId} from '../../helpers/ids'
35
23
  import {useAiAssistanceConfig} from '../../assistLayout/AiAssistanceConfigContext'
24
+ import {documentTypeFromAiDocumentId} from '../../helpers/ids'
25
+ import {
26
+ AssistDocument,
27
+ AssistField,
28
+ assistFieldTypeName,
29
+ AssistInspectorRouteParams,
30
+ documentRootKey,
31
+ fieldPathParam,
32
+ instructionParam,
33
+ StudioInstruction,
34
+ } from '../../types'
35
+ import {BackToInstructionListLink} from './instruction/BackToInstructionsLink'
36
+ import {SelectedFieldContextProvider, SelectedFieldContextValue} from './SelectedFieldContext'
36
37
 
37
38
  const EMPTY_FIELDS: AssistField[] = []
38
39
 
@@ -96,7 +97,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
96
97
  documentSchema,
97
98
  fieldSchema: fieldSchema ?? documentSchema,
98
99
  }),
99
- [fieldSchema, documentSchema]
100
+ [fieldSchema, documentSchema],
100
101
  )
101
102
 
102
103
  const title = value?.title
@@ -118,7 +119,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
118
119
  typed<AssistInspectorRouteParams>({
119
120
  ...params,
120
121
  [instructionParam]: (path[3] as KeyedSegment)?._key,
121
- }) as Record<keyof AssistInspectorRouteParams, string | undefined>
122
+ }) as Record<keyof AssistInspectorRouteParams, string | undefined>,
122
123
  )
123
124
  onPathOpen([])
124
125
  } else {
@@ -126,7 +127,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
126
127
  }
127
128
  },
128
129
  }),
129
- [formCallbacks, onPathOpen, params, setParams, instruction]
130
+ [formCallbacks, onPathOpen, params, setParams, instruction],
130
131
  )
131
132
 
132
133
  useEffect(() => {
@@ -164,7 +165,7 @@ function AssistDocumentFormEditable(props: ObjectInputProps) {
164
165
 
165
166
  function useSelectedSchema(
166
167
  fieldPath: string | undefined,
167
- documentSchema: ObjectSchemaType | undefined
168
+ documentSchema: ObjectSchemaType | undefined,
168
169
  ): SchemaType | undefined {
169
170
  return useMemo(() => {
170
171
  if (!fieldPath) {
@@ -221,7 +222,7 @@ function FieldsInitializer({
221
222
  const existingInstructions = existingField?.instructions
222
223
  const presetField = documentPresets.fields?.find((f) => f.path === pathKey)
223
224
  return presetField?.instructions?.filter(
224
- (i) => !existingInstructions?.some((ei) => ei._key === i._key)
225
+ (i) => !existingInstructions?.some((ei) => ei._key === i._key),
225
226
  )
226
227
  }, [documentPresets, pathKey, existingField])
227
228
 
@@ -248,8 +249,8 @@ function FieldsInitializer({
248
249
  }),
249
250
  ],
250
251
  'after',
251
- ['fields', -1]
252
- )
252
+ ['fields', -1],
253
+ ),
253
254
  )
254
255
  }
255
256
 
@@ -265,11 +266,11 @@ function FieldsInitializer({
265
266
  ...preset,
266
267
  _type: 'sanity.assist.instruction',
267
268
  prompt: preset.prompt?.map((p) => ({markDefs: [], ...p})),
268
- })
269
+ }),
269
270
  ),
270
271
  'after',
271
- ['fields', {_key: pathKey}, 'instructions', -1]
272
- )
272
+ ['fields', {_key: pathKey}, 'instructions', -1],
273
+ ),
273
274
  )
274
275
  }
275
276
  onChange(event)