@cocoar/vue-fragment-parser 1.6.4 → 1.6.5

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.
Files changed (2) hide show
  1. package/dist/index.js +125 -102
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -1,106 +1,129 @@
1
- import { match as d } from "path-to-regexp";
2
- import { useRouter as g, useRoute as R } from "vue-router";
3
- import { computed as v, shallowRef as y, watch as P, markRaw as w, onUnmounted as $ } from "vue";
4
- import { useDialog as M, getOverlayService as S, modalPreset as O } from "@cocoar/vue-ui";
5
- function q(r, u) {
6
- const p = u.flatMap((e) => Array.isArray(e.path) ? e.path.map((a) => ({ ...e, path: a })) : [e]);
7
- return r.split("#").map((e) => {
8
- const [a, o] = e.split("?"), t = {}, n = p.find((c) => !!d(c.path, { decode: decodeURIComponent })(a));
9
- if (n) {
10
- const h = d(n.path, { decode: decodeURIComponent })(a);
11
- return h && Object.assign(t, h.params), o && new URLSearchParams(o).forEach((i, l) => {
12
- let m;
13
- try {
14
- m = JSON.parse(i);
15
- } catch {
16
- m = i;
17
- }
18
- t[l] = m;
19
- }), { fragment: e, params: t, route: n };
20
- }
21
- return null;
22
- }).filter((e) => e !== null);
1
+ import { match as e } from "path-to-regexp";
2
+ import { useRoute as t, useRouter as n } from "vue-router";
3
+ import { computed as r, markRaw as i, onUnmounted as a, shallowRef as o, watch as s } from "vue";
4
+ import { getOverlayService as c, modalPreset as l, useDialog as u } from "@cocoar/vue-ui";
5
+ //#region src/lib/fragment-parser.ts
6
+ function d(t, n) {
7
+ let r = n.flatMap((e) => Array.isArray(e.path) ? e.path.map((t) => ({
8
+ ...e,
9
+ path: t
10
+ })) : [e]);
11
+ return t.split("#").map((t) => {
12
+ let [n, i] = t.split("?"), a = {}, o = r.find((t) => !!e(t.path, { decode: decodeURIComponent })(n));
13
+ if (o) {
14
+ let r = e(o.path, { decode: decodeURIComponent })(n);
15
+ return r && Object.assign(a, r.params), i && new URLSearchParams(i).forEach((e, t) => {
16
+ let n;
17
+ try {
18
+ n = JSON.parse(e);
19
+ } catch {
20
+ n = e;
21
+ }
22
+ a[t] = n;
23
+ }), {
24
+ fragment: t,
25
+ params: a,
26
+ route: o
27
+ };
28
+ }
29
+ return null;
30
+ }).filter((e) => e !== null);
23
31
  }
24
- function U() {
25
- const r = g();
26
- function u(s, e, a) {
27
- const o = e ? "?" + Object.entries(e).filter(([, n]) => n !== void 0).map(([n, c]) => `${n}=${encodeURIComponent(String(c))}`).join("&") : "", t = `${s}${o}`;
28
- if (a?.append) {
29
- const n = r.currentRoute.value.hash.replace(/^#/, ""), c = n ? `${n}#${t}` : t;
30
- r.push({ ...r.currentRoute.value, hash: `#${c}` });
31
- } else
32
- r.push({ ...r.currentRoute.value, hash: `#${t}` });
33
- }
34
- function p(s) {
35
- const e = r.currentRoute.value.hash.replace(/^#/, "");
36
- if (!e) return;
37
- const a = e.split("#"), o = a.filter((t) => t.split("?")[0] !== s);
38
- if (o.length !== a.length)
39
- if (o.length > 0)
40
- r.push({ ...r.currentRoute.value, hash: `#${o.join("#")}` });
41
- else {
42
- const { path: t, query: n } = r.currentRoute.value;
43
- r.push({ path: t, query: n });
44
- }
45
- }
46
- return { navigateToModal: u, closeModal: p };
32
+ //#endregion
33
+ //#region src/composables/useFragmentNavigation.ts
34
+ function f() {
35
+ let e = n();
36
+ function t(t, n, r) {
37
+ let i = `${t}${n ? "?" + Object.entries(n).filter(([, e]) => e !== void 0).map(([e, t]) => `${e}=${encodeURIComponent(String(t))}`).join("&") : ""}`;
38
+ if (r?.append) {
39
+ let t = e.currentRoute.value.hash.replace(/^#/, ""), n = t ? `${t}#${i}` : i;
40
+ e.push({
41
+ ...e.currentRoute.value,
42
+ hash: `#${n}`
43
+ });
44
+ } else e.push({
45
+ ...e.currentRoute.value,
46
+ hash: `#${i}`
47
+ });
48
+ }
49
+ function r(t) {
50
+ let n = e.currentRoute.value.hash.replace(/^#/, "");
51
+ if (!n) return;
52
+ let r = n.split("#"), i = r.filter((e) => e.split("?")[0] !== t);
53
+ if (i.length !== r.length) if (i.length > 0) e.push({
54
+ ...e.currentRoute.value,
55
+ hash: `#${i.join("#")}`
56
+ });
57
+ else {
58
+ let { path: t, query: n } = e.currentRoute.value;
59
+ e.push({
60
+ path: t,
61
+ query: n
62
+ });
63
+ }
64
+ }
65
+ return {
66
+ navigateToModal: t,
67
+ closeModal: r
68
+ };
47
69
  }
48
- function j(r) {
49
- const u = R();
50
- return { fragments: v(() => {
51
- const s = u.hash.replace(/^#/, "");
52
- if (!s) return [];
53
- const e = r ?? u.meta?.routedFragments ?? [];
54
- return e.length === 0 ? [] : q(s, e);
55
- }) };
70
+ //#endregion
71
+ //#region src/composables/useRoutedFragments.ts
72
+ function p(e) {
73
+ let n = t();
74
+ return { fragments: r(() => {
75
+ let t = n.hash.replace(/^#/, "");
76
+ if (!t) return [];
77
+ let r = e ?? n.meta?.routedFragments ?? [];
78
+ return r.length === 0 ? [] : d(t, r);
79
+ }) };
56
80
  }
57
- function I() {
58
- const { fragments: r } = j(), { closeModal: u } = U(), { open: p } = M(), s = y(/* @__PURE__ */ new Map());
59
- P(
60
- r,
61
- async (e) => {
62
- const a = new Set(e.map((t) => t.fragment.split("?")[0])), o = new Map(s.value);
63
- for (const [t, n] of o)
64
- a.has(t) || (n.close(), o.delete(t));
65
- for (const t of e) {
66
- const n = t.fragment.split("?")[0];
67
- if (o.has(n)) continue;
68
- const c = t.route, f = (await c.component()).default;
69
- let i;
70
- if (c.type === "dialog") {
71
- const l = p(
72
- f,
73
- c.dialogOptions ?? {},
74
- { ...t.params }
75
- );
76
- i = { close: () => l.close(), result: l.result };
77
- } else {
78
- const l = S().open({
79
- spec: { ...O, ...c.overlayOptions },
80
- content: { kind: "component", component: w(f) },
81
- inputs: {
82
- ...t.params,
83
- close: (m) => l.close(m)
84
- }
85
- });
86
- i = { close: () => l.close(), result: l.afterClosed };
87
- }
88
- o.set(n, i), i.result.then(() => {
89
- s.value.delete(n), u(n);
90
- });
91
- }
92
- s.value = o;
93
- },
94
- { immediate: !0 }
95
- ), $(() => {
96
- for (const e of s.value.values())
97
- e.close();
98
- s.value.clear();
99
- });
81
+ //#endregion
82
+ //#region src/composables/useRoutedModals.ts
83
+ function m() {
84
+ let { fragments: e } = p(), { closeModal: t } = f(), { open: n } = u(), r = o(/* @__PURE__ */ new Map());
85
+ s(e, async (e) => {
86
+ let a = new Set(e.map((e) => e.fragment.split("?")[0])), o = new Map(r.value);
87
+ for (let [e, t] of o) a.has(e) || (t.close(), o.delete(e));
88
+ for (let a of e) {
89
+ let e = a.fragment.split("?")[0];
90
+ if (o.has(e)) continue;
91
+ let s = a.route, u = (await s.component()).default, d;
92
+ if (s.type === "dialog") {
93
+ let e = n(u, s.dialogOptions ?? {}, { ...a.params });
94
+ d = {
95
+ close: () => e.close(),
96
+ result: e.result
97
+ };
98
+ } else {
99
+ let e = c().open({
100
+ spec: {
101
+ ...l,
102
+ ...s.overlayOptions
103
+ },
104
+ content: {
105
+ kind: "component",
106
+ component: i(u)
107
+ },
108
+ inputs: {
109
+ ...a.params,
110
+ close: (t) => e.close(t)
111
+ }
112
+ });
113
+ d = {
114
+ close: () => e.close(),
115
+ result: e.afterClosed
116
+ };
117
+ }
118
+ o.set(e, d), d.result.then(() => {
119
+ r.value.delete(e), t(e);
120
+ });
121
+ }
122
+ r.value = o;
123
+ }, { immediate: !0 }), a(() => {
124
+ for (let e of r.value.values()) e.close();
125
+ r.value.clear();
126
+ });
100
127
  }
101
- export {
102
- q as parseFragment,
103
- U as useFragmentNavigation,
104
- j as useRoutedFragments,
105
- I as useRoutedModals
106
- };
128
+ //#endregion
129
+ export { d as parseFragment, f as useFragmentNavigation, p as useRoutedFragments, m as useRoutedModals };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocoar/vue-fragment-parser",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "HTML fragment parser utility for Cocoar UI components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,12 +35,12 @@
35
35
  "lint": "eslint src/"
36
36
  },
37
37
  "dependencies": {
38
- "path-to-regexp": "^8.3.0"
38
+ "path-to-regexp": "^8.4.2"
39
39
  },
40
40
  "peerDependencies": {
41
+ "@cocoar/vue-ui": "1.6.5",
41
42
  "vue": "^3.5.0",
42
- "vue-router": "^4.5.0",
43
- "@cocoar/vue-ui": "1.6.4"
43
+ "vue-router": "^4.5.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "vue-router": {
@@ -51,8 +51,8 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "vue": "^3.5.0",
55
- "vue-router": "^4.5.0",
56
- "@cocoar/vue-ui": "workspace:*"
54
+ "@cocoar/vue-ui": "workspace:*",
55
+ "vue": "^3.5.32",
56
+ "vue-router": "^5.0.4"
57
57
  }
58
58
  }