mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	standard widget => collapsible widget
This commit is contained in:
		
							
								
								
									
										20
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										20
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "trilium", |   "name": "trilium", | ||||||
|   "version": "0.40.1", |   "version": "0.40.2", | ||||||
|   "lockfileVersion": 1, |   "lockfileVersion": 1, | ||||||
|   "requires": true, |   "requires": true, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
| @@ -566,8 +566,7 @@ | |||||||
|     "@types/debug": { |     "@types/debug": { | ||||||
|       "version": "4.1.5", |       "version": "4.1.5", | ||||||
|       "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", |       "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", | ||||||
|       "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", |       "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==" | ||||||
|       "dev": true |  | ||||||
|     }, |     }, | ||||||
|     "@types/events": { |     "@types/events": { | ||||||
|       "version": "3.0.0", |       "version": "3.0.0", | ||||||
| @@ -3848,12 +3847,12 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "file-type": { |     "file-type": { | ||||||
|       "version": "13.1.2", |       "version": "14.0.0", | ||||||
|       "resolved": "https://registry.npmjs.org/file-type/-/file-type-13.1.2.tgz", |       "resolved": "https://registry.npmjs.org/file-type/-/file-type-14.0.0.tgz", | ||||||
|       "integrity": "sha512-NiHXbmclwHN38eHZfRklosbm7/W+1yacDzRCyddd0NiyuJUArQDmzJ8GPSFJGl82+I59u7sNGfcAVnJsfXJb8A==", |       "integrity": "sha512-+gxNvurlwHfTohZC6gqf0ybMl+cXYB9f1x++kw9AgKItdFx20J0fV9wCVR38a5/jphL5EUcusJ9tLYkPRtGHaw==", | ||||||
|       "requires": { |       "requires": { | ||||||
|         "readable-web-to-node-stream": "^2.0.0", |         "readable-web-to-node-stream": "^2.0.0", | ||||||
|         "strtok3": "^5.0.2", |         "strtok3": "^6.0.0", | ||||||
|         "token-types": "^2.0.0", |         "token-types": "^2.0.0", | ||||||
|         "typedarray-to-buffer": "^3.1.5" |         "typedarray-to-buffer": "^3.1.5" | ||||||
|       } |       } | ||||||
| @@ -9522,11 +9521,12 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "strtok3": { |     "strtok3": { | ||||||
|       "version": "5.0.2", |       "version": "6.0.0", | ||||||
|       "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-5.0.2.tgz", |       "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.0.tgz", | ||||||
|       "integrity": "sha512-EFeVpFC5qDsqPEJSrIYyS/ueFBknGhgSK9cW+YAJF/cgJG/KSjoK7X6rK5xnpcLe7y1LVkVFCXWbAb+ClNKzKQ==", |       "integrity": "sha512-ZXlmE22LZnIBvEU3n/kZGdh770fYFie65u5+2hLK9s74DoFtpkQIdBZVeYEzlolpGa+52G5IkzjUWn+iXynOEQ==", | ||||||
|       "requires": { |       "requires": { | ||||||
|         "@tokenizer/token": "^0.1.1", |         "@tokenizer/token": "^0.1.1", | ||||||
|  |         "@types/debug": "^4.1.5", | ||||||
|         "debug": "^4.1.1", |         "debug": "^4.1.1", | ||||||
|         "peek-readable": "^3.1.0" |         "peek-readable": "^3.1.0" | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ | |||||||
|     "electron-window-state": "5.0.3", |     "electron-window-state": "5.0.3", | ||||||
|     "express": "4.17.1", |     "express": "4.17.1", | ||||||
|     "express-session": "1.17.0", |     "express-session": "1.17.0", | ||||||
|     "file-type": "13.1.2", |     "file-type": "14.0.0", | ||||||
|     "fs-extra": "8.1.0", |     "fs-extra": "8.1.0", | ||||||
|     "helmet": "3.21.2", |     "helmet": "3.21.2", | ||||||
|     "html": "1.0.0", |     "html": "1.0.0", | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ import treeCache from './tree_cache.js'; | |||||||
| import noteTooltipService from './note_tooltip.js'; | import noteTooltipService from './note_tooltip.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionService from './protected_session.js'; | ||||||
| import dateNotesService from './date_notes.js'; | import dateNotesService from './date_notes.js'; | ||||||
| import StandardWidget from '../widgets/standard_widget.js'; | import CollapsibleWidget from '../widgets/standard_widget.js'; | ||||||
| import ws from "./ws.js"; | import ws from "./ws.js"; | ||||||
| import hoistedNoteService from "./hoisted_note.js"; | import hoistedNoteService from "./hoisted_note.js"; | ||||||
| import appContext from "./app_context.js"; | import appContext from "./app_context.js"; | ||||||
| @@ -37,8 +37,8 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte | |||||||
|     /** @property {TabContext|null} - experimental! */ |     /** @property {TabContext|null} - experimental! */ | ||||||
|     this.tabContext = tabContext; |     this.tabContext = tabContext; | ||||||
|  |  | ||||||
|     /** @property {StandardWidget} */ |     /** @property {CollapsibleWidget} */ | ||||||
|     this.StandardWidget = StandardWidget; |     this.StandardWidget = CollapsibleWidget; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Activates note in the tree and in the note detail. |      * Activates note in the tree and in the note detail. | ||||||
|   | |||||||
| @@ -69,7 +69,10 @@ class TabContext extends Component { | |||||||
|             protectedSessionHolder.touchProtectedSession(); |             protectedSessionHolder.touchProtectedSession(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.trigger('tabNoteSwitched', {tabId: this.tabId}); |         this.trigger('tabNoteSwitched', { | ||||||
|  |             tabId: this.tabId, | ||||||
|  |             notePath: this.notePath | ||||||
|  |         }); | ||||||
|         this.trigger('openTabsChanged'); |         this.trigger('openTabsChanged'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -114,11 +117,14 @@ class TabContext extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     noteDeletedListener({noteId}) { |     noteDeletedListener({noteId}) { | ||||||
|         if (this.note && noteId === this.note.noteId) { |         if (this.noteId === noteId) { | ||||||
|             this.note = null; |             this.noteId = null; | ||||||
|             this.notePath = null; |             this.notePath = null; | ||||||
|  |  | ||||||
|             this.trigger('tabNoteSwitched', {tabId: this.tabId}); |             this.trigger('tabNoteSwitched', { | ||||||
|  |                 tabId: this.tabId, | ||||||
|  |                 notePath: this.notePath | ||||||
|  |             }); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| import utils from "../services/utils.js"; | import utils from "../services/utils.js"; | ||||||
| import linkService from "../services/link.js"; | import linkService from "../services/link.js"; | ||||||
| import ws from "../services/ws.js"; | import ws from "../services/ws.js"; | ||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
|  |  | ||||||
| class AttributesWidget extends StandardWidget { | class AttributesWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Attributes"; } |     getWidgetTitle() { return "Attributes"; } | ||||||
|  |  | ||||||
|     getHelp() { |     getHelp() { | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
| import libraryLoader from "../services/library_loader.js"; | import libraryLoader from "../services/library_loader.js"; | ||||||
| import utils from "../services/utils.js"; | import utils from "../services/utils.js"; | ||||||
| import dateNoteService from "../services/date_notes.js"; | import dateNoteService from "../services/date_notes.js"; | ||||||
| @@ -24,7 +24,7 @@ const TPL = ` | |||||||
| </div> | </div> | ||||||
| `; | `; | ||||||
|  |  | ||||||
| class CalendarWidget extends StandardWidget { | class CalendarWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Calendar"; } |     getWidgetTitle() { return "Calendar"; } | ||||||
|  |  | ||||||
|     async isEnabled() { |     async isEnabled() { | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ const WIDGET_TPL = ` | |||||||
| </div> | </div> | ||||||
| `;
 | `;
 | ||||||
| 
 | 
 | ||||||
| class StandardWidget extends TabAwareWidget { | class CollapsibleWidget extends TabAwareWidget { | ||||||
|     getWidgetTitle() { return "Untitled widget"; } |     getWidgetTitle() { return "Untitled widget"; } | ||||||
| 
 | 
 | ||||||
|     getHeaderActions() { return []; } |     getHeaderActions() { return []; } | ||||||
| @@ -30,20 +30,14 @@ class StandardWidget extends TabAwareWidget { | |||||||
| 
 | 
 | ||||||
|     getMaxHeight() { return null; } |     getMaxHeight() { return null; } | ||||||
| 
 | 
 | ||||||
|     //getPosition() { return this.widgetOptions.position; }
 |  | ||||||
| 
 |  | ||||||
|     render() { |     render() { | ||||||
|         const widgetInstanceId = this.componentId + "-" + utils.randomString(10); |  | ||||||
| 
 |  | ||||||
|         this.$widget = $(WIDGET_TPL); |         this.$widget = $(WIDGET_TPL); | ||||||
|         this.$widget.find('[data-target]').attr('data-target', "#" + widgetInstanceId); |         this.$widget.find('[data-target]').attr('data-target', "#" + this.componentId); | ||||||
| 
 | 
 | ||||||
|         this.$bodyWrapper = this.$widget.find('.body-wrapper'); |         this.$bodyWrapper = this.$widget.find('.body-wrapper'); | ||||||
|         this.$bodyWrapper.attr('id', widgetInstanceId); |         this.$bodyWrapper.attr('id', this.componentId); | ||||||
| 
 | 
 | ||||||
| //        if (this.state.expanded) {
 |  | ||||||
|         this.$bodyWrapper.collapse("show"); |         this.$bodyWrapper.collapse("show"); | ||||||
| //        }
 |  | ||||||
| 
 | 
 | ||||||
|         this.$body = this.$bodyWrapper.find('.card-body'); |         this.$body = this.$bodyWrapper.find('.card-body'); | ||||||
| 
 | 
 | ||||||
| @@ -54,10 +48,6 @@ class StandardWidget extends TabAwareWidget { | |||||||
|             this.$body.css("overflow", "auto"); |             this.$body.css("overflow", "auto"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // this.$widget.on('shown.bs.collapse', () => this.renderBody());
 |  | ||||||
|         // this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged());
 |  | ||||||
|         // this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged());
 |  | ||||||
| 
 |  | ||||||
|         this.$title = this.$widget.find('.widget-title'); |         this.$title = this.$widget.find('.widget-title'); | ||||||
|         this.$title.text(this.getWidgetTitle()); |         this.$title.text(this.getWidgetTitle()); | ||||||
| 
 | 
 | ||||||
| @@ -91,31 +81,11 @@ class StandardWidget extends TabAwareWidget { | |||||||
|     /** for overriding */ |     /** for overriding */ | ||||||
|     async doRenderBody() {} |     async doRenderBody() {} | ||||||
| 
 | 
 | ||||||
|     async isEnabled() { |  | ||||||
|         const label = await this.ctx.note.getLabelValue(this.widgetName); |  | ||||||
| 
 |  | ||||||
|         if (label === 'enabled') { |  | ||||||
|             return true; |  | ||||||
|         } else if (label === 'disabled') { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             return this.widgetOptions.enabled; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     isExpanded() { |     isExpanded() { | ||||||
|         return this.$bodyWrapper.hasClass("show"); |         return this.$bodyWrapper.hasClass("show"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     getWidgetState() { |  | ||||||
|         return { |  | ||||||
|             name: this.widgetName, |  | ||||||
|             expanded: this.isExpanded() |  | ||||||
|         }; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     cleanup() {} |     cleanup() {} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default StandardWidget; | export default CollapsibleWidget; | ||||||
| @@ -3,7 +3,7 @@ import utils from '../services/utils.js'; | |||||||
| export default class Component { | export default class Component { | ||||||
|     /** @param {AppContext} appContext */ |     /** @param {AppContext} appContext */ | ||||||
|     constructor(appContext) { |     constructor(appContext) { | ||||||
|         this.componentId = `comp-${this.constructor.name}-` + utils.randomString(10); |         this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6); | ||||||
|         this.appContext = appContext; |         this.appContext = appContext; | ||||||
|         /** @type Component[] */ |         /** @type Component[] */ | ||||||
|         this.children = []; |         this.children = []; | ||||||
| @@ -13,8 +13,6 @@ export default class Component { | |||||||
|     async eventReceived(name, data, sync = false) { |     async eventReceived(name, data, sync = false) { | ||||||
|         await this.initialized; |         await this.initialized; | ||||||
|  |  | ||||||
| //        console.log(`Received ${name} to ${this.componentId}`); |  | ||||||
|  |  | ||||||
|         const fun = this[name + 'Listener']; |         const fun = this[name + 'Listener']; | ||||||
|  |  | ||||||
|         let propagateToChildren = true; |         let propagateToChildren = true; | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
| import linkService from "../services/link.js"; | import linkService from "../services/link.js"; | ||||||
| import server from "../services/server.js"; | import server from "../services/server.js"; | ||||||
| import treeCache from "../services/tree_cache.js"; | import treeCache from "../services/tree_cache.js"; | ||||||
|  |  | ||||||
| class EditedNotesWidget extends StandardWidget { | class EditedNotesWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Edited notes on this day"; } |     getWidgetTitle() { return "Edited notes on this day"; } | ||||||
|  |  | ||||||
|     getHelp() { |     getHelp() { | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
|  |  | ||||||
| let linkMapContainerIdCtr = 1; | let linkMapContainerIdCtr = 1; | ||||||
|  |  | ||||||
| @@ -8,7 +8,7 @@ const TPL = ` | |||||||
| </div> | </div> | ||||||
| `; | `; | ||||||
|  |  | ||||||
| class LinkMapWidget extends StandardWidget { | class LinkMapWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Link map"; } |     getWidgetTitle() { return "Link map"; } | ||||||
|  |  | ||||||
|     getHelp() { |     getHelp() { | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
|  |  | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <table class="note-info-widget-table"> | <table class="note-info-widget-table"> | ||||||
| @@ -35,34 +35,34 @@ const TPL = ` | |||||||
| </table> | </table> | ||||||
| `; | `; | ||||||
|  |  | ||||||
| class NoteInfoWidget extends StandardWidget { | class NoteInfoWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Note info"; } |     getWidgetTitle() { return "Note info"; } | ||||||
|  |  | ||||||
|     doRenderBody() { |     doRenderBody() { | ||||||
|         this.$body.html(TPL); |         this.$body.html(TPL); | ||||||
|  |  | ||||||
|  |         this.$noteId = this.$body.find(".note-info-note-id"); | ||||||
|  |         this.$dateCreated = this.$body.find(".note-info-date-created"); | ||||||
|  |         this.$dateModified = this.$body.find(".note-info-date-modified"); | ||||||
|  |         this.$type = this.$body.find(".note-info-type"); | ||||||
|  |         this.$mime = this.$body.find(".note-info-mime"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async refreshWithNote(note) { |     async refreshWithNote(note) { | ||||||
|         const $noteId = this.$body.find(".note-info-note-id"); |  | ||||||
|         const $dateCreated = this.$body.find(".note-info-date-created"); |  | ||||||
|         const $dateModified = this.$body.find(".note-info-date-modified"); |  | ||||||
|         const $type = this.$body.find(".note-info-type"); |  | ||||||
|         const $mime = this.$body.find(".note-info-mime"); |  | ||||||
|  |  | ||||||
|         const noteComplement = await this.tabContext.getNoteComplement(); |         const noteComplement = await this.tabContext.getNoteComplement(); | ||||||
|  |  | ||||||
|         $noteId.text(note.noteId); |         this.$noteId.text(note.noteId); | ||||||
|         $dateCreated |         this.$dateCreated | ||||||
|             .text(noteComplement.dateCreated) |             .text(noteComplement.dateCreated) | ||||||
|             .attr("title", noteComplement.dateCreated); |             .attr("title", noteComplement.dateCreated); | ||||||
|  |  | ||||||
|         $dateModified |         this.$dateModified | ||||||
|             .text(noteComplement.dateModified) |             .text(noteComplement.dateModified) | ||||||
|             .attr("title", noteComplement.dateCreated); |             .attr("title", noteComplement.dateCreated); | ||||||
|  |  | ||||||
|         $type.text(note.type); |         this.$type.text(note.type); | ||||||
|  |  | ||||||
|         $mime |         this.$mime | ||||||
|             .text(note.mime) |             .text(note.mime) | ||||||
|             .attr("title", note.mime); |             .attr("title", note.mime); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,12 +1,12 @@ | |||||||
| import server from "../services/server.js"; | import server from "../services/server.js"; | ||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
|  |  | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <ul class="note-revision-list" style="max-height: 150px; overflow: auto;"> | <ul class="note-revision-list" style="max-height: 150px; overflow: auto;"> | ||||||
| </ul> | </ul> | ||||||
| `; | `; | ||||||
|  |  | ||||||
| class NoteRevisionsWidget extends StandardWidget { | class NoteRevisionsWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Note revisions"; } |     getWidgetTitle() { return "Note revisions"; } | ||||||
|  |  | ||||||
|     getHelp() { |     getHelp() { | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
| import linkService from "../services/link.js"; | import linkService from "../services/link.js"; | ||||||
| import server from "../services/server.js"; | import server from "../services/server.js"; | ||||||
| import treeCache from "../services/tree_cache.js"; | import treeCache from "../services/tree_cache.js"; | ||||||
|  |  | ||||||
| class SimilarNotesWidget extends StandardWidget { | class SimilarNotesWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "Similar notes"; } |     getWidgetTitle() { return "Similar notes"; } | ||||||
|  |  | ||||||
|     getHelp() { |     getHelp() { | ||||||
|   | |||||||
| @@ -28,8 +28,9 @@ export default class TabAwareWidget extends BasicWidget { | |||||||
|         return this.tabContext && this.tabContext.notePath; |         return this.tabContext && this.tabContext.notePath; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     tabNoteSwitchedListener({tabId}) { |     tabNoteSwitchedListener({tabId, notePath}) { | ||||||
|         if (this.isTab(tabId)) { |         // if notePath does not match then the tabContext has been switched to another note in the mean time | ||||||
|  |         if (this.isTab(tabId) && this.notePath === notePath) { | ||||||
|             this.noteSwitched(); |             this.noteSwitched(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| import StandardWidget from "./standard_widget.js"; | import CollapsibleWidget from "./standard_widget.js"; | ||||||
| import linkService from "../services/link.js"; | import linkService from "../services/link.js"; | ||||||
|  |  | ||||||
| class WhatLinksHereWidget extends StandardWidget { | class WhatLinksHereWidget extends CollapsibleWidget { | ||||||
|     getWidgetTitle() { return "What links here"; } |     getWidgetTitle() { return "What links here"; } | ||||||
|  |  | ||||||
|     getMaxHeight() { return "200px"; } |     getMaxHeight() { return "200px"; } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user