aprog 2.3.0 → 2.3.2
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/index.js +1 -1
- package/package.json +1 -1
- package/src/helper.js +9 -0
- package/src/router.js +26 -4
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export {
|
|
|
23
23
|
} from './src/html.js';
|
|
24
24
|
export { prism } from "./src/prism.js";
|
|
25
25
|
export { uniquePage } from "./src/pages.js";
|
|
26
|
-
export { state, wrap, toast, abort, useTableDrag } from "./src/helper.js";
|
|
26
|
+
export { state, wrap, toast, abort, useTableDrag, callback } from "./src/helper.js";
|
|
27
27
|
export { loadTranslations, translate } from "./src/translator.js";
|
|
28
28
|
export { svg } from "./src/svg.js";
|
|
29
29
|
export { Modal, modal, closeAllModals, closeThisModal } from "./src/modal.js";
|
package/package.json
CHANGED
package/src/helper.js
CHANGED
|
@@ -105,3 +105,12 @@ export const useTableDrag = (selectorOrElement, onReorder = null, time = 1000) =
|
|
|
105
105
|
|
|
106
106
|
return { getOrder };
|
|
107
107
|
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates a callback with predefined arguments.
|
|
111
|
+
*
|
|
112
|
+
* @param {Function} fn
|
|
113
|
+
* @param {...*} args
|
|
114
|
+
* @returns {Function}
|
|
115
|
+
*/
|
|
116
|
+
export const callback = (fn, ...args) => (...extra) => fn(...args, ...extra);
|
package/src/router.js
CHANGED
|
@@ -2,6 +2,11 @@ import NotFound from "./NotFound.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ініціалізація роутера.
|
|
5
|
+
* @param routes
|
|
6
|
+
* @param main
|
|
7
|
+
* @param message
|
|
8
|
+
* @param props
|
|
9
|
+
* @returns {Promise<void>}
|
|
5
10
|
*/
|
|
6
11
|
export const router = async ({routes, main, message = "", props = {}}) => {
|
|
7
12
|
const renderRoute = async () => {
|
|
@@ -29,6 +34,8 @@ export const router = async ({routes, main, message = "", props = {}}) => {
|
|
|
29
34
|
|
|
30
35
|
/**
|
|
31
36
|
* Перехід без рендеру.
|
|
37
|
+
* @param path
|
|
38
|
+
* @param props
|
|
32
39
|
*/
|
|
33
40
|
export const navigateTo = (path, props = {}) => {
|
|
34
41
|
window.history.pushState(props, "", path);
|
|
@@ -36,6 +43,9 @@ export const navigateTo = (path, props = {}) => {
|
|
|
36
43
|
|
|
37
44
|
/**
|
|
38
45
|
* Перехід + рендер.
|
|
46
|
+
* @param path
|
|
47
|
+
* @param props
|
|
48
|
+
* @returns {Promise<void>}
|
|
39
49
|
*/
|
|
40
50
|
export const navi = async (path, props = {}) => {
|
|
41
51
|
window.history.pushState(props, "", path);
|
|
@@ -59,6 +69,9 @@ export const navi = async (path, props = {}) => {
|
|
|
59
69
|
* category_id: "15",
|
|
60
70
|
* product_id: "128"
|
|
61
71
|
* }
|
|
72
|
+
* @param routePath
|
|
73
|
+
* @param path
|
|
74
|
+
* @returns {*|null}
|
|
62
75
|
*/
|
|
63
76
|
const matchRoute = (routePath, path) => {
|
|
64
77
|
const keys = [];
|
|
@@ -84,19 +97,28 @@ const matchRoute = (routePath, path) => {
|
|
|
84
97
|
|
|
85
98
|
/**
|
|
86
99
|
* Знаходить поточний route.
|
|
100
|
+
* @param routes
|
|
101
|
+
* @returns {{routeComponent: ((function({colors?: {backgroundColor: string, numberColor: string, textColor: string}, message?: string}): HTMLDivElement)|*), props: {}}|{routeComponent: RTCIceComponent, props: {}}}
|
|
87
102
|
*/
|
|
88
103
|
const useRoutes = (routes) => {
|
|
89
104
|
const path = window.location.pathname;
|
|
90
105
|
|
|
91
106
|
for (const route of routes) {
|
|
92
107
|
const params = matchRoute(route.path, path);
|
|
108
|
+
|
|
93
109
|
if (params !== null) {
|
|
110
|
+
const props = {
|
|
111
|
+
...(window.history.state || {}),
|
|
112
|
+
...params,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (props.title) {
|
|
116
|
+
document.title = props.title;
|
|
117
|
+
}
|
|
118
|
+
|
|
94
119
|
return {
|
|
95
120
|
routeComponent: route.component,
|
|
96
|
-
props
|
|
97
|
-
...(window.history.state || {}),
|
|
98
|
-
...params,
|
|
99
|
-
},
|
|
121
|
+
props,
|
|
100
122
|
};
|
|
101
123
|
}
|
|
102
124
|
}
|