From efe6956a796f99f8142e2bb8dd8cccc995dbe746 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 19 Oct 2020 09:59:56 +0200 Subject: [PATCH 1/3] support render method and value in StaticView --- src/ui/web/general/StaticView.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ui/web/general/StaticView.js b/src/ui/web/general/StaticView.js index ae4f0f98..c87a0f3c 100644 --- a/src/ui/web/general/StaticView.js +++ b/src/ui/web/general/StaticView.js @@ -18,8 +18,12 @@ limitations under the License. import {tag} from "../general/html.js"; export class StaticView { - constructor(render) { - this._root = render(tag); + constructor(value, render = undefined) { + if (typeof value === "function" && !render) { + render = value; + value = null; + } + this._root = render ? render(tag, value) : this.render(tag, value); } mount() { From 4828e141c93a4ea7a8845da4baf8814570326b57 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 19 Oct 2020 10:00:18 +0200 Subject: [PATCH 2/3] add br tag to html template --- src/ui/web/general/html.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/web/general/html.js b/src/ui/web/general/html.js index 846539c7..67d9fcd9 100644 --- a/src/ui/web/general/html.js +++ b/src/ui/web/general/html.js @@ -92,7 +92,7 @@ export const SVG_NS = "http://www.w3.org/2000/svg"; export const TAG_NAMES = { [HTML_NS]: [ - "a", "ol", "ul", "li", "div", "h1", "h2", "h3", "h4", "h5", "h6", + "br", "a", "ol", "ul", "li", "div", "h1", "h2", "h3", "h4", "h5", "h6", "p", "strong", "em", "span", "img", "section", "main", "article", "aside", "pre", "button", "time", "input", "textarea", "label"], [SVG_NS]: ["svg", "circle"] From 90910dae1512733c8c38936fab3c7576de2e3ce5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 19 Oct 2020 10:00:32 +0200 Subject: [PATCH 3/3] render multiline messages with br's --- .../session/room/timeline/TextMessageView.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ui/web/session/room/timeline/TextMessageView.js b/src/ui/web/session/room/timeline/TextMessageView.js index 886eae5d..5562f97d 100644 --- a/src/ui/web/session/room/timeline/TextMessageView.js +++ b/src/ui/web/session/room/timeline/TextMessageView.js @@ -15,12 +15,33 @@ limitations under the License. */ import {TemplateView} from "../../../general/TemplateView.js"; +import {StaticView} from "../../../general/StaticView.js"; import {renderMessage} from "./common.js"; export class TextMessageView extends TemplateView { render(t, vm) { + const bodyView = t.mapView(vm => vm.text, text => new BodyView(text)); return renderMessage(t, vm, - [t.p([vm => vm.text, t.time({className: {hidden: !vm.date}}, vm.date + " " + vm.time)])] + [t.p([bodyView, t.time({className: {hidden: !vm.date}}, vm.date + " " + vm.time)])] ); } } + +class BodyView extends StaticView { + render(t, value) { + const lines = value.split("\n"); + if (lines.length === 1) { + return lines[0]; + } + const elements = []; + for (const line of lines) { + if (elements.length) { + elements.push(t.br()); + } + if (line.length) { + elements.push(t.span(line)); + } + } + return t.span(elements); + } +}