From 6e26b71a5756a8ab9aa87008515f4cef014db374 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Thu, 16 Feb 2017 14:02:04 +0200 Subject: [PATCH] table of content works except real time rendering --- .../SimpleEditor/ContainerEditor.js | 31 +++++++------------ app/components/SimpleEditor/Editor.js | 26 ++++++++-------- app/components/SimpleEditor/config.js | 5 +-- .../panes/TableOfContents/TableOfContents.js | 11 ++++--- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/app/components/SimpleEditor/ContainerEditor.js b/app/components/SimpleEditor/ContainerEditor.js index 7dc30b3..9932954 100644 --- a/app/components/SimpleEditor/ContainerEditor.js +++ b/app/components/SimpleEditor/ContainerEditor.js @@ -11,26 +11,19 @@ class ContainerEditor extends SubstanceContainerEditor { render ($$) { let el = super.render($$) - var doc = this.getDocument() - var containerId = this.getContainerId() - var containerNode = doc.get(containerId) + // var doc = this.getDocument() + // var containerId = this.getContainerId() + // var containerNode = doc.get(containerId) - if (!containerNode) { - console.warn('No container node found for ', containerId) - } - - el.addClass('sc-container-editor container-node ' + containerId) - .attr({ - spellCheck: false, - 'data-id': containerId - }) - - // if it IS empty, handle in didMount - if (!this.isEmpty()) { - // containerNode.getNodes().forEach(function (node) { - // el.append(this._renderNode($$, node).ref(node.id)) - // }.bind(this)) - } + // if (!containerNode) { + // console.warn('No container node found for ', containerId) + // } + // + // el.addClass('sc-container-editor container-node ' + containerId) + // .attr({ + // spellCheck: false, + // 'data-id': containerId + // }) // open for editing // TODO -- should maybe change to isEditable ? diff --git a/app/components/SimpleEditor/Editor.js b/app/components/SimpleEditor/Editor.js index a44b839..c928a5b 100644 --- a/app/components/SimpleEditor/Editor.js +++ b/app/components/SimpleEditor/Editor.js @@ -14,7 +14,7 @@ import ContainerEditor from './ContainerEditor' // import Overlay from './Overlay' // import Notes from './panes/Notes/Notes' // import NotesProvider from './panes/Notes/NotesProvider' -// import TableOfContents from './panes/TableOfContents/TableOfContents' +import TableOfContents from './panes/TableOfContents/TableOfContents' // import TrackChangesProvider from './elements/track_change/TrackChangesProvider' class Editor extends ProseEditor { @@ -68,14 +68,8 @@ class Editor extends ProseEditor { // var footerNotes = $$(Notes) const footerNotes = $$('div') - var props = { - book: this.props.book, - fragment: this.props.fragment, - history: this.props.history - } - // var toc = $$(TableOfContents, props) - const toc = $$('div') + const toc = $$(TableOfContents) var editorWithFooter = $$('div') .append( @@ -186,10 +180,16 @@ class Editor extends ProseEditor { const oldContext = super.getChildContext() const doc = this.doc + const props = { + book: this.props.book, + fragment: this.props.fragment, + history: this.props.history + } // toc provider - // const tocProvider = new TOCProvider(doc, { - // containerId: 'body' - // }) + const tocProvider = new TOCProvider(doc, { + containerId: 'body', + props: props + }) // // notes provider // const notesProvider = new NotesProvider(doc) @@ -220,8 +220,8 @@ class Editor extends ProseEditor { // attach all to context return { - ...oldContext - // tocProvider, + ...oldContext, + tocProvider // notesProvider, // commentsProvider, // trackChangesProvider diff --git a/app/components/SimpleEditor/config.js b/app/components/SimpleEditor/config.js index 2b09d19..63daa97 100644 --- a/app/components/SimpleEditor/config.js +++ b/app/components/SimpleEditor/config.js @@ -11,7 +11,8 @@ import { LinkPackage, StrongPackage, SubscriptPackage, - SuperscriptPackage + SuperscriptPackage, + SwitchTextTypePackage } from 'substance' // My Elements @@ -40,7 +41,7 @@ let config = { config.import(BasePackage, { noBaseStyles: options.noBaseStyles }) - + config.import(SwitchTextTypePackage) config.import(ParagraphPackage) config.import(HeadingPackage) config.import(BlockquotePackage) diff --git a/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js b/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js index 5ab4a84..c20f34e 100644 --- a/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js +++ b/app/components/SimpleEditor/panes/TableOfContents/TableOfContents.js @@ -3,7 +3,6 @@ import { FontAwesomeIcon as Icon, TOC as Toc } from 'substance' class TableOfContents extends Toc { constructor (props) { super(props) - this.handleAction('tocEntrySelected', (nodeId) => { const editor = this.getEditor() editor.scrollTo(nodeId) @@ -16,8 +15,9 @@ class TableOfContents extends Toc { } render ($$) { - const book = this.props.book - const fragment = this.props.fragment + console.log('in renderrr') + const provider = this.getProvider() + const { book, fragment } = provider.config.props const tocProvider = this.getProvider() const activeEntry = tocProvider.activeEntry @@ -100,7 +100,7 @@ class TableOfContents extends Toc { } getEditor () { - return this.context.controller + return this.context.editor } getProvider () { @@ -108,7 +108,8 @@ class TableOfContents extends Toc { } goToBookBuilder () { - const { book, history } = this.props + const provider = this.getProvider() + const { book, history } = provider.config.props const url = '/books/' + book.id + '/book-builder' history.push(url) -- GitLab