Skip to content
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
2 changes: 2 additions & 0 deletions apps/web/core/components/editor/lite-text/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const LiteTextEditor = React.forwardRef(function LiteTextEditor(
placeholder = t("issue.comments.placeholder"),
disabledExtensions: additionalDisabledExtensions = [],
editorClassName = "",
showPlaceholderOnEmpty = true,
...rest
} = props;
// states
Expand Down Expand Up @@ -154,6 +155,7 @@ export const LiteTextEditor = React.forwardRef(function LiteTextEditor(
}),
}}
placeholder={placeholder}
showPlaceholderOnEmpty={showPlaceholderOnEmpty}
containerClassName={cn(containerClassName, "relative", {
"p-2": !editable,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function EditorWrapper(props: Props) {
handleEditorReady,
autofocus,
placeholder,
showPlaceholderOnEmpty,
tabIndex,
value,
} = props;
Expand All @@ -67,6 +68,7 @@ export function EditorWrapper(props: Props) {
handleEditorReady,
autofocus,
placeholder,
showPlaceholderOnEmpty,
tabIndex,
value,
});
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/core/extensions/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type TArguments = Pick<
| "isTouchDevice"
| "mentionHandler"
| "placeholder"
| "showPlaceholderOnEmpty"
| "tabIndex"
| "extendedEditorProps"
> & {
Expand All @@ -65,6 +66,7 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
isTouchDevice = false,
mentionHandler,
placeholder,
showPlaceholderOnEmpty,
tabIndex,
editable,
extendedEditorProps,
Expand Down Expand Up @@ -108,7 +110,7 @@ export const CoreEditorExtensions = (args: TArguments): Extensions => {
TableCell,
TableRow,
CustomMentionExtension(mentionHandler),
CustomPlaceholderExtension({ placeholder }),
CustomPlaceholderExtension({ placeholder, showPlaceholderOnEmpty }),
CharacterCount,
CustomColorExtension,
CustomTextAlignExtension,
Expand Down
10 changes: 9 additions & 1 deletion packages/editor/src/core/extensions/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import type { IEditorProps } from "@/types";

type TArgs = {
placeholder: IEditorProps["placeholder"];
showPlaceholderOnEmpty: IEditorProps["showPlaceholderOnEmpty"];
};

export const CustomPlaceholderExtension = (args: TArgs) => {
const { placeholder } = args;
const { placeholder, showPlaceholderOnEmpty = false } = args;

return Placeholder.configure({
placeholder: ({ editor, node }) => {
Expand All @@ -29,6 +30,13 @@ export const CustomPlaceholderExtension = (args: TArgs) => {

if (shouldHidePlaceholder) return "";

if (showPlaceholderOnEmpty) {
const isDocumentEmpty = editor.state.doc.textContent.length === 0;
if (!isDocumentEmpty) {
return "";
}
}

if (placeholder) {
if (typeof placeholder === "string") return placeholder;
else return placeholder(editor.isFocused, editor.getHTML());
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/hooks/use-collaborative-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
mentionHandler,
onEditorFocus,
placeholder,
showPlaceholderOnEmpty,
realtimeConfig,
serverHandler,
tabIndex,
Expand Down Expand Up @@ -119,6 +120,7 @@ export const useCollaborativeEditor = (props: TCollaborativeEditorHookProps) =>
onEditorFocus,
onTransaction,
placeholder,
showPlaceholderOnEmpty,
provider,
tabIndex,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/hooks/use-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useEditor = (props: TEditorHookProps) => {
onEditorFocus,
onTransaction,
placeholder,
showPlaceholderOnEmpty,
tabIndex,
provider,
value,
Expand Down Expand Up @@ -70,6 +71,7 @@ export const useEditor = (props: TEditorHookProps) => {
isTouchDevice,
mentionHandler,
placeholder,
showPlaceholderOnEmpty,
tabIndex,
provider,
}),
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/core/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export type IEditorProps = {
onEnterKeyPress?: (e?: any) => void;
onTransaction?: () => void;
placeholder?: string | ((isFocused: boolean, value: string) => string);
showPlaceholderOnEmpty?: boolean;
tabIndex?: number;
value?: string | null;
extendedEditorProps: IEditorPropsExtended;
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/core/types/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type TEditorHookProps = TCoreHookProps &
| "onChange"
| "onTransaction"
| "placeholder"
| "showPlaceholderOnEmpty"
| "tabIndex"
| "value"
> & {
Expand All @@ -50,6 +51,7 @@ export type TCollaborativeEditorHookProps = TCoreHookProps &
| "onChange"
| "onTransaction"
| "placeholder"
| "showPlaceholderOnEmpty"
| "tabIndex"
> &
Pick<
Expand Down
Loading