diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts index a56139d36..d33ba76a0 100644 --- a/apps/client/src/services/bundle.ts +++ b/apps/client/src/services/bundle.ts @@ -46,17 +46,7 @@ export async function executeBundle(bundle: Bundle, originEntity?: Entity | null return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); }.call(apiContext); } catch (e: any) { - const note = await froca.getNote(bundle.noteId); - toastService.showPersistent({ - id: `custom-script-failure-${note?.noteId}`, - title: t("toast.bundle-error.title"), - icon: "bx bx-error-circle", - message: t("toast.bundle-error.message", { - id: note?.noteId, - title: note?.title, - message: e.message - }) - }); + showErrorForScriptNote(bundle.noteId, t("toast.bundle-error.message", { message: e.message })); logError("Widget initialization failed: ", e); } } @@ -151,17 +141,7 @@ async function getWidgetBundlesByParent() { } } catch (e: any) { const noteId = bundle.noteId; - const note = await froca.getNote(noteId); - toastService.showPersistent({ - id: `custom-script-failure-${noteId}`, - title: t("toast.bundle-error.title"), - icon: "bx bx-error-circle", - message: t("toast.bundle-error.message", { - id: noteId, - title: note?.title, - message: e.message - }) - }); + showErrorForScriptNote(noteId, t("toast.bundle-error.message", { message: e.message })); logError("Widget initialization failed: ", e); continue; diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts index 641b3cdce..f31e242cd 100644 --- a/apps/client/src/services/toast.ts +++ b/apps/client/src/services/toast.ts @@ -69,7 +69,7 @@ export async function showErrorForScriptNote(noteId: string, message: string) { showPersistent({ id: `custom-widget-failure-${noteId}`, - title: note?.title ?? "", + title: t("toast.scripting-error", { title: note?.title ?? "" }), icon: note?.getIcon() ?? "bx bx-error-circle", message, timeout: 15_000, diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 75e116753..9cfc8b2e1 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -21,7 +21,7 @@ }, "bundle-error": { "title": "Failed to load a custom script", - "message": "Script from note with ID \"{{id}}\", titled \"{{title}}\" could not be executed due to:\n\n{{message}}" + "message": "Script could not be executed due to:\n\n{{message}}" }, "widget-list-error": { "title": "Failed to obtain the list of widgets from the server" @@ -30,7 +30,8 @@ "title": "Failed to render a custom React widget" }, "widget-missing-parent": "Custom widget does not have mandatory '{{property}}' property defined.", - "open-script-note": "Open script note" + "open-script-note": "Open script note", + "scripting-error": "Custom script error: {{title}}" }, "add_link": { "add_link": "Add link", @@ -1779,7 +1780,8 @@ "note_type_switcher_others": "Other note type", "note_type_switcher_templates": "Template", "note_type_switcher_collection": "Collection", - "edited_notes": "Edited notes" + "edited_notes": "Notes edited on this day", + "promoted_attributes": "Promoted attributes" }, "search_result": { "no_notes_found": "No notes have been found for given search parameters.", diff --git a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx index 07ecf6b66..42b461df0 100644 --- a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx +++ b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx @@ -15,7 +15,7 @@ export default function TabHistoryNavigationButtons() { const legacyBackVisible = useLauncherVisibility("_lbBackInHistory"); const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory"); - return (isElectron() && + return (
When you run Trilium for the first time, it will generate a new database containing demo notes. These notes showcase its many features, such as:
You can easily restore the demo notes by using Trilium's built-in import feature by importing them:
const $dateEl = api.$container.find(".date");
+ note created previously; with the following content:const $dateEl = api.$container.find(".date");
$dateEl.text(new Date());
Now create a render note at any place and set its ~renderNote relation
to point to the HTML note. When the render note is accessed it will display:
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.html
index c6983e5d7..7617ab9a4 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.html
@@ -32,41 +32,30 @@
Let's start by creating a widget that shows a message near the content
area. Follow the previous section to create a code note, and use the following
content.
-
-
-
- Legacy
- Preact (v0.101.0+)
-
-
-
-
- class HelloNoteDetail extends api.BasicWidget {
+Legacy version (jQuery)
class HelloCenterPane extends api.BasicWidget {
-constructor() {
- super();
- this.contentSized();
+ constructor() {
+ super();
+ this.contentSized();
+ }
+
+ get parentWidget() { return "center-pane" }
+
+ doRender() {
+ this.$widget = $("<span>Center pane</span>");
+ }
+
}
-get parentWidget() { return "center-pane" }
+module.exports = new HelloCenterPane();
+Refresh the application and the widget
+ should appear underneath the content area.
+Preact version
import { defineWidget } from "trilium:preact";
-doRender() {
- this.<!--FORMULA_INLINE_1766526977514_0-->("<span>Center pane</span>");
-}
- }
- module.exports = new HelloNoteDetail();
-
-
-
- import { defineWidget } from "trilium:preact";export default defineWidget({
+export default defineWidget({
parent: "center-pane",
render: () => <span>Center pane from Preact.</span>
-});
-
-
-
-
-
+});
Refresh the application and the widget should appear underneath the content area.
import { defineLauncherWidget, useActiveNoteContext } from "trilium:preact";
+Preact widget (v0.101.0+)
import { defineLauncherWidget, useActiveNoteContext } from "trilium:preact";
export default defineLauncherWidget({
render: () => {
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact.html
index 82c823548..1a2ce8779 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact.html
@@ -2,9 +2,9 @@
support for JSX.
Preact can be used for:
- - Render Note, where
+
- Render Note, where
a JSX code note is used instead of a HTML one.
- - Custom Widgets,
+
- Custom Widgets,
where JSX can be used to replace the old, jQuery-based mechanism.
To get started, the first step is to enable JSX in the list of Code languages.
@@ -20,22 +20,23 @@
Import/exports
When using Preact with JSX, there is a special syntax which provides ES-like
- imports. This import syntax makes way for a more intuitive that
- doesn't make use of global objects and paves the way for better auto-completion
- support that might be introduced in the future.
+ imports. This import syntax makes way for
+ a more intuitive that doesn't make use of global objects and paves the
+ way for better auto-completion support that might be introduced in the
+ future.
API imports
-Instead of:
api.showMessage("Hello");
-the JSX version looks like this:
import { showMessage } from "trilium:api";
+Instead of:
api.showMessage("Hello");
+the JSX version looks like this:
import { showMessage } from "trilium:api";
showMessage("hello");
Preact API imports (hooks, components)
There's a new Script API dedicated
to Preact, which provides shared components that are also used by Trilium
- internally as well as hooks, for example.
import { useState } from "trilium:preact";
+ internally as well as hooks, for example.import { useState } from "trilium:preact";
const [ myState, setMyState ] = useState("Hi");
Exporting
JSX notes can export a component for use in Render Note or for Component libraries:
export default function() {
+ href="#root/_help_Bqde6BvPo05g">Component libraries: export default function() {
return (
<>
<p>Hello world.</p>
@@ -43,13 +44,15 @@ const [ myState, setMyState ] = useState("Hi");
);
}
Import/export are not required
-These imports are syntactic sugar meant to replace the usage for the api global
- object (see Script API).
+These imports are syntactic sugar meant to replace the usage for the
+ apiglobal object (see Script API).
Under the hood
Unlike JavaScript, JSX requires pre-processing to turn it into JavaScript
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.html
index 27aa57582..209519800 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.html
@@ -7,8 +7,8 @@
also available to Custom Widgets and
Render Note.
-To use these components, simply import them from trilium:preact:
import { ActionButton, Button, LinkButton } from "trilium:preact";
-and then use them:
export default function MyRenderNote() {
+To use these components, simply import them from trilium:preact:
import { ActionButton, Button, LinkButton } from "trilium:preact";
+and then use them:
export default function MyRenderNote() {
const onClick = () => showMessage("A button was pressed");
return (
@@ -33,12 +33,12 @@
to custom widgets and JSX render notes.
To use it, simply:
- - Create a render note.
- - Create a child code note of JSX type with the content of this file:
+
- Create a render note.
+ - Create a child code note of JSX type with the content of this file:
Widget showcase
- - Set the
~renderNote relation of the parent note to the child
- note.
- - Refresh the render note to see the results.
+ - Set the
~renderNote relation of the parent
+ note to the child note.
+ - Refresh the render note to see the results.
\ No newline at end of file
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.html
index 2cdec3295..a148c29f2 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.html
@@ -1,4 +1,4 @@
-Inline styles
<div style={{
+Inline styles
<div style={{
display: "flex",
height: "53px",
width: "fit-content",
@@ -9,4 +9,4 @@
Custom CSS file
Simply create a Custom app-wide CSS.
Make sure the class names are unique enough to not intersect with other
- UI elements, consider adding a prefix (e.g. x-mywidget-).
\ No newline at end of file
+ UI elements, consider adding a prefix (e.g. x-mywidget-).
\ No newline at end of file
diff --git a/docs/Developer Guide/Developer Guide/Documentation.md b/docs/Developer Guide/Developer Guide/Documentation.md
index c4c3cfb06..a7dbaff23 100644
--- a/docs/Developer Guide/Developer Guide/Documentation.md
+++ b/docs/Developer Guide/Developer Guide/Documentation.md
@@ -1,5 +1,5 @@
# Documentation
-There are multiple types of documentation for Trilium:
+There are multiple types of documentation for Trilium:
* The _User Guide_ represents the user-facing documentation. This documentation can be browsed by users directly from within Trilium, by pressing F1.
* The _Developer's Guide_ represents a set of Markdown documents that present the internals of Trilium, for developers.
diff --git a/docs/User Guide/User Guide/Note Types/Render Note.md b/docs/User Guide/User Guide/Note Types/Render Note.md
index 828d7dfef..01e2e1c24 100644
--- a/docs/User Guide/User Guide/Note Types/Render Note.md
+++ b/docs/User Guide/User Guide/Note Types/Render Note.md
@@ -24,7 +24,7 @@ The current date & time is
Now we need to add the script. Create another Code, but this time of JavaScript (frontend) language. Make sure the newly created note is a direct child of the HTML note created previously; with the following content:
-```
+```javascript
const $dateEl = api.$container.find(".date");
$dateEl.text(new Date());
```
diff --git a/docs/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.md b/docs/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.md
index cc011c514..dec4cfd3f 100644
--- a/docs/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.md
+++ b/docs/User Guide/User Guide/Scripting/Frontend Basics/Custom Widgets.md
@@ -23,21 +23,39 @@ Wherever possible, widget examples will be both in the legacy and Preact format.
Let's start by creating a widget that shows a message near the content area. Follow the previous section to create a code note, and use the following content.
-Legacy Preact (v0.101.0+) class HelloNoteDetail extends api.BasicWidget {
+### Legacy version (jQuery)
-constructor() {
- super();
- this.contentSized();
+```
+class HelloCenterPane extends api.BasicWidget {
+
+ constructor() {
+ super();
+ this.contentSized();
+ }
+
+ get parentWidget() { return "center-pane" }
+
+ doRender() {
+ this.$widget = $("Center pane");
+ }
+
}
-get parentWidget() { return "center-pane" }
+module.exports = new HelloCenterPane();
+```
-doRender() {
- this.<!--FORMULA_INLINE_1766526977514_0-->("<span>Center pane</span>");
-}
}
module.exports = new HelloNoteDetail();
import { defineWidget } from "trilium:preact";export default defineWidget({
+[Refresh the application](../../Troubleshooting/Refreshing%20the%20application.md) and the widget should appear underneath the content area.
+
+### Preact version
+
+```
+import { defineWidget } from "trilium:preact";
+
+export default defineWidget({
parent: "center-pane",
- render: () => <span>Center pane from Preact.</span>
-});
+ render: () => Center pane from Preact.
+});
+```
[Refresh the application](../../Troubleshooting/Refreshing%20the%20application.md) and the widget should appear underneath the content area.
diff --git a/docs/User Guide/User Guide/Scripting/Frontend Basics/Launch Bar Widgets/Note Title Widget.md b/docs/User Guide/User Guide/Scripting/Frontend Basics/Launch Bar Widgets/Note Title Widget.md
index 78a69eb8a..c892e3365 100644
--- a/docs/User Guide/User Guide/Scripting/Frontend Basics/Launch Bar Widgets/Note Title Widget.md
+++ b/docs/User Guide/User Guide/Scripting/Frontend Basics/Launch Bar Widgets/Note Title Widget.md
@@ -35,7 +35,7 @@ module.exports = new NoteTitleWidget();
## Preact widget (v0.101.0+)
-```
+```jsx
import { defineLauncherWidget, useActiveNoteContext } from "trilium:preact";
export default defineLauncherWidget({
diff --git a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact.md b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact.md
index db3811479..6f05765fc 100644
--- a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact.md
+++ b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact.md
@@ -19,13 +19,13 @@ When using Preact with JSX, there is a special syntax which provides ES-like imp
Instead of:
-```
+```jsx
api.showMessage("Hello");
```
the JSX version looks like this:
-```
+```jsx
import { showMessage } from "trilium:api";
showMessage("hello");
```
@@ -34,7 +34,7 @@ showMessage("hello");
There's a new Script API dedicated to Preact, which provides shared components that are also used by Trilium internally as well as hooks, for example.
-```
+```jsx
import { useState } from "trilium:preact";
const [ myState, setMyState ] = useState("Hi");
```
@@ -43,7 +43,7 @@ const [ myState, setMyState ] = useState("Hi");
JSX notes can export a component for use in Render Note or for Component libraries:
-```
+```jsx
export default function() {
return (
<>
diff --git a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.md b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.md
index 8d3c86e4f..db05c9255 100644
--- a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.md
+++ b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/Built-in components.md
@@ -5,13 +5,13 @@ Trilium comes with its own set of Preact components, some of which are also avai
To use these components, simply import them from `trilium:preact`:
-```
+```jsx
import { ActionButton, Button, LinkButton } from "trilium:preact";
```
and then use them:
-```
+```jsx
export default function MyRenderNote() {
const onClick = () => showMessage("A button was pressed");
diff --git a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.md b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.md
index bda9f195a..3b959261f 100644
--- a/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.md
+++ b/docs/User Guide/User Guide/Scripting/Frontend Basics/Preact/CSS.md
@@ -1,7 +1,7 @@
# CSS
## Inline styles
-```
+```jsx