Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-playground] Bug Fix: Disable image and inline focusing, adding caption and editing in read-only mode #6705

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/lexical-playground/src/nodes/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {HashtagPlugin} from '@lexical/react/LexicalHashtagPlugin';
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
import {LexicalNestedComposer} from '@lexical/react/LexicalNestedComposer';
import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin';
import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
import {useLexicalNodeSelection} from '@lexical/react/useLexicalNodeSelection';
import {mergeRegister} from '@lexical/utils';
import {
Expand Down Expand Up @@ -171,6 +172,7 @@ export default function ImageComponent({
const [selection, setSelection] = useState<BaseSelection | null>(null);
const activeEditorRef = useRef<LexicalEditor | null>(null);
const [isLoadError, setIsLoadError] = useState<boolean>(false);
const isEditable = useLexicalEditable();

const $onDelete = useCallback(
(payload: KeyboardEvent) => {
Expand Down Expand Up @@ -398,7 +400,7 @@ export default function ImageComponent({
} = useSettings();

const draggable = isSelected && $isNodeSelection(selection) && !isResizing;
const isFocused = isSelected || isResizing;
const isFocused = (isSelected || isResizing) && isEditable;
return (
<Suspense fallback={null}>
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
import {LexicalNestedComposer} from '@lexical/react/LexicalNestedComposer';
import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin';
import {useLexicalEditable} from '@lexical/react/useLexicalEditable';
import {useLexicalNodeSelection} from '@lexical/react/useLexicalNodeSelection';
import {mergeRegister} from '@lexical/utils';
import {
Expand Down Expand Up @@ -200,6 +201,7 @@ export default function InlineImageComponent({
const [editor] = useLexicalComposerContext();
const [selection, setSelection] = useState<BaseSelection | null>(null);
const activeEditorRef = useRef<LexicalEditor | null>(null);
const isEditable = useLexicalEditable();

const $onDelete = useCallback(
(payload: KeyboardEvent) => {
Expand Down Expand Up @@ -352,25 +354,27 @@ export default function InlineImageComponent({
]);

const draggable = isSelected && $isNodeSelection(selection);
const isFocused = isSelected;
const isFocused = isSelected && isEditable;
return (
<Suspense fallback={null}>
<>
<span draggable={draggable}>
<button
className="image-edit-button"
ref={buttonRef}
onClick={() => {
showModal('Update Inline Image', (onClose) => (
<UpdateInlineImageDialog
activeEditor={editor}
nodeKey={nodeKey}
onClose={onClose}
/>
));
}}>
Edit
</button>
{isEditable && (
<button
className="image-edit-button"
ref={buttonRef}
onClick={() => {
showModal('Update Inline Image', (onClose) => (
<UpdateInlineImageDialog
activeEditor={editor}
nodeKey={nodeKey}
onClose={onClose}
/>
));
}}>
Edit
</button>
)}
<LazyImage
className={
isFocused
Expand Down
Loading