From 902e48544c37d468a20b91aa87af0260841fa6ed Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 7 May 2017 11:56:49 -0700 Subject: [PATCH 1/5] This commit intentionally left blank From 0516d04bafefd3593385f3217d4d022741f38506 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 7 May 2017 12:06:21 -0700 Subject: [PATCH 2/5] :satellite::money_with_wings: Updated at https://danielx.net/editor/ --- editor.coffee | 3 ++- pixie.cson | 2 +- remote-interface.coffee | 14 ++++++++++ style.styl | 4 ++- templates/editor.haml.md | 58 ---------------------------------------- templates/editor.jadelet | 48 +++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 61 deletions(-) create mode 100644 remote-interface.coffee delete mode 100644 templates/editor.haml.md create mode 100644 templates/editor.jadelet diff --git a/editor.coffee b/editor.coffee index a3d6411..513e5e6 100644 --- a/editor.coffee +++ b/editor.coffee @@ -13,6 +13,7 @@ Drop = require "./drop" GridGen = require "grid-gen" Notifications = require "./notifications" Postmaster = require "postmaster" +RemoteInterface = require "./remote-interface" Tools = require "./tools" Undo = require "undo" @@ -44,7 +45,7 @@ module.exports = (I={}, self=Model(I)) -> self.include Undo self.include Tools - Postmaster(self) + self.include RemoteInterface activeTool = self.activeTool diff --git a/pixie.cson b/pixie.cson index b1882ea..3056495 100644 --- a/pixie.cson +++ b/pixie.cson @@ -9,7 +9,7 @@ dependencies: matrix: "distri/matrix:v0.3.1" observable: "distri/observable:v0.3.7" point: "distri/point:v0.2.0" - postmaster: "distri/postmaster:v0.5.2" + postmaster: "distri/postmaster:v0.5.3" runtime: "distri/runtime:v0.3.0" size: "distri/size:v0.1.4" "touch-canvas": "distri/touch-canvas:v0.4.2" diff --git a/remote-interface.coffee b/remote-interface.coffee new file mode 100644 index 0000000..3d9a286 --- /dev/null +++ b/remote-interface.coffee @@ -0,0 +1,14 @@ +module.exports = (I, self) -> + # Embedded package in ZineOS + if system? and postmaster? + postmaster.delegate = self + else if window.location.origin is "null" + # Assume we're in a secure enough embedded iframe + localPostmaster = require("postmaster")(self) + else if window is window.parent + # Not embedded, no need to enable remote interface + else + # otherwise we can't allow the remote interface as it could enable XSS + console.warn "Remote interface disabled, iframe must be sandboxed" + + return self diff --git a/style.styl b/style.styl index de3a53b..0c89e2e 100644 --- a/style.styl +++ b/style.styl @@ -42,10 +42,12 @@ body width: 100% -.editor +editor background-color: #AAA box-sizing: border-box + display: block height: 100% + line-height: initial padding: 0px 50px 64px 35px position: relative user-select: none diff --git a/templates/editor.haml.md b/templates/editor.haml.md deleted file mode 100644 index 603bcf9..0000000 --- a/templates/editor.haml.md +++ /dev/null @@ -1,58 +0,0 @@ -Editor template - - - activeIndex = @activeIndex - - activeTool = @activeTool - - previousTool = @previousTool - - editor = this - - Symmetry = require "../symmetry" - - - Action = require "./action" - - ActionPresenter = require "../presenters/action" - - Palette = require "./palette" - - Tool = require "./tool" - - ToolPresenter = require "../presenters/tool" - - .editor(class=@loadingClass) - -The toolbar holds our tools. - - .toolbar - .tools - - @tools.each (tool) -> - = Tool ToolPresenter(editor, tool) - %h2 Symmetry - .tools - - symmetryMode = @symmetryMode - - ["normal", "flip", "flop", "quad"].forEach (mode) -> - - activeClass = -> "active" if mode is symmetryMode() - - activate = -> symmetryMode(mode) - .tool(style="background-image: url(#{Symmetry.icon[mode]})" class=activeClass click=activate) - -Our layers and preview canvases are placed in the viewport. - - .main - .viewport(style=@viewportStyle class=@viewportCenter class=@viewportChecker) - .overlay(style=@gridStyle) - = @canvas.element() - = @previewCanvas.element() - .thumbnail(click=@thumbnailClick) - = @thumbnailCanvas.element() - - .position - = @positionDisplay - - .notifications - - @notifications.forEach (notification) -> - %p - = notification - -The palette holds our colors. - - = Palette(this) - - .actions - - @actions.forEach (action) -> - = Action ActionPresenter action, editor - - #loader - %progress.vertical-center(value=@loadingProgress) diff --git a/templates/editor.jadelet b/templates/editor.jadelet new file mode 100644 index 0000000..a95a786 --- /dev/null +++ b/templates/editor.jadelet @@ -0,0 +1,48 @@ +- activeIndex = @activeIndex +- activeTool = @activeTool +- previousTool = @previousTool +- editor = this +- Symmetry = require "../symmetry" + +- Action = require "./action" +- ActionPresenter = require "../presenters/action" +- Palette = require "./palette" +- Tool = require "./tool" +- ToolPresenter = require "../presenters/tool" + +editor(class=@loadingClass) + .toolbar + .tools + - @tools.each (tool) -> + = Tool ToolPresenter(editor, tool) + h2 Symmetry + .tools + - symmetryMode = @symmetryMode + - ["normal", "flip", "flop", "quad"].forEach (mode) -> + - activeClass = -> "active" if mode is symmetryMode() + - activate = -> symmetryMode(mode) + .tool(style="background-image: url(#{Symmetry.icon[mode]})" class=activeClass click=activate) + + .main + .viewport(style=@viewportStyle class=@viewportCenter class=@viewportChecker) + .overlay(style=@gridStyle) + = @canvas.element() + = @previewCanvas.element() + .thumbnail(click=@thumbnailClick) + = @thumbnailCanvas.element() + + .position + = @positionDisplay + + .notifications + - @notifications.forEach (notification) -> + p= notification + + = Palette(this) + + .actions + - @actions.forEach (action) -> + = Action ActionPresenter action, editor + + #loader + progress.vertical-center(value=@loadingProgress) From 9553eb67208087b72c2a76bb2a9181864e46162e Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 7 May 2017 12:19:54 -0700 Subject: [PATCH 3/5] :small_orange_diamond::black_circle: Updated at https://danielx.net/editor/ --- main.coffee | 6 +++--- pixie.cson | 1 - remote-interface.coffee | 3 +++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/main.coffee b/main.coffee index eb2a1bc..26274b4 100644 --- a/main.coffee +++ b/main.coffee @@ -29,9 +29,9 @@ if PACKAGE.name is "ROOT" global.PACKAGE = PACKAGE global.require = require - runtime = require("runtime")(PACKAGE) - runtime.boot() - runtime.applyStyleSheet(require('./style')) + styleNode = document.createElement("style") + styleNode.innerHTML = require('./style') + document.head.appendChild(styleNode) metaTag = document.createElement('meta') metaTag.name = "viewport" diff --git a/pixie.cson b/pixie.cson index 3056495..3e4ba76 100644 --- a/pixie.cson +++ b/pixie.cson @@ -10,7 +10,6 @@ dependencies: observable: "distri/observable:v0.3.7" point: "distri/point:v0.2.0" postmaster: "distri/postmaster:v0.5.3" - runtime: "distri/runtime:v0.3.0" size: "distri/size:v0.1.4" "touch-canvas": "distri/touch-canvas:v0.4.2" "undo": "distri/undo:v0.2.0" diff --git a/remote-interface.coffee b/remote-interface.coffee index 3d9a286..d267840 100644 --- a/remote-interface.coffee +++ b/remote-interface.coffee @@ -1,12 +1,15 @@ module.exports = (I, self) -> # Embedded package in ZineOS if system? and postmaster? + console.info "Attached ZineOS remote delegate" postmaster.delegate = self else if window.location.origin is "null" # Assume we're in a secure enough embedded iframe + console.info "Attached remote interface" localPostmaster = require("postmaster")(self) else if window is window.parent # Not embedded, no need to enable remote interface + console.info "Not embedded, no remote interface" else # otherwise we can't allow the remote interface as it could enable XSS console.warn "Remote interface disabled, iframe must be sandboxed" From 579101f9bc05f4b5ca7ddf05c5813288c70058a7 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 7 May 2017 12:30:07 -0700 Subject: [PATCH 4/5] :sake::soon: Updated at https://danielx.net/editor/ --- main.coffee | 3 +-- remote-interface.coffee | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.coffee b/main.coffee index 26274b4..8585e03 100644 --- a/main.coffee +++ b/main.coffee @@ -11,8 +11,7 @@ launch = -> editorElement = Template editor document.body.appendChild editorElement - try - editor.invokeRemote "childLoaded" + editor.invokeRemote? "childLoaded" updateViewportCentering = -> {height: mainHeight, width: mainWidth} = editorElement.querySelector(".main").getBoundingClientRect() diff --git a/remote-interface.coffee b/remote-interface.coffee index d267840..c4974e7 100644 --- a/remote-interface.coffee +++ b/remote-interface.coffee @@ -2,6 +2,7 @@ module.exports = (I, self) -> # Embedded package in ZineOS if system? and postmaster? console.info "Attached ZineOS remote delegate" + editor.invokeRemote = postmaster.invokeRemote postmaster.delegate = self else if window.location.origin is "null" # Assume we're in a secure enough embedded iframe From 4fedeed82eae3cab896f15250f99ae497e707ed0 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 7 May 2017 12:35:54 -0700 Subject: [PATCH 5/5] :japanese_goblin::clubs: Updated at https://danielx.net/editor/ --- remote-interface.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-interface.coffee b/remote-interface.coffee index c4974e7..c5c5fa3 100644 --- a/remote-interface.coffee +++ b/remote-interface.coffee @@ -2,7 +2,7 @@ module.exports = (I, self) -> # Embedded package in ZineOS if system? and postmaster? console.info "Attached ZineOS remote delegate" - editor.invokeRemote = postmaster.invokeRemote + self.invokeRemote = postmaster.invokeRemote postmaster.delegate = self else if window.location.origin is "null" # Assume we're in a secure enough embedded iframe