Skip to content

Commit

Permalink
fix(core): add PortableTextInputProps to InputProps union (#4522)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed May 24, 2023
1 parent 6fb3855 commit 4031d3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
@@ -1,11 +1,8 @@
import {ArraySchemaType, PortableTextBlock} from '@sanity/types'
import {PortableTextBlock} from '@sanity/types'
import {
EditorChange,
OnCopyFn,
OnPasteFn,
Patch as EditorPatch,
PortableTextEditor,
HotkeyOptions,
InvalidValue,
EditorSelection,
Patch,
Expand All @@ -25,7 +22,7 @@ import {Box, useToast} from '@sanity/ui'
import {debounce} from 'lodash'
import {FormPatch, SANITY_PATCH_TYPE} from '../../patch'
import {ArrayOfObjectsItemMember, ObjectFormNode} from '../../store'
import type {ArrayOfObjectsInputProps, PortableTextMarker, RenderCustomMarkers} from '../../types'
import type {PortableTextInputProps} from '../../types'
import {EMPTY_ARRAY} from '../../../util'
import {pathToString} from '../../../field'
import {isMemberArrayOfObjects} from '../../members/object/fields/asserters'
Expand All @@ -34,7 +31,6 @@ import {FIXME} from '../../../FIXME'
import {Compositor, PortableTextEditorElement} from './Compositor'
import {InvalidValue as RespondToInvalidContent} from './InvalidValue'
import {usePatches} from './usePatches'
import {RenderBlockActionsCallback} from './types'
import {PortableTextMarkersProvider} from './contexts/PortableTextMarkers'
import {PortableTextMemberItemsProvider} from './contexts/PortableTextMembers'
import {_isArrayOfObjectsFieldMember, _isBlockType} from './_helpers'
Expand All @@ -49,19 +45,6 @@ export interface PortableTextMemberItem {
input?: ReactNode
}

/**
* @beta
*/
export interface PortableTextInputProps
extends ArrayOfObjectsInputProps<PortableTextBlock, ArraySchemaType<PortableTextBlock>> {
hotkeys?: HotkeyOptions
markers?: PortableTextMarker[]
onCopy?: OnCopyFn
onPaste?: OnPasteFn
renderBlockActions?: RenderBlockActionsCallback
renderCustomMarkers?: RenderCustomMarkers
}

/**
* The root Portable Text Input component
*
Expand Down
Expand Up @@ -2,8 +2,8 @@ import {fireEvent, waitFor} from '@testing-library/react'
import React from 'react'
import {PortableTextMarker} from '../../../../types'
// import {renderInput} from '../../../../test/renderInput'
import {PortableTextInput, PortableTextInputProps} from '../../PortableTextInput'
import {portableTextType} from './schema'
// import {PortableTextInput, PortableTextInputProps} from '../../PortableTextInput'
// import {portableTextType} from './schema'

jest.setTimeout(10000)

Expand Down
25 changes: 20 additions & 5 deletions packages/sanity/src/core/form/types/inputProps.ts
Expand Up @@ -8,12 +8,14 @@ import {
NumberSchemaType,
ObjectSchemaType,
Path,
PortableTextBlock,
ReferenceValue,
SchemaType,
SlugValue,
StringSchemaType,
} from '@sanity/types'
import React, {ComponentType, FocusEventHandler, FormEventHandler} from 'react'
import {HotkeyOptions, OnCopyFn, OnPasteFn} from '@sanity/portable-text-editor'
import {FormPatch, PatchEvent} from '../patch'
import {
ArrayOfObjectsFormNode,
Expand All @@ -26,6 +28,7 @@ import {

import {UploaderResolver} from '../studio'
import {FormFieldGroup} from '../store'
import {RenderBlockActionsCallback} from '../inputs'
import {
RenderArrayOfObjectsItemCallback,
RenderArrayOfPrimitivesItemCallback,
Expand All @@ -34,7 +37,7 @@ import {
RenderPreviewCallback,
} from './renderCallback'
import {ArrayInputInsertEvent, ArrayInputMoveItemEvent, UploadEvent} from './event'
import {ArrayInputFunctionsProps} from './_transitional'
import {ArrayInputFunctionsProps, PortableTextMarker, RenderCustomMarkers} from './_transitional'

/** @beta */
export interface BaseInputProps {
Expand Down Expand Up @@ -285,17 +288,29 @@ export interface BooleanInputProps<S extends BooleanSchemaType = BooleanSchemaTy
/** @beta */
export type PrimitiveInputProps = StringInputProps | BooleanInputProps | NumberInputProps

/** @beta */
export interface PortableTextInputProps
extends ArrayOfObjectsInputProps<PortableTextBlock, ArraySchemaType<PortableTextBlock>> {
hotkeys?: HotkeyOptions
markers?: PortableTextMarker[]
onCopy?: OnCopyFn
onPaste?: OnPasteFn
renderBlockActions?: RenderBlockActionsCallback
renderCustomMarkers?: RenderCustomMarkers
}

/** @beta */
export type InputProps =
| ArrayOfObjectsInputProps
| ArrayOfPrimitivesInputProps
| BooleanInputProps
| NumberInputProps
| ObjectInputProps
| ObjectInputProps<CrossDatasetReferenceValue>
| ObjectInputProps<FileValue>
| ObjectInputProps<GeopointValue>
| ObjectInputProps<ImageValue>
| ObjectInputProps<ReferenceValue>
| ObjectInputProps<SlugValue>
| ArrayOfObjectsInputProps
| ArrayOfPrimitivesInputProps
| PortableTextInputProps
| StringInputProps
| BooleanInputProps
| NumberInputProps

2 comments on commit 4031d3c

@vercel
Copy link

@vercel vercel bot commented on 4031d3c May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 4031d3c May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.