@unhingged/vizu-core 0.1.7 → 0.1.9
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/dist/auto.cjs +25 -3
- package/dist/auto.cjs.map +1 -1
- package/dist/auto.js +25 -3
- package/dist/auto.js.map +1 -1
- package/dist/index.cjs +25 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/vizu.min.js +3 -3
- package/dist/vizu.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -416,7 +416,9 @@ var CloudStorageAdapter = class {
|
|
|
416
416
|
const payload = params.get("vizu_auth");
|
|
417
417
|
if (!payload) return null;
|
|
418
418
|
try {
|
|
419
|
-
const
|
|
419
|
+
const bytes = Uint8Array.from(atob(payload), (c) => c.charCodeAt(0));
|
|
420
|
+
const decoded = new TextDecoder("utf-8").decode(bytes);
|
|
421
|
+
const json = JSON.parse(decoded);
|
|
420
422
|
if (!json.t || !json.e || !json.u || !json.w) return null;
|
|
421
423
|
if (json.w !== this.workspace) return null;
|
|
422
424
|
const stored = {
|
|
@@ -470,6 +472,11 @@ var CloudStorageAdapter = class {
|
|
|
470
472
|
}
|
|
471
473
|
/* ─── StorageAdapter v2 ───────────────────────────────────────────── */
|
|
472
474
|
async load(_namespace) {
|
|
475
|
+
if (!this.cachedToken || this.isExpired(this.cachedToken)) {
|
|
476
|
+
const fresh = this.readStoredToken();
|
|
477
|
+
if (!fresh || this.isExpired(fresh)) return [];
|
|
478
|
+
this.cachedToken = fresh;
|
|
479
|
+
}
|
|
473
480
|
const out = [];
|
|
474
481
|
let cursor = null;
|
|
475
482
|
do {
|
|
@@ -3187,6 +3194,14 @@ var Vizu = class {
|
|
|
3187
3194
|
this.selfHealedThisSession = /* @__PURE__ */ new Set();
|
|
3188
3195
|
this.actions = [];
|
|
3189
3196
|
this.user = null;
|
|
3197
|
+
/**
|
|
3198
|
+
* Flipped true once the initial loadComments() at construction has
|
|
3199
|
+
* settled (success or failure). The cloud onAuthChanged callback uses
|
|
3200
|
+
* this to decide whether a subsequent auth change should trigger a
|
|
3201
|
+
* re-load: skipped for the initial fire (the explicit loadComments
|
|
3202
|
+
* below handles it), fired for every later token acquisition.
|
|
3203
|
+
*/
|
|
3204
|
+
this.hasLoadedComments = false;
|
|
3190
3205
|
this.enabled = false;
|
|
3191
3206
|
this.rafScheduled = false;
|
|
3192
3207
|
this.bus = new EventBus();
|
|
@@ -3255,21 +3270,28 @@ var Vizu = class {
|
|
|
3255
3270
|
this.opts.namespace = options.namespace ?? DEFAULTS.namespace;
|
|
3256
3271
|
this.opts.accent = options.accent ?? DEFAULTS.accent;
|
|
3257
3272
|
this.parsedShortcut = parseShortcut(this.opts.shortcut);
|
|
3273
|
+
this.user = options.user ?? null;
|
|
3258
3274
|
this.storage = resolveStorage(
|
|
3259
3275
|
options.storage,
|
|
3260
3276
|
options.cloud,
|
|
3261
3277
|
_defaultStorage,
|
|
3262
3278
|
(info) => {
|
|
3263
3279
|
if (info.user) this.setUser(info.user);
|
|
3280
|
+
if (this.hasLoadedComments) {
|
|
3281
|
+
void this.loadComments();
|
|
3282
|
+
}
|
|
3264
3283
|
}
|
|
3265
3284
|
);
|
|
3266
|
-
this.user = options.user ?? null;
|
|
3267
3285
|
if (options.actions) this.actions = [...options.actions];
|
|
3268
3286
|
if (options.onCommentAdded) this.bus.on("comment:added", (p) => options.onCommentAdded(p.comment));
|
|
3269
3287
|
if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
|
|
3270
3288
|
if (typeof window !== "undefined") {
|
|
3271
3289
|
window.addEventListener("keydown", this.onKeyDown);
|
|
3272
|
-
void this.loadComments().
|
|
3290
|
+
void this.loadComments().catch(() => {
|
|
3291
|
+
}).finally(() => {
|
|
3292
|
+
this.hasLoadedComments = true;
|
|
3293
|
+
this.subscribeStorage();
|
|
3294
|
+
});
|
|
3273
3295
|
if (options.startEnabled) this.deferred(() => this.enable());
|
|
3274
3296
|
}
|
|
3275
3297
|
}
|