From 637010577bd0be18f8ff5636ee96ae0a03f8abe7 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 27 Feb 2020 00:58:10 +0100 Subject: [PATCH] layout changes WIP --- src/public/javascripts/widgets/component.js | 12 ++-- .../javascripts/widgets/flex_container.js | 59 +++++++++++++--- src/public/javascripts/widgets/layout.js | 69 ++++++++++--------- .../javascripts/widgets/note_actions.js | 6 ++ src/public/javascripts/widgets/note_title.js | 2 - .../widgets/protected_note_switch.js | 6 +- .../javascripts/widgets/tab_caching_widget.js | 4 +- src/public/stylesheets/desktop.css | 2 +- src/public/stylesheets/style.css | 9 --- 9 files changed, 101 insertions(+), 68 deletions(-) diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js index 35020cfa4..5fec19f72 100644 --- a/src/public/javascripts/widgets/component.js +++ b/src/public/javascripts/widgets/component.js @@ -2,19 +2,19 @@ import utils from '../services/utils.js'; import Mutex from "../services/mutex.js"; export default class Component { - /** - * @param {Component} parent - */ - constructor(parent) { + constructor() { this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6); - /** @type Component */ - this.parent = parent; /** @type Component[] */ this.children = []; this.initialized = Promise.resolve(); this.mutex = new Mutex(); } + setParent(parent) { + /** @type Component */ + this.parent = parent; + } + async handleEvent(name, data) { await this.initialized; diff --git a/src/public/javascripts/widgets/flex_container.js b/src/public/javascripts/widgets/flex_container.js index cfe56b697..549618298 100644 --- a/src/public/javascripts/widgets/flex_container.js +++ b/src/public/javascripts/widgets/flex_container.js @@ -1,25 +1,62 @@ import BasicWidget from "./basic_widget.js"; export default class FlexContainer extends BasicWidget { - constructor(parent, attrs, widgetFactories) { - super(parent); + constructor(direction) { + super(); - this.attrs = attrs; - this.children = widgetFactories.map(wf => wf(this)); + if (!direction) { + throw new Error(`Direction argument missing, use either 'row' or 'column'`); + } + + this.attrs = { + style: 'display: flex;' + }; + + this.children = []; + } + + id(id) { + this.attrs.id = id; + return this; + } + + css(name, value) { + this.attrs.style += `${name}: ${value};`; + return this; + } + + rowFlex() { + this.css('flex-direction', 'row'); + return this; + } + + columnFlex() { + this.css('flex-direction', 'column'); + return this; + } + + cssBlock(block) { + this.cssEl = block; + return this; + } + + child(widgetFactory) { + this.children = widgetFactory(this); } doRender() { - this.$widget = $(`
`); + this.$widget = $(`
`); + + if (this.cssEl) { + this.$widget.append($(` + -
`; +
`;``; export default class ProtectedNoteSwitchWidget extends TabAwareWidget { doRender() { diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js index 1b729372e..eb587d7f4 100644 --- a/src/public/javascripts/widgets/tab_caching_widget.js +++ b/src/public/javascripts/widgets/tab_caching_widget.js @@ -2,8 +2,8 @@ import TabAwareWidget from "./tab_aware_widget.js"; import keyboardActionsService from "../services/keyboard_actions.js"; export default class TabCachingWidget extends TabAwareWidget { - constructor(parent, widgetFactory) { - super(parent); + constructor(widgetFactory) { + super(); this.widgetFactory = widgetFactory; this.widgets = {}; diff --git a/src/public/stylesheets/desktop.css b/src/public/stylesheets/desktop.css index 7aba0c8bb..3e48e3abf 100644 --- a/src/public/stylesheets/desktop.css +++ b/src/public/stylesheets/desktop.css @@ -149,7 +149,7 @@ body { #right-pane .card-header { background: inherit; - padding: 5px 10px 5px 10px; + padding: 3px 10px 3px 10px; width: 99%; /* to give minimal right margin */ background-color: var(--button-background-color); border-color: var(--button-border-color); diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 857847b6a..cd5d63521 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -380,15 +380,6 @@ button.icon-button { max-height: 34px; } -.note-actions { - margin-left: 10px; - margin-right: 10px; -} - -.note-actions .dropdown-menu { - width: 15em; -} - .ck.ck-block-toolbar-button { transform: translateX(7px); color: var(--muted-text-color);