diff --git a/config.js b/config.js index 5173c24..34afa1d 100644 --- a/config.js +++ b/config.js @@ -4,6 +4,7 @@ module.exports = { examples: [ 'code-editor', 'collabwriter', + 'container-annotation', 'form', 'focused', 'images', diff --git a/container-annotation/ContainerAnnotationExampleConfig.js b/container-annotation/ContainerAnnotationExampleConfig.js new file mode 100644 index 0000000..8cf8fd3 --- /dev/null +++ b/container-annotation/ContainerAnnotationExampleConfig.js @@ -0,0 +1,11 @@ +'use strict'; +var ProseEditorPackage = require('substance/packages/prose-editor/ProseEditorPackage'); +var HighlightPackage = require('./highlight/HighlightPackage'); + +module.exports = { + name: 'container-annotation-example', + configure: function(config) { + config.import(ProseEditorPackage); + config.import(HighlightPackage); + } +}; diff --git a/container-annotation/app.js b/container-annotation/app.js new file mode 100644 index 0000000..5d8d7df --- /dev/null +++ b/container-annotation/app.js @@ -0,0 +1,34 @@ +'use strict'; + +var DocumentSession = require('substance/model/DocumentSession'); +var Component = require('substance/ui/Component'); +var Configurator = require('substance/util/Configurator'); +var ProseEditor = require('substance/packages/prose-editor/ProseEditor'); +var fixture = require('./fixture'); +var configurator = new Configurator(require('./ContainerAnnotationExampleConfig')); + +function App() { + App.super.apply(this, arguments); + var doc = configurator.createArticle(fixture); + window.doc = doc; + var documentSession = new DocumentSession(doc); + this.documentSession = documentSession; +} + +App.Prototype = function() { + this.render = function($$) { + var el = $$('div').addClass('app'); + var editor = $$(ProseEditor, { + configurator: configurator, + documentSession: this.documentSession + }); + el.append(editor); + return el; + }; +}; + +Component.extend(App); + +window.onload = function() { + Component.mount(App, 'body'); +}; diff --git a/container-annotation/app.scss b/container-annotation/app.scss new file mode 100644 index 0000000..6f0ddba --- /dev/null +++ b/container-annotation/app.scss @@ -0,0 +1,16 @@ +$fa-font-path: "../fonts" !default; +@import '../node_modules/font-awesome/scss/font-awesome'; +@import '../node_modules/substance/styles/base/index'; + +// Substance modules +@import '../node_modules/substance/styles/components/_all'; +@import '../node_modules/substance/packages/_all'; +@import './highlight/_highlight'; + +body { + overflow: hidden; +} + +.sc-editor .sc-surface.body { + padding: 40px; +} diff --git a/container-annotation/fixture.js b/container-annotation/fixture.js new file mode 100644 index 0000000..aa0680d --- /dev/null +++ b/container-annotation/fixture.js @@ -0,0 +1,44 @@ +'use strict'; +/* eslint-disable indent */ + +module.exports = function(tx) { + var body = tx.get('body'); + + tx.create({ + id: 'title', + type: 'heading', + level: 1, + content: 'Container Annotations' + }); + body.show('title'); + + tx.create({ + id: 'p1', + type: 'paragraph', + content: [ + "Container Annotations are special in that they" + ].join(' ') + }); + body.show('p1'); + + tx.create({ + id: 'p2', + type: 'paragraph', + content: [ + "can span over multiple paragraphs." + ].join(' ') + }); + body.show('p2'); + + tx.create({ + "id": "h1", + "type": "highlight", + "containerId": "body", + "startPath": ["p1", "content"], + "startOffset": 10, + "endPath": ["p2", "content"], + "endOffset": 20 + }); + + +}; diff --git a/container-annotation/highlight/Highlight.js b/container-annotation/highlight/Highlight.js new file mode 100644 index 0000000..6b35a25 --- /dev/null +++ b/container-annotation/highlight/Highlight.js @@ -0,0 +1,16 @@ +'use strict'; + +var ContainerAnnotation = require('substance/model/ContainerAnnotation'); +var Fragmenter = require('substance/model/Fragmenter'); + +function Highlight() { + Highlight.super.apply(this, arguments); +} + +ContainerAnnotation.extend(Highlight); + +Highlight.static.name = 'highlight'; + +Highlight.static.fragmentation = Fragmenter.SHOULD_NOT_SPLIT; + +module.exports = Highlight; \ No newline at end of file diff --git a/container-annotation/highlight/HighlightCommand.js b/container-annotation/highlight/HighlightCommand.js new file mode 100644 index 0000000..4a905c6 --- /dev/null +++ b/container-annotation/highlight/HighlightCommand.js @@ -0,0 +1,13 @@ +'use strict'; + +var AnnotationCommand = require('substance/ui/AnnotationCommand'); + +function HighlightCommand() { + HighlightCommand.super.apply(this, arguments); +} + +AnnotationCommand.extend(HighlightCommand); + +HighlightCommand.static.name = 'highlight'; + +module.exports = HighlightCommand; \ No newline at end of file diff --git a/container-annotation/highlight/HighlightPackage.js b/container-annotation/highlight/HighlightPackage.js new file mode 100644 index 0000000..b81f3b2 --- /dev/null +++ b/container-annotation/highlight/HighlightPackage.js @@ -0,0 +1,15 @@ +'use strict'; + +var Highlight = require('./Highlight'); +var HighlightCommand = require('./HighlightCommand'); +var HighlightTool = require('./HighlightTool'); + +module.exports = { + name: 'highlight', + configure: function(config) { + config.addNode(Highlight); + config.addCommand(HighlightCommand); + config.addTool(HighlightTool); + config.addIcon(HighlightCommand.static.name, { 'fontawesome': 'fa-pencil' }); + } +}; diff --git a/container-annotation/highlight/HighlightTool.js b/container-annotation/highlight/HighlightTool.js new file mode 100644 index 0000000..47ff167 --- /dev/null +++ b/container-annotation/highlight/HighlightTool.js @@ -0,0 +1,12 @@ +'use strict'; + +var AnnotationTool = require('substance/ui/AnnotationTool'); + +function HighlightTool() { + HighlightTool.super.apply(this, arguments); +} +AnnotationTool.extend(HighlightTool); + +HighlightTool.static.name = 'highlight'; + +module.exports = HighlightTool; \ No newline at end of file diff --git a/container-annotation/highlight/_highlight.scss b/container-annotation/highlight/_highlight.scss new file mode 100644 index 0000000..8d34ae0 --- /dev/null +++ b/container-annotation/highlight/_highlight.scss @@ -0,0 +1,3 @@ +.sc-highlight { + background: yellow; +} \ No newline at end of file diff --git a/container-annotation/index.html b/container-annotation/index.html new file mode 100644 index 0000000..e902689 --- /dev/null +++ b/container-annotation/index.html @@ -0,0 +1,11 @@ + + +
+