This repository was archived by the owner on Jun 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathshared_info.ts
More file actions
78 lines (64 loc) · 2.62 KB
/
shared_info.ts
File metadata and controls
78 lines (64 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import options from "../services/options.js";
import attributeService from "../services/attributes.js";
import { t } from "../services/i18n.js";
import type FNote from "../entities/fnote.js";
import type { EventData } from "../components/app_context.js";
const TPL = /*html*/`
<div class="shared-info-widget alert alert-warning use-tn-links">
<style>
.shared-info-widget {
margin: 10px;
contain: none;
padding: 10px;
font-weight: bold;
}
</style>
<span class="shared-text"></span> <a class="shared-link external"></a>. ${t("shared_info.help_link")}
</div>`;
export default class SharedInfoWidget extends NoteContextAwareWidget {
private $sharedLink!: JQuery<HTMLElement>;
private $sharedText!: JQuery<HTMLElement>;
isEnabled() {
return super.isEnabled() && this.noteId !== "_share" && this.note?.hasAncestor("_share");
}
doRender() {
this.$widget = $(TPL);
this.$sharedLink = this.$widget.find(".shared-link");
this.$sharedText = this.$widget.find(".shared-text");
this.contentSized();
}
async refreshWithNote(note: FNote) {
const syncServerHost = options.get("syncServerHost");
const sharePath = options.get("sharePath");
let link;
const shareId = this.getShareId(note);
if (syncServerHost) {
link = `${syncServerHost}${sharePath}/${shareId}`;
this.$sharedText.text(t("shared_info.shared_publicly"));
} else {
let host = location.host;
if (host.endsWith("/")) {
// seems like IE has trailing slash
// https://github.com/zadam/trilium/issues/3782
host = host.slice(0, -1);
}
link = `${location.protocol}//${host}${location.pathname}${sharePath.slice(1)}/${shareId}`;
this.$sharedText.text(t("shared_info.shared_locally"));
}
this.$sharedLink.attr("href", link).text(link);
}
getShareId(note: FNote) {
if (note.hasOwnedLabel("shareRoot")) {
return "";
}
return note.getOwnedLabelValue("shareAlias") || note.noteId;
}
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {
this.refresh();
} else if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId)) {
this.refresh();
}
}
}