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

Rename HeaderNode to HeadingNode #2

Merged
merged 2 commits into from
Dec 10, 2020
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
3 changes: 0 additions & 3 deletions packages/outline-extensions/HeaderNode.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/outline-extensions/HeadingNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./dist/OutlineHeadingNode');
46 changes: 0 additions & 46 deletions packages/outline-extensions/src/OutlineHeaderNode.js

This file was deleted.

46 changes: 46 additions & 0 deletions packages/outline-extensions/src/OutlineHeadingNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @flow strict

import type {NodeKey} from 'outline';

import {BlockNode} from 'outline';

type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';

export class HeadingNode extends BlockNode {
_type: 'heading';
_tag: HeadingTagType;

constructor(tag: HeadingTagType, key?: NodeKey) {
super(key);
this._tag = tag;
this.type = 'heading';
}
static parse(
// $FlowFixMe: TODO: refine
data: Object,
): HeadingNode {
const header = new HeadingNode(data._tag);
header.flags = data.flags;
return header;
}
clone(): HeadingNode {
const clone = new HeadingNode(this._tag, this.key);
clone.children = [...this.children];
clone.parent = this.parent;
clone.flags = this.flags;
return clone;
}

// View

createDOM(): HTMLElement {
return document.createElement(this._tag);
}
updateDOM(prevNode: HeadingNode, dom: HTMLElement): boolean {
return false;
}
}

export function createHeadingNode(headingTag: HeadingTagType): HeadingNode {
return new HeadingNode(headingTag);
}
14 changes: 7 additions & 7 deletions packages/outline-react/src/useOutlineAutoFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {TextNode} from 'outline';

import {useEffect} from 'react';
import {createListItemNode, ParagraphNode} from 'outline';
import {createHeaderNode} from 'outline-extensions/HeaderNode';
import {createHeadingNode} from 'outline-extensions/HeadingNode';
import {createListNode} from 'outline-extensions/ListNode';
import {createQuoteNode} from 'outline-extensions/QuoteNode';

Expand All @@ -25,10 +25,10 @@ function textNodeTransform(node: TextNode, view: View): void {
if (textContent.length > 1 && secondChar === ' ') {
if (firstChar === '#') {
node.spliceText(0, 2, '', true);
const header = createHeaderNode('h1');
const heading = createHeadingNode('h1');
const children = block.getChildren();
children.forEach((child) => header.append(child));
block.replace(header);
children.forEach((child) => heading.append(child));
block.replace(heading);
} else if (firstChar === '>') {
node.spliceText(0, 2, '', true);
const quote = createQuoteNode();
Expand All @@ -47,10 +47,10 @@ function textNodeTransform(node: TextNode, view: View): void {
} else if (textContent.length > 2 && thirdChar === ' ') {
if (firstChar === '#' && secondChar === '#') {
node.spliceText(0, 2, '', true);
const header = createHeaderNode('h2');
const heading = createHeadingNode('h2');
const children = block.getChildren();
children.forEach((child) => header.append(child));
block.replace(header);
children.forEach((child) => heading.append(child));
block.replace(heading);
} else if (firstChar === '1' && secondChar === '.') {
node.spliceText(0, 2, '', true);
const list = createListNode('ol');
Expand Down
6 changes: 3 additions & 3 deletions packages/outline-react/src/useOutlineRichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {OutlineEditor, Selection} from 'outline';
import {useEffect, useRef} from 'react';
import useOutlineInputEvents from 'outline-react/useOutlineInputEvents';
import useOutlineFocusIn from 'outline-react/useOutlineFocusIn';
import {HeaderNode} from 'outline-extensions/HeaderNode';
import {HeadingNode} from 'outline-extensions/HeadingNode';
import {ListNode} from 'outline-extensions/ListNode';
import {QuoteNode} from 'outline-extensions/QuoteNode';

Expand Down Expand Up @@ -36,12 +36,12 @@ export default function useOutlineRichText(

useEffect(() => {
if (editor !== null) {
const removeHeaderType = editor.addNodeType('header', HeaderNode);
const removeHeadingType = editor.addNodeType('heading', HeadingNode);
const removeListType = editor.addNodeType('list', ListNode);
const removeQuoteType = editor.addNodeType('quote', QuoteNode);

return () => {
removeHeaderType();
removeHeadingType();
removeListType();
removeQuoteType();
};
Expand Down