This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/components/Tree/Node.js
Jori Lallo ff17047791 Slate editor (#38)
* WIP: Slate editor

* WIP

* Focus at start / end working

* ah ha

* Super basic floating toolbar

* Nested list editing

* Pulling more logic into plugins

* inline code markdown

* Backspace at end of code block should remove mark

* Ensure there is always an empty line at editor end

* Add keyboard shortcuts for bold, italic, underline

* Add strikethrough shortcode and toolbar

* Toolbar to declarative
Fixed paragraph styling
Removed unused stuffs

* Super basic link editing

* Split Toolbar, now possible to edit and remove links

* Add new link to selection from toolbar working

* Ensure toolbar doesn't extend off screen

* Fix minor js issues, disable formatting of document title

* Boom, icons

* Remove codemirror, fix MD parsing issues

* CMD+S now saves inplace

* Add --- shortcut for horizontal rule

* Improved styling for link editor

* Add header anchors in readOnly

* More readable core text color

* Restored image file uploading 🎉

* Add support for inline md syntax, ** __ etc

* Centered

* Flooooow

* Checklist support

* Upgrade edit list plugin

* Finally. Allow keydown within rich textarea

* Update Markdown serializer

* Cleanup, remove async editor loading

* Editor > MarkdownEditor
Fixed unsaved changes warning triggered when all changes are saved

* MOAR typing

* Combine edit and view

* Fixed checkboxes still editable in readOnly

* wip

* Breadcrumb
Restored scroll

* Move document scene actions to menu

* Added: Support for code blocks, syntax highlighting

* Cleanup

*  > styled component

* Prevent CMD+Enter from adding linebreak

* Show image uploading in layout activity indicator

* Upgrade editor deps

* Improve link toolbar. Only one scenario where it's not working now
2017-05-17 19:36:31 -07:00

140 lines
3.4 KiB
JavaScript

/* eslint-disable */
import React from 'react';
import history from 'utils/History';
import styles from './Tree.scss';
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
class Node extends React.Component {
displayName: 'UITreeNode';
renderCollapse = () => {
const index = this.props.index;
if (index.children && index.children.length) {
const collapsed = index.node.collapsed;
return (
<span
className={cx(
styles.collapse,
collapsed ? styles.caretRight : styles.caretDown
)}
onMouseDown={function(e) {
e.stopPropagation();
}}
onClick={this.handleCollapse}
>
<img alt="Expand" src={require('./assets/chevron.svg')} />
</span>
);
}
return null;
};
renderChildren = () => {
const index = this.props.index;
const tree = this.props.tree;
const dragging = this.props.dragging;
if (index.children && index.children.length) {
const childrenStyles = {};
if (!this.props.rootNode) {
if (index.node.collapsed) childrenStyles.display = 'none';
childrenStyles.paddingLeft = `${this.props.paddingLeft}px`;
}
return (
<div className={styles.children} style={childrenStyles}>
{index.children.map(child => {
const childIndex = tree.getIndex(child);
return (
<Node
tree={tree}
index={childIndex}
key={childIndex.id}
dragging={dragging}
allowUpdates={this.props.allowUpdates}
paddingLeft={this.props.paddingLeft}
onCollapse={this.props.onCollapse}
onDragStart={this.props.onDragStart}
/>
);
})}
</div>
);
}
return null;
};
isModifying = () => {
return this.props.allowUpdates && !this.props.rootNode;
};
onClick = () => {
const index = this.props.index;
const node = index.node;
if (!this.isModifying()) history.push(node.url);
};
render() {
const index = this.props.index;
const dragging = this.props.dragging;
const node = index.node;
const style = {};
return (
<div
className={cx(styles.node, {
placeholder: index.id === dragging,
rootNode: this.props.rootNode,
})}
style={style}
>
<div
className={styles.inner}
ref="inner"
onMouseDown={
this.props.rootNode || !this.props.allowUpdates
? e => e.stopPropagation()
: this.handleMouseDown
}
>
{!this.props.rootNode && this.renderCollapse()}
<span
className={cx(styles.nodeLabel, {
rootLabel: this.props.rootNode,
isModifying: this.isModifying(),
})}
onClick={this.onClick}
>
{node.title}
</span>
</div>
{this.renderChildren()}
</div>
);
}
handleCollapse = e => {
e.stopPropagation();
const nodeId = this.props.index.id;
if (this.props.onCollapse) this.props.onCollapse(nodeId);
};
handleMouseDown = e => {
const nodeId = this.props.index.id;
const dom = this.refs.inner;
if (this.props.onDragStart) {
this.props.onDragStart(nodeId, dom, e);
}
};
}
module.exports = Node;