vue-router-query-sync 0.0.6 → 0.0.8

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/index.js CHANGED
@@ -1 +1 @@
1
- (function(n,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("vue-router")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router"],u):(n=typeof globalThis<"u"?globalThis:n||self,u(n.VueRouterQuerySync={},n.Vue,n.VueRouter))})(this,(function(n,u,S){"use strict";let c={};const l=new Set;let q=!1;function f(o,r){const d=S.useRouter();r===null?o in c||l.add(o):(c[o]=r,l.delete(o)),q||(q=!0,queueMicrotask(()=>{const y={...d.currentRoute.value.query};l.forEach(a=>{delete y[a]});const s={...y,...c};d.replace({query:s}),c={},l.clear(),q=!1}))}function R(o,r,d,y={}){const s=S.useRoute();console.log("!!!!",s);const{deps:a=[],context:m}=y,t=m?`${m}_${o}`:o,h=(e,p=!1)=>{if(typeof e=="string"){const i=isNaN(Number(e))?e:Number(e);if(p||i!==r()){d(i);const Q=r();Q!==i&&Q!==null&&f(t,Q)}}else{const i=r();i!==null&&f(t,i)}};u.onBeforeMount(()=>{a.length>0?u.watch(a,()=>h(s.query[t])):h(s.query[t])}),u.watch(r,e=>{const p=s.query[t];e===null?p!==void 0&&f(t,null):p!==String(e)&&f(t,e)}),u.watch(()=>s.query[t],e=>{h(e)}),u.onBeforeUnmount(()=>{f(t,null)})}n.useQuerySync=R,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vue-router")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.VueRouterQuerySync={},n.Vue,n.VueRouter))})(this,(function(n,e,R){"use strict";let f={};const d=new Set;let m=!1;function c(r,s){const a=e.getCurrentInstance();if(!a)throw new Error("useReplaceRouterQueue must be called within a Vue component setup.");const l=a.appContext.config.globalProperties.$router;if(!l)throw new Error("Router not found. Ensure app.use(router) is called in your main.ts.");s===null?r in f||d.add(r):(f[r]=s,d.delete(r)),m||(m=!0,queueMicrotask(()=>{const o={...l.currentRoute.value.query};d.forEach(y=>{delete o[y]});const p={...o,...f};l.replace({query:p}),f={},d.clear(),m=!1}))}function w(r,s,a,l={}){const o=R.useRoute();console.log("!!!!",o);const{deps:p=[],context:y}=l,u=y?`${y}_${r}`:r,q=(t,h=!1)=>{if(typeof t=="string"){const i=isNaN(Number(t))?t:Number(t);if(h||i!==s()){a(i);const Q=s();Q!==i&&Q!==null&&c(u,Q)}}else{const i=s();i!==null&&c(u,i)}};e.onBeforeMount(()=>{p.length>0?e.watch(p,()=>q(o.query[u])):q(o.query[u])}),e.watch(s,t=>{const h=o.query[u];t===null?h!==void 0&&c(u,null):h!==String(t)&&c(u,t)}),e.watch(()=>o.query[u],t=>{q(t)}),e.onBeforeUnmount(()=>{c(u,null)})}n.useQuerySync=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
package/dist/index.mjs CHANGED
@@ -1,52 +1,57 @@
1
- import { onBeforeMount as N, watch as m, onBeforeUnmount as R } from "vue";
2
- import { useRouter as h, useRoute as S } from "vue-router";
3
- let a = {};
1
+ import { getCurrentInstance as h, onBeforeMount as R, watch as q, onBeforeUnmount as w } from "vue";
2
+ import { useRoute as b } from "vue-router";
3
+ let p = {};
4
4
  const d = /* @__PURE__ */ new Set();
5
- let q = !1;
6
- function l(u, o) {
7
- const s = h();
8
- o === null ? u in a || d.add(u) : (a[u] = o, d.delete(u)), q || (q = !0, queueMicrotask(() => {
9
- const c = { ...s.currentRoute.value.query };
5
+ let Q = !1;
6
+ function s(u, n) {
7
+ const c = h();
8
+ if (!c)
9
+ throw new Error("useReplaceRouterQueue must be called within a Vue component setup.");
10
+ const l = c.appContext.config.globalProperties.$router;
11
+ if (!l)
12
+ throw new Error("Router not found. Ensure app.use(router) is called in your main.ts.");
13
+ n === null ? u in p || d.add(u) : (p[u] = n, d.delete(u)), Q || (Q = !0, queueMicrotask(() => {
14
+ const o = { ...l.currentRoute.value.query };
10
15
  d.forEach((f) => {
11
- delete c[f];
16
+ delete o[f];
12
17
  });
13
- const n = {
14
- ...c,
15
- ...a
18
+ const i = {
19
+ ...o,
20
+ ...p
16
21
  };
17
- s.replace({ query: n }), a = {}, d.clear(), q = !1;
22
+ l.replace({ query: i }), p = {}, d.clear(), Q = !1;
18
23
  }));
19
24
  }
20
- function x(u, o, s, c = {}) {
21
- const n = S();
22
- console.log("!!!!", n);
23
- const { deps: f = [], context: Q } = c, t = Q ? `${Q}_${u}` : u, p = (e, i = !1) => {
25
+ function N(u, n, c, l = {}) {
26
+ const o = b();
27
+ console.log("!!!!", o);
28
+ const { deps: i = [], context: f } = l, t = f ? `${f}_${u}` : u, m = (e, a = !1) => {
24
29
  if (typeof e == "string") {
25
30
  const r = isNaN(Number(e)) ? e : Number(e);
26
- if (i || r !== o()) {
27
- s(r);
28
- const y = o();
29
- y !== r && y !== null && l(t, y);
31
+ if (a || r !== n()) {
32
+ c(r);
33
+ const y = n();
34
+ y !== r && y !== null && s(t, y);
30
35
  }
31
36
  } else {
32
- const r = o();
33
- r !== null && l(t, r);
37
+ const r = n();
38
+ r !== null && s(t, r);
34
39
  }
35
40
  };
36
- N(() => {
37
- f.length > 0 ? m(f, () => p(n.query[t])) : p(n.query[t]);
38
- }), m(o, (e) => {
39
- const i = n.query[t];
40
- e === null ? i !== void 0 && l(t, null) : i !== String(e) && l(t, e);
41
- }), m(
42
- () => n.query[t],
41
+ R(() => {
42
+ i.length > 0 ? q(i, () => m(o.query[t])) : m(o.query[t]);
43
+ }), q(n, (e) => {
44
+ const a = o.query[t];
45
+ e === null ? a !== void 0 && s(t, null) : a !== String(e) && s(t, e);
46
+ }), q(
47
+ () => o.query[t],
43
48
  (e) => {
44
- p(e);
49
+ m(e);
45
50
  }
46
- ), R(() => {
47
- l(t, null);
51
+ ), w(() => {
52
+ s(t, null);
48
53
  });
49
54
  }
50
55
  export {
51
- x as useQuerySync
56
+ N as useQuerySync
52
57
  };
@@ -1 +1 @@
1
- {"version":3,"file":"replaceRouterQueue.d.ts","sourceRoot":"","sources":["../../src/utils/replaceRouterQueue.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,QAiCpF"}
1
+ {"version":3,"file":"replaceRouterQueue.d.ts","sourceRoot":"","sources":["../../src/utils/replaceRouterQueue.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,QAyCpF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-router-query-sync",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Vue composable for syncing router query params with store",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",