@rmdes/indiekit-endpoint-activitypub 3.9.0 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,19 +23,30 @@ document.addEventListener("alpine:init", () => {
23
23
  likeCount: null,
24
24
  boostCount: null,
25
25
 
26
+ // Stored from data attributes in init() — must use $root to guarantee
27
+ // we read from the x-data element, not a child element in event context.
28
+ _mountPath: "",
29
+ _csrfToken: "",
30
+ _itemUid: "",
31
+ _itemUrl: "",
32
+
26
33
  init() {
27
- this.liked = this.$el.dataset.liked === "true";
28
- this.boosted = this.$el.dataset.boosted === "true";
29
- const lc = this.$el.dataset.likeCount;
30
- const bc = this.$el.dataset.boostCount;
34
+ const root = this.$root;
35
+ this.liked = root.dataset.liked === "true";
36
+ this.boosted = root.dataset.boosted === "true";
37
+ this._mountPath = root.dataset.mountPath || "";
38
+ this._csrfToken = root.dataset.csrfToken || "";
39
+ this._itemUid = root.dataset.itemUid || "";
40
+ this._itemUrl = root.dataset.itemUrl || "";
41
+ const lc = root.dataset.likeCount;
42
+ const bc = root.dataset.boostCount;
31
43
  this.likeCount = lc != null && lc !== "" ? Number(lc) : null;
32
44
  this.boostCount = bc != null && bc !== "" ? Number(bc) : null;
33
45
  },
34
46
 
35
47
  async saveLater() {
36
48
  if (this.saved) return;
37
- const el = this.$el;
38
- const itemUrl = el.dataset.itemUrl;
49
+ const itemUrl = this._itemUrl;
39
50
  try {
40
51
  const res = await fetch("/readlater/save", {
41
52
  method: "POST",
@@ -43,7 +54,7 @@ document.addEventListener("alpine:init", () => {
43
54
  body: JSON.stringify({
44
55
  url: itemUrl,
45
56
  title:
46
- el.closest("article")?.querySelector("p")?.textContent?.substring(0, 80) ||
57
+ this.$root.closest("article")?.querySelector("p")?.textContent?.substring(0, 80) ||
47
58
  itemUrl,
48
59
  source: "activitypub",
49
60
  }),
@@ -61,10 +72,9 @@ document.addEventListener("alpine:init", () => {
61
72
  if (this.loading) return;
62
73
  this.loading = true;
63
74
  this.error = "";
64
- const el = this.$el;
65
- const itemUid = el.dataset.itemUid;
66
- const csrfToken = el.dataset.csrfToken;
67
- const basePath = el.dataset.mountPath;
75
+ const itemUid = this._itemUid;
76
+ const csrfToken = this._csrfToken;
77
+ const basePath = this._mountPath;
68
78
  const prev = {
69
79
  liked: this.liked,
70
80
  boosted: this.boosted,