5 files changed +38
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { defineType } from 'sanity'
2
+
3
+ export default defineType ( {
4
+ name : 'ptReference' ,
5
+ title : 'Portable Text Reference' ,
6
+ type : 'document' ,
7
+ fields : [
8
+ {
9
+ name : 'body' ,
10
+ title : 'Body' ,
11
+ type : 'array' ,
12
+ of : [
13
+ {
14
+ type : 'block' ,
15
+ marks : {
16
+ annotations : [ { type : 'reference' , to : { type : 'author' } } ] ,
17
+ } ,
18
+ of : [ { type : 'reference' , to : { type : 'author' } } ] ,
19
+ } ,
20
+ { type : 'reference' , to : { type : 'author' } } ,
21
+ ] ,
22
+ } ,
23
+ ] ,
24
+ } )
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ import crossDatasetReference, {crossDatasetSubtype} from './standard/crossDatase
107
107
import { circularCrossDatasetReferenceTest } from './debug/circularCrossDatasetReference'
108
108
import { allNativeInputComponents } from './debug/allNativeInputComponents'
109
109
import fieldGroupsWithFieldsets from './debug/fieldGroupsWithFieldsets'
110
+ import ptReference from './debug/ptReference'
110
111
111
112
// @todo temporary, until code input is v3 compatible
112
113
const codeInputType = {
@@ -203,6 +204,7 @@ export const schemaTypes = [
203
204
previewSelectBugRepro ,
204
205
ptAllTheBellsAndWhistlesType ,
205
206
ptCustomMarkersTestType ,
207
+ ptReference ,
206
208
radio ,
207
209
readOnly ,
208
210
recursive ,
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export const DEBUG_INPUT_TYPES = [
72
72
'validationTest' ,
73
73
'allNativeInputComponents' ,
74
74
'scrollBug' ,
75
+ 'ptReference' ,
75
76
]
76
77
77
78
export const CI_INPUT_TYPES = [ 'conditionalFieldset' , 'validationCI' ]
Original file line number Diff line number Diff line change @@ -324,6 +324,7 @@ export function ReferenceInput(props: ReferenceInputProps) {
324
324
renderValue = { renderValue }
325
325
openButton = { { onClick : handleAutocompleteOpenButtonClick } }
326
326
portalRef = { autoCompletePortalRef }
327
+ value = { value ?. _ref }
327
328
/>
328
329
329
330
{ createOptions . length > 0 && (
Original file line number Diff line number Diff line change @@ -186,6 +186,14 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
186
186
[ refType ?. name , value ?. _ref ]
187
187
)
188
188
189
+ const handleReplace = useCallback ( ( ) => {
190
+ if ( hasRef && isEditing ) {
191
+ onPathFocus ( [ ] )
192
+ } else {
193
+ onPathFocus ( [ '_ref' ] )
194
+ }
195
+ } , [ hasRef , isEditing , onPathFocus ] )
196
+
189
197
const menu = useMemo (
190
198
( ) =>
191
199
readOnly ? null : (
@@ -201,9 +209,7 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
201
209
< MenuItem
202
210
text = { hasRef && isEditing ? 'Cancel replace' : 'Replace' }
203
211
icon = { hasRef && isEditing ? CloseIcon : ReplaceIcon }
204
- onClick = {
205
- hasRef && isEditing ? ( ) => onPathFocus ( [ ] ) : ( ) => onPathFocus ( [ '_ref' ] )
206
- }
212
+ onClick = { handleReplace }
207
213
/>
208
214
< MenuItem text = "Duplicate" icon = { DuplicateIcon } onClick = { handleDuplicate } />
209
215
< InsertMenu onInsert = { handleInsert } types = { insertableTypes } />
@@ -231,11 +237,11 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
231
237
onRemove ,
232
238
hasRef ,
233
239
isEditing ,
240
+ handleReplace ,
234
241
handleDuplicate ,
235
242
handleInsert ,
236
243
insertableTypes ,
237
244
OpenLink ,
238
- onPathFocus ,
239
245
]
240
246
)
241
247
0 commit comments