From 07d80a7bfa7f0abc5028838727d862635196c574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gr=C3=B8ngaard?= Date: Fri, 13 Dec 2024 13:15:09 +0100 Subject: [PATCH] fix(core): make PTE read-only until it's `'ready'` (#8033) --- .../form/inputs/PortableText/PortableTextInput.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/core/form/inputs/PortableText/PortableTextInput.tsx b/packages/sanity/src/core/form/inputs/PortableText/PortableTextInput.tsx index 2c56a8ee883..a3aeac6e850 100644 --- a/packages/sanity/src/core/form/inputs/PortableText/PortableTextInput.tsx +++ b/packages/sanity/src/core/form/inputs/PortableText/PortableTextInput.tsx @@ -132,6 +132,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { const [isFullscreen, setIsFullscreen] = useState(initialFullscreen ?? false) const [isActive, setIsActive] = useState(initialActive ?? false) const [hasFocusWithin, setHasFocusWithin] = useState(false) + const [ready, setReady] = useState(false) const telemetry = useTelemetry() const toast = useToast() @@ -237,6 +238,9 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { description: change.description, }) break + case 'ready': + setReady(true) + break default: } if (editorRef.current && onEditorChange) { @@ -305,7 +309,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { file, uploaderCandidates: getUploadCandidates(schemaType.of, resolveUploader, file), })) - const ready = tasks.filter((task) => task.uploaderCandidates.length > 0) + const readyTasks = tasks.filter((task) => task.uploaderCandidates.length > 0) const rejected: UploadTask[] = tasks.filter((task) => task.uploaderCandidates.length === 0) if (rejected.length > 0) { @@ -330,7 +334,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { // todo: consider if we should to ask the user here // the list of candidates is sorted by their priority and the first one is selected - ready.forEach((task) => { + readyTasks.forEach((task) => { uploadFile( task.file, // eslint-disable-next-line max-nested-callbacks @@ -379,7 +383,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { onChange={handleEditorChange} maxBlocks={undefined} // TODO: from schema? ref={editorRef} - readOnly={readOnly} + readOnly={readOnly || !ready} schemaType={schemaType} value={value} > @@ -397,6 +401,7 @@ export function PortableTextInput(props: PortableTextInputProps): ReactNode { onPaste={handlePaste} onToggleFullscreen={handleToggleFullscreen} rangeDecorations={rangeDecorations} + readOnly={readOnly || !ready} renderBlockActions={renderBlockActions} renderCustomMarkers={renderCustomMarkers} renderEditable={renderEditable}