Skip to content

Commit

Permalink
Fix: don't render FloatingLink on readOnly (#1978)
Browse files Browse the repository at this point in the history
* fix

* Create popular-spoons-type.md

* Create large-tips-heal.md
  • Loading branch information
zbeyens authored Nov 7, 2022
1 parent 28679ac commit 0bdfb47
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-tips-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-core": minor
---

Plugin fields `renderBeforeEditable` and `renderAfterEditable` now have `TEditableProps` passed as the first parameter.
5 changes: 5 additions & 0 deletions .changeset/popular-spoons-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-ui-link": patch
---

Fix: don't render `FloatingLink` on `readOnly`
4 changes: 2 additions & 2 deletions packages/core/src/components/plate/PlateEditable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const PlateEditable = <V extends Value = Value>({
afterEditable = (
<>
{afterEditable}
{renderAfterEditable()}
{renderAfterEditable(editableProps)}
</>
);
}
Expand All @@ -70,7 +70,7 @@ export const PlateEditable = <V extends Value = Value>({
beforeEditable = (
<>
{beforeEditable}
{renderBeforeEditable()}
{renderBeforeEditable(editableProps)}
</>
);
}
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/types/plugin/PlatePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, ReactNode } from 'react';
import { Value } from '../../slate/editor/TEditor';
import { TEditableProps } from '../../slate/index';
import { AnyObject } from '../misc/AnyObject';
import { Nullable } from '../misc/Nullable';
import { WithRequired } from '../misc/types';
Expand Down Expand Up @@ -164,12 +165,16 @@ export type PlatePlugin<
/**
* Render a component after `Editable`.
*/
renderAfterEditable?: () => JSX.Element | null;
renderAfterEditable?: (
editableProps: TEditableProps<V>
) => JSX.Element | null;

/**
* Render a component before `Editable`.
*/
renderBeforeEditable?: () => JSX.Element | null;
renderBeforeEditable?: (
editableProps: TEditableProps<V>
) => JSX.Element | null;

/**
* Property used by `serializeHtml` util to replace `renderElement` and `renderLeaf` when serializing a node of this `type`.
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/nodes/link/src/PlateFloatingLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { TEditableProps } from '@udecode/plate-core';
import {
FloatingLink,
LaunchIcon,
Expand All @@ -18,9 +19,11 @@ import {
FloatingVerticalDivider,
} from '@udecode/plate-ui-toolbar';

export const PlateFloatingLink = () => {
export const PlateFloatingLink = ({ readOnly }: TEditableProps) => {
const isEditing = useFloatingLinkSelectors().isEditing();

if (readOnly) return null;

const input = (
<div tw="flex flex-col w-[330px]">
<FloatingInputWrapper>
Expand Down

2 comments on commit 0bdfb47

@vercel
Copy link

@vercel vercel bot commented on 0bdfb47 Nov 7, 2022

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:

plate-examples – ./

plate-examples.vercel.app
plate-examples-udecode.vercel.app
plate-examples-git-main-udecode.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0bdfb47 Nov 7, 2022

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:

plate – ./

plate.udecode.io
plate-udecode.vercel.app
plate-git-main-udecode.vercel.app
www.plate.udecode.io

Please sign in to comment.