mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
state is now applied to sidebar widgets
This commit is contained in:
parent
aa981d3cd4
commit
f259c60b54
34
package-lock.json
generated
34
package-lock.json
generated
@ -1960,9 +1960,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cli-spinners": {
|
"cli-spinners": {
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz",
|
||||||
"integrity": "sha512-8B00fJOEh1HPrx4fo5eW16XmE1PcL1tGpGrxy63CXGP9nHdPBN63X75hA1zhvQuhVztJWLqV58Roj2qlNM7cAA==",
|
"integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"cli-table3": {
|
"cli-table3": {
|
||||||
@ -4017,20 +4017,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"electron-rebuild": {
|
"electron-rebuild": {
|
||||||
"version": "1.8.5",
|
"version": "1.8.6",
|
||||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.8.6.tgz",
|
||||||
"integrity": "sha512-gDwRA3utfiPnFwBZ1z8M4SEMwsdsy6Bg4VGO2ohelMOIO0vxiCrDQ/FVdLk3h2g7fLb06QFUsQU+86jiTSmZxw==",
|
"integrity": "sha512-4BAPcNG0XP6stByqvFXggrjmf/C47P2L6HFFrWdR2ako1VLiTDIeZAOmU4WEBuWdaXYNqstleszVmcNHdRDojA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"colors": "^1.3.3",
|
"colors": "^1.3.3",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"node-abi": "^2.8.0",
|
"node-abi": "^2.9.0",
|
||||||
"node-gyp": "^4.0.0",
|
"node-gyp": "^5.0.1",
|
||||||
"ora": "^3.4.0",
|
"ora": "^3.4.0",
|
||||||
"spawn-rx": "^3.0.0",
|
"spawn-rx": "^3.0.0",
|
||||||
"yargs": "^13.2.2"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": {
|
"colors": {
|
||||||
@ -9135,17 +9135,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-gyp": {
|
"node-gyp": {
|
||||||
"version": "4.0.0",
|
"version": "5.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-5.0.3.tgz",
|
||||||
"integrity": "sha512-2XiryJ8sICNo6ej8d0idXDEMKfVfFK7kekGCtJAuelGsYHQxhj13KTf95swTCN2dZ/4lTfZ84Fu31jqJEEgjWA==",
|
"integrity": "sha512-z/JdtkFGUm0QaQUusvloyYuGDub3nUbOo5de1Fz57cM++osBTvQatBUSTlF1k/w8vFHPxxXW6zxGvkxXSpaBkQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"env-paths": "^1.0.0",
|
||||||
"glob": "^7.0.3",
|
"glob": "^7.0.3",
|
||||||
"graceful-fs": "^4.1.2",
|
"graceful-fs": "^4.1.2",
|
||||||
"mkdirp": "^0.5.0",
|
"mkdirp": "^0.5.0",
|
||||||
"nopt": "2 || 3",
|
"nopt": "2 || 3",
|
||||||
"npmlog": "0 || 1 || 2 || 3 || 4",
|
"npmlog": "0 || 1 || 2 || 3 || 4",
|
||||||
"osenv": "0",
|
|
||||||
"request": "^2.87.0",
|
"request": "^2.87.0",
|
||||||
"rimraf": "2",
|
"rimraf": "2",
|
||||||
"semver": "~5.3.0",
|
"semver": "~5.3.0",
|
||||||
@ -9173,7 +9173,7 @@
|
|||||||
},
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "5.3.0",
|
"version": "5.3.0",
|
||||||
"resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
|
||||||
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
|
"integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=",
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
@ -13405,9 +13405,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ws": {
|
"ws": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",
|
||||||
"integrity": "sha512-o41D/WmDeca0BqYhsr3nJzQyg9NF5X8l/UdnFNux9cS3lwB+swm8qGWX5rn+aD6xfBU3rGmtHij7g7x6LxFU3A==",
|
"integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"async-limiter": "^1.0.0"
|
"async-limiter": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
"tar-stream": "2.1.0",
|
"tar-stream": "2.1.0",
|
||||||
"turndown": "5.0.3",
|
"turndown": "5.0.3",
|
||||||
"unescape": "1.0.1",
|
"unescape": "1.0.1",
|
||||||
"ws": "7.1.1",
|
"ws": "7.1.2",
|
||||||
"xml2js": "0.4.19"
|
"xml2js": "0.4.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -83,7 +83,7 @@
|
|||||||
"electron-compile": "6.4.4",
|
"electron-compile": "6.4.4",
|
||||||
"electron-installer-debian": "2.0.0",
|
"electron-installer-debian": "2.0.0",
|
||||||
"electron-packager": "14.0.4",
|
"electron-packager": "14.0.4",
|
||||||
"electron-rebuild": "1.8.5",
|
"electron-rebuild": "1.8.6",
|
||||||
"lorem-ipsum": "2.0.3",
|
"lorem-ipsum": "2.0.3",
|
||||||
"xo": "0.24.0"
|
"xo": "0.24.0"
|
||||||
},
|
},
|
||||||
|
@ -133,7 +133,6 @@ async function switchToTab(tabId, notePath) {
|
|||||||
if (!tabContext) {
|
if (!tabContext) {
|
||||||
await loadNoteDetail(notePath, {
|
await loadNoteDetail(notePath, {
|
||||||
newTab: true,
|
newTab: true,
|
||||||
tabId: tabId,
|
|
||||||
activate: true
|
activate: true
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -262,7 +261,7 @@ async function loadNoteDetail(origNotePath, options = {}) {
|
|||||||
|
|
||||||
if (!getActiveTabContext() || newTab) {
|
if (!getActiveTabContext() || newTab) {
|
||||||
// if it's a new tab explicitly by user then it's in background
|
// if it's a new tab explicitly by user then it's in background
|
||||||
ctx = new TabContext(tabRow, options.tabId);
|
ctx = new TabContext(tabRow, options.state);
|
||||||
tabContexts.push(ctx);
|
tabContexts.push(ctx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3,14 +3,13 @@ import LinkMapWidget from "../widgets/link_map.js";
|
|||||||
import NoteRevisionsWidget from "../widgets/note_revisions.js";
|
import NoteRevisionsWidget from "../widgets/note_revisions.js";
|
||||||
import AttributesWidget from "../widgets/attributes.js";
|
import AttributesWidget from "../widgets/attributes.js";
|
||||||
|
|
||||||
let widgetIdCtr = 1;
|
|
||||||
|
|
||||||
class Sidebar {
|
class Sidebar {
|
||||||
/**
|
/**
|
||||||
* @param {TabContext} ctx
|
* @param {TabContext} ctx
|
||||||
*/
|
*/
|
||||||
constructor(ctx) {
|
constructor(ctx, state) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
this.state = state;
|
||||||
this.widgets = [];
|
this.widgets = [];
|
||||||
this.rendered = false;
|
this.rendered = false;
|
||||||
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
|
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
|
||||||
@ -51,7 +50,9 @@ class Sidebar {
|
|||||||
const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget];
|
const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget];
|
||||||
|
|
||||||
for (const widgetClass of widgetClasses) {
|
for (const widgetClass of widgetClasses) {
|
||||||
const widget = new widgetClass(this.ctx);
|
const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
|
||||||
|
|
||||||
|
const widget = new widgetClass(this.ctx, state);
|
||||||
this.widgets.push(widget);
|
this.widgets.push(widget);
|
||||||
|
|
||||||
widget.renderBody(); // let it run in parallel
|
widget.renderBody(); // let it run in parallel
|
||||||
|
@ -37,10 +37,11 @@ const componentClasses = {
|
|||||||
class TabContext {
|
class TabContext {
|
||||||
/**
|
/**
|
||||||
* @param {TabRow} tabRow
|
* @param {TabRow} tabRow
|
||||||
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
constructor(tabRow, tabId = null) {
|
constructor(tabRow, state = {}) {
|
||||||
this.tabRow = tabRow;
|
this.tabRow = tabRow;
|
||||||
this.tabId = tabId || utils.randomString(4);
|
this.tabId = state.tabId || utils.randomString(4);
|
||||||
this.$tab = $(this.tabRow.addTab(this.tabId));
|
this.$tab = $(this.tabRow.addTab(this.tabId));
|
||||||
|
|
||||||
this.$tabContent = $(".note-tab-content-template").clone();
|
this.$tabContent = $(".note-tab-content-template").clone();
|
||||||
@ -62,7 +63,7 @@ class TabContext {
|
|||||||
this.attributes = new Attributes(this);
|
this.attributes = new Attributes(this);
|
||||||
|
|
||||||
if (utils.isDesktop()) {
|
if (utils.isDesktop()) {
|
||||||
this.sidebar = new Sidebar(this);
|
this.sidebar = new Sidebar(this, state.sidebar);
|
||||||
this.noteType = new NoteTypeContext(this);
|
this.noteType = new NoteTypeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ async function treeInitialized() {
|
|||||||
|
|
||||||
for (const tab of filteredTabs) {
|
for (const tab of filteredTabs) {
|
||||||
await noteDetailService.loadNoteDetail(tab.notePath, {
|
await noteDetailService.loadNoteDetail(tab.notePath, {
|
||||||
tabId: tab.tabId,
|
state: tab,
|
||||||
newTab: true,
|
newTab: true,
|
||||||
activate: tab.active
|
activate: tab.active
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import StandardWidget from "./standard_widget.js";
|
|||||||
|
|
||||||
class AttributesWidget extends StandardWidget {
|
class AttributesWidget extends StandardWidget {
|
||||||
constructor(ctx, state) {
|
constructor(ctx, state) {
|
||||||
super(ctx, state, 'attributes');
|
super(ctx, state);
|
||||||
|
|
||||||
this.$title.text("Attributes");
|
this.$title.text("Attributes");
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class LinkMapWidget extends StandardWidget {
|
|||||||
* @param {object} state
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
constructor(ctx, state) {
|
constructor(ctx, state) {
|
||||||
super(ctx, state,'link-map');
|
super(ctx, state);
|
||||||
|
|
||||||
this.$title.text("Link map");
|
this.$title.text("Link map");
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class NoteInfoWidget extends StandardWidget {
|
|||||||
* @param {object} state
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
constructor(ctx, state) {
|
constructor(ctx, state) {
|
||||||
super(ctx, state, 'note-info');
|
super(ctx, state);
|
||||||
|
|
||||||
this.$title.text("Note info");
|
this.$title.text("Note info");
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class NoteRevisionsWidget extends StandardWidget {
|
|||||||
* @param {object} state
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
constructor(ctx, state) {
|
constructor(ctx, state) {
|
||||||
super(ctx, state, 'note-revisions');
|
super(ctx, state);
|
||||||
|
|
||||||
this.$title.text("Note revisions");
|
this.$title.text("Note revisions");
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,12 @@ class StandardWidget {
|
|||||||
/**
|
/**
|
||||||
* @param {TabContext} ctx
|
* @param {TabContext} ctx
|
||||||
* @param {object} state
|
* @param {object} state
|
||||||
* @param {string} widgetName
|
|
||||||
*/
|
*/
|
||||||
constructor(ctx, state, widgetName) {
|
constructor(ctx, state) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.widgetName = widgetName;
|
this.widgetName = this.constructor.name;
|
||||||
|
|
||||||
const widgetId = `tab-${ctx.tabId}-widget-${widgetName}`;
|
const widgetId = `tab-${ctx.tabId}-widget-${this.widgetName}`;
|
||||||
|
|
||||||
this.$widget = $(WIDGET_TPL);
|
this.$widget = $(WIDGET_TPL);
|
||||||
this.$widget.find('[data-target]').attr('data-target', "#" + widgetId);
|
this.$widget.find('[data-target]').attr('data-target', "#" + widgetId);
|
||||||
@ -33,7 +32,7 @@ class StandardWidget {
|
|||||||
this.$bodyWrapper.attr('id', widgetId);
|
this.$bodyWrapper.attr('id', widgetId);
|
||||||
|
|
||||||
if (state && state.visible) {
|
if (state && state.visible) {
|
||||||
this.$bodyWrapper.addClass("show");
|
this.$bodyWrapper.collapse("show");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$body = this.$bodyWrapper.find('.card-body');
|
this.$body = this.$bodyWrapper.find('.card-body');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user