Adds a 60px area to the left and right of editable area (#5197

* Adds a 60px area to the left and right of editable area that allows clicking to focus paragraphs

* tsc
This commit is contained in:
Tom Moor
2023-04-13 22:24:33 -04:00
committed by GitHub
parent 515f5e8e73
commit 169a99f21e
5 changed files with 23 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
import styled from "styled-components"; import styled from "styled-components";
const ClickablePadding = styled.div<{ grow?: boolean; minHeight?: string }>` const ClickablePadding = styled.div<{
grow?: boolean;
minHeight?: React.CSSProperties["paddingBottom"];
}>`
min-height: ${(props) => props.minHeight || "50vh"}; min-height: ${(props) => props.minHeight || "50vh"};
flex-grow: 100; flex-grow: 100;
cursor: text; cursor: text;

View File

@@ -47,7 +47,7 @@ export type Props = Optional<
onHeadingsChange?: (headings: Heading[]) => void; onHeadingsChange?: (headings: Heading[]) => void;
onSynced?: () => Promise<void>; onSynced?: () => Promise<void>;
onPublish?: (event: React.MouseEvent) => any; onPublish?: (event: React.MouseEvent) => any;
bottomPadding?: string; editorStyle?: React.CSSProperties;
}; };
function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) { function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
@@ -340,12 +340,12 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
placeholder={props.placeholder || ""} placeholder={props.placeholder || ""}
defaultValue={props.defaultValue || ""} defaultValue={props.defaultValue || ""}
/> />
{props.bottomPadding && !props.readOnly && ( {props.editorStyle?.paddingBottom && !props.readOnly && (
<ClickablePadding <ClickablePadding
onClick={focusAtEnd} onClick={focusAtEnd}
onDrop={handleDrop} onDrop={handleDrop}
onDragOver={handleDragOver} onDragOver={handleDragOver}
minHeight={props.bottomPadding} minHeight={props.editorStyle.paddingBottom}
/> />
)} )}
{activeLinkElement && !shareId && ( {activeLinkElement && !shareId && (

View File

@@ -127,8 +127,10 @@ export type Props = {
/** Callback when a toast message is triggered (eg "link copied") */ /** Callback when a toast message is triggered (eg "link copied") */
onShowToast: (message: string) => void; onShowToast: (message: string) => void;
className?: string; className?: string;
/** Optional style overrides */ /** Optional style overrides for the container*/
style?: React.CSSProperties; style?: React.CSSProperties;
/** Optional style overrides for the contenteeditable */
editorStyle?: React.CSSProperties;
}; };
type State = { type State = {
@@ -759,6 +761,7 @@ export class Editor extends React.PureComponent<
readOnly={readOnly} readOnly={readOnly}
readOnlyWriteCheckboxes={readOnlyWriteCheckboxes} readOnlyWriteCheckboxes={readOnlyWriteCheckboxes}
focusedCommentId={this.props.focusedCommentId} focusedCommentId={this.props.focusedCommentId}
editorStyle={this.props.editorStyle}
ref={this.elementRef} ref={this.elementRef}
/> />
{!readOnly && this.view && ( {!readOnly && this.view && (

View File

@@ -25,7 +25,7 @@ import EditableTitle from "./EditableTitle";
const extensions = withComments(richExtensions); const extensions = withComments(richExtensions);
type Props = Omit<EditorProps, "extensions"> & { type Props = Omit<EditorProps, "extensions" | "editorStyle"> & {
onChangeTitle: (text: string) => void; onChangeTitle: (text: string) => void;
id: string; id: string;
document: Document; document: Document;
@@ -189,12 +189,18 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
: undefined : undefined
} }
onDeleteCommentMark={ onDeleteCommentMark={
team?.getPreference(TeamPreference.Commenting) team?.getPreference(TeamPreference.Commenting) && can.comment
? handleRemoveComment ? handleRemoveComment
: undefined : undefined
} }
extensions={extensions} extensions={extensions}
bottomPadding={`calc(50vh - ${childRef.current?.offsetHeight || 0}px)`} editorStyle={{
padding: "0 60px",
margin: "0 -60px",
paddingBottom: `calc(50vh - ${
childRef.current?.offsetHeight || 0
}px)`,
}}
{...rest} {...rest}
/> />
<div ref={childRef}>{children}</div> <div ref={childRef}>{children}</div>

View File

@@ -7,6 +7,7 @@ export type Props = {
rtl: boolean; rtl: boolean;
readOnly?: boolean; readOnly?: boolean;
readOnlyWriteCheckboxes?: boolean; readOnlyWriteCheckboxes?: boolean;
editorStyle?: React.CSSProperties;
grow?: boolean; grow?: boolean;
theme: DefaultTheme; theme: DefaultTheme;
}; };
@@ -143,6 +144,8 @@ width: 100%;
-webkit-font-variant-ligatures: none; -webkit-font-variant-ligatures: none;
font-variant-ligatures: none; font-variant-ligatures: none;
font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
padding: ${props.editorStyle?.padding ?? "initial"};
margin: ${props.editorStyle?.margin ?? "initial"};
& > .ProseMirror-yjs-cursor { & > .ProseMirror-yjs-cursor {
display: none; display: none;