Skip to content
Snippets Groups Projects
Commit d07c6e37 authored by john's avatar john
Browse files

comments can now be used normally in read-only mode

parent cf12f14f
No related branches found
No related tags found
No related merge requests found
import { each, keys, includes } from 'lodash'
import { import {
ContainerEditor as SubstanceContainerEditor, ContainerEditor as SubstanceContainerEditor,
Surface, Surface,
...@@ -31,11 +32,18 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -31,11 +32,18 @@ class ContainerEditor extends SubstanceContainerEditor {
} }
// open for editing // open for editing
// TODO -- should maybe change to isEditable ?
if (!this.props.disabled) { if (!this.props.disabled) {
el.addClass('sm-enabled') el.addClass('sm-enabled')
el.setAttribute('contenteditable', true) el.setAttribute('contenteditable', true)
} }
// editing locked, selection open (for comments)
if (this.isReadOnlyMode()) {
const documentSession = this.getDocumentSession()
documentSession.on('didUpdate', this.disableToolbar, this)
}
return el return el
} }
...@@ -43,6 +51,8 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -43,6 +51,8 @@ class ContainerEditor extends SubstanceContainerEditor {
Surface.prototype.didMount.apply(this, arguments) Surface.prototype.didMount.apply(this, arguments)
this.container.on('nodes:changed', this.onContainerChange, this) this.container.on('nodes:changed', this.onContainerChange, this)
if (this.isEmpty()) this.createText() if (this.isEmpty()) this.createText()
if (this.isReadOnlyMode()) this.links()
} }
// create an empty paragraph with an empty node // create an empty paragraph with an empty node
...@@ -73,6 +83,33 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -73,6 +83,33 @@ class ContainerEditor extends SubstanceContainerEditor {
this.rerender() this.rerender()
this.setSelection(newSel) this.setSelection(newSel)
} }
// only runs if editor is in read-only mode
// disables all tools, apart from comments
disableToolbar () {
const commandStates = this.getCommandStates()
each(keys(commandStates), key => {
const allowed = ['comment', 'save', 'undo', 'redo']
if (!includes(allowed, key)) commandStates[key].disabled = true
})
}
getCommandStates () {
const commandManager = this.context.commandManager
return commandManager.getCommandStates()
}
isReadOnlyMode () {
return !this.isEditable() && this.isSelectable()
}
links () {
const allLinks = this.el.findAll('a')
each(allLinks, link =>
link.attr('target', '_blank')
)
}
} }
export default ContainerEditor export default ContainerEditor
import { import {
ProseEditor, ProseEditor,
ProseEditorOverlayTools,
ScrollPane, ScrollPane,
SplitPane, SplitPane,
TOCProvider TOCProvider
...@@ -8,7 +9,7 @@ import { ...@@ -8,7 +9,7 @@ import {
import Comments from './panes/Comments/CommentBoxList' import Comments from './panes/Comments/CommentBoxList'
import CommentsProvider from './panes/Comments/CommentsProvider' import CommentsProvider from './panes/Comments/CommentsProvider'
import ContainerEditor from './ContainerEditor' import ContainerEditor from './ContainerEditor'
import Overlay from './Overlay' // import Overlay from './Overlay'
import Notes from './panes/Notes/Notes' import Notes from './panes/Notes/Notes'
import NotesProvider from './panes/Notes/NotesProvider' import NotesProvider from './panes/Notes/NotesProvider'
import TableOfContents from './panes/TableOfContents/TableOfContents' import TableOfContents from './panes/TableOfContents/TableOfContents'
...@@ -69,7 +70,7 @@ class Editor extends ProseEditor { ...@@ -69,7 +70,7 @@ class Editor extends ProseEditor {
var contentPanel = $$(ScrollPane, { var contentPanel = $$(ScrollPane, {
scrollbarPosition: 'right', scrollbarPosition: 'right',
overlay: Overlay overlay: ProseEditorOverlayTools
}) })
.append(editorWithComments) .append(editorWithComments)
.attr('id', 'content-panel') .attr('id', 'content-panel')
...@@ -132,20 +133,19 @@ class Editor extends ProseEditor { ...@@ -132,20 +133,19 @@ class Editor extends ProseEditor {
} }
getChildContext () { getChildContext () {
var doc = this.doc const oldContext = super.getChildContext()
// TODO -- check whether this is correct const doc = this.doc
var oldContext = super.getChildContext()
// toc provider // toc provider
var tocProvider = new TOCProvider(doc, { const tocProvider = new TOCProvider(doc, {
containerId: 'body' containerId: 'body'
}) })
// // notes provider // // notes provider
var notesProvider = new NotesProvider(doc) const notesProvider = new NotesProvider(doc)
// // comments provider // // comments provider
var commentsProvider = new CommentsProvider(doc, { const commentsProvider = new CommentsProvider(doc, {
commandManager: this.commandManager, commandManager: this.commandManager,
comments: this.props.fragment.comments, comments: this.props.fragment.comments,
containerId: this.props.containerId, containerId: this.props.containerId,
...@@ -156,10 +156,11 @@ class Editor extends ProseEditor { ...@@ -156,10 +156,11 @@ class Editor extends ProseEditor {
}) })
// attach all to context // attach all to context
return { ...oldContext, return {
tocProvider: tocProvider, ...oldContext,
notesProvider: notesProvider, tocProvider,
commentsProvider: commentsProvider notesProvider,
commentsProvider
} }
} }
} }
......
import { ProseEditorOverlayTools } from 'substance'
import { each, includes, keys } from 'lodash'
class Overlay extends ProseEditorOverlayTools {
getActiveTools () {
const surface = this.getSurface()
if (!surface) return []
const activeTools = super.getActiveTools()
if (!surface.isEditable() && surface.isSelectable()) {
const commandStates = this.getCommandStates()
each(keys(commandStates), key => {
const allowed = ['comment', 'save']
if (!includes(allowed, key)) commandStates[key].disabled = true
})
console.log('filter it', activeTools)
}
return activeTools
}
getCommandStates () {
const commandManager = this.context.commandManager
return commandManager.getCommandStates()
}
getContainerId () {
const editor = this.getEditor()
return editor.props.containerId
}
getEditor () {
return this.context.controller
}
getSurface () {
const containerId = this.getContainerId()
const surfaceManager = this.context.surfaceManager
return surfaceManager.getSurface(containerId)
}
}
export default Overlay
...@@ -104,7 +104,7 @@ export default class SimpleEditor extends React.Component { ...@@ -104,7 +104,7 @@ export default class SimpleEditor extends React.Component {
let viewMode = !canEdit let viewMode = !canEdit
? ( ? (
<Alert bsStyle='warning' className='view-mode'> <Alert bsStyle='warning' className='view-mode'>
<span>Editor is in View Mode</span> <span>Editor is in Read-Only Mode</span>
</Alert> </Alert>
) )
: null : null
......
...@@ -14,6 +14,7 @@ $primary: #eee; ...@@ -14,6 +14,7 @@ $primary: #eee;
$ultra-light-gray: #fafafa; $ultra-light-gray: #fafafa;
$black: #000; $black: #000;
$shadow: rgba(0, 0, 0, .05);
$teal: #46b9ba; $teal: #46b9ba;
$toolbar-active-bg: rgba(204, 204, 204, .75); $toolbar-active-bg: rgba(204, 204, 204, .75);
$transparent-black: rgba(0, 0, 0, .75); $transparent-black: rgba(0, 0, 0, .75);
...@@ -24,9 +25,6 @@ $white: #fff; ...@@ -24,9 +25,6 @@ $white: #fff;
position: relative; position: relative;
.view-mode { .view-mode {
// background-color: $primary;
// border-bottom: 1px solid $border;
// border-top: 1px solid $border;
height: 44px; height: 44px;
position: fixed; position: fixed;
right: 0; right: 0;
...@@ -53,7 +51,6 @@ $white: #fff; ...@@ -53,7 +51,6 @@ $white: #fff;
background-color: $primary; background-color: $primary;
border: 1px solid $border; border: 1px solid $border;
border-right: 0; border-right: 0;
// padding: 1px;
padding-left: 0; padding-left: 0;
button { button {
...@@ -114,7 +111,7 @@ $white: #fff; ...@@ -114,7 +111,7 @@ $white: #fff;
.sc-switch-text-type { .sc-switch-text-type {
margin-left: 1px; margin-left: 1px;
width: 150px !important; width: 150px;
.se-toggle { .se-toggle {
background: transparent; background: transparent;
...@@ -203,7 +200,7 @@ $white: #fff; ...@@ -203,7 +200,7 @@ $white: #fff;
.se-context-section { .se-context-section {
background-color: $ultra-light-gray; background-color: $ultra-light-gray;
border-left: 1px solid $light-gray; border-left: 1px solid $light-gray;
box-shadow: inset 0 0 10px rgba(0, 0, 0, .05); box-shadow: inset 0 0 10px $shadow;
} }
.sc-comments-pane { .sc-comments-pane {
......
...@@ -7,12 +7,11 @@ import { ...@@ -7,12 +7,11 @@ import {
class CommentBubble extends Tool { class CommentBubble extends Tool {
render ($$) { render ($$) {
const mode = this.getMode()
const title = 'Create a new comment' const title = 'Create a new comment'
let commands = this.getCommentState()
if (commands.mode !== 'create') return $$('div') if (mode !== 'create') return $$('div')
commands.active = true
this.setBubblePosition()
const icon = $$(Icon, { icon: 'fa-comment' }) const icon = $$(Icon, { icon: 'fa-comment' })
.addClass('sc-comment-icon') .addClass('sc-comment-icon')
...@@ -31,18 +30,23 @@ class CommentBubble extends Tool { ...@@ -31,18 +30,23 @@ class CommentBubble extends Tool {
// calculated relative to the overlay container, which gets positioned // calculated relative to the overlay container, which gets positioned
// wrong on resize (substance bug -- TODO) // wrong on resize (substance bug -- TODO)
didMount () { didMount () {
this.position()
DefaultDOMElement.getBrowserWindow().on('resize', this.didUpdate, this) DefaultDOMElement.getBrowserWindow().on('resize', this.didUpdate, this)
} }
didUpdate () { didUpdate () {
if (this.el.getChildCount() === 0) return this.position()
this.setBubblePosition()
} }
dispose () { dispose () {
DefaultDOMElement.getBrowserWindow().off(this) DefaultDOMElement.getBrowserWindow().off(this)
} }
position () {
if (this.el.getChildCount() === 0) return
this.setBubblePosition()
}
setBubblePosition () { setBubblePosition () {
// without this check, the editor will break on first load // without this check, the editor will break on first load
const surface = this.getSurface() const surface = this.getSurface()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment