From 5ba2416e45b2ad8cb27db32f0e8b9697fac9aad4 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 7 Apr 2017 16:47:39 +0300
Subject: [PATCH] TextPropertyEditor in BlockNodeComponent works and can add
 trackchange text

---
 .../isolatedNote/IsolatedNoteComponent.js     | 32 ++++-------
 .../isolatedNote/TextPropertyEditor.js        | 54 ++++++-------------
 2 files changed, 27 insertions(+), 59 deletions(-)

diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js
index e8daa2a..9967cb6 100644
--- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js
+++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js
@@ -2,28 +2,18 @@ import { BlockNodeComponent } from 'substance'
 import TextPropertyEditor from './TextPropertyEditor'
 
 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,
+  render ($$) {
+    let el = $$('div').addClass('sc-entity')
+    el.append(
+    $$(TextPropertyEditor, {
+      path: [this.props.node.id, 'description'],
+      disabled: this.props.disabled,
+      tagName: 'p',
+      multiLine: true
+    }).ref('nameEditor'))
 
-      }).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
-    }
+    return el
+  }
 }
 
 export default IsolatedNoteComponent
diff --git a/app/components/SimpleEditor/elements/isolatedNote/TextPropertyEditor.js b/app/components/SimpleEditor/elements/isolatedNote/TextPropertyEditor.js
index 9f2fad2..3eb47ba 100644
--- a/app/components/SimpleEditor/elements/isolatedNote/TextPropertyEditor.js
+++ b/app/components/SimpleEditor/elements/isolatedNote/TextPropertyEditor.js
@@ -1,48 +1,26 @@
 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.")
+// Substance TextPropertyEditor Extends directly Surface and we don't oerwrite Surface. In our CantainerEditor we overwrite
+// TextInput to enbale TrackChanges. So if trackChanges is on We want to execute onTextInput From ContainerEditor
+  onTextInput (event) {
+    if (!this.isTrackChangesOn()) {
+      return super.onTextInput(event)
     }
+
+    let surface = this.getSurface()
+    if (!surface) return
+    return surface.onTextInput(event)
   }
 
-  onTextInput (event) {
-      let surface = this.context.surfaceManager.getFocusedSurface()
-      if(!surface) return
-     return surface.onTextInput(event)
-      
+  isTrackChangesOn () {
+    return this.context.editor.props.trackChanges
   }
-}
 
+  getSurface () {
+    // TODO How to get ContainerID
+    return this.context.surfaceManager.getSurface('body')
+  }
+}
 
 export default TextPropertyEditor
-- 
GitLab