mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
feat(docs): reorganize scripting notes and finalize attribute reference
This commit is contained in:
@@ -15,7 +15,7 @@ New tasks are created in the TODO note which has `~child:template` [relation](..
|
||||
|
||||
### Attributes
|
||||
|
||||
Task template defines several [promoted attributes](../Attributes/Promoted%20Attributes.md) - todoDate, doneDate, tags, location. Importantly it also defines `~runOnAttributeChange` relation - [event](../../Note%20Types/Code/Events.md) handler which is run on attribute change. This [script](../../Scripting.md) handles when e.g. we fill out the doneDate attribute - meaning the task is done and should be moved to "Done" note and removed from TODO, locations and tags.
|
||||
Task template defines several [promoted attributes](../Attributes/Promoted%20Attributes.md) - todoDate, doneDate, tags, location. Importantly it also defines `~runOnAttributeChange` relation - [event](../../Scripting/Events.md) handler which is run on attribute change. This [script](../../Scripting.md) handles when e.g. we fill out the doneDate attribute - meaning the task is done and should be moved to "Done" note and removed from TODO, locations and tags.
|
||||
|
||||
### New task button
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Weight Tracker
|
||||

|
||||
|
||||
The `Weight Tracker` is a [Script API](../../Note%20Types/Code/Script%20API.md) showcase present in the [demo notes](../Database.md).
|
||||
The `Weight Tracker` is a [Script API](../../Scripting/Script%20API.md) showcase present in the [demo notes](../Database.md).
|
||||
|
||||
By adding `weight` as a [promoted attribute](../Attributes/Promoted%20Attributes.md) in the [template](../Templates.md) from which [day notes](Day%20Notes.md) are created, you can aggregate the data and plot weight change over time.
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ Labels are also searchable, enhancing note retrieval.
|
||||
|
||||
### Common Labels for Advanced Configuration
|
||||
|
||||
See the corresponding section in <a class="reference-link" href="Attributes/Attribute%20Reference.md">Attribute Reference</a> for a comprehensive list of attributes.
|
||||
|
||||
## Relations
|
||||
|
||||
Relations define connections between notes, similar to links.
|
||||
@@ -31,8 +33,7 @@ Relations define connections between notes, similar to links.
|
||||
|
||||
### Common Relations
|
||||
|
||||
* **Event-based Relations**: Such as `runOnNoteCreation` or `runOnNoteChange`, which trigger scripts on specific actions
|
||||
* **Other Relations**: Include `template`, `renderNote`, `widget`, and sharing-related relations
|
||||
See the corresponding section in <a class="reference-link" href="Attributes/Attribute%20Reference.md">Attribute Reference</a> for a comprehensive list of relations.
|
||||
|
||||
## Multiplicity
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,19 @@
|
||||
# Trilium instance
|
||||
A Trilium instance represents a server. If <a class="reference-link" href="../../Installation%20%26%20Setup/Synchronization.md">Synchronization</a> is set up, since multiple servers are involved (the one from the desktop client and the one the synchronisation is set up with), sometimes it can be useful to distinguish the instance you are running on.
|
||||
|
||||
## Setting the instance name
|
||||
|
||||
To set up a name for the instance, modify the `config.ini`:
|
||||
|
||||
```
|
||||
[General]
|
||||
instanceName=Hello
|
||||
```
|
||||
|
||||
## Distinguishing the instance on back-end
|
||||
|
||||
Use `api.getInstanceName()` to obtain the instance name of the current server, as specified in the config file or in environment variables.
|
||||
|
||||
## Limiting script runs based on instance
|
||||
|
||||
For a script that is run periodically or on a certain event, it's possible to limit it to certain instances without having to change the code. Just add `runOnInstance` and set as the value the instance name where the script should run. To run on multiple named instances, simply add the label multiple times.
|
||||
@@ -53,7 +53,7 @@ Trilium will then find our code note created above and execute it. `api.req`, `a
|
||||
|
||||
In the code note we check the request method and then use trivial authentication - keep in mind that these endpoints are by default totally unauthenticated, and you need to take care of this yourself.
|
||||
|
||||
Once we pass these checks we will just create the desired note using [Script API](../Note%20Types/Code/Script%20API.md).
|
||||
Once we pass these checks we will just create the desired note using [Script API](../Scripting/Script%20API.md).
|
||||
|
||||
## Custom resource provider
|
||||
|
||||
|
||||
@@ -17,14 +17,16 @@ And all children of "2022 Books" will be created with initial title "\[Author na
|
||||
|
||||
The value of `#titleTemplate` is evaluated at the point of note's creation as a JavaScript string, which means it can be enriched with the help of JS string interpolation with dynamic data.
|
||||
|
||||
As an example, imagine you collect server outage incidents and write some notes. It looks like this:
|
||||
Second variable injected is `parentNote` which gives access to the parent [`FNote`](../Scripting/Script%20API/Frontend%20API/FNote.md).
|
||||
|
||||
* Incidents
|
||||
* 2022-05-09: System crash
|
||||
* 2022-05-15: Backup delay
|
||||
See also <a class="reference-link" href="Templates.md">Templates</a> which provides similar capabilities, including default note's content.
|
||||
|
||||
You can automatize the date assignment by assigning a label `#titleTemplate="${now.format('YYYY-MM-DD')}: "` to the parent note "Incidents". Whenever a new child note is created, the title template is evaluated with the injected [now](https://day.js.org/docs/en/display/format) object.
|
||||
### Examples
|
||||
|
||||
Second variable injected is [parentNote](https://triliumnext.github.io/Notes/backend_api/BNote.html), an example could be `#titleTemplate="${parentNote.getLabelValue('authorName')}'s literary works"`.
|
||||
|
||||
See also \[\[[template](Templates.md)\]\] which provides similar capabilities, including default note's content.
|
||||
* Imagine you collect server outage incidents and write some notes. It looks like this:
|
||||
* Incidents
|
||||
* 2022-05-09: System crash
|
||||
* 2022-05-15: Backup delay
|
||||
* You can automatize the date assignment by assigning a label `#titleTemplate="${now.format('YYYY-MM-DD')}: "` to the parent note "Incidents". Whenever a new child note is created, the title template is evaluated with the injected [now](https://day.js.org/docs/en/display/format) object.
|
||||
* To use a parent's attribute in the title of new notes: `#titleTemplate="${parentNote.getLabelValue('authorName')}'s literary works"`
|
||||
* To mirror the parent's note title: `${parentNote.title}`
|
||||
@@ -3,7 +3,7 @@ Trilium allows you to share selected notes as **publicly accessible** read-only
|
||||
|
||||
## Prerequisites
|
||||
|
||||
To use the sharing feature, you must have a [server installation](../Installation%20%26%20Setup/Server%20Installation.md) of Trilium. This is necessary because the notes will be hosted from the server.
|
||||
To use the sharing feature, you must have a <a class="reference-link" href="../Installation%20%26%20Setup/Server%20Installation.md">Server Installation</a> of Trilium. This is necessary because the notes will be hosted from the server.
|
||||
|
||||
## How to Share a Note
|
||||
|
||||
@@ -40,7 +40,7 @@ To protect shared notes with a username and password, you can use the `#shareCre
|
||||
|
||||
The default shared page is basic in design, but you can customize it using your own CSS:
|
||||
|
||||
* **Custom CSS**: Link a CSS [code note](../Note%20Types/Code.md) to the shared page by adding a `~shareCss` relation to the note. If you want this style to apply to the entire subtree, make the label inheritable. You can hide the CSS code note from the tree navigation by adding the `#shareHiddenFromTree` label.
|
||||
* **Custom CSS**: Link a CSS <a class="reference-link" href="../Note%20Types/Code.md">Code</a> note to the shared page by adding a `~shareCss` relation to the note. If you want this style to apply to the entire subtree, make the label inheritable. You can hide the CSS code note from the tree navigation by adding the `#shareHiddenFromTree` label.
|
||||
* **Omitting Default CSS**: For extensive styling changes, use the `#shareOmitDefaultCss` label to avoid conflicts with Trilium's [default stylesheet](../Basic%20Concepts%20and%20Features/Themes.md).
|
||||
|
||||
### Adding JavaScript
|
||||
@@ -81,12 +81,6 @@ To customize the favicon for your shared pages, create a relation `~shareFavicon
|
||||
|
||||
You can designate a specific note or folder as the root of your shared content by adding the `#shareRoot` label. This note will be linked when visiting `[http://domain.tld/share](http://domain/share)`, making it easier to use Trilium as a fully-fledged website. Consider combining this with the `#shareIndex` label, which will display a list of all shared notes.
|
||||
|
||||
## Additional Options
|
||||
|
||||
* **Raw Note Sharing**: Use the `#shareRaw` label to share a note without any HTML wrapper.
|
||||
* **Disallow Robot Indexing**: Add the `#shareDisallowRobotIndexing` label to prevent search engines from indexing the shared page by including a `noindex, follow` meta tag and `X-Robots-Tag: noindex` header.
|
||||
* **Shared Notes Index**: For text notes with the `#shareIndex` label, the content will display a list of all shared note roots.
|
||||
|
||||
## Limitations
|
||||
|
||||
While the sharing feature is powerful, it has some limitations:
|
||||
@@ -98,4 +92,8 @@ While the sharing feature is powerful, it has some limitations:
|
||||
* **Protected Notes**: Cannot be shared.
|
||||
* **Include Notes**: Not supported.
|
||||
|
||||
Some of these limitations may be addressed in future updates.
|
||||
Some of these limitations may be addressed in future updates.
|
||||
|
||||
## Attribute reference
|
||||
|
||||
<figure class="table"><table><thead><tr><th>Attribute</th><th>Description</th></tr></thead><tbody><tr><td><code>shareHiddenFromTree</code></td><td>this note is hidden from left navigation tree, but still accessible with its URL</td></tr><tr><td><code>shareExternalLink</code></td><td>note will act as a link to an external website in the share tree</td></tr><tr><td><code>shareAlias</code></td><td>define an alias using which the note will be available under <code>https://your_trilium_host/share/[your_alias]</code></td></tr><tr><td><code>shareOmitDefaultCss</code></td><td>default share page CSS will be omitted. Use when you make extensive styling changes.</td></tr><tr><td><code>shareRoot</code></td><td>marks note which is served on /share root.</td></tr><tr><td><code>shareDescription</code></td><td>define text to be added to the HTML meta tag for description</td></tr><tr><td><code>shareRaw</code></td><td>Note will be served in its raw format, without HTML wrapper. See also <a class="reference-link" href="Sharing/Serving%20directly%20the%20content%20o.md">Serving directly the content of a note</a> for an alternative method without setting an attribute.</td></tr><tr><td><code>shareDisallowRobotIndexing</code></td><td><p>Indicates to web crawlers that the page should not be indexed of this note by:</p><ul><li>Setting the <code>X-Robots-Tag: noindex</code> HTTP header.</li><li>Setting the <code>noindex, follow</code> meta tag.</li></ul></td></tr><tr><td><code>shareCredentials</code></td><td>require credentials to access this shared note. Value is expected to be in format <code>username:password</code>. Don't forget to make this inheritable to apply to child-notes/images.</td></tr><tr><td><code>shareIndex</code></td><td>Note with this label will list all roots of shared notes.</td></tr></tbody></table></figure>
|
||||
@@ -23,7 +23,7 @@ To create an instance note through the UI:
|
||||
|
||||

|
||||
|
||||
For the template to appear in the menu, the template note must have the `#template` label. Do not confuse this with the `~template` relation, which links the instance note to the template note. If you use [workspaces](../Basic%20Concepts%20and%20Features/Navigation/Workspace.md), you can also mark templates with `#workspaceTemplate` to display them only in the workspace.
|
||||
For the template to appear in the menu, the template note must have the `#template` label. Do not confuse this with the `~template` relation, which links the instance note to the template note. If you use [workspaces](../Basic%20Concepts%20and%20Features/Navigation/Workspaces.md), you can also mark templates with `#workspaceTemplate` to display them only in the workspace.
|
||||
|
||||
Templates can also be added or changed after note creation by creating a `~template` relation pointing to the desired template note.
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -5,4 +5,4 @@ Hoisting is a standard outliner feature which allows you to focus on (or "zoom i
|
||||
|
||||
In addition to showing only this subtree, this also narrows both full text search and [“jump to note”](Note%20Navigation.md) to just notes present in hoisted subtree.
|
||||
|
||||
See also [Workspace](Workspace.md) which extends this feature.
|
||||
See also [Workspace](Workspaces.md) which extends this feature.
|
||||
@@ -1,24 +0,0 @@
|
||||
# Workspace
|
||||
Workspace is a concept built up on top of [note hoisting](Note%20Hoisting.md). It is based on the idea that a user has several distinct spheres of interest. An example might be "Personal" and "Work", these two spheres are quite distinct and don't interact together. When I focus on Work, I don't really care about personal notes.
|
||||
|
||||
So far workspace consists of these features:
|
||||
|
||||
* [note hoisting](Note%20Hoisting.md) - you can "zoom" into a workspace subtree to focus only on the relevant notes
|
||||
|
||||
* easy entering of workspace:
|
||||
|
||||

|
||||
|
||||
* visual identification of workspace in tabs:
|
||||

|
||||
|
||||
|
||||
### How to use workspaces
|
||||
|
||||
Let's say you have identified the workspaces and their subtrees. Define on the root of this subtree following labels:
|
||||
|
||||
* `#workspace` - Marks this note as a workspace, button to enter the workspace is controlled by this
|
||||
* `#workspaceIconClass` - controls the box icon to be displayed in the tree and tabs, example `bx bx-home`. See [https://boxicons.com/](https://boxicons.com/)
|
||||
* `#workspaceTabBackgroundColor` - Background color of the tab, use any CSS color format, e.g. "lightblue" or "#ddd". See [https://www.w3schools.com/cssref/css\_colors.asp](https://www.w3schools.com/cssref/css_colors.asp).
|
||||
* `#workspaceCalendarRoot` - marking a note with this label will define a new per-workspace calendar. If there's no such note, the global calendar will be used.
|
||||
* `#workspaceTemplate` - This note will appear in the selection of available templates when creating a new note, but only when you are currently hoisted into a workspace containing this template.
|
||||
@@ -0,0 +1,16 @@
|
||||
# Workspaces
|
||||
Workspace is a concept built up on top of [note hoisting](Note%20Hoisting.md). It is based on the idea that a user has several distinct spheres of interest. An example might be "Personal" and "Work", these two spheres are quite distinct and don't interact together. When I focus on Work, I don't really care about personal notes.
|
||||
|
||||
So far workspace consists of these features:
|
||||
|
||||
* [note hoisting](Note%20Hoisting.md) - you can "zoom" into a workspace subtree to focus only on the relevant notes
|
||||
* easy entering of workspace:
|
||||
|
||||

|
||||
|
||||
* visual identification of workspace in tabs:
|
||||

|
||||
|
||||
### Configuration
|
||||
|
||||
<figure class="table"><table><thead><tr><th>Label</th><th>Description</th></tr></thead><tbody><tr><td><code>workspace</code></td><td>Marks this note as a workspace, button to enter the workspace is controlled by this</td></tr><tr><td><code>workspaceIconClass</code></td><td>defines box icon CSS class which will be used in tab when hoisted to this note</td></tr><tr><td><code>workspaceTabBackgroundColor</code></td><td>CSS color used in the note tab when hoisted to this note, use any CSS color format, e.g. "lightblue" or "#ddd". See <a href="https://www.w3schools.com/cssref/css_colors.asp">https://www.w3schools.com/cssref/css_colors.asp</a>.</td></tr><tr><td><code>workspaceCalendarRoot</code></td><td>Marking a note with this label will define a new per-workspace calendar for <a class="reference-link" href="../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a>. If there's no such note, the global calendar will be used.</td></tr><tr><td><code>workspaceTemplate</code></td><td>This note will appear in the selection of available template when creating new note, but only when hoisted into a workspace containing this template</td></tr><tr><td><code>workspaceSearchHome</code></td><td>new search notes will be created as children of this note when hoisted to some ancestor of this workspace note</td></tr><tr><td><code>workspaceInbox</code></td><td>default inbox location for new notes when hoisted to some ancestor of this workspace note</td></tr></tbody></table></figure>
|
||||
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
@@ -1,9 +1,10 @@
|
||||
# Note List
|
||||
When a note has one or more child notes, they will be listed at the end of the note for easy navigation.
|
||||
|
||||
## Hide the note list for a given note
|
||||
## Configuration
|
||||
|
||||
If the note list is not desireable for a particular note, simply apply the `hideChildrenOverview` [label](../../Advanced%20Usage/Attributes.md).
|
||||
* To hide the note list for a particular note, simply apply the `hideChildrenOverview` [label](../../Advanced%20Usage/Attributes.md).
|
||||
* For some view types, such as Grid view, only a subset of notes will be displayed and pagination can be used to navigate through all of them for performance reasons. To adjust the number of notes per page, set `pageSize` to the desired number.
|
||||
|
||||
## View types
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ Right click either the _Available launchers_ or _Visible launchers_ sections and
|
||||
2. Optionally, set a `keyboardShortcut` to trigger the launcher.
|
||||
3. **Custom Widget**
|
||||
|
||||
Allows defining a custom widget to be rendered inside the launcher. See [Widget Basics](../../Scripting/Widget%20Basics.md) for more information.
|
||||
Allows defining a custom widget to be rendered inside the launcher. See [Widget Basics](../../Scripting/Custom%20Widgets/Widget%20Basics.md) for more information.
|
||||
|
||||
4. **Spacers**
|
||||
Launchers that create some distance between other launchers for better visual distinction.
|
||||
|
||||
@@ -61,4 +61,6 @@ This section displays information about the current note:
|
||||
|
||||
### Edited notes
|
||||
|
||||
This section pops automatically when entering a [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) and shows the notes that were edited that day.
|
||||
This section pops automatically when entering a [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) and shows the notes that were edited that day.
|
||||
|
||||
It is possible to disable this behavior from settings, by going to <a class="reference-link" href="#root/_hidden/_options/_optionsAppearance">Appearance</a> settings and looking for the _Ribbon widgets_ section.
|
||||
@@ -1,29 +0,0 @@
|
||||
# Events
|
||||
[Script](../../Scripting.md) notes can be triggered by events. Note that these are backend events and thus relation need to point to the "JS backend" code note.
|
||||
|
||||
## Global events
|
||||
|
||||
Global events are attached to the script note via label. Simply create e.g. "run" label with some of these values and script note will be executed once the event occurs.
|
||||
|
||||
* `run`
|
||||
* `frontendStartup` - executes on frontend upon startup
|
||||
* `mobileStartup` - executes on mobile frontend upon startup
|
||||
* `backendStartup` - executes on backend upon startup
|
||||
* `hourly` - executes once an hour on backend
|
||||
* `daily` - executes once a day on backend
|
||||
|
||||
## Entity events
|
||||
|
||||
Other events are bound to some entity, these are defined as [relations](../../Advanced%20Usage/Attributes.md) - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).
|
||||
|
||||
* `runOnNoteCreation` - executes when note is created on backend
|
||||
* `runOnNoteTitleChange` - executes when note title is changed (includes note creation as well)
|
||||
* `runOnNoteContentChange` - executes when note content is changed (includes note creation as well).
|
||||
* `runOnNoteChange` - executes when note is changed (includes note creation as well)
|
||||
* `runOnNoteDeletion` - executes when note is being deleted
|
||||
* `runOnBranchCreation` - executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.
|
||||
* `runOnBranchChange` (since v0.62) - executes when a branch is changed - either expanded status or prefix are changed.
|
||||
* `runOnBranchDeletion` - executes when a branch is delete. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).
|
||||
* `runOnChildNoteCreation` - executes when new note is created under _this_ note
|
||||
* `runOnAttributeCreation` - executes when new attribute is created under _this_ note
|
||||
* `runOnAttributeChange` - executes when attribute is changed under _this_ note
|
||||
@@ -5,4 +5,4 @@ Trilium allows you to save common searches as notes within the note tree. The se
|
||||
|
||||
## Location
|
||||
|
||||
By default, saved searches are stored in the day note. However, you can designate a different note to store saved searches by marking it with the `#searchHome` label. Additionally, for [workspaces](../Basic%20Concepts%20and%20Features/Navigation/Workspace.md), you can use the `#workspaceSearchHome` label to specify a storage location for saved searches within that workspace.
|
||||
By default, saved searches are stored in the day note. However, you can designate a different note to store saved searches by marking it with the `#searchHome` label. Additionally, for [workspaces](../Basic%20Concepts%20and%20Features/Navigation/Workspaces.md), you can use the `#workspaceSearchHome` label to specify a storage location for saved searches within that workspace.
|
||||
@@ -1,5 +1,5 @@
|
||||
# Scripting
|
||||
Trilium supports creating <a class="reference-link" href="Note%20Types/Code.md">Code</a> notes, i.e. notes which allow you to store some programming code and highlight it. Special case is JavaScript code notes which can also be executed inside Trilium which can in conjunction with <a class="reference-link" href="Note%20Types/Code/Script%20API.md">Script API</a> provide extra functionality.
|
||||
Trilium supports creating <a class="reference-link" href="Note%20Types/Code.md">Code</a> notes, i.e. notes which allow you to store some programming code and highlight it. Special case is JavaScript code notes which can also be executed inside Trilium which can in conjunction with <a class="reference-link" href="Scripting/Script%20API.md">Script API</a> provide extra functionality.
|
||||
|
||||
## Scripting
|
||||
|
||||
@@ -34,8 +34,8 @@ You can see more scripting with explanation in <a class="reference-link" href="
|
||||
|
||||
## Events
|
||||
|
||||
See <a class="reference-link" href="Note%20Types/Code/Events.md">Events</a>.
|
||||
See <a class="reference-link" href="Scripting/Events.md">Events</a>.
|
||||
|
||||
## Script API
|
||||
|
||||
See <a class="reference-link" href="Note%20Types/Code/Script%20API.md">Script API</a>.
|
||||
See <a class="reference-link" href="Scripting/Script%20API.md">Script API</a>.
|
||||
@@ -22,10 +22,10 @@ module.exports = new MyWidget();
|
||||
To implement this widget:
|
||||
|
||||
1. Create a new `JS Frontend` note in Trilium and paste in the code above.
|
||||
2. Assign the `#widget` [attribute](../Advanced%20Usage/Attributes.md) to the [note](../Basic%20Concepts%20and%20Features/Notes.md).
|
||||
2. Assign the `#widget` [attribute](../../Advanced%20Usage/Attributes.md) to the [note](../../Basic%20Concepts%20and%20Features/Notes.md).
|
||||
3. Restart Trilium or reload the window.
|
||||
|
||||
To verify that the widget is working, open the developer tools (`Cmd` + `Shift` + `I`) and run `document.querySelector("#my-widget")`. If the element is found, the widget is functioning correctly. If `undefined` is returned, double-check that the [note](../Basic%20Concepts%20and%20Features/Notes.md) has the `#widget` [attribute](../Advanced%20Usage/Attributes.md).
|
||||
To verify that the widget is working, open the developer tools (`Cmd` + `Shift` + `I`) and run `document.querySelector("#my-widget")`. If the element is found, the widget is functioning correctly. If `undefined` is returned, double-check that the [note](../../Basic%20Concepts%20and%20Features/Notes.md) has the `#widget` [attribute](../../Advanced%20Usage/Attributes.md).
|
||||
|
||||
### Step 2: Adding an UI Element
|
||||
|
||||
@@ -85,7 +85,7 @@ After reloading Trilium, the button should now appear at the bottom left of the
|
||||
|
||||
### Step 4: Adding User Interaction
|
||||
|
||||
Let’s make the button interactive by showing a message when it’s clicked. We'll use the `api.showMessage` method from the [Script API](../Note%20Types/Code/Script%20API.md).
|
||||
Let’s make the button interactive by showing a message when it’s clicked. We'll use the `api.showMessage` method from the [Script API](../Script%20API.md).
|
||||
|
||||
```
|
||||
class MyWidget extends api.BasicWidget {
|
||||
@@ -1,8 +1,8 @@
|
||||
# Word count widget
|
||||
> [!TIP]
|
||||
> This widget is also present in new installations in the <a class="reference-link" href="../../../Advanced%20Usage/Database/Demo%20Notes.md">Demo Notes</a>.
|
||||
> This widget is also present in new installations in the <a class="reference-link" href="../../Advanced%20Usage/Database/Demo%20Notes.md">Demo Notes</a>.
|
||||
|
||||
Create a <a class="reference-link" href="../../Code.md">Code</a> note of type JS frontend and **give it a** `#widget` **label**.
|
||||
Create a <a class="reference-link" href="../../Note%20Types/Code.md">Code</a> note of type JS frontend and **give it a** `#widget` **label**.
|
||||
|
||||
```
|
||||
/*
|
||||
@@ -82,7 +82,7 @@ class WordCountWidget extends api.NoteContextAwareWidget {
|
||||
module.exports = new WordCountWidget();
|
||||
```
|
||||
|
||||
After you make changes it is necessary to [restart Trilium](../../../Troubleshooting/Refreshing%20the%20application.md) so that the layout can be rebuilt.
|
||||
After you make changes it is necessary to [restart Trilium](../../Troubleshooting/Refreshing%20the%20application.md) so that the layout can be rebuilt.
|
||||
|
||||
At the bottom of the note you can see the resulting widget:
|
||||
|
||||
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
14
docs/User Guide/User Guide/Scripting/Events.md
Normal file
14
docs/User Guide/User Guide/Scripting/Events.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Events
|
||||
[Script](../Scripting.md) notes can be triggered by events. Note that these are backend events and thus relation need to point to the "JS backend" code note.
|
||||
|
||||
## Global events
|
||||
|
||||
Global events are attached to the script note via label. Simply create e.g. "run" label with some of these values and script note will be executed once the event occurs.
|
||||
|
||||
<figure class="table"><table><thead><tr><th>Label</th><th>Description</th></tr></thead><tbody><tr><td><code>run</code></td><td><p>Defines on which events script should run. Possible values are:</p><ul><li><code>frontendStartup</code> - when Trilium frontend starts up (or is refreshed), but not on mobile.</li><li><code>mobileStartup</code> - when Trilium frontend starts up (or is refreshed), on mobile.</li><li><code>backendStartup</code> - when Trilium backend starts up</li><li><code>hourly</code> - run once an hour. You can use additional label <code>runAtHour</code> to specify at which hour, on the back-end.</li><li><code>daily</code> - run once a day, on the back-end</li></ul></td></tr><tr><td><code>runOnInstance</code></td><td>Specifies that the script should only run on a particular <a class="reference-link" href="../Advanced%20Usage/Configuration%20(config.ini%20or%20environment%20variables)/Trilium%20instance.md">Trilium instance</a>.</td></tr><tr><td><code>runAtHour</code></td><td>On which hour should this run. Should be used together with <code>#run=hourly</code>. Can be defined multiple times for more runs during the day.</td></tr></tbody></table></figure>
|
||||
|
||||
## Entity events
|
||||
|
||||
Other events are bound to some entity, these are defined as [relations](../Advanced%20Usage/Attributes.md) - meaning that script is triggered only if note has this script attached to it through relations (or it can inherit it).
|
||||
|
||||
<figure class="table"><table><thead><tr><th>Relation</th><th>Description</th></tr></thead><tbody><tr><td><code>runOnNoteCreation</code></td><td>executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.</td></tr><tr><td><code>runOnChildNoteCreation</code></td><td>executes when new note is created under the note where this relation is defined</td></tr><tr><td><code>runOnNoteTitleChange</code></td><td>executes when note title is changed (includes note creation as well)</td></tr><tr><td><code>runOnNoteContentChange</code></td><td>executes when note content is changed (includes note creation as well).</td></tr><tr><td><code>runOnNoteChange</code></td><td>executes when note is changed (includes note creation as well). Does not include content changes</td></tr><tr><td><code>runOnNoteDeletion</code></td><td>executes when note is being deleted</td></tr><tr><td><code>runOnBranchCreation</code></td><td>executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.</td></tr><tr><td><code>runOnBranchChange</code></td><td>executes when a branch is updated. (since v0.62)</td></tr><tr><td><code>runOnBranchDeletion</code></td><td>executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).</td></tr><tr><td><code>runOnAttributeCreation</code></td><td>executes when new attribute is created for the note which defines this relation</td></tr><tr><td><code>runOnAttributeChange</code></td><td>executes when the attribute is changed of a note which defines this relation. This is triggered also when the attribute is deleted</td></tr></tbody></table></figure>
|
||||
@@ -1,7 +1,7 @@
|
||||
# Frontend Basics
|
||||
## Frontend API
|
||||
|
||||
The frontend api supports two styles, regular scripts that are run with the current app and note context, and widgets that export an object to Trilium to be used in the UI. In both cases, the frontend api of Trilium is available to scripts running in the frontend context as global variable `api`. The members and methods of the api can be seen on the [Script API](../Note%20Types/Code/Script%20API.md) page.
|
||||
The frontend api supports two styles, regular scripts that are run with the current app and note context, and widgets that export an object to Trilium to be used in the UI. In both cases, the frontend api of Trilium is available to scripts running in the frontend context as global variable `api`. The members and methods of the api can be seen on the [Script API](Script%20API.md) page.
|
||||
|
||||
## Scripts
|
||||
|
||||
@@ -54,4 +54,4 @@ Conversely to scripts, widgets do have some specific requirements in order to wo
|
||||
|
||||
### Tutorial
|
||||
|
||||
For more information on building widgets, take a look at [Widget Basics](Widget%20Basics.md).
|
||||
For more information on building widgets, take a look at [Widget Basics](Custom%20Widgets/Widget%20Basics.md).
|
||||
@@ -21,7 +21,7 @@ TRILIUM_START_NOTE_ID=root ./trilium
|
||||
|
||||
## Broken Script Prevents Application Startup
|
||||
|
||||
If a custom script causes Triliumto crash, and it is set as a startup script or in an active [custom widget](Note%20Types/Code/Custom%20Widgets.md), start Triliumin "safe mode" to prevent any custom scripts from executing:
|
||||
If a custom script causes Triliumto crash, and it is set as a startup script or in an active [custom widget](Scripting/Custom%20Widgets.md), start Triliumin "safe mode" to prevent any custom scripts from executing:
|
||||
|
||||
```
|
||||
TRILIUM_SAFE_MODE=true ./trilium
|
||||
|
||||
Reference in New Issue
Block a user