@cocoar/vue-fragment-parser 1.6.4 → 1.6.6
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 +125 -102
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,106 +1,129 @@
|
|
|
1
|
-
import { match as
|
|
2
|
-
import {
|
|
3
|
-
import { computed as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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.
|
|
3
|
+
"version": "1.6.6",
|
|
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.
|
|
38
|
+
"path-to-regexp": "^8.4.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
+
"@cocoar/vue-ui": "1.6.6",
|
|
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": "
|
|
55
|
-
"vue
|
|
56
|
-
"
|
|
54
|
+
"@cocoar/vue-ui": "workspace:*",
|
|
55
|
+
"vue": "^3.5.32",
|
|
56
|
+
"vue-router": "^5.0.4"
|
|
57
57
|
}
|
|
58
58
|
}
|