@sanity/assist 1.1.1 → 1.1.3

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.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -81,7 +81,7 @@
81
81
  "react": "^18.2.0",
82
82
  "react-dom": "^18.2.0",
83
83
  "rimraf": "^4.4.0",
84
- "sanity": "^3.14.5",
84
+ "sanity": "^3.16.1",
85
85
  "semantic-release": "^21.0.5",
86
86
  "styled-components": "^5.3.9",
87
87
  "typescript": "^5.1.3",
@@ -89,7 +89,7 @@
89
89
  },
90
90
  "peerDependencies": {
91
91
  "react": "^18",
92
- "sanity": "^3.14.5",
92
+ "sanity": "^3.16",
93
93
  "styled-components": "^5.2"
94
94
  },
95
95
  "engines": {
@@ -1,12 +1,14 @@
1
- import {FieldProps, isArraySchemaType} from 'sanity'
1
+ import {FieldProps, isArraySchemaType, pathToString} from 'sanity'
2
2
  import {useAssistPresence} from '../presence/useAssistPresence'
3
- import {useMemo} from 'react'
3
+ import {useContext, useMemo} from 'react'
4
4
  import {Box, Flex} from '@sanity/ui'
5
5
  import {contextDocumentTypeName} from '../types'
6
6
  import {isAssistSupported} from '../helpers/assistSupported'
7
7
  import {isPortableTextArray, isType} from '../helpers/typeUtils'
8
8
  import {AiFieldPresence} from '../presence/AiFieldPresence'
9
- import {FieldActionsOnboarding} from '../onboarding/FieldActionsOnboarding'
9
+ import {AssistOnboardingPopover} from '../onboarding/FieldActionsOnboarding'
10
+ import {FirstAssistedPathContext} from '../onboarding/FirstAssistedPathProvider'
11
+ import {fieldOnboardingKey, useOnboardingFeature} from '../onboarding/onboardingStore'
10
12
 
11
13
  export function AssistFieldWrapper(props: FieldProps) {
12
14
  const {schemaType} = props
@@ -28,6 +30,8 @@ export function AssistFieldWrapper(props: FieldProps) {
28
30
  }
29
31
 
30
32
  export function AssistField(props: FieldProps) {
33
+ const {path} = props
34
+
31
35
  const isPortableText = useMemo(
32
36
  () => !!(isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)),
33
37
  [props.schemaType]
@@ -35,6 +39,14 @@ export function AssistField(props: FieldProps) {
35
39
 
36
40
  const presence = useAssistPresence(props.path, isPortableText)
37
41
 
42
+ const firstAssistedPath = useContext(FirstAssistedPathContext)
43
+ const isFirstAssisted = useMemo(
44
+ () => pathToString(path) === firstAssistedPath,
45
+ [path, firstAssistedPath]
46
+ )
47
+
48
+ const {showOnboarding, dismissOnboarding} = useOnboardingFeature(fieldOnboardingKey)
49
+
38
50
  const actions = (
39
51
  <Flex gap={2} align="center" justify="space-between">
40
52
  {presence.map((pre) => (
@@ -43,9 +55,18 @@ export function AssistField(props: FieldProps) {
43
55
  </Box>
44
56
  ))}
45
57
 
46
- <FieldActionsOnboarding {...props}>{props.actions}</FieldActionsOnboarding>
58
+ {isFirstAssisted && showOnboarding && <AssistOnboardingPopover dismiss={dismissOnboarding} />}
47
59
  </Flex>
48
60
  )
49
61
 
50
- return props.renderDefault({...props, actions})
62
+ return props.renderDefault({
63
+ ...props,
64
+
65
+ // When showing the onboarding, prevent default field actions from being rendered
66
+ actions: isFirstAssisted && showOnboarding ? [] : props.actions,
67
+
68
+ // Render presence (and possibly onboarding) in the internal slot (between presence and the field actions)
69
+ // eslint-disable-next-line camelcase
70
+ __internal_slot: actions,
71
+ })
51
72
  }
@@ -1,56 +1,33 @@
1
- import {Path, pathToString} from 'sanity'
2
- import {Button, Flex, Popover, Stack, Text} from '@sanity/ui'
3
- import {PropsWithChildren, useContext, useMemo, useRef} from 'react'
4
- import {FirstAssistedPathContext} from './FirstAssistedPathProvider'
1
+ import {Button, Card, Flex, Popover, Stack, Text} from '@sanity/ui'
2
+ import {useRef} from 'react'
5
3
  import {AssistFeatureBadge} from '../components/AssistFeatureBadge'
6
4
  import {ArrowRightIcon, CheckmarkIcon, SparklesIcon} from '@sanity/icons'
7
5
  import {pluginTitle, releaseAnnouncementUrl} from '../constants'
8
- import {fieldOnboardingKey, useOnboardingFeature} from './onboardingStore'
9
6
 
10
7
  export interface FieldActionsOnboardingProps {
11
- path: Path
8
+ dismiss: () => void
12
9
  }
13
10
 
14
- export function FieldActionsOnboarding(props: PropsWithChildren<FieldActionsOnboardingProps>) {
15
- const {path, children} = props
16
-
17
- const firstAssistedPath = useContext(FirstAssistedPathContext)
18
- const isFirstAssisted = useMemo(
19
- () => pathToString(path) === firstAssistedPath,
20
- [path, firstAssistedPath]
21
- )
22
-
23
- if (!isFirstAssisted) {
24
- return <>{children}</>
25
- }
26
-
27
- return <AssistOnboardingPopover {...props} />
28
- }
29
-
30
- function AssistOnboardingPopover(props: PropsWithChildren<FieldActionsOnboardingProps>) {
31
- const {showOnboarding, dismissOnboarding} = useOnboardingFeature(fieldOnboardingKey)
32
-
33
- if (!showOnboarding) {
34
- return <>{props.children}</>
35
- }
11
+ export function AssistOnboardingPopover(props: FieldActionsOnboardingProps) {
12
+ const {dismiss} = props
36
13
 
37
14
  return (
38
15
  <Popover
39
- content={<AssistIntroCard path={props.path} dismiss={dismissOnboarding} />}
16
+ content={<AssistIntroCard dismiss={dismiss} />}
40
17
  open
41
18
  portal
42
19
  placeholder="bottom"
43
20
  tone="default"
44
21
  width={0}
45
22
  >
46
- <div>
47
- <Button disabled fontSize={1} icon={SparklesIcon} mode="ghost" padding={2} />
48
- </div>
23
+ <Card radius={2} shadow={2} style={{padding: 2, lineHeight: 0}}>
24
+ <Button disabled fontSize={1} icon={SparklesIcon} mode="bleed" padding={2} />
25
+ </Card>
49
26
  </Popover>
50
27
  )
51
28
  }
52
29
 
53
- function AssistIntroCard(props: FieldActionsOnboardingProps & {dismiss: () => void}) {
30
+ function AssistIntroCard(props: {dismiss: () => void}) {
54
31
  const buttonRef = useRef<HTMLButtonElement>(null)
55
32
 
56
33
  return (