@pinia/colada-devtools 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023-present Eduardo San Martin Morote
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Pinia Colada Devtools
2
+
3
+ ## Development
4
+
5
+ ```sh
6
+ pnpm run dev
7
+ ```
8
+
9
+ ## Build and test
10
+
11
+ Build the package:
12
+
13
+ ```sh
14
+ pnpm run build
15
+ ```
16
+
17
+ Then test it on the playground (root folder):
18
+
19
+ ```sh
20
+ pnpm run play # at root
21
+ ```
@@ -0,0 +1,8 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { DefineComponent } from 'vue';
4
+ import { PublicProps } from 'vue';
5
+
6
+ export declare const PiniaColadaDevtools: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
7
+
8
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,466 @@
1
+ import { defineComponent as F, ref as T, onMounted as $, renderSlot as X, createCommentVNode as N, useTemplateRef as Z, shallowRef as A, watch as q, onBeforeUnmount as ee, createBlock as W, openBlock as O, Teleport as te, createElementVNode as ne, nextTick as B, readonly as H, getCurrentInstance as oe, toRef as re, customRef as ie, getCurrentScope as ae, onScopeDispose as se, computed as J, toValue as C, unref as M, withCtx as le, createElementBlock as ue } from "vue";
2
+ import { useQueryCache as ce } from "@pinia/colada";
3
+ import { addDevtoolsInfo as de, DuplexChannel as fe, createQueryEntryPayload as y, DEVTOOLS_INFO_KEY as b, useEventListener as pe } from "@pinia/colada-devtools/shared";
4
+ const ve = /* @__PURE__ */ F({
5
+ __name: "ClientOnly",
6
+ setup(e) {
7
+ const t = T(!1);
8
+ return $(() => {
9
+ t.value = !0;
10
+ }), (r, s) => t.value ? X(r.$slots, "default", { key: 0 }) : N("", !0);
11
+ }
12
+ }), me = [".isPip", ".port"], ye = /* @__PURE__ */ F({
13
+ __name: "PiniaColadaDevtools",
14
+ setup(e) {
15
+ const t = ce();
16
+ de(t), t.$onAction(({ name: n, after: o, onError: f, args: h }) => {
17
+ if (n === "remove") {
18
+ const [a] = h;
19
+ o(() => {
20
+ i.emit("queries:delete", y(a));
21
+ });
22
+ } else if (n === "track" || n === "untrack" || n === "cancel" || n === "invalidate" || n === "fetch" || n === "setEntryState") {
23
+ const [a] = h;
24
+ if (n === "fetch") {
25
+ const v = y(a);
26
+ v.asyncStatus = "loading", i.emit("queries:update", v);
27
+ }
28
+ o(() => {
29
+ var v;
30
+ a[b].simulate = null, i.emit("queries:update", y(a)), n === "fetch" && ((v = a.options) == null ? void 0 : v.staleTime) != null && Number.isFinite(a.options.staleTime) && setTimeout(() => {
31
+ i.emit("queries:update", y(a));
32
+ }, a.options.staleTime);
33
+ }), f(() => {
34
+ i.emit("queries:update", y(a));
35
+ });
36
+ } else if (n === "create")
37
+ o((a) => {
38
+ i.emit("queries:update", y(a));
39
+ });
40
+ else if (n === "setQueryData") {
41
+ const [a] = h;
42
+ o(() => {
43
+ const v = t.getEntries({ key: a, exact: !0 })[0];
44
+ v && i.emit("queries:update", y(v));
45
+ });
46
+ }
47
+ });
48
+ const r = Z("devtools"), s = A(new MessageChannel()), i = new fe(s.value.port1);
49
+ q(
50
+ s,
51
+ (n) => {
52
+ i.setPort(n.port1);
53
+ },
54
+ { flush: "sync" }
55
+ ), i.on("ping", () => {
56
+ console.log("[App] Received ping from devtools"), i.emit("pong");
57
+ }), i.on("pong", () => {
58
+ console.log("[App] Received pong from devtools");
59
+ }), i.on("queries:refetch", (n) => {
60
+ t.invalidateQueries({ key: n, exact: !0, active: null, stale: null });
61
+ }), i.on("queries:invalidate", (n) => {
62
+ t.invalidateQueries({ key: n, exact: !0 });
63
+ }), i.on("queries:reset", (n) => {
64
+ const o = t.getEntries({ key: n, exact: !0 })[0];
65
+ o && (t.cancel(o), t.setEntryState(o, {
66
+ status: "pending",
67
+ data: void 0,
68
+ error: null
69
+ }));
70
+ }), i.on("queries:set:state", (n, o) => {
71
+ const f = t.getEntries({ key: n, exact: !0 })[0];
72
+ f && (t.setEntryState(f, o), i.emit("queries:update", y(f)));
73
+ }), i.on("queries:simulate:loading", (n) => {
74
+ const o = t.getEntries({ key: n, exact: !0 })[0];
75
+ o && (o.asyncStatus.value = "loading", o[b].simulate = "loading", i.emit("queries:update", y(o)));
76
+ }), i.on("queries:simulate:loading:stop", (n) => {
77
+ const o = t.getEntries({ key: n, exact: !0 })[0];
78
+ o && o[b].simulate === "loading" && (o.asyncStatus.value = "idle", o[b].simulate = null, i.emit("queries:update", y(o)));
79
+ }), i.on("queries:simulate:error", (n) => {
80
+ const o = t.getEntries({ key: n, exact: !0 })[0];
81
+ o && (t.cancel(o), t.setEntryState(o, {
82
+ ...o.state.value,
83
+ status: "error",
84
+ error: new Error("Simulated error")
85
+ }), o[b].simulate = "error", i.emit("queries:update", y(o)));
86
+ }), i.on("queries:simulate:error:stop", (n) => {
87
+ const o = t.getEntries({ key: n, exact: !0 })[0];
88
+ o && o[b].simulate === "error" && (t.cancel(o), t.setEntryState(o, {
89
+ ...o.state.value,
90
+ status: o.state.value.data !== void 0 ? "success" : "pending",
91
+ error: null
92
+ }), o[b].simulate = null, i.emit("queries:update", y(o)));
93
+ });
94
+ const u = A(null);
95
+ q(u, () => {
96
+ s.value = new MessageChannel();
97
+ }), pe(
98
+ window,
99
+ "unload",
100
+ () => {
101
+ var n;
102
+ (n = u.value) == null || n.close();
103
+ },
104
+ { passive: !0 }
105
+ ), ee(() => {
106
+ var n;
107
+ (n = u.value) == null || n.close();
108
+ });
109
+ function g() {
110
+ var n;
111
+ (n = u.value) == null || n.close(), u.value = null;
112
+ }
113
+ function c() {
114
+ const n = r.value;
115
+ if (!n || !n.shadowRoot)
116
+ throw new Error("No devtools elemnt found for Pinia Colada devtools");
117
+ const o = n.shadowRoot.getElementById("root");
118
+ if (!o)
119
+ throw new Error("No devtools root element found for Pinia Colada devtools");
120
+ const f = Math.max(o.offsetWidth, 400), h = Math.max(o.offsetHeight, 400), a = window.open(
121
+ "",
122
+ "pinia-colada-devtools",
123
+ `popup,width=${f},height=${h}`
124
+ );
125
+ if (!a)
126
+ throw new Error("Failed to open PiP window for Pinia Colada devtools");
127
+ u.value = a, a.document.head.innerHTML = "", a.document.body.innerHTML = "", a.document.title = "🍹 Pinia Colada Devtools", a.document.body.style.margin = "0", d(n, a.document), a.addEventListener(
128
+ "unload",
129
+ () => {
130
+ u.value = null;
131
+ },
132
+ { passive: !0 }
133
+ );
134
+ }
135
+ function d(n, o = document) {
136
+ if (!n || !n.shadowRoot)
137
+ throw new Error("No devtools element found for Pinia Colada devtools");
138
+ const f = o.getElementById("__pc-tw-properties") ?? o.createElement("style");
139
+ f.setAttribute("id", "__pc-tw-properties");
140
+ const h = [...n.shadowRoot.styleSheets].flatMap((a) => [...a.cssRules]).filter((a) => a instanceof CSSPropertyRule).map((a) => a.cssText).join("");
141
+ f.textContent = h, o.head.appendChild(f);
142
+ }
143
+ function p() {
144
+ u.value ? g() : c();
145
+ }
146
+ async function w() {
147
+ d(r.value), i.emit("queries:all", t.getEntries({}).map(y)), i.emit(
148
+ "mutations:all",
149
+ // FIXME: mutations
150
+ t.getEntries({}).map(y)
151
+ );
152
+ }
153
+ return (n, o) => (O(), W(te, {
154
+ to: u.value ? u.value.document.body : "body"
155
+ }, [
156
+ ne("pinia-colada-devtools-panel", {
157
+ ref: "devtools",
158
+ ".isPip": !!u.value,
159
+ ".port": s.value.port2,
160
+ onTogglePip: o[0] || (o[0] = (f) => p()),
161
+ onReady: o[1] || (o[1] = (f) => w())
162
+ }, null, 40, me)
163
+ ], 8, ["to"]));
164
+ }
165
+ });
166
+ function ge(e) {
167
+ return ae() ? (se(e), !0) : !1;
168
+ }
169
+ const he = typeof window < "u" && typeof document < "u";
170
+ typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
171
+ const we = Object.prototype.toString, Se = (e) => we.call(e) === "[object Object]", Ee = () => {
172
+ };
173
+ function be(...e) {
174
+ if (e.length !== 1)
175
+ return re(...e);
176
+ const t = e[0];
177
+ return typeof t == "function" ? H(ie(() => ({ get: t, set: Ee }))) : T(t);
178
+ }
179
+ function Ce(e, t) {
180
+ function r(...s) {
181
+ return new Promise((i, u) => {
182
+ Promise.resolve(e(() => t.apply(this, s), { fn: t, thisArg: this, args: s })).then(i).catch(u);
183
+ });
184
+ }
185
+ return r;
186
+ }
187
+ const Q = (e) => e();
188
+ function _e(e = Q, t = {}) {
189
+ const {
190
+ initialState: r = "active"
191
+ } = t, s = be(r === "active");
192
+ function i() {
193
+ s.value = !1;
194
+ }
195
+ function u() {
196
+ s.value = !0;
197
+ }
198
+ const g = (...c) => {
199
+ s.value && e(...c);
200
+ };
201
+ return { isActive: H(s), pause: i, resume: u, eventFilter: g };
202
+ }
203
+ function k(e) {
204
+ return Array.isArray(e) ? e : [e];
205
+ }
206
+ function Pe(e) {
207
+ return oe();
208
+ }
209
+ function qe(e, t, r = {}) {
210
+ const {
211
+ eventFilter: s = Q,
212
+ ...i
213
+ } = r;
214
+ return q(
215
+ e,
216
+ Ce(
217
+ s,
218
+ t
219
+ ),
220
+ i
221
+ );
222
+ }
223
+ function xe(e, t, r = {}) {
224
+ const {
225
+ eventFilter: s,
226
+ initialState: i = "active",
227
+ ...u
228
+ } = r, { eventFilter: g, pause: c, resume: d, isActive: p } = _e(s, { initialState: i });
229
+ return { stop: qe(
230
+ e,
231
+ t,
232
+ {
233
+ ...u,
234
+ eventFilter: g
235
+ }
236
+ ), pause: c, resume: d, isActive: p };
237
+ }
238
+ function De(e, t = !0, r) {
239
+ Pe() ? $(e, r) : t ? e() : B(e);
240
+ }
241
+ function Oe(e, t, r) {
242
+ return q(
243
+ e,
244
+ t,
245
+ {
246
+ ...r,
247
+ immediate: !0
248
+ }
249
+ );
250
+ }
251
+ const R = he ? window : void 0;
252
+ function Re(e) {
253
+ var t;
254
+ const r = C(e);
255
+ return (t = r == null ? void 0 : r.$el) != null ? t : r;
256
+ }
257
+ function I(...e) {
258
+ const t = [], r = () => {
259
+ t.forEach((c) => c()), t.length = 0;
260
+ }, s = (c, d, p, w) => (c.addEventListener(d, p, w), () => c.removeEventListener(d, p, w)), i = J(() => {
261
+ const c = k(C(e[0])).filter((d) => d != null);
262
+ return c.every((d) => typeof d != "string") ? c : void 0;
263
+ }), u = Oe(
264
+ () => {
265
+ var c, d;
266
+ return [
267
+ (d = (c = i.value) == null ? void 0 : c.map((p) => Re(p))) != null ? d : [R].filter((p) => p != null),
268
+ k(C(i.value ? e[1] : e[0])),
269
+ k(M(i.value ? e[2] : e[1])),
270
+ // @ts-expect-error - TypeScript gets the correct types, but somehow still complains
271
+ C(i.value ? e[3] : e[2])
272
+ ];
273
+ },
274
+ ([c, d, p, w]) => {
275
+ if (r(), !(c != null && c.length) || !(d != null && d.length) || !(p != null && p.length))
276
+ return;
277
+ const n = Se(w) ? { ...w } : w;
278
+ t.push(
279
+ ...c.flatMap(
280
+ (o) => d.flatMap(
281
+ (f) => p.map((h) => s(o, f, h, n))
282
+ )
283
+ )
284
+ );
285
+ },
286
+ { flush: "post" }
287
+ ), g = () => {
288
+ u(), r();
289
+ };
290
+ return ge(r), g;
291
+ }
292
+ const x = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, D = "__vueuse_ssr_handlers__", Te = /* @__PURE__ */ ke();
293
+ function ke() {
294
+ return D in x || (x[D] = x[D] || {}), x[D];
295
+ }
296
+ function Ne(e, t) {
297
+ return Te[e] || t;
298
+ }
299
+ function Ae(e) {
300
+ return e == null ? "any" : e instanceof Set ? "set" : e instanceof Map ? "map" : e instanceof Date ? "date" : typeof e == "boolean" ? "boolean" : typeof e == "string" ? "string" : typeof e == "object" ? "object" : Number.isNaN(e) ? "any" : "number";
301
+ }
302
+ const We = {
303
+ boolean: {
304
+ read: (e) => e === "true",
305
+ write: (e) => String(e)
306
+ },
307
+ object: {
308
+ read: (e) => JSON.parse(e),
309
+ write: (e) => JSON.stringify(e)
310
+ },
311
+ number: {
312
+ read: (e) => Number.parseFloat(e),
313
+ write: (e) => String(e)
314
+ },
315
+ any: {
316
+ read: (e) => e,
317
+ write: (e) => String(e)
318
+ },
319
+ string: {
320
+ read: (e) => e,
321
+ write: (e) => String(e)
322
+ },
323
+ map: {
324
+ read: (e) => new Map(JSON.parse(e)),
325
+ write: (e) => JSON.stringify(Array.from(e.entries()))
326
+ },
327
+ set: {
328
+ read: (e) => new Set(JSON.parse(e)),
329
+ write: (e) => JSON.stringify(Array.from(e))
330
+ },
331
+ date: {
332
+ read: (e) => new Date(e),
333
+ write: (e) => e.toISOString()
334
+ }
335
+ }, z = "vueuse-storage";
336
+ function Me(e, t, r, s = {}) {
337
+ var i;
338
+ const {
339
+ flush: u = "pre",
340
+ deep: g = !0,
341
+ listenToStorageChanges: c = !0,
342
+ writeDefaults: d = !0,
343
+ mergeDefaults: p = !1,
344
+ shallow: w,
345
+ window: n = R,
346
+ eventFilter: o,
347
+ onError: f = (l) => {
348
+ console.error(l);
349
+ },
350
+ initOnMounted: h
351
+ } = s, a = (w ? A : T)(t), v = J(() => C(e));
352
+ if (!r)
353
+ try {
354
+ r = Ne("getDefaultStorage", () => {
355
+ var l;
356
+ return (l = R) == null ? void 0 : l.localStorage;
357
+ })();
358
+ } catch (l) {
359
+ f(l);
360
+ }
361
+ if (!r)
362
+ return a;
363
+ const E = C(t), L = Ae(E), _ = (i = s.serializer) != null ? i : We[L], { pause: G, resume: j } = xe(
364
+ a,
365
+ () => K(a.value),
366
+ { flush: u, deep: g, eventFilter: o }
367
+ );
368
+ q(v, () => P(), { flush: u }), n && c && De(() => {
369
+ r instanceof Storage ? I(n, "storage", P, { passive: !0 }) : I(n, z, Y), h && P();
370
+ }), h || P();
371
+ function V(l, m) {
372
+ if (n) {
373
+ const S = {
374
+ key: v.value,
375
+ oldValue: l,
376
+ newValue: m,
377
+ storageArea: r
378
+ };
379
+ n.dispatchEvent(r instanceof Storage ? new StorageEvent("storage", S) : new CustomEvent(z, {
380
+ detail: S
381
+ }));
382
+ }
383
+ }
384
+ function K(l) {
385
+ try {
386
+ const m = r.getItem(v.value);
387
+ if (l == null)
388
+ V(m, null), r.removeItem(v.value);
389
+ else {
390
+ const S = _.write(l);
391
+ m !== S && (r.setItem(v.value, S), V(m, S));
392
+ }
393
+ } catch (m) {
394
+ f(m);
395
+ }
396
+ }
397
+ function U(l) {
398
+ const m = l ? l.newValue : r.getItem(v.value);
399
+ if (m == null)
400
+ return d && E != null && r.setItem(v.value, _.write(E)), E;
401
+ if (!l && p) {
402
+ const S = _.read(m);
403
+ return typeof p == "function" ? p(S, E) : L === "object" && !Array.isArray(S) ? { ...E, ...S } : S;
404
+ } else return typeof m != "string" ? m : _.read(m);
405
+ }
406
+ function P(l) {
407
+ if (!(l && l.storageArea !== r)) {
408
+ if (l && l.key == null) {
409
+ a.value = E;
410
+ return;
411
+ }
412
+ if (!(l && l.key !== v.value)) {
413
+ G();
414
+ try {
415
+ (l == null ? void 0 : l.newValue) !== _.write(a.value) && (a.value = U(l));
416
+ } catch (m) {
417
+ f(m);
418
+ } finally {
419
+ l ? B(j) : j();
420
+ }
421
+ }
422
+ }
423
+ }
424
+ function Y(l) {
425
+ P(l.detail);
426
+ }
427
+ return a;
428
+ }
429
+ function Fe(e, t, r = {}) {
430
+ const { window: s = R } = r;
431
+ return Me(e, t, s == null ? void 0 : s.localStorage, r);
432
+ }
433
+ const Ve = /* @__PURE__ */ F({
434
+ __name: "PCDevtoolsWrapper",
435
+ setup(e) {
436
+ const t = T(!1), r = Fe("pinia-colada-devtools-open", !1);
437
+ async function s() {
438
+ if (!t.value && (t.value = !0, !customElements.get("pinia-colada-devtools-panel"))) {
439
+ const { DevtoolsPanel: u } = await import("@pinia/colada-devtools/panel");
440
+ customElements.define("pinia-colada-devtools-panel", u);
441
+ }
442
+ }
443
+ async function i() {
444
+ await s(), r.value = !0;
445
+ }
446
+ return $(() => {
447
+ requestIdleCallback(() => {
448
+ import("@pinia/colada-devtools/panel");
449
+ }), r.value && i();
450
+ }), (u, g) => (O(), W(ve, null, {
451
+ default: le(() => [
452
+ M(r) ? N("", !0) : (O(), ue("button", {
453
+ key: 0,
454
+ class: "fixed bottom-2 right-2 bg-primary-500 hover:cursor-pointer z-99999",
455
+ onClick: g[0] || (g[0] = (c) => i())
456
+ }, " 🍹 Devtools ")),
457
+ t.value && M(r) ? (O(), W(ye, { key: 1 })) : N("", !0)
458
+ ]),
459
+ _: 1
460
+ }));
461
+ }
462
+ });
463
+ export {
464
+ Ve as PiniaColadaDevtools
465
+ };
466
+ //# sourceMappingURL=index.js.map