@jamwidgets/astro 0.6.3 → 0.6.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamwidgets/astro",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Astro components and content loaders for Jamwidgets",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,7 +60,7 @@
60
60
  ],
61
61
  "license": "MIT",
62
62
  "dependencies": {
63
- "@jamwidgets/core": "^0.5.2"
63
+ "@jamwidgets/core": "^0.5.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "astro": "^5.9.0 || ^6.0.0 || ^7.0.0"
@@ -54,16 +54,7 @@ import Theme from "./Theme.astro";
54
54
  isDismissible: boolean;
55
55
  }
56
56
 
57
- // Get or create a visitor ID for anonymous users
58
- const VISITOR_KEY = "jamwidgets_visitor_id";
59
- function getVisitorId(): string {
60
- let id = localStorage.getItem(VISITOR_KEY);
61
- if (!id) {
62
- id = crypto.randomUUID();
63
- localStorage.setItem(VISITOR_KEY, id);
64
- }
65
- return id;
66
- }
57
+ import { getVisitorId } from "@jamwidgets/core";
67
58
 
68
59
  document.querySelectorAll("[data-jamwidgets-announcements]").forEach((container) => {
69
60
  const endpoint = (container as HTMLElement).dataset.endpoint;
package/src/Embed.astro CHANGED
@@ -64,16 +64,7 @@ import Theme from "./Theme.astro";
64
64
  userVotes?: string[];
65
65
  }
66
66
 
67
- // Get or create a visitor ID for anonymous users
68
- const VISITOR_KEY = "jamwidgets_visitor_id";
69
- function getVisitorId(): string {
70
- let id = localStorage.getItem(VISITOR_KEY);
71
- if (!id) {
72
- id = crypto.randomUUID();
73
- localStorage.setItem(VISITOR_KEY, id);
74
- }
75
- return id;
76
- }
67
+ import { getVisitorId } from "@jamwidgets/core";
77
68
 
78
69
  class JamwidgetsEmbed extends HTMLElement {
79
70
  connectedCallback() {
@@ -90,16 +90,7 @@ import Theme from "./Theme.astro";
90
90
  </div>
91
91
 
92
92
  <script>
93
- // Get or create a visitor ID for anonymous users
94
- const VISITOR_KEY = "jamwidgets_visitor_id";
95
- function getVisitorId(): string {
96
- let id = localStorage.getItem(VISITOR_KEY);
97
- if (!id) {
98
- id = crypto.randomUUID();
99
- localStorage.setItem(VISITOR_KEY, id);
100
- }
101
- return id;
102
- }
93
+ import { getVisitorId } from "@jamwidgets/core";
103
94
 
104
95
  document.querySelectorAll("[data-jamwidgets-feedback]").forEach((container) => {
105
96
  const endpoint = (container as HTMLElement).dataset.endpoint;
package/src/Poll.astro CHANGED
@@ -89,16 +89,7 @@ import Theme from "./Theme.astro";
89
89
  userVotes?: string[];
90
90
  }
91
91
 
92
- // Get or create a visitor ID for anonymous users
93
- const VISITOR_KEY = "jamwidgets_visitor_id";
94
- function getVisitorId(): string {
95
- let id = localStorage.getItem(VISITOR_KEY);
96
- if (!id) {
97
- id = crypto.randomUUID();
98
- localStorage.setItem(VISITOR_KEY, id);
99
- }
100
- return id;
101
- }
92
+ import { getVisitorId } from "@jamwidgets/core";
102
93
 
103
94
  document.querySelectorAll("[data-jamwidgets-poll]").forEach((container) => {
104
95
  const endpoint = (container as HTMLElement).dataset.endpoint;
@@ -106,11 +106,14 @@ import Theme from "./Theme.astro";
106
106
  "X-Jamwidgets-Visitor": visitorId,
107
107
  };
108
108
 
109
- // Track which reactions the user has made (stored in localStorage)
110
109
  const storageKey = `jamwidgets-reactions-${pageId}`;
111
- const userReactions = new Set<string>(
112
- JSON.parse(localStorage.getItem(storageKey) || "[]")
113
- );
110
+ const userReactions = new Set<string>();
111
+ try {
112
+ const stored = JSON.parse(localStorage.getItem(storageKey) || "[]");
113
+ if (Array.isArray(stored)) {
114
+ for (const type of stored) if (typeof type === "string") userReactions.add(type);
115
+ }
116
+ } catch {}
114
117
 
115
118
  // Apply initial "reacted" state
116
119
  container.querySelectorAll(".jamwidgets-reaction-btn").forEach((btn) => {
@@ -134,7 +137,7 @@ import Theme from "./Theme.astro";
134
137
 
135
138
  // Sync with server's user reactions
136
139
  serverUserReactions.forEach((type: string) => userReactions.add(type));
137
- localStorage.setItem(storageKey, JSON.stringify([...userReactions]));
140
+ try { localStorage.setItem(storageKey, JSON.stringify([...userReactions])); } catch {}
138
141
 
139
142
  container.querySelectorAll(".jamwidgets-reaction-btn").forEach((btn) => {
140
143
  const type = (btn as HTMLElement).dataset.reactionType;
@@ -204,7 +207,7 @@ import Theme from "./Theme.astro";
204
207
  }),
205
208
  );
206
209
  }
207
- localStorage.setItem(storageKey, JSON.stringify([...userReactions]));
210
+ try { localStorage.setItem(storageKey, JSON.stringify([...userReactions])); } catch {}
208
211
  } catch (e) {
209
212
  console.error(isReacted ? "Failed to remove reaction:" : "Failed to add reaction:", e);
210
213
  } finally {
@@ -93,16 +93,7 @@ import Theme from "./Theme.astro";
93
93
  message: string;
94
94
  }
95
95
 
96
- // Get or create a visitor ID for anonymous users
97
- const VISITOR_KEY = "jamwidgets_visitor_id";
98
- function getVisitorId(): string {
99
- let id = localStorage.getItem(VISITOR_KEY);
100
- if (!id) {
101
- id = crypto.randomUUID();
102
- localStorage.setItem(VISITOR_KEY, id);
103
- }
104
- return id;
105
- }
96
+ import { getVisitorId } from "@jamwidgets/core";
106
97
 
107
98
  document.querySelectorAll("[data-jamwidgets-subscribe]").forEach((form) => {
108
99
  form.addEventListener("submit", async (e) => {
package/src/Views.astro CHANGED
@@ -65,16 +65,7 @@ import Theme from "./Theme.astro";
65
65
  </div>
66
66
 
67
67
  <script>
68
- // Get or create a visitor ID for anonymous users
69
- const VISITOR_KEY = "jamwidgets_visitor_id";
70
- function getVisitorId(): string {
71
- let id = localStorage.getItem(VISITOR_KEY);
72
- if (!id) {
73
- id = crypto.randomUUID();
74
- localStorage.setItem(VISITOR_KEY, id);
75
- }
76
- return id;
77
- }
68
+ import { getVisitorId } from "@jamwidgets/core";
78
69
 
79
70
  document.querySelectorAll("[data-jamwidgets-views]").forEach((container) => {
80
71
  const endpoint = (container as HTMLElement).dataset.endpoint;
@@ -71,16 +71,7 @@ import Theme from "./Theme.astro";
71
71
  </div>
72
72
 
73
73
  <script>
74
- // Get or create a visitor ID for anonymous users
75
- const VISITOR_KEY = "jamwidgets_visitor_id";
76
- function getVisitorId(): string {
77
- let id = localStorage.getItem(VISITOR_KEY);
78
- if (!id) {
79
- id = crypto.randomUUID();
80
- localStorage.setItem(VISITOR_KEY, id);
81
- }
82
- return id;
83
- }
74
+ import { getVisitorId } from "@jamwidgets/core";
84
75
 
85
76
  document.querySelectorAll("[data-jamwidgets-waitlist]").forEach((container) => {
86
77
  const endpoint = (container as HTMLElement).dataset.endpoint;