Skip to content

Commit

Permalink
chore: cleanup old slate code
Browse files Browse the repository at this point in the history
  • Loading branch information
demshy committed Jul 26, 2023
1 parent 9ae9f0c commit c4e0c0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ function RawEditor(props) {
)}
value={value}
onChange={handleChange}
// onPaste={this.handlePaste}
// onCut={this.handleCut}
// onCopy={this.handleCopy}
/>
)}
</ClassNames>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function Editor(props) {
} = props;

const editor = useMemo(
() => withReact(withHistory(withShortcodes(withBlocks(withLists(withInlines(createEditor())))))),
() =>
withReact(withHistory(withShortcodes(withBlocks(withLists(withInlines(createEditor())))))),
[],
);

Expand Down Expand Up @@ -177,20 +178,8 @@ function Editor(props) {
}
const [toolbarKey, setToolbarKey] = useState(0);

// const handleDocumentChange = debounce(newValue => {
// setEditorValue(() => newValue);
// onChange(
// slateToMarkdown(newValue, {
// voidCodeBlock: !!codeBlockComponent,
// remarkPlugins: getRemarkPlugins(),
// }),
// );
// }, 150);

function handleChange(newValue) {
if (!isEqual(newValue, editorValue)) {
// debounce makes rerendering quite unpredictible
// handleDocumentChange(newValue);
setEditorValue(() => newValue);
onChange(
slateToMarkdown(newValue, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function withInlines(editor) {
editor.isInline = element =>
['link', 'button', 'break', 'image'].includes(element.type) || isInline(element);

editor.isVoid = element => ['break', 'image', 'thematic-break'].includes(element.type) || isVoid(element);
editor.isVoid = element =>
['break', 'image', 'thematic-break'].includes(element.type) || isVoid(element);

if (editor.keyDownHandlers === undefined) {
editor.keyDownHandlers = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,6 @@ const StyledBlockQuote = styled.blockquote`
margin-bottom: ${bottomMargin};
`;

const StyledPre = styled.pre`
margin-bottom: ${bottomMargin};
white-space: pre-wrap;
& > code {
display: block;
width: 100%;
overflow-y: auto;
background-color: #000;
color: #ccc;
border-radius: ${lengths.borderRadius};
padding: 10px;
}
`;

const StyledCode = styled.code`
background-color: ${colors.background};
border-radius: ${lengths.borderRadius};
Expand Down Expand Up @@ -157,14 +142,6 @@ function Quote(props) {
return <StyledBlockQuote {...props.attributes}>{props.children}</StyledBlockQuote>;
}

function CodeBlock(props) {
return (
<StyledPre>
<StyledCode {...props.attributes}>{props.children}</StyledCode>
</StyledPre>
);
}

function HeadingOne(props) {
return <StyledH1 {...props.attributes}>{props.children}</StyledH1>;
}
Expand Down Expand Up @@ -276,21 +253,6 @@ function Image(props) {
);
}

export function renderMark__DEPRECATED() {
return props => {
switch (props.mark.type) {
case 'bold':
return <Bold {...props} />;
case 'italic':
return <Italic {...props} />;
case 'strikethrough':
return <Strikethrough {...props} />;
case 'code':
return <Code {...props} />;
}
};
}

export function Leaf({ attributes, children, leaf }) {
if (leaf.bold) {
children = <Bold>{children}</Bold>;
Expand Down Expand Up @@ -388,64 +350,3 @@ export function Element(props) {
return <Paragraph style={style}>{children}</Paragraph>;
}
}

export function renderBlock__DEPRECATED({ classNameWrapper, codeBlockComponent }) {
return props => {
switch (props.node.type) {
case 'paragraph':
return <Paragraph {...props} />;
case 'list-item':
return <ListItem {...props} />;
case 'quote':
return <Quote {...props} />;
case 'code-block':
if (codeBlockComponent) {
return (
<VoidBlock {...props}>
<Shortcode
classNameWrapper={classNameWrapper}
typeOverload="code-block"
dataKey={false}
{...props}
/>
</VoidBlock>
);
}
return <CodeBlock {...props} />;
case 'heading-one':
return <HeadingOne {...props} />;
case 'heading-two':
return <HeadingTwo {...props} />;
case 'heading-three':
return <HeadingThree {...props} />;
case 'heading-four':
return <HeadingFour {...props} />;
case 'heading-five':
return <HeadingFive {...props} />;
case 'heading-six':
return <HeadingSix {...props} />;
case 'table':
return <Table {...props} />;
case 'table-row':
return <TableRow {...props} />;
case 'table-cell':
return <TableCell {...props} />;
case 'thematic-break':
return (
<VoidBlock {...props}>
<ThematicBreak />
</VoidBlock>
);
case 'bulleted-list':
return <BulletedList {...props} />;
case 'numbered-list':
return <NumberedList {...props} />;
case 'shortcode':
return (
<VoidBlock {...props} node={props.node}>
<Shortcode classNameWrapper={classNameWrapper} {...props} />
</VoidBlock>
);
}
};
}

0 comments on commit c4e0c0b

Please sign in to comment.