Skip to content
Snippets Groups Projects
Commit b0fe696f authored by Alexandros Georgantas's avatar Alexandros Georgantas Committed by john
Browse files

TextPropertyEditor added

parent 09d6b906
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
ContainerEditor as SubstanceContainerEditor, ContainerEditor as SubstanceContainerEditor,
// deleteCharacter, // deleteCharacter,
// deleteSelection, // deleteSelection,
// Surface,
keys as keyboardKeys, keys as keyboardKeys,
uuid uuid
} from 'substance' } from 'substance'
...@@ -10,12 +11,12 @@ import { ...@@ -10,12 +11,12 @@ import {
class ContainerEditor extends SubstanceContainerEditor { class ContainerEditor extends SubstanceContainerEditor {
constructor (...args) { constructor (...args) {
super(...args) super(...args)
// this.name = 'body'
this.controlBackButton = this.controlBackButton.bind(this) this.controlBackButton = this.controlBackButton.bind(this)
} }
render ($$) { render ($$) {
let el = super.render($$) let el = super.render($$)
// native spellcheck // native spellcheck
// TODO -- there is a hasNativeSpellcheck fn // TODO -- there is a hasNativeSpellcheck fn
const isSpellcheckNative = (this.props.spellcheck === 'native') const isSpellcheckNative = (this.props.spellcheck === 'native')
...@@ -87,8 +88,9 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -87,8 +88,9 @@ class ContainerEditor extends SubstanceContainerEditor {
} }
onTextInput (event) { onTextInput (event) {
console.log('before')
if (!this.props.trackChanges) return super.onTextInput(event) if (!this.props.trackChanges) return super.onTextInput(event)
console.log('after')
this.handleTracking({ this.handleTracking({
event: event, event: event,
status: 'add', status: 'add',
......
import {InlineNode} from 'substance' import {DocumentNode} from 'substance'
class IsolatedNote extends InlineNode {} class IsolatedNote extends DocumentNode {}
IsolatedNote.define({ IsolatedNote.define({
'type': 'isolated-note', 'type': 'isolated-note',
...@@ -11,7 +11,8 @@ IsolatedNote.define({ ...@@ -11,7 +11,8 @@ IsolatedNote.define({
'index': { 'index': {
type: 'number', type: 'number',
optional: true optional: true
} },
description: 'text'
}) })
export default IsolatedNote export default IsolatedNote
...@@ -24,7 +24,7 @@ class IsolatedNoteCommand extends Command { ...@@ -24,7 +24,7 @@ class IsolatedNoteCommand extends Command {
editorSession.transaction((tx) => { editorSession.transaction((tx) => {
let nodeData = this.createNodeData(tx, params) let nodeData = this.createNodeData(tx, params)
console.log('nodeData', nodeData) console.log('nodeData', nodeData)
tx.insertInlineNode(nodeData) tx.insertBlockNode(nodeData)
}) })
} }
......
import { IsolatedNodeComponent } from 'substance' import { BlockNodeComponent } from 'substance'
import TextPropertyEditor from './TextPropertyEditor'
class IsolatedNoteComponent extends IsolatedNodeComponent {} class IsolatedNoteComponent extends BlockNodeComponent {
render($$) {
console.log('this', this)
let el = $$('div').addClass('sc-entity')
el.append($$('paragraph'))
el.append($$('paragraph').append(
$$(TextPropertyEditor, {
path: [this.props.node.id, 'description'],
disabled: this.props.disabled,
tagName: 'p',
multiLine: true,
}).ref('nameEditor')))
// el.on('click', function (e) {
// console.log(this)
// this.el.attr('contentEditable', true)
// this.el.attr('hi', true)
// console.log(this)
// })
return el
}
}
export default IsolatedNoteComponent export default IsolatedNoteComponent
import { TextPropertyEditor as SubstanceTextPropertyEditor } from 'substance'
/**
Editor for a text property (annotated string). Needs to be
instantiated inside a {@link ui/Controller} context.
@class
@component
@extends ui/Surface
@prop {String} name unique editor name
@prop {String[]} path path to a text property
@prop {ui/SurfaceCommand[]} commands array of command classes to be available
@example
Create a `TextPropertyEditor` for the `name` property of an author object. Allow emphasis annotations.
```js
$$(TextPropertyEditor, {
name: 'authorNameEditor',
path: ['author_1', 'name'],
commands: [EmphasisCommand]
})
```
*/
class TextPropertyEditor extends SubstanceTextPropertyEditor {
constructor(parent, props) {
// making props.name optional
props.name = props.name || props.path.join('.')
super(parent, props)
if (!props.path) {
throw new Error("Property 'path' is mandatory.")
}
}
onTextInput (event) {
let surface = this.context.surfaceManager.getFocusedSurface()
if(!surface) return
return surface.onTextInput(event)
}
}
export default TextPropertyEditor
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