@karta.io/utils 1.0.0-beta.5 → 1.0.0-beta.51
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/helpers/appComponentsResolver.d.ts +5 -0
- package/dist/helpers/camelizeKeys.d.ts +2 -0
- package/dist/helpers/convertEnumToOptions.d.ts +8 -0
- package/dist/helpers/enrichError.d.ts +8 -0
- package/dist/helpers/formatError.d.ts +7 -0
- package/dist/helpers/formatMoney.d.ts +6 -0
- package/dist/helpers/genHash.d.ts +1 -0
- package/dist/helpers/genRandomNumber.d.ts +1 -0
- package/dist/helpers/genUUID.d.ts +1 -0
- package/dist/helpers/getCardNumber.d.ts +7 -0
- package/dist/helpers/getCountryFromPhone.d.ts +1 -0
- package/dist/helpers/isElementIgnored.d.ts +4 -0
- package/dist/helpers/isEmptyObject.d.ts +1 -0
- package/dist/helpers/isHtml.d.ts +1 -0
- package/dist/helpers/mapDataObjectForFilters.d.ts +10 -0
- package/dist/helpers/pagination.d.ts +18 -0
- package/dist/helpers/parsePhone.d.ts +1 -0
- package/dist/helpers/snakelizeKeys.d.ts +3 -0
- package/dist/helpers/uiComponentsResolver.d.ts +5 -0
- package/dist/helpers/unformatNumber.d.ts +19 -0
- package/dist/helpers/validateNumber.d.ts +1 -0
- package/dist/hooks/useAbortController.d.ts +6 -0
- package/dist/hooks/useAsyncItems.d.ts +19 -0
- package/dist/hooks/useAsyncMultiselect.d.ts +31 -0
- package/dist/hooks/useAsyncSelect.d.ts +30 -0
- package/dist/hooks/useBreakpoint.d.ts +11 -0
- package/dist/hooks/useClassName.d.ts +9 -0
- package/dist/hooks/useDayjs.d.ts +10 -0
- package/dist/hooks/useDetectBrowser.d.ts +13 -0
- package/dist/hooks/useDialog.d.ts +48 -0
- package/dist/hooks/useFilters.d.ts +18 -0
- package/dist/hooks/useGlobalScroll.d.ts +6 -0
- package/dist/hooks/useLogger.d.ts +8 -0
- package/dist/hooks/usePanel.d.ts +27 -0
- package/dist/index.cjs +1550 -1352
- package/dist/index.d.ts +37 -350
- package/dist/index.mjs +1503 -1329
- package/dist/types.d.ts +11 -0
- package/dist/validator/formRules.d.ts +14 -0
- package/dist/validator/validatePhone.d.ts +1 -0
- package/package.json +39 -41
- package/dist/index.d.cts +0 -350
- package/dist/index.d.mts +0 -350
package/dist/index.mjs
CHANGED
|
@@ -1,1419 +1,1593 @@
|
|
|
1
|
-
import camelCase from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { useQuery, useQueryClient } from
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import
|
|
21
|
-
|
|
1
|
+
import camelCase from "lodash/camelCase.js";
|
|
2
|
+
import flatMap from "lodash/flatMap.js";
|
|
3
|
+
import { BREAKPOINTS, CURRENCY_DEFAULT } from "@karta.io/common-data";
|
|
4
|
+
import { parsePhoneNumberFromString } from "libphonenumber-js";
|
|
5
|
+
import snakeCase from "lodash/snakeCase.js";
|
|
6
|
+
import { computed, createVNode, getCurrentInstance, isRef, nextTick, onBeforeUnmount, onMounted, reactive, ref, render, toValue, watch } from "vue";
|
|
7
|
+
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
|
8
|
+
import { useBreakpoints, useDebounceFn } from "@vueuse/core";
|
|
9
|
+
import get from "lodash/get.js";
|
|
10
|
+
import has from "lodash/has.js";
|
|
11
|
+
import union from "lodash/union.js";
|
|
12
|
+
import logdown from "logdown";
|
|
13
|
+
import dayjs from "dayjs";
|
|
14
|
+
import utc from "dayjs/plugin/utc.js";
|
|
15
|
+
import tz from "dayjs/plugin/timezone.js";
|
|
16
|
+
import updateLocale from "dayjs/plugin/updateLocale.js";
|
|
17
|
+
import isToday from "dayjs/plugin/isToday.js";
|
|
18
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
19
|
+
import { detect } from "detect-browser";
|
|
20
|
+
import { useRoute, useRouter } from "vue-router";
|
|
21
|
+
import qs from "qs";
|
|
22
|
+
//#region src/helpers/appComponentsResolver.ts
|
|
22
23
|
function AppComponentsResolver(options = {}) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const { prefix = "" } = options;
|
|
25
|
+
return (name) => {
|
|
26
|
+
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
27
|
+
if (componentName.startsWith("App")) return {
|
|
28
|
+
name: componentName,
|
|
29
|
+
from: "@karta.io/app-components"
|
|
30
|
+
};
|
|
31
|
+
};
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/helpers/camelizeKeys.ts
|
|
32
35
|
function camelizeKeys(object) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
[camelCase(key)]: camelizeKeys(object[key])
|
|
40
|
-
}),
|
|
41
|
-
{}
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return object;
|
|
36
|
+
if (Array.isArray(object)) return object.map((v) => camelizeKeys(v));
|
|
37
|
+
if (object !== null && object.constructor === Object) return Object.keys(object).reduce((result, key) => ({
|
|
38
|
+
...result,
|
|
39
|
+
[camelCase(key)]: camelizeKeys(object[key])
|
|
40
|
+
}), {});
|
|
41
|
+
return object;
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/helpers/convertEnumToOptions.ts
|
|
45
|
+
var OPTIONS_DEFAULT = { labelType: "value" };
|
|
50
46
|
function convertEnumToOptions(obj, options) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
const newOptions = {
|
|
48
|
+
...OPTIONS_DEFAULT,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
return Object.entries(obj).map(([key, value]) => ({
|
|
52
|
+
value,
|
|
53
|
+
label: newOptions.labelType === "key" ? key : value
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/helpers/enrichError.ts
|
|
58
|
+
var EnrichError = class extends Error {
|
|
59
|
+
constructor(data) {
|
|
60
|
+
super(data.message);
|
|
61
|
+
Object.assign(this, data);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/helpers/isHtml.ts
|
|
66
|
+
function isHtml(data) {
|
|
67
|
+
try {
|
|
68
|
+
if (typeof DOMParser !== "undefined") {
|
|
69
|
+
const doc = new DOMParser().parseFromString(data, "text/html");
|
|
70
|
+
return Array.from(doc.body.childNodes).some((node) => node.nodeType === Node.ELEMENT_NODE);
|
|
71
|
+
}
|
|
72
|
+
return /<\/?[a-z][\s\S]*>/i.test(data);
|
|
73
|
+
} catch (_) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/helpers/formatError.ts
|
|
79
|
+
function getStatusMessage(status) {
|
|
80
|
+
let message = "";
|
|
81
|
+
switch (status) {
|
|
82
|
+
case 200:
|
|
83
|
+
message = "All done. Request successfully executed";
|
|
84
|
+
break;
|
|
85
|
+
case 201:
|
|
86
|
+
message = "Data successfully created";
|
|
87
|
+
break;
|
|
88
|
+
case 400:
|
|
89
|
+
message = "Bad request";
|
|
90
|
+
break;
|
|
91
|
+
case 401:
|
|
92
|
+
message = "Need auth";
|
|
93
|
+
break;
|
|
94
|
+
case 404:
|
|
95
|
+
message = "Not found";
|
|
96
|
+
break;
|
|
97
|
+
case 500:
|
|
98
|
+
message = "Something wrong. Internal server error";
|
|
99
|
+
break;
|
|
100
|
+
case 501:
|
|
101
|
+
message = "501: Not implemented";
|
|
102
|
+
break;
|
|
103
|
+
case 502:
|
|
104
|
+
message = "502: Bad gateway";
|
|
105
|
+
break;
|
|
106
|
+
case 503:
|
|
107
|
+
message = "Service unavailable. Try again later";
|
|
108
|
+
break;
|
|
109
|
+
default: message = "Something wrong. Client default error message";
|
|
110
|
+
}
|
|
111
|
+
return message;
|
|
112
|
+
}
|
|
113
|
+
function formatErrorDataMessage(data) {
|
|
114
|
+
if (!data) return "";
|
|
115
|
+
return Object.values(data).reduce((accum, current) => {
|
|
116
|
+
if (current && typeof current === "string") return accum ? `${accum} | ${current}` : current;
|
|
117
|
+
if (Array.isArray(current) && current.length) {
|
|
118
|
+
const value = `${flatMap(current).join(" | ")}`;
|
|
119
|
+
return accum ? `${accum} | ${value}` : value;
|
|
120
|
+
}
|
|
121
|
+
return accum;
|
|
122
|
+
}, "");
|
|
123
|
+
}
|
|
124
|
+
function formatErrorForNotify(error) {
|
|
125
|
+
if (!error) return;
|
|
126
|
+
if (error.status >= 400 && error.status < 500) {
|
|
127
|
+
let message = "";
|
|
128
|
+
if (!error.data || typeof error.data === "string" && isHtml(error.data)) message = error.statusMessage || error.message || getStatusMessage(error.status);
|
|
129
|
+
else if (typeof error.data === "string" && !isHtml(error.data)) message = error.data;
|
|
130
|
+
else message = formatErrorDataMessage(error.data);
|
|
131
|
+
return {
|
|
132
|
+
title: "Request error",
|
|
133
|
+
message
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (error.status >= 500) return {
|
|
137
|
+
title: "Internal server error",
|
|
138
|
+
message: error.statusMessage || error.message || getStatusMessage(error.status)
|
|
139
|
+
};
|
|
140
|
+
if (error instanceof Error) return {
|
|
141
|
+
title: "Internal client error",
|
|
142
|
+
message: error.message
|
|
143
|
+
};
|
|
59
144
|
}
|
|
60
|
-
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/helpers/formatMoney.ts
|
|
61
147
|
function formatMoney(value, currency = CURRENCY_DEFAULT, options = {}) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return defaultValue;
|
|
80
|
-
}
|
|
148
|
+
const { locale = "en-US", defaultValue = 0, ...otherOptions } = options;
|
|
149
|
+
try {
|
|
150
|
+
let convertedValue = Number(value);
|
|
151
|
+
if (value === null || Number.isNaN(convertedValue)) {
|
|
152
|
+
if (defaultValue === "") return defaultValue;
|
|
153
|
+
convertedValue = Number(defaultValue);
|
|
154
|
+
}
|
|
155
|
+
return new Intl.NumberFormat(locale, {
|
|
156
|
+
style: "currency",
|
|
157
|
+
currency,
|
|
158
|
+
minimumFractionDigits: 2,
|
|
159
|
+
maximumFractionDigits: 2,
|
|
160
|
+
...otherOptions
|
|
161
|
+
}).format(convertedValue);
|
|
162
|
+
} catch (_error) {
|
|
163
|
+
return defaultValue;
|
|
164
|
+
}
|
|
81
165
|
}
|
|
82
|
-
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/helpers/genHash.ts
|
|
83
168
|
function genHash(hashLength) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
169
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
170
|
+
let result = "";
|
|
171
|
+
for (let i = 0; i < hashLength; i++) result += chars.charAt(Math.floor(Math.random() * 62));
|
|
172
|
+
return result;
|
|
90
173
|
}
|
|
91
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/helpers/genRandomNumber.ts
|
|
92
176
|
function genRandomNumber(min, max) {
|
|
93
|
-
|
|
177
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
94
178
|
}
|
|
95
|
-
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/helpers/genUUID.ts
|
|
96
181
|
function genUUID() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
182
|
+
/**
|
|
183
|
+
* @see https://stackoverflow.com/a/8809472
|
|
184
|
+
*/
|
|
185
|
+
let d = (/* @__PURE__ */ new Date()).getTime();
|
|
186
|
+
let d2 = performance && performance.now && performance.now() * 1e3 || 0;
|
|
187
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
188
|
+
let r = Math.random() * 16;
|
|
189
|
+
if (d > 0) {
|
|
190
|
+
r = (d + r) % 16 | 0;
|
|
191
|
+
d = Math.floor(d / 16);
|
|
192
|
+
} else {
|
|
193
|
+
r = (d2 + r) % 16 | 0;
|
|
194
|
+
d2 = Math.floor(d2 / 16);
|
|
195
|
+
}
|
|
196
|
+
return (c === "x" ? r : r & 7 | 8).toString(16);
|
|
197
|
+
});
|
|
110
198
|
}
|
|
111
|
-
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/helpers/getCardNumber.ts
|
|
112
201
|
function getCardNumber(number, options) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
result = number.replace(
|
|
119
|
-
/(\d{4})?(\d{4})?(\d{4})?(\d{4})?/,
|
|
120
|
-
hasOnlyLast4 ? "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 $4" : "$1 $2 $3 $4"
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
return dot === "\u2022" ? result : result.replaceAll("\u2022", dot);
|
|
202
|
+
const { hasOnlyLast4 = false, isHidden = false, dot = "•" } = options || {};
|
|
203
|
+
let result;
|
|
204
|
+
if (isHidden) result = "•••• •••• •••• ••••";
|
|
205
|
+
else result = number.replace(/(\d{4})?(\d{4})?(\d{4})?(\d{4})?/, hasOnlyLast4 ? "•••• •••• •••• $4" : "$1 $2 $3 $4");
|
|
206
|
+
return dot === "•" ? result : result.replaceAll("•", dot);
|
|
124
207
|
}
|
|
125
|
-
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/helpers/getCountryFromPhone.ts
|
|
126
210
|
function getCountryFromPhone(phone) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
131
|
-
return phoneNumber?.country ?? "";
|
|
211
|
+
if (!phone) return "";
|
|
212
|
+
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
213
|
+
return parsePhoneNumberFromString(replacedPhone)?.country ?? "";
|
|
132
214
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return acc.concat(array);
|
|
143
|
-
}, []).some((item) => ignoredClasses.includes(item));
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/helpers/isElementIgnored.ts
|
|
217
|
+
function isElementIgnored({ ignoredClasses, event } = {}) {
|
|
218
|
+
if (ignoredClasses && event) return Array.from(event.composedPath()).filter((item) => item.nodeType && item.nodeType !== 9).reduce((acc, item) => {
|
|
219
|
+
const elementClasses = item.getAttribute("class");
|
|
220
|
+
const array = elementClasses ? elementClasses.split(" ") : [];
|
|
221
|
+
return acc.concat(array);
|
|
222
|
+
}, []).some((item) => ignoredClasses.includes(item));
|
|
223
|
+
return false;
|
|
146
224
|
}
|
|
147
|
-
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/helpers/isEmptyObject.ts
|
|
148
227
|
function isEmptyObject(object) {
|
|
149
|
-
|
|
228
|
+
return !object || !Object.keys(object).length;
|
|
150
229
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/helpers/mapDataObjectForFilters.ts
|
|
232
|
+
var optionsDefault = {
|
|
233
|
+
labelKey: "title",
|
|
234
|
+
valueKey: "",
|
|
235
|
+
excludedItems: []
|
|
156
236
|
};
|
|
157
237
|
function mapDataObjectForFilters(data, options) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}));
|
|
238
|
+
const { labelKey, valueKey, excludedItems } = {
|
|
239
|
+
...optionsDefault,
|
|
240
|
+
...options
|
|
241
|
+
};
|
|
242
|
+
return Object.entries(data).filter(([key]) => !excludedItems.includes(key)).map(([key, value]) => ({
|
|
243
|
+
label: value?.[labelKey] || "Unknown label",
|
|
244
|
+
value: value?.[valueKey] || key
|
|
245
|
+
}));
|
|
167
246
|
}
|
|
168
|
-
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/helpers/validateNumber.ts
|
|
169
249
|
function validateNumber(value, defaultValue) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return Number.isNaN(Number(value)) ? defaultValue : Number(value);
|
|
250
|
+
if (value === "") return defaultValue;
|
|
251
|
+
return Number.isNaN(Number(value)) ? defaultValue : Number(value);
|
|
173
252
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
offset: validatedPage * validatedLimit - validatedLimit
|
|
186
|
-
};
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/helpers/pagination.ts
|
|
255
|
+
var PAGE_DEFAULT = 1;
|
|
256
|
+
var LIMIT_DEFAULT = 25;
|
|
257
|
+
function getPaginationParams({ page, limit }) {
|
|
258
|
+
const validatedPage = validateNumber(page, PAGE_DEFAULT);
|
|
259
|
+
const validatedLimit = validateNumber(limit, LIMIT_DEFAULT);
|
|
260
|
+
return {
|
|
261
|
+
limit: validatedLimit,
|
|
262
|
+
offset: validatedPage * validatedLimit - validatedLimit
|
|
263
|
+
};
|
|
187
264
|
}
|
|
188
265
|
function getPaginationLimit({ limit }) {
|
|
189
|
-
|
|
266
|
+
return validateNumber(limit, LIMIT_DEFAULT);
|
|
190
267
|
}
|
|
191
|
-
function getPaginationOffset({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const validatedPage = validateNumber(page, PAGE_DEFAULT);
|
|
196
|
-
const validatedLimit = validateNumber(limit, LIMIT_DEFAULT);
|
|
197
|
-
return validatedPage * validatedLimit - validatedLimit;
|
|
268
|
+
function getPaginationOffset({ page, limit }) {
|
|
269
|
+
const validatedPage = validateNumber(page, PAGE_DEFAULT);
|
|
270
|
+
const validatedLimit = validateNumber(limit, LIMIT_DEFAULT);
|
|
271
|
+
return validatedPage * validatedLimit - validatedLimit;
|
|
198
272
|
}
|
|
199
|
-
function getPaginationPages({
|
|
200
|
-
|
|
201
|
-
limit
|
|
202
|
-
}) {
|
|
203
|
-
return Math.ceil(count / validateNumber(limit, LIMIT_DEFAULT));
|
|
273
|
+
function getPaginationPages({ count, limit }) {
|
|
274
|
+
return Math.ceil(count / validateNumber(limit, LIMIT_DEFAULT));
|
|
204
275
|
}
|
|
205
|
-
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/helpers/parsePhone.ts
|
|
206
278
|
function parsePhone(phone) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
213
|
-
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
279
|
+
if (!phone || typeof phone !== "string") return "";
|
|
280
|
+
const replacedPhone = phone.replace(/[a-zA-Z]/g, "");
|
|
281
|
+
if (replacedPhone.length === 1 && replacedPhone !== "+") return `+${replacedPhone}`;
|
|
282
|
+
const phoneNumber = parsePhoneNumberFromString(replacedPhone);
|
|
283
|
+
return phoneNumber ? phoneNumber.formatInternational() : replacedPhone;
|
|
214
284
|
}
|
|
215
|
-
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/helpers/snakelizeKeys.ts
|
|
216
287
|
function snakelizeKeys(prop) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
[snakeCase(current)]: snakelizeKeys(prop[current])
|
|
224
|
-
}),
|
|
225
|
-
{}
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
return prop;
|
|
288
|
+
if (Array.isArray(prop)) return prop.map((item) => snakelizeKeys(item));
|
|
289
|
+
if (prop !== null && prop !== void 0 && prop.constructor === Object) return Object.keys(prop).reduce((accum, current) => ({
|
|
290
|
+
...accum,
|
|
291
|
+
[snakeCase(current)]: snakelizeKeys(prop[current])
|
|
292
|
+
}), {});
|
|
293
|
+
return prop;
|
|
229
294
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/helpers/unformatNumber.ts
|
|
297
|
+
var LOCALE_RU = "ru-RU";
|
|
298
|
+
var LOCALE_EN = "en-US";
|
|
299
|
+
/**
|
|
300
|
+
* Принимает на вход число в виде строки или числа,
|
|
301
|
+
* возвращает корректное значение типа Number (убирает лишние пробелы и запятые)
|
|
302
|
+
* @example
|
|
303
|
+
* // returns 1000
|
|
304
|
+
* unformatNumber('1 000');
|
|
305
|
+
* @example
|
|
306
|
+
* // returns 1000
|
|
307
|
+
* unformatNumber('1,000')
|
|
308
|
+
* @example
|
|
309
|
+
* // returns 1000.123
|
|
310
|
+
* unformatNummber('1 000,123')
|
|
311
|
+
* @example
|
|
312
|
+
* // returns 1000.123
|
|
313
|
+
* unformatNummber('1,000.123')
|
|
314
|
+
* @param value
|
|
315
|
+
* @return number
|
|
316
|
+
*/
|
|
233
317
|
function unformatNumber(value) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (hasComma && !hasSpace && !hasDot && commasCount > 1)
|
|
254
|
-
locale = LOCALE_EN;
|
|
255
|
-
if (commasCount === 1 && !hasSpace && !hasDot) {
|
|
256
|
-
locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
257
|
-
}
|
|
258
|
-
if (locale === LOCALE_RU)
|
|
259
|
-
return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
260
|
-
if (locale === LOCALE_EN)
|
|
261
|
-
return Number(string.replaceAll(",", ""));
|
|
262
|
-
return value;
|
|
318
|
+
if (!value || typeof value !== "string") return value;
|
|
319
|
+
const string = value.trim();
|
|
320
|
+
let locale;
|
|
321
|
+
const spaceIndex = string.lastIndexOf(" ");
|
|
322
|
+
const commaIndex = string.lastIndexOf(",");
|
|
323
|
+
const dotIndex = string.lastIndexOf(".");
|
|
324
|
+
const hasSpace = spaceIndex !== -1;
|
|
325
|
+
const hasComma = commaIndex !== -1;
|
|
326
|
+
const hasDot = dotIndex !== -1;
|
|
327
|
+
const commasCount = (string.match(/,/g) || []).length;
|
|
328
|
+
if (!Number.isNaN(Number(string))) return Number(string);
|
|
329
|
+
if (hasSpace && hasComma && commaIndex > spaceIndex) locale = LOCALE_RU;
|
|
330
|
+
if (hasSpace && !hasComma && !hasDot) locale = LOCALE_RU;
|
|
331
|
+
if (hasComma && hasDot && dotIndex > commaIndex) locale = LOCALE_EN;
|
|
332
|
+
if (hasComma && !hasSpace && !hasDot && commasCount > 1) locale = LOCALE_EN;
|
|
333
|
+
if (commasCount === 1 && !hasSpace && !hasDot) locale = string.length - 1 - commaIndex === 3 ? LOCALE_EN : LOCALE_RU;
|
|
334
|
+
if (locale === LOCALE_RU) return Number(string.replaceAll(" ", "").replace(",", "."));
|
|
335
|
+
if (locale === LOCALE_EN) return Number(string.replaceAll(",", ""));
|
|
336
|
+
return value;
|
|
263
337
|
}
|
|
264
|
-
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/helpers/uiComponentsResolver.ts
|
|
265
340
|
function UiComponentsResolver(options = {}) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
341
|
+
const { prefix = "" } = options;
|
|
342
|
+
return (name) => {
|
|
343
|
+
const componentName = prefix && name.startsWith(prefix) ? name.substring(prefix.length) : name;
|
|
344
|
+
if (componentName.startsWith("Ui")) return {
|
|
345
|
+
name: componentName,
|
|
346
|
+
from: "@karta.io/ui-components"
|
|
347
|
+
};
|
|
348
|
+
};
|
|
273
349
|
}
|
|
274
|
-
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/hooks/useAbortController.ts
|
|
275
352
|
function useAbortController(callback) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (!controller)
|
|
297
|
-
return;
|
|
298
|
-
controller.abort();
|
|
299
|
-
controller = null;
|
|
300
|
-
},
|
|
301
|
-
isAborted(error) {
|
|
302
|
-
return error.status === 418;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
353
|
+
let controller = null;
|
|
354
|
+
return {
|
|
355
|
+
async call(...args) {
|
|
356
|
+
if (controller) controller.abort();
|
|
357
|
+
controller = new AbortController();
|
|
358
|
+
let response;
|
|
359
|
+
if (args.length > 0) response = await callback(...args, { signal: controller.signal });
|
|
360
|
+
else response = await callback({ signal: controller.signal });
|
|
361
|
+
controller = null;
|
|
362
|
+
return response;
|
|
363
|
+
},
|
|
364
|
+
abort() {
|
|
365
|
+
if (!controller) return;
|
|
366
|
+
controller.abort();
|
|
367
|
+
controller = null;
|
|
368
|
+
},
|
|
369
|
+
isAborted(error) {
|
|
370
|
+
return error.status === 418;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
305
373
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
isError,
|
|
341
|
-
data,
|
|
342
|
-
error,
|
|
343
|
-
items,
|
|
344
|
-
count,
|
|
345
|
-
refetch,
|
|
346
|
-
reload,
|
|
347
|
-
abort
|
|
348
|
-
};
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/hooks/useAsyncItems.ts
|
|
376
|
+
function useAsyncItems({ apiMethod, queryKey, params, config = void 0 }) {
|
|
377
|
+
const getQueryKey = () => [queryKey, params];
|
|
378
|
+
const { call, abort } = useAbortController(apiMethod);
|
|
379
|
+
const { isLoading, isFetching, isError, data, error } = useQuery({
|
|
380
|
+
queryKey: getQueryKey(),
|
|
381
|
+
queryFn: () => call(toValue(params), config)
|
|
382
|
+
});
|
|
383
|
+
const items = computed(() => data.value?.results || []);
|
|
384
|
+
const count = ref(0);
|
|
385
|
+
watch(data, (newValue) => {
|
|
386
|
+
if (newValue === void 0 || newValue.count === void 0) return;
|
|
387
|
+
count.value = newValue.count;
|
|
388
|
+
}, { immediate: true });
|
|
389
|
+
const queryClient = useQueryClient();
|
|
390
|
+
const refetch = () => {
|
|
391
|
+
queryClient.invalidateQueries({ queryKey: getQueryKey() });
|
|
392
|
+
};
|
|
393
|
+
const reload = () => {
|
|
394
|
+
queryClient.resetQueries({ queryKey: getQueryKey() });
|
|
395
|
+
};
|
|
396
|
+
return {
|
|
397
|
+
isLoading,
|
|
398
|
+
isFetching,
|
|
399
|
+
isError,
|
|
400
|
+
data,
|
|
401
|
+
error,
|
|
402
|
+
items,
|
|
403
|
+
count,
|
|
404
|
+
refetch,
|
|
405
|
+
reload,
|
|
406
|
+
abort
|
|
407
|
+
};
|
|
349
408
|
}
|
|
350
|
-
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/hooks/useLogger.ts
|
|
411
|
+
/**
|
|
412
|
+
* @see https://github.com/caiogondim/logdown.js#readme
|
|
413
|
+
*/
|
|
351
414
|
function isEnabled(options) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const debug = process.env.NODE_DEBUG;
|
|
365
|
-
if (debug === "true")
|
|
366
|
-
return true;
|
|
367
|
-
if (debug === "false")
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
return false;
|
|
415
|
+
if (options?.debug !== void 0) return options.debug;
|
|
416
|
+
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
|
|
417
|
+
const debug = localStorage.getItem("debug");
|
|
418
|
+
if (debug === "true") return true;
|
|
419
|
+
if (debug === "false") return false;
|
|
420
|
+
}
|
|
421
|
+
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
|
|
422
|
+
const debug = process.env.NODE_DEBUG;
|
|
423
|
+
if (debug === "true") return true;
|
|
424
|
+
if (debug === "false") return false;
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
371
427
|
}
|
|
372
428
|
function useLogger(scope, options) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
429
|
+
const prefix = options?.tag ? `[${scope.toUpperCase()}.${options.tag}]:` : `[${scope.toUpperCase()}]:`;
|
|
430
|
+
const logger = logdown(prefix, { prefixColor: options?.color });
|
|
431
|
+
logger.state.isEnabled = isEnabled(options);
|
|
432
|
+
return logger;
|
|
377
433
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/hooks/useAsyncMultiselect.ts
|
|
436
|
+
function useAsyncMultiselect({ apiMethod, mapOptionCallback = void 0, selectedValues = void 0, params = void 0, queryKey, dataItemsKey = "results", dataItemIdKey = "id", dataCountKey = "count", delay = 300, onUpdated = void 0 }) {
|
|
437
|
+
const logger = useLogger("UTILS", {
|
|
438
|
+
tag: "useAsyncMultiselect",
|
|
439
|
+
color: "#b54708",
|
|
440
|
+
debug: true
|
|
441
|
+
});
|
|
442
|
+
const paramsForLogger = {
|
|
443
|
+
queryKey,
|
|
444
|
+
dataItemsKey,
|
|
445
|
+
dataItemIdKey,
|
|
446
|
+
dataCountKey
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Это объект прокидывается как доп данные для queryKey.
|
|
450
|
+
* Если сделать отдельные ref на search, page и тд, то возникают кейсы,
|
|
451
|
+
* когда нужно обновить одновременно несколько параметров (например selectedValues и page),
|
|
452
|
+
* чтобы не получить лишние запросы от vue-query.
|
|
453
|
+
*/
|
|
454
|
+
const reactiveData = reactive({
|
|
455
|
+
search: "",
|
|
456
|
+
page: 1,
|
|
457
|
+
selectedValues: toValue(selectedValues),
|
|
458
|
+
params: JSON.stringify(toValue(params))
|
|
459
|
+
});
|
|
460
|
+
/**
|
|
461
|
+
* search в данном случае используется чисто как переменная для хранения актуального состояния
|
|
462
|
+
* А в асинхронную функцию уже передается reactiveData.search, который изменяется с задержкой
|
|
463
|
+
*/
|
|
464
|
+
const search = ref("");
|
|
465
|
+
const { call, abort } = useAbortController(apiMethod);
|
|
466
|
+
const loadWAC = () => {
|
|
467
|
+
/**
|
|
468
|
+
* Добавил возможность добавлять в params includedIds
|
|
469
|
+
* для кейсов "выталкивания" наверх определенных пунктов
|
|
470
|
+
*/
|
|
471
|
+
const includedIdsBySelectedValues = reactiveData.selectedValues ?? [];
|
|
472
|
+
const includedIdsByParams = (Boolean(reactiveData.params) && JSON.parse(reactiveData.params || {})?.includedIds) ?? [];
|
|
473
|
+
const includedIds = union(includedIdsBySelectedValues, includedIdsByParams);
|
|
474
|
+
return call({
|
|
475
|
+
page: reactiveData.page,
|
|
476
|
+
search: reactiveData.search,
|
|
477
|
+
...reactiveData.params && { ...JSON.parse(reactiveData.params) },
|
|
478
|
+
...includedIds.length && { includedIds }
|
|
479
|
+
});
|
|
480
|
+
};
|
|
481
|
+
const { data, isFetching, isLoading } = useQuery({
|
|
482
|
+
queryKey: [queryKey, reactiveData],
|
|
483
|
+
queryFn: loadWAC
|
|
484
|
+
});
|
|
485
|
+
const itemsByPages = ref(null);
|
|
486
|
+
const count = ref(0);
|
|
487
|
+
/**
|
|
488
|
+
* Сохраняем элементы, полученные из includedIds во внутреннюю память,
|
|
489
|
+
* чтобы корректно работать с кейсом, когда у нас активен поиск и есть selectedValues
|
|
490
|
+
*/
|
|
491
|
+
const selectedItemsCached = ref([]);
|
|
492
|
+
watch(data, (newValue) => {
|
|
493
|
+
if (!newValue) return;
|
|
494
|
+
if (!has(newValue, dataItemsKey)) {
|
|
495
|
+
logger.warn(`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`, paramsForLogger);
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (!has(newValue, dataCountKey)) {
|
|
499
|
+
logger.warn(`Unable to find key *"${dataCountKey}"* (property "dataCountKey") in data object from API.`, paramsForLogger);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) return;
|
|
503
|
+
count.value = get(newValue, dataCountKey, 0);
|
|
504
|
+
const newItems = get(newValue, dataItemsKey);
|
|
505
|
+
/**
|
|
506
|
+
* Проверка на номер страницы очень важна:
|
|
507
|
+
*
|
|
508
|
+
* Если номер равен 1, то мы предполагаем,
|
|
509
|
+
* что изменилось одно из ключевых реактивных свойств (search, SelectedValue, params),
|
|
510
|
+
* а значит нам нужно полностью удалить все лишние данные для остальных страниц.
|
|
511
|
+
*
|
|
512
|
+
* Если номер больше 1, то мы лишь продолжаем формировать нашу "бесконечную" ленту - предыдущие данные остаются
|
|
513
|
+
*/
|
|
514
|
+
itemsByPages.value = {
|
|
515
|
+
...reactiveData.page !== 1 && itemsByPages.value,
|
|
516
|
+
[reactiveData.page]: newItems
|
|
517
|
+
};
|
|
518
|
+
if (reactiveData.page === 1 && reactiveData.selectedValues?.length && !reactiveData.search) {
|
|
519
|
+
if (newItems.some((item) => !has(item, dataItemIdKey))) logger.warn(`Unable to find key *"${dataItemIdKey}"* (property "dataItemIdKey") in items from API.`, "This key must be match with \"optionValue\" in UiMultiselect.", paramsForLogger);
|
|
520
|
+
selectedItemsCached.value = newItems.filter((item) => reactiveData.selectedValues.includes(get(item, dataItemIdKey)));
|
|
521
|
+
}
|
|
522
|
+
onUpdated?.({
|
|
523
|
+
search: reactiveData.search,
|
|
524
|
+
page: reactiveData.page,
|
|
525
|
+
selectedValues: reactiveData.selectedValues,
|
|
526
|
+
params: reactiveData.params ? JSON.parse(reactiveData.params) : void 0
|
|
527
|
+
});
|
|
528
|
+
}, { immediate: true });
|
|
529
|
+
const items = computed(() => {
|
|
530
|
+
if (!itemsByPages.value) return selectedItemsCached.value;
|
|
531
|
+
if (!Object.keys(itemsByPages.value).length) return selectedItemsCached.value;
|
|
532
|
+
const itemsByPagesAsArray = Object.values(itemsByPages.value).reduce((acc, item) => [...acc, ...item], []);
|
|
533
|
+
return [...[...selectedItemsCached.value, ...itemsByPagesAsArray].reduce((acc, item) => {
|
|
534
|
+
const key = get(item, dataItemIdKey, JSON.stringify(item));
|
|
535
|
+
return acc.set(key, item);
|
|
536
|
+
}, /* @__PURE__ */ new Map()).values()];
|
|
537
|
+
});
|
|
538
|
+
const options = computed(() => {
|
|
539
|
+
if (!items.value.length) return [];
|
|
540
|
+
if (!mapOptionCallback) return items.value;
|
|
541
|
+
return items.value.map(mapOptionCallback);
|
|
542
|
+
});
|
|
543
|
+
const hasNextPage = computed(() => count.value > items.value.length);
|
|
544
|
+
const loadPage = (newPage = 1) => {
|
|
545
|
+
reactiveData.page = newPage;
|
|
546
|
+
/**
|
|
547
|
+
* Изменение reactiveData генерирует новый запрос в API с за данными.
|
|
548
|
+
*
|
|
549
|
+
* Но нам нужно обрабатывать кейс с closeAfterSelect=true у UiMultiselect.
|
|
550
|
+
* В этом случае дропдаун не закрывается и, если добавляем новое значение
|
|
551
|
+
* на 3ей, 4ой и тд странице, то перезапрос данных обнулит пагинацию и начнет
|
|
552
|
+
* загружать все с 1ой страницы.
|
|
553
|
+
*
|
|
554
|
+
* Для обработки такого кейсы мы обновляем selectedValues в reactiveData только если:
|
|
555
|
+
* 1. Страница сброшена до 1ой
|
|
556
|
+
* 2. Изменилось значение поиска, а значит смотри пункт 1
|
|
557
|
+
* 3. Изменилось значение params, а значит смотри пункт 1
|
|
558
|
+
*/
|
|
559
|
+
if (newPage === 1) reactiveData.selectedValues = toValue(selectedValues);
|
|
560
|
+
};
|
|
561
|
+
const updateSearchWithDebounce = useDebounceFn((value) => {
|
|
562
|
+
reactiveData.search = value;
|
|
563
|
+
reactiveData.page = 1;
|
|
564
|
+
reactiveData.selectedValues = toValue(selectedValues);
|
|
565
|
+
}, delay);
|
|
566
|
+
const updateSearch = (value) => {
|
|
567
|
+
search.value = value;
|
|
568
|
+
updateSearchWithDebounce(value);
|
|
569
|
+
};
|
|
570
|
+
const queryClient = useQueryClient();
|
|
571
|
+
const refetch = () => {
|
|
572
|
+
/**
|
|
573
|
+
* Такой кейс может быть полезен при обновлении value в UiMultiselect.
|
|
574
|
+
*
|
|
575
|
+
* Если страница не первая:
|
|
576
|
+
*
|
|
577
|
+
* Вначале помечаем все запросы по ключу устаревшими.
|
|
578
|
+
* refetchType: 'none' - предотвращает refetch по активному ключу.
|
|
579
|
+
* Это нужно для того, чтобы не запрашивать последнюю страницу.
|
|
580
|
+
*
|
|
581
|
+
* Переключаем страницу вручную - сразу происходит reFetch именно первой страницы.
|
|
582
|
+
*
|
|
583
|
+
* Если страница первая:
|
|
584
|
+
*
|
|
585
|
+
* Делаем обычный queryClient.invalidateQueries,
|
|
586
|
+
* функция сама сделает refetch.
|
|
587
|
+
*
|
|
588
|
+
* isLoading: false
|
|
589
|
+
* isFetching: true
|
|
590
|
+
*/
|
|
591
|
+
if (reactiveData.page !== 1) {
|
|
592
|
+
queryClient.invalidateQueries({
|
|
593
|
+
queryKey: [queryKey],
|
|
594
|
+
refetchType: "none"
|
|
595
|
+
});
|
|
596
|
+
loadPage(1);
|
|
597
|
+
} else queryClient.invalidateQueries({ queryKey: [queryKey] });
|
|
598
|
+
};
|
|
599
|
+
const reload = () => {
|
|
600
|
+
/**
|
|
601
|
+
* Такой кейс может быть полезен при добавлении в UiMultiselect нового value.
|
|
602
|
+
*
|
|
603
|
+
* Если страница не первая:
|
|
604
|
+
*
|
|
605
|
+
* queryClient.resetQueries не имеет опции refetchType: 'none'
|
|
606
|
+
* и по умолчанию делает refetch последней активной страницы.
|
|
607
|
+
*
|
|
608
|
+
* Поэтому используем queryClient.removeQueries - он удаляет все запросы по ключу из кэша.
|
|
609
|
+
*
|
|
610
|
+
* Переключаем страницу вручную - сразу происходит fetch именно первой страницы.
|
|
611
|
+
*
|
|
612
|
+
* Если страница первая:
|
|
613
|
+
*
|
|
614
|
+
* Делаем обычный queryClient.resetQueries,
|
|
615
|
+
* функция сама сделает refetch.
|
|
616
|
+
*
|
|
617
|
+
* isLoading: true
|
|
618
|
+
* isFetching: true
|
|
619
|
+
*/
|
|
620
|
+
if (reactiveData.page !== 1) {
|
|
621
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
622
|
+
loadPage(1);
|
|
623
|
+
} else queryClient.resetQueries({ queryKey: [queryKey] });
|
|
624
|
+
};
|
|
625
|
+
if (isRef(selectedValues)) watch(selectedValues, async (newSelectedValues) => {
|
|
626
|
+
if (!newSelectedValues.length) selectedItemsCached.value = [];
|
|
627
|
+
else {
|
|
628
|
+
if (items.value.some((item) => !has(item, dataItemIdKey))) logger.warn(`Unable to find key *"${dataItemIdKey}"* (property "dataItemIdKey") in items from API.`, "This key must be match with \"optionValue\" in UiMultiselect.", paramsForLogger);
|
|
629
|
+
selectedItemsCached.value = items.value.filter((item) => newSelectedValues.includes(get(item, dataItemIdKey)));
|
|
630
|
+
}
|
|
631
|
+
await nextTick();
|
|
632
|
+
if (reactiveData.page === 1) reactiveData.selectedValues = newSelectedValues;
|
|
633
|
+
});
|
|
634
|
+
if (isRef(params)) watch(params, (newParams) => {
|
|
635
|
+
reactiveData.page = 1;
|
|
636
|
+
reactiveData.params = JSON.stringify(newParams);
|
|
637
|
+
reactiveData.selectedValues = toValue(selectedValues);
|
|
638
|
+
});
|
|
639
|
+
onBeforeUnmount(() => {
|
|
640
|
+
abort?.();
|
|
641
|
+
});
|
|
642
|
+
return {
|
|
643
|
+
items,
|
|
644
|
+
options,
|
|
645
|
+
search,
|
|
646
|
+
hasNextPage,
|
|
647
|
+
isFetching,
|
|
648
|
+
isLoading,
|
|
649
|
+
loadPage,
|
|
650
|
+
updateSearch,
|
|
651
|
+
refetch,
|
|
652
|
+
reload
|
|
653
|
+
};
|
|
552
654
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region src/hooks/useAsyncSelect.ts
|
|
657
|
+
function useAsyncSelect({ apiMethod, mapOptionCallback = void 0, selectedValue = void 0, params = void 0, queryKey, dataItemsKey = "results", dataCountKey = "count", delay = 300, onUpdated = void 0 }) {
|
|
658
|
+
const logger = useLogger("UTILS", {
|
|
659
|
+
tag: "useAsyncSelect",
|
|
660
|
+
color: "#b54708",
|
|
661
|
+
debug: true
|
|
662
|
+
});
|
|
663
|
+
const paramsForLogger = {
|
|
664
|
+
queryKey,
|
|
665
|
+
dataItemsKey,
|
|
666
|
+
dataCountKey
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Это объект прокидывается как доп данные для queryKey.
|
|
670
|
+
* Если сделать отдельные ref на search, page и тд, то возникают кейсы,
|
|
671
|
+
* когда нужно обновить одновременно несколько параметров (например selectedValue и page),
|
|
672
|
+
* чтобы не получить лишние запросы от vue-query.
|
|
673
|
+
*/
|
|
674
|
+
const reactiveData = reactive({
|
|
675
|
+
search: "",
|
|
676
|
+
page: 1,
|
|
677
|
+
selectedValue: toValue(selectedValue),
|
|
678
|
+
params: JSON.stringify(toValue(params))
|
|
679
|
+
});
|
|
680
|
+
/**
|
|
681
|
+
* search в данном случае используется чисто как переменная для хранения актуального состояния
|
|
682
|
+
* А в асинхронную функцию уже передается reactiveData.search, который изменяется с задержкой
|
|
683
|
+
*/
|
|
684
|
+
const search = ref("");
|
|
685
|
+
const { call, abort } = useAbortController(apiMethod);
|
|
686
|
+
const loadWAC = () => call({
|
|
687
|
+
page: reactiveData.page,
|
|
688
|
+
search: reactiveData.search,
|
|
689
|
+
...reactiveData.selectedValue && { includedIds: [reactiveData.selectedValue] },
|
|
690
|
+
...reactiveData.params && { ...JSON.parse(reactiveData.params) }
|
|
691
|
+
});
|
|
692
|
+
const { data, isFetching, isLoading } = useQuery({
|
|
693
|
+
queryKey: [queryKey, reactiveData],
|
|
694
|
+
queryFn: loadWAC
|
|
695
|
+
});
|
|
696
|
+
const itemsByPages = ref(null);
|
|
697
|
+
const count = ref(0);
|
|
698
|
+
watch(data, (newValue) => {
|
|
699
|
+
if (!newValue) return;
|
|
700
|
+
if (!has(newValue, dataItemsKey)) {
|
|
701
|
+
logger.warn(`Unable to find key *"${dataItemsKey}"* (property "dataItemsKey") in data object from API.`, paramsForLogger);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (!has(newValue, dataCountKey)) {
|
|
705
|
+
logger.warn(`Unable to find key *"${dataCountKey}"* (property "dataCountKey") in data object from API.`, paramsForLogger);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (!get(newValue, dataItemsKey) || get(newValue, dataCountKey) === void 0) return;
|
|
709
|
+
count.value = get(newValue, dataCountKey, 0);
|
|
710
|
+
const newItems = get(newValue, dataItemsKey);
|
|
711
|
+
/**
|
|
712
|
+
* Проверка на номер страницы очень важна:
|
|
713
|
+
*
|
|
714
|
+
* Если номер равен 1, то мы предполагаем,
|
|
715
|
+
* что изменилось одно из ключевых реактивных свойств (search, SelectedValue, params),
|
|
716
|
+
* а значит нам нужно полностью удалить все лишние данные для остальных страниц.
|
|
717
|
+
*
|
|
718
|
+
* Если номер больше 1, то мы лишь продолжаем формировать нашу "бесконечную" ленту - предыдущие данные остаются
|
|
719
|
+
*/
|
|
720
|
+
itemsByPages.value = {
|
|
721
|
+
...reactiveData.page !== 1 && itemsByPages.value,
|
|
722
|
+
[reactiveData.page]: newItems
|
|
723
|
+
};
|
|
724
|
+
onUpdated?.({
|
|
725
|
+
search: reactiveData.search,
|
|
726
|
+
page: reactiveData.page,
|
|
727
|
+
selectedValue: reactiveData.selectedValue,
|
|
728
|
+
params: reactiveData.params ? JSON.parse(reactiveData.params) : void 0
|
|
729
|
+
});
|
|
730
|
+
}, { immediate: true });
|
|
731
|
+
const items = computed(() => {
|
|
732
|
+
if (!itemsByPages.value) return [];
|
|
733
|
+
if (!Object.keys(itemsByPages.value).length) return [];
|
|
734
|
+
return Object.values(itemsByPages.value).reduce((acc, item) => [...acc, ...item], []);
|
|
735
|
+
});
|
|
736
|
+
const options = computed(() => {
|
|
737
|
+
if (!items.value.length) return [];
|
|
738
|
+
if (!mapOptionCallback) return items.value;
|
|
739
|
+
return items.value.map(mapOptionCallback);
|
|
740
|
+
});
|
|
741
|
+
const hasNextPage = computed(() => count.value > items.value.length);
|
|
742
|
+
const loadPage = (newPage = 1) => {
|
|
743
|
+
reactiveData.page = newPage;
|
|
744
|
+
};
|
|
745
|
+
const updateSearchWithDebounce = useDebounceFn((value) => {
|
|
746
|
+
reactiveData.search = value;
|
|
747
|
+
reactiveData.page = 1;
|
|
748
|
+
}, delay);
|
|
749
|
+
const updateSearch = (value) => {
|
|
750
|
+
search.value = value;
|
|
751
|
+
updateSearchWithDebounce(value);
|
|
752
|
+
};
|
|
753
|
+
const queryClient = useQueryClient();
|
|
754
|
+
const refetch = () => {
|
|
755
|
+
/**
|
|
756
|
+
* Такой кейс может быть полезен при обновлении value в UiSelect.
|
|
757
|
+
*
|
|
758
|
+
* Если страница не первая:
|
|
759
|
+
*
|
|
760
|
+
* Вначале помечаем все запросы по ключу устаревшими.
|
|
761
|
+
* refetchType: 'none' - предотвращает refetch по активному ключу.
|
|
762
|
+
* Это нужно для того, чтобы не запрашивать последнюю страницу.
|
|
763
|
+
*
|
|
764
|
+
* Переключаем страницу вручную - сразу происходит reFetch именно первой страницы.
|
|
765
|
+
*
|
|
766
|
+
* Если страница первая:
|
|
767
|
+
*
|
|
768
|
+
* Делаем обычный queryClient.invalidateQueries,
|
|
769
|
+
* функция сама сделает refetch.
|
|
770
|
+
*
|
|
771
|
+
* isLoading: false
|
|
772
|
+
* isFetching: true
|
|
773
|
+
*/
|
|
774
|
+
if (reactiveData.page !== 1) {
|
|
775
|
+
queryClient.invalidateQueries({
|
|
776
|
+
queryKey: [queryKey],
|
|
777
|
+
refetchType: "none"
|
|
778
|
+
});
|
|
779
|
+
loadPage(1);
|
|
780
|
+
} else queryClient.invalidateQueries({ queryKey: [queryKey] });
|
|
781
|
+
};
|
|
782
|
+
const reload = () => {
|
|
783
|
+
/**
|
|
784
|
+
* Такой кейс может быть полезен при добавлении в UiSelect нового value.
|
|
785
|
+
*
|
|
786
|
+
* Если страница не первая:
|
|
787
|
+
*
|
|
788
|
+
* queryClient.resetQueries не имеет опции refetchType: 'none'
|
|
789
|
+
* и по умолчанию делает refetch последней активной страницы.
|
|
790
|
+
*
|
|
791
|
+
* Поэтому используем queryClient.removeQueries - он удаляет все запросы по ключу из кэша.
|
|
792
|
+
*
|
|
793
|
+
* Переключаем страницу вручную - сразу происходит fetch именно первой страницы.
|
|
794
|
+
*
|
|
795
|
+
* Если страница первая:
|
|
796
|
+
*
|
|
797
|
+
* Делаем обычный queryClient.resetQueries,
|
|
798
|
+
* функция сама сделает refetch.
|
|
799
|
+
*
|
|
800
|
+
* isLoading: true
|
|
801
|
+
* isFetching: true
|
|
802
|
+
*/
|
|
803
|
+
if (reactiveData.page !== 1) {
|
|
804
|
+
queryClient.removeQueries({ queryKey: [queryKey] });
|
|
805
|
+
loadPage(1);
|
|
806
|
+
} else queryClient.resetQueries({ queryKey: [queryKey] });
|
|
807
|
+
};
|
|
808
|
+
if (isRef(selectedValue)) watch(selectedValue, (newSelectedValue) => {
|
|
809
|
+
reactiveData.page = 1;
|
|
810
|
+
reactiveData.selectedValue = newSelectedValue;
|
|
811
|
+
});
|
|
812
|
+
if (isRef(params)) watch(params, (newParams) => {
|
|
813
|
+
reactiveData.page = 1;
|
|
814
|
+
reactiveData.params = JSON.stringify(newParams);
|
|
815
|
+
});
|
|
816
|
+
onBeforeUnmount(() => {
|
|
817
|
+
abort?.();
|
|
818
|
+
});
|
|
819
|
+
return {
|
|
820
|
+
items,
|
|
821
|
+
options,
|
|
822
|
+
search,
|
|
823
|
+
hasNextPage,
|
|
824
|
+
isFetching,
|
|
825
|
+
isLoading,
|
|
826
|
+
loadPage,
|
|
827
|
+
updateSearch,
|
|
828
|
+
refetch,
|
|
829
|
+
reload
|
|
830
|
+
};
|
|
681
831
|
}
|
|
682
|
-
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region src/hooks/useBreakpoint.ts
|
|
683
834
|
function useBreakpoint() {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
isDesktop,
|
|
696
|
-
isGreaterXxs,
|
|
697
|
-
isGreaterXs,
|
|
698
|
-
isGreaterSm,
|
|
699
|
-
isGreaterMd,
|
|
700
|
-
isGreaterLg,
|
|
701
|
-
isGreaterXl
|
|
702
|
-
};
|
|
835
|
+
const breakpoints = useBreakpoints(BREAKPOINTS);
|
|
836
|
+
return {
|
|
837
|
+
isMobile: breakpoints.smaller("sm"),
|
|
838
|
+
isDesktop: breakpoints.greaterOrEqual("md"),
|
|
839
|
+
isGreaterXxs: breakpoints.greaterOrEqual("xxs"),
|
|
840
|
+
isGreaterXs: breakpoints.greaterOrEqual("xs"),
|
|
841
|
+
isGreaterSm: breakpoints.greaterOrEqual("sm"),
|
|
842
|
+
isGreaterMd: breakpoints.greaterOrEqual("md"),
|
|
843
|
+
isGreaterLg: breakpoints.greaterOrEqual("lg"),
|
|
844
|
+
isGreaterXl: breakpoints.greaterOrEqual("xl")
|
|
845
|
+
};
|
|
703
846
|
}
|
|
704
|
-
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region src/hooks/useClassName.ts
|
|
705
849
|
function _bem(block, blockSuffix, element, modifier, modifierValue) {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
cls += `_${modifier}`;
|
|
713
|
-
if (modifierValue)
|
|
714
|
-
cls += `_${modifierValue}`;
|
|
715
|
-
return cls;
|
|
850
|
+
let cls = block;
|
|
851
|
+
if (blockSuffix) cls += `-${blockSuffix}`;
|
|
852
|
+
if (element) cls += `__${element}`;
|
|
853
|
+
if (modifier) cls += `_${modifier}`;
|
|
854
|
+
if (modifierValue) cls += `_${modifierValue}`;
|
|
855
|
+
return cls;
|
|
716
856
|
}
|
|
717
857
|
function useClassName(block) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
cssVarName
|
|
739
|
-
};
|
|
858
|
+
const b = (blockSuffix = "") => _bem(block, blockSuffix, "", "", "");
|
|
859
|
+
const e = (element) => element ? _bem(block, "", element, "", "") : "";
|
|
860
|
+
const m = (modifier, condition = true) => modifier && condition ? _bem(block, "", "", modifier, "") : "";
|
|
861
|
+
const em = (element, modifier, condition = true) => element && modifier && condition ? _bem(block, "", element, modifier, "") : "";
|
|
862
|
+
const mv = (modifier, modifierValue, condition = true) => modifier && modifierValue && condition ? _bem(block, "", "", modifier, modifierValue) : "";
|
|
863
|
+
const cssVar = (object) => {
|
|
864
|
+
const styles = {};
|
|
865
|
+
for (const key in object) styles[`--${block}-${key}`] = object[key];
|
|
866
|
+
return styles;
|
|
867
|
+
};
|
|
868
|
+
const cssVarName = (name) => `--${block}-${name}`;
|
|
869
|
+
return {
|
|
870
|
+
b,
|
|
871
|
+
e,
|
|
872
|
+
m,
|
|
873
|
+
em,
|
|
874
|
+
mv,
|
|
875
|
+
cssVar,
|
|
876
|
+
cssVarName
|
|
877
|
+
};
|
|
740
878
|
}
|
|
741
|
-
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/hooks/useDayjs.ts
|
|
742
881
|
dayjs.extend(utc);
|
|
743
882
|
dayjs.extend(tz);
|
|
744
883
|
dayjs.extend(updateLocale);
|
|
745
884
|
dayjs.extend(isToday);
|
|
746
885
|
dayjs.extend(customParseFormat);
|
|
886
|
+
/**
|
|
887
|
+
* Обертка над dayjs, позволяющая задавать timezone
|
|
888
|
+
* @see https://day.js.org/en/
|
|
889
|
+
*
|
|
890
|
+
* Использовать параметр timezone нужно крайне аккуратно,
|
|
891
|
+
* может привести к утечкам памяти
|
|
892
|
+
* @todo Подумать как сделать оптимальнее
|
|
893
|
+
*/
|
|
747
894
|
function useDayjs(timezone) {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
return dayjs;
|
|
753
|
-
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
754
|
-
return dayjsExtended;
|
|
895
|
+
dayjs.updateLocale("en", { weekStart: 1 });
|
|
896
|
+
if (!timezone) return dayjs;
|
|
897
|
+
const dayjsExtended = (date, format, locale, strict) => dayjs(date, format, locale, strict).tz(timezone);
|
|
898
|
+
return dayjsExtended;
|
|
755
899
|
}
|
|
756
|
-
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/hooks/useDetectBrowser.ts
|
|
757
902
|
function parseVersion(version) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
build
|
|
767
|
-
};
|
|
903
|
+
if (typeof version !== "string" && typeof version !== "number") throw new TypeError("Browser version must be type of string, number or negative boolean");
|
|
904
|
+
const [major, minor = 0, patch = 0, build = 0] = typeof version === "string" ? version.split(".").map(Number) : [version];
|
|
905
|
+
return {
|
|
906
|
+
major,
|
|
907
|
+
minor,
|
|
908
|
+
patch,
|
|
909
|
+
build
|
|
910
|
+
};
|
|
768
911
|
}
|
|
769
912
|
function isVersionLower(minimum, target) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
913
|
+
for (const k of [
|
|
914
|
+
"major",
|
|
915
|
+
"minor",
|
|
916
|
+
"patch"
|
|
917
|
+
]) if (minimum[k] !== target[k]) return minimum[k] > target[k];
|
|
918
|
+
return minimum.build > target.build;
|
|
775
919
|
}
|
|
776
920
|
function useDetectBrowser(versions, userAgent) {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
const rule = versions[browserInfo.name];
|
|
792
|
-
return Object.freeze({
|
|
793
|
-
isDeprecated: rule !== void 0 ? rule === false || isVersionLower(parseVersion(rule), parseVersion(browserInfo.version)) : false,
|
|
794
|
-
...browserInfo,
|
|
795
|
-
options: Object.freeze(versions)
|
|
796
|
-
});
|
|
921
|
+
const browserInfo = {};
|
|
922
|
+
if (userAgent) Object.assign(browserInfo, userAgent ? detect(userAgent) : {
|
|
923
|
+
name: null,
|
|
924
|
+
version: null,
|
|
925
|
+
type: null,
|
|
926
|
+
os: null
|
|
927
|
+
});
|
|
928
|
+
else Object.assign(browserInfo, detect());
|
|
929
|
+
const rule = versions[browserInfo.name];
|
|
930
|
+
return Object.freeze({
|
|
931
|
+
isDeprecated: rule !== void 0 ? rule === false || isVersionLower(parseVersion(rule), parseVersion(browserInfo.version)) : false,
|
|
932
|
+
...browserInfo,
|
|
933
|
+
options: Object.freeze(versions)
|
|
934
|
+
});
|
|
797
935
|
}
|
|
798
|
-
|
|
799
|
-
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region src/hooks/useGlobalScroll.ts
|
|
938
|
+
var isLocked = ref(false);
|
|
800
939
|
function useGlobalScroll() {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
940
|
+
const lock = () => {
|
|
941
|
+
isLocked.value = true;
|
|
942
|
+
document.body.style.paddingRight = `${window.innerWidth - document.documentElement.clientWidth}px`;
|
|
943
|
+
document.body.style.overflow = "hidden";
|
|
944
|
+
};
|
|
945
|
+
const unlock = () => {
|
|
946
|
+
isLocked.value = false;
|
|
947
|
+
document.body.style.overflow = "auto";
|
|
948
|
+
document.body.style.paddingRight = "0px";
|
|
949
|
+
};
|
|
950
|
+
return {
|
|
951
|
+
isLocked,
|
|
952
|
+
lock,
|
|
953
|
+
unlock
|
|
954
|
+
};
|
|
816
955
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
956
|
+
//#endregion
|
|
957
|
+
//#region src/hooks/useDialog.ts
|
|
958
|
+
var CONFIRM_TEXT = "Are you sure you want to close? \nAll changes will be lost.";
|
|
959
|
+
var dialogs = [];
|
|
960
|
+
var HASH_PREFIX = "#ud_";
|
|
961
|
+
function useDialog(options) {
|
|
962
|
+
const logger = useLogger("use-dialog");
|
|
963
|
+
let hashPrefix = HASH_PREFIX;
|
|
964
|
+
if (options?.hashPrefix) if (options.hashPrefix.charAt(0) === "#") hashPrefix = options?.hashPrefix;
|
|
965
|
+
else logger.warn(`*hashPrefix* must start with "#". The default prefix "${HASH_PREFIX}" will be used`);
|
|
966
|
+
let appContext;
|
|
967
|
+
const { isLocked: isGlobalScrollLocked, lock: lockGlobalScroll, unlock: unlockGlobalScroll } = useGlobalScroll();
|
|
968
|
+
const route = useRoute();
|
|
969
|
+
const router = useRouter();
|
|
970
|
+
const genHash = ({ layer = 0, componentName, props }) => {
|
|
971
|
+
const data = {
|
|
972
|
+
name: componentName,
|
|
973
|
+
layer,
|
|
974
|
+
props
|
|
975
|
+
};
|
|
976
|
+
return `${hashPrefix}${window.btoa(JSON.stringify(data))}`;
|
|
977
|
+
};
|
|
978
|
+
const parseHash = (hash, componentName) => {
|
|
979
|
+
if (!hash) return void 0;
|
|
980
|
+
if (!hash.includes(hashPrefix)) return void 0;
|
|
981
|
+
let dataFromHash;
|
|
982
|
+
try {
|
|
983
|
+
dataFromHash = JSON.parse(window.atob(hash.slice(hashPrefix.length)));
|
|
984
|
+
} catch (_error) {
|
|
985
|
+
logger.warn("*parseHash* cant parse hash");
|
|
986
|
+
}
|
|
987
|
+
if (typeof dataFromHash !== "object") return void 0;
|
|
988
|
+
if (!dataFromHash.name) {
|
|
989
|
+
logger.warn("*parseHash* cant find component name in hash");
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (dataFromHash.name !== componentName) return void 0;
|
|
993
|
+
return dataFromHash;
|
|
994
|
+
};
|
|
995
|
+
const clearHash = () => {
|
|
996
|
+
router.push({
|
|
997
|
+
name: route.name || void 0,
|
|
998
|
+
query: route.query,
|
|
999
|
+
hash: void 0
|
|
1000
|
+
});
|
|
1001
|
+
};
|
|
1002
|
+
onMounted(() => {
|
|
1003
|
+
appContext = getCurrentInstance()?.appContext;
|
|
1004
|
+
});
|
|
1005
|
+
const open = ({ layer = 0, component, props }) => {
|
|
1006
|
+
const uuid = genUUID();
|
|
1007
|
+
const createComponent = () => {
|
|
1008
|
+
const newProps = {
|
|
1009
|
+
...props,
|
|
1010
|
+
layer
|
|
1011
|
+
};
|
|
1012
|
+
const el = document.createElement("div");
|
|
1013
|
+
const vnode = createVNode(component, {
|
|
1014
|
+
...newProps,
|
|
1015
|
+
modelValue: true,
|
|
1016
|
+
uuid
|
|
1017
|
+
});
|
|
1018
|
+
vnode.appContext = { ...appContext };
|
|
1019
|
+
/**
|
|
1020
|
+
* Если у компонента не объявлен свой обработчик на onUpdate:modelValue,
|
|
1021
|
+
* то создаем его самостоятельно
|
|
1022
|
+
*
|
|
1023
|
+
* Например:
|
|
1024
|
+
* openDialog({
|
|
1025
|
+
* component: SomeDialog,
|
|
1026
|
+
* })
|
|
1027
|
+
*
|
|
1028
|
+
* Если же его явно объявили, то никаких костылей не нужно
|
|
1029
|
+
*
|
|
1030
|
+
* Пример кода когда диалог открывается и закрывается по хешу в роутере
|
|
1031
|
+
* openDialog({
|
|
1032
|
+
* component: SomeDialog,
|
|
1033
|
+
* props: {
|
|
1034
|
+
* 'onUpdate:modelValue': (value: boolean) => {
|
|
1035
|
+
if (value) return;
|
|
1036
|
+
router.push({ hash: undefined });
|
|
1037
|
+
},
|
|
1038
|
+
* },
|
|
1039
|
+
* })
|
|
1040
|
+
*/
|
|
1041
|
+
if (!vnode?.props?.["onUpdate:modelValue"]) vnode.props["onUpdate:modelValue"] = (value) => {
|
|
1042
|
+
if (vnode && vnode.component) {
|
|
1043
|
+
vnode.component.props.modelValue = value;
|
|
1044
|
+
if (!value && route?.hash) {
|
|
1045
|
+
if (parseHash(route.hash, component.name)?.layer === layer) clearHash();
|
|
1046
|
+
}
|
|
1047
|
+
if (!value && (dialogs.length === 1 || layer === 0) && isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
vnode.close = () => {
|
|
1051
|
+
if (!vnode || !vnode.component) return;
|
|
1052
|
+
vnode.component.props.modelValue = false;
|
|
1053
|
+
if (!route?.hash) return;
|
|
1054
|
+
if (parseHash(route.hash, component.name)?.layer === layer) clearHash();
|
|
1055
|
+
};
|
|
1056
|
+
vnode.props.onDestroy = () => {
|
|
1057
|
+
render(null, el);
|
|
1058
|
+
dialogs = dialogs.filter((dialog) => dialog.uuid !== uuid);
|
|
1059
|
+
logger.info("Dialogs after destroy", dialogs);
|
|
1060
|
+
};
|
|
1061
|
+
const name = vnode?.type?.name ?? "Unknown component";
|
|
1062
|
+
const newDialog = {
|
|
1063
|
+
uuid,
|
|
1064
|
+
name,
|
|
1065
|
+
vnode,
|
|
1066
|
+
layer
|
|
1067
|
+
};
|
|
1068
|
+
logger.log(`Open new dialog: "${name}"`);
|
|
1069
|
+
if (!isGlobalScrollLocked.value) lockGlobalScroll();
|
|
1070
|
+
return {
|
|
1071
|
+
vnode,
|
|
1072
|
+
el,
|
|
1073
|
+
newDialog
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Если нет диалогов, то просто открываем новый
|
|
1078
|
+
*/
|
|
1079
|
+
if (!dialogs.length) {
|
|
1080
|
+
const { vnode, el, newDialog } = createComponent();
|
|
1081
|
+
render(vnode, el);
|
|
1082
|
+
dialogs = [newDialog];
|
|
1083
|
+
logger.info("Dialogs after open", dialogs);
|
|
1084
|
+
return uuid;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Если открываем новый диалог с нулевым слоем,
|
|
1088
|
+
* то все другие диалоги надо закрыть
|
|
1089
|
+
*/
|
|
1090
|
+
if (layer === 0) {
|
|
1091
|
+
closeAll();
|
|
1092
|
+
const { vnode, el, newDialog } = createComponent();
|
|
1093
|
+
render(vnode, el);
|
|
1094
|
+
dialogs = [newDialog];
|
|
1095
|
+
logger.info("Dialogs after open", dialogs);
|
|
1096
|
+
return uuid;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Если мы пытаемся открыть диалог со слоем отличным от 0,
|
|
1100
|
+
* то нужно проверить наличие уже открытого диалога на этом слое.
|
|
1101
|
+
* Если диалога нет, то просто пушим в массив новый элемент
|
|
1102
|
+
* Если диалог есть, то через таймаут подменяем его
|
|
1103
|
+
*/
|
|
1104
|
+
if (!dialogs.some((dialog) => dialog.layer === layer)) {
|
|
1105
|
+
const { vnode, el, newDialog } = createComponent();
|
|
1106
|
+
render(vnode, el);
|
|
1107
|
+
dialogs = [...dialogs, newDialog];
|
|
1108
|
+
logger.info("Dialogs after open", dialogs);
|
|
1109
|
+
return uuid;
|
|
1110
|
+
}
|
|
1111
|
+
const dialogOnCurrentLayer = dialogs.find((dialog) => dialog.layer === layer);
|
|
1112
|
+
close(dialogOnCurrentLayer?.uuid || "");
|
|
1113
|
+
const { vnode, el, newDialog } = createComponent();
|
|
1114
|
+
render(vnode, el);
|
|
1115
|
+
dialogs = [...dialogs, newDialog];
|
|
1116
|
+
logger.info("Dialogs after open", dialogs);
|
|
1117
|
+
return uuid;
|
|
1118
|
+
};
|
|
1119
|
+
const close = (uuid) => {
|
|
1120
|
+
const dialog = dialogs.find((item) => item.uuid === uuid);
|
|
1121
|
+
logger.log(`Close dialog: "${uuid}"`);
|
|
1122
|
+
if ((dialogs.length === 1 || dialog.layer === 0) && isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1123
|
+
dialog?.vnode.close();
|
|
1124
|
+
};
|
|
1125
|
+
const closeAll = () => {
|
|
1126
|
+
dialogs.forEach((dialog) => {
|
|
1127
|
+
dialog?.vnode.close();
|
|
1128
|
+
});
|
|
1129
|
+
if (isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1130
|
+
};
|
|
1131
|
+
const getInstance = (uuid) => {
|
|
1132
|
+
return dialogs.find((item) => item.uuid === uuid)?.vnode;
|
|
1133
|
+
};
|
|
1134
|
+
const getLayer = (uuid) => {
|
|
1135
|
+
if (!dialogs.length) return 0;
|
|
1136
|
+
return dialogs.find((dialog) => dialog.uuid === uuid)?.layer || 0;
|
|
1137
|
+
};
|
|
1138
|
+
const isOnTop = (uuid) => {
|
|
1139
|
+
if (!dialogs.length) return false;
|
|
1140
|
+
return [...dialogs].sort((a, b) => b.layer - a.layer)[0].uuid === uuid;
|
|
1141
|
+
};
|
|
1142
|
+
const showConfirm = (text = CONFIRM_TEXT) => {
|
|
1143
|
+
return window.confirm(text);
|
|
1144
|
+
};
|
|
1145
|
+
/**
|
|
1146
|
+
* Открытие диалога через hash
|
|
1147
|
+
*
|
|
1148
|
+
* Метод openByHash только дергает router и прокидывает в hash все необходимые данные.
|
|
1149
|
+
* Для полноценной работы на конкретной странице необходимо
|
|
1150
|
+
* для этого же компонента подключить watchHash
|
|
1151
|
+
*/
|
|
1152
|
+
const openByHash = ({ layer = 0, component, props }) => {
|
|
1153
|
+
router.push({
|
|
1154
|
+
name: route.name || void 0,
|
|
1155
|
+
query: route.query,
|
|
1156
|
+
hash: genHash({
|
|
1157
|
+
layer,
|
|
1158
|
+
props,
|
|
1159
|
+
componentName: component.name
|
|
1160
|
+
})
|
|
1161
|
+
});
|
|
1162
|
+
};
|
|
1163
|
+
const watchHash = ({ component, events }) => {
|
|
1164
|
+
logger.info(`start watching route.hash for dialog *${component.name}*`);
|
|
1165
|
+
const stopWatch = watch(() => route.hash, async (newHash) => {
|
|
1166
|
+
if (!newHash) {
|
|
1167
|
+
if (!dialogs.length) return;
|
|
1168
|
+
closeAll();
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const dataFromHash = parseHash(newHash, component.name);
|
|
1172
|
+
if (!dataFromHash) return;
|
|
1173
|
+
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1174
|
+
await nextTick();
|
|
1175
|
+
open({
|
|
1176
|
+
component,
|
|
1177
|
+
layer: dataFromHash.layer || 0,
|
|
1178
|
+
props: {
|
|
1179
|
+
...dataFromHash.props,
|
|
1180
|
+
...events
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
}, { immediate: true });
|
|
1184
|
+
const stopWatchHash = () => {
|
|
1185
|
+
logger.info(`stop watching route.hash for dialog *${component.name}*`);
|
|
1186
|
+
stopWatch();
|
|
1187
|
+
};
|
|
1188
|
+
onBeforeUnmount(() => {
|
|
1189
|
+
stopWatchHash();
|
|
1190
|
+
});
|
|
1191
|
+
return stopWatchHash;
|
|
1192
|
+
};
|
|
1193
|
+
return {
|
|
1194
|
+
open,
|
|
1195
|
+
getInstance,
|
|
1196
|
+
getLayer,
|
|
1197
|
+
close,
|
|
1198
|
+
closeAll,
|
|
1199
|
+
showConfirm,
|
|
1200
|
+
isOnTop,
|
|
1201
|
+
genHash,
|
|
1202
|
+
parseHash,
|
|
1203
|
+
clearHash,
|
|
1204
|
+
openByHash,
|
|
1205
|
+
watchHash
|
|
1206
|
+
};
|
|
1050
1207
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/hooks/useFilters.ts
|
|
1210
|
+
var QS_STRINGIFY_PARAMS = {
|
|
1211
|
+
arrayFormat: "comma",
|
|
1212
|
+
encode: false,
|
|
1213
|
+
skipNulls: true,
|
|
1214
|
+
addQueryPrefix: true
|
|
1057
1215
|
};
|
|
1058
|
-
|
|
1059
|
-
function useFilters({
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1216
|
+
var isOpen = ref(false);
|
|
1217
|
+
function useFilters({ config, initialFilters }) {
|
|
1218
|
+
const router = useRouter();
|
|
1219
|
+
const route = useRoute();
|
|
1220
|
+
const parseRouteQuery = (query) => qs.parse(query ?? route.query);
|
|
1221
|
+
const filtersFromQuery = computed(() => {
|
|
1222
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
1223
|
+
if (!parsedRouteQuery.filters) return void 0;
|
|
1224
|
+
return Object.entries(config).reduce((accum, [currentKey, currentValue]) => {
|
|
1225
|
+
if (!parsedRouteQuery.filters[currentKey]) return accum;
|
|
1226
|
+
if (currentValue.type === "ARRAY") {
|
|
1227
|
+
const splitValues = parsedRouteQuery.filters[currentKey].split(",");
|
|
1228
|
+
const checkedValue = currentValue?.possibleValues ? splitValues.filter((k) => currentValue?.possibleValues?.includes(k)) : splitValues;
|
|
1229
|
+
if (!checkedValue?.length) return accum;
|
|
1230
|
+
return {
|
|
1231
|
+
...accum,
|
|
1232
|
+
[currentKey]: checkedValue
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
return {
|
|
1236
|
+
...accum,
|
|
1237
|
+
[currentKey]: parsedRouteQuery.filters[currentKey]
|
|
1238
|
+
};
|
|
1239
|
+
}, {});
|
|
1240
|
+
});
|
|
1241
|
+
const filtersCount = computed(() => filtersFromQuery.value ? Object.keys(filtersFromQuery.value).length : 0);
|
|
1242
|
+
const setQueryFromFilters = (filters) => {
|
|
1243
|
+
const parsedRouteQuery = parseRouteQuery();
|
|
1244
|
+
const filteredValue = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1245
|
+
if (!currentValue?.length) return accum;
|
|
1246
|
+
return {
|
|
1247
|
+
...accum,
|
|
1248
|
+
[currentKey]: currentValue
|
|
1249
|
+
};
|
|
1250
|
+
}, {});
|
|
1251
|
+
const query = qs.stringify({
|
|
1252
|
+
...parsedRouteQuery,
|
|
1253
|
+
filters: filteredValue,
|
|
1254
|
+
page: void 0
|
|
1255
|
+
}, QS_STRINGIFY_PARAMS);
|
|
1256
|
+
/**
|
|
1257
|
+
* Очищаем символ # из строки, чтобы роутер не воспринимал часть за данных за этим символом как хеш
|
|
1258
|
+
*/
|
|
1259
|
+
router.push(query.replaceAll("#", ""));
|
|
1260
|
+
};
|
|
1261
|
+
const getValidatedParams = (query) => {
|
|
1262
|
+
const parsedRouteQuery = parseRouteQuery(query);
|
|
1263
|
+
if (query?.filters) {
|
|
1264
|
+
const filters = {
|
|
1265
|
+
...query.filters,
|
|
1266
|
+
...filtersFromQuery.value
|
|
1267
|
+
};
|
|
1268
|
+
return {
|
|
1269
|
+
...parsedRouteQuery,
|
|
1270
|
+
filters
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
...parsedRouteQuery,
|
|
1275
|
+
filters: filtersFromQuery.value
|
|
1276
|
+
};
|
|
1277
|
+
};
|
|
1278
|
+
const open = () => {
|
|
1279
|
+
isOpen.value = true;
|
|
1280
|
+
};
|
|
1281
|
+
const clear = () => setQueryFromFilters({});
|
|
1282
|
+
const filtersModel = ref({
|
|
1283
|
+
...initialFilters,
|
|
1284
|
+
...filtersFromQuery.value
|
|
1285
|
+
});
|
|
1286
|
+
const updateOne = (key, value) => {
|
|
1287
|
+
setQueryFromFilters({
|
|
1288
|
+
...filtersModel.value,
|
|
1289
|
+
[key]: value ? String(value) : void 0
|
|
1290
|
+
});
|
|
1291
|
+
};
|
|
1292
|
+
const updateMany = (filters) => {
|
|
1293
|
+
const newFilters = Object.entries(filters).reduce((accum, [currentKey, currentValue]) => {
|
|
1294
|
+
return {
|
|
1295
|
+
...accum,
|
|
1296
|
+
[currentKey]: currentValue ? String(currentValue) : void 0
|
|
1297
|
+
};
|
|
1298
|
+
}, {});
|
|
1299
|
+
setQueryFromFilters({
|
|
1300
|
+
...filtersModel.value,
|
|
1301
|
+
...newFilters
|
|
1302
|
+
});
|
|
1303
|
+
};
|
|
1304
|
+
watch(filtersFromQuery, (newFilters) => {
|
|
1305
|
+
if (!newFilters) {
|
|
1306
|
+
filtersModel.value = { ...initialFilters };
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
filtersModel.value = {
|
|
1310
|
+
...initialFilters,
|
|
1311
|
+
...newFilters
|
|
1312
|
+
};
|
|
1313
|
+
});
|
|
1314
|
+
return {
|
|
1315
|
+
isOpen,
|
|
1316
|
+
filtersModel,
|
|
1317
|
+
filtersFromQuery,
|
|
1318
|
+
filtersCount,
|
|
1319
|
+
updateOne,
|
|
1320
|
+
updateMany,
|
|
1321
|
+
open,
|
|
1322
|
+
clear,
|
|
1323
|
+
setQueryFromFilters,
|
|
1324
|
+
getValidatedParams
|
|
1325
|
+
};
|
|
1165
1326
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1327
|
+
//#endregion
|
|
1328
|
+
//#region src/hooks/usePanel.ts
|
|
1329
|
+
var panels = [];
|
|
1330
|
+
/**
|
|
1331
|
+
* @deprecated use useDialog
|
|
1332
|
+
*/
|
|
1168
1333
|
function usePanel() {
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1334
|
+
let appContext;
|
|
1335
|
+
const logger = useLogger("use-panel");
|
|
1336
|
+
const { isLocked: isGlobalScrollLocked, lock: lockGlobalScroll, unlock: unlockGlobalScroll } = useGlobalScroll();
|
|
1337
|
+
const route = useRoute();
|
|
1338
|
+
const router = useRouter();
|
|
1339
|
+
onMounted(() => {
|
|
1340
|
+
appContext = getCurrentInstance()?.appContext;
|
|
1341
|
+
});
|
|
1342
|
+
const open = ({ layer = 0, component, props }) => {
|
|
1343
|
+
const uuid = genUUID();
|
|
1344
|
+
const createComponent = () => {
|
|
1345
|
+
const newProps = {
|
|
1346
|
+
...props,
|
|
1347
|
+
layer
|
|
1348
|
+
};
|
|
1349
|
+
const el = document.createElement("div");
|
|
1350
|
+
const vnode = createVNode(component, {
|
|
1351
|
+
...newProps,
|
|
1352
|
+
modelValue: true,
|
|
1353
|
+
uuid
|
|
1354
|
+
});
|
|
1355
|
+
vnode.appContext = { ...appContext };
|
|
1356
|
+
/**
|
|
1357
|
+
* Если у компонента не объявлен свой обработчик на onUpdate:modelValue,
|
|
1358
|
+
* то создаем его самостоятельно
|
|
1359
|
+
*
|
|
1360
|
+
* Например:
|
|
1361
|
+
* openPanel({
|
|
1362
|
+
* component: SomePanel,
|
|
1363
|
+
* })
|
|
1364
|
+
*
|
|
1365
|
+
* Если же его явно объявили, то никаких костылей не нужно
|
|
1366
|
+
*
|
|
1367
|
+
* Пример кода когда панель открывается и закрывается по хешу в роутере
|
|
1368
|
+
* openPanel({
|
|
1369
|
+
* component: SomePanel,
|
|
1370
|
+
* props: {
|
|
1371
|
+
* 'onUpdate:modelValue': (value: boolean) => {
|
|
1372
|
+
if (value) return;
|
|
1373
|
+
router.push({ hash: undefined });
|
|
1374
|
+
},
|
|
1375
|
+
* },
|
|
1376
|
+
* })
|
|
1377
|
+
*/
|
|
1378
|
+
if (!vnode?.props?.["onUpdate:modelValue"]) vnode.props["onUpdate:modelValue"] = (value) => {
|
|
1379
|
+
if (vnode && vnode.component) {
|
|
1380
|
+
vnode.component.props.modelValue = value;
|
|
1381
|
+
if (!value && panels.length === 1 && isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
vnode.close = () => {
|
|
1385
|
+
if (vnode && vnode.component) vnode.component.props.modelValue = false;
|
|
1386
|
+
};
|
|
1387
|
+
vnode.props.onDestroy = () => {
|
|
1388
|
+
render(null, el);
|
|
1389
|
+
panels = panels.filter((panel) => panel.uuid !== uuid);
|
|
1390
|
+
logger.info("Panels after destroy", panels);
|
|
1391
|
+
};
|
|
1392
|
+
const name = vnode?.type?.name ?? "Unknown component";
|
|
1393
|
+
const newPanel = {
|
|
1394
|
+
uuid,
|
|
1395
|
+
name,
|
|
1396
|
+
vnode,
|
|
1397
|
+
layer
|
|
1398
|
+
};
|
|
1399
|
+
logger.log(`Open new panel: "${name}"`);
|
|
1400
|
+
if (!isGlobalScrollLocked.value) lockGlobalScroll();
|
|
1401
|
+
return {
|
|
1402
|
+
vnode,
|
|
1403
|
+
el,
|
|
1404
|
+
newPanel
|
|
1405
|
+
};
|
|
1406
|
+
};
|
|
1407
|
+
/**
|
|
1408
|
+
* Если нет панелей, то просто открываем новую
|
|
1409
|
+
*/
|
|
1410
|
+
if (!panels.length) {
|
|
1411
|
+
const { vnode, el, newPanel } = createComponent();
|
|
1412
|
+
render(vnode, el);
|
|
1413
|
+
panels = [newPanel];
|
|
1414
|
+
logger.info("Panels after open", panels);
|
|
1415
|
+
return uuid;
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* При открытии новой панели с нулевым слоем нужно закрыть
|
|
1419
|
+
* все предыдущие панели без учета их количества
|
|
1420
|
+
*/
|
|
1421
|
+
if (layer === 0) {
|
|
1422
|
+
closeAll();
|
|
1423
|
+
const { vnode, el, newPanel } = createComponent();
|
|
1424
|
+
render(vnode, el);
|
|
1425
|
+
panels = [newPanel];
|
|
1426
|
+
logger.info("Panels after open", panels);
|
|
1427
|
+
return uuid;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Если мы пытается открыть панель со слоем отличным от 0,
|
|
1431
|
+
* то нужно проверить наличие уже открытой панели на этом слое.
|
|
1432
|
+
* Если панели нет, то просто пушим в массив новый элемент
|
|
1433
|
+
* Если панель есть, то через таймаут подменяем ее
|
|
1434
|
+
*/
|
|
1435
|
+
if (!panels.some((panel) => panel.layer === layer)) {
|
|
1436
|
+
const { vnode, el, newPanel } = createComponent();
|
|
1437
|
+
render(vnode, el);
|
|
1438
|
+
panels = [...panels, newPanel];
|
|
1439
|
+
logger.info("Panels after open", panels);
|
|
1440
|
+
return uuid;
|
|
1441
|
+
}
|
|
1442
|
+
const panelOnCurrentLayer = panels.find((panel) => panel.layer === layer);
|
|
1443
|
+
close(panelOnCurrentLayer?.uuid || "");
|
|
1444
|
+
const { vnode, el, newPanel } = createComponent();
|
|
1445
|
+
render(vnode, el);
|
|
1446
|
+
panels = [...panels, newPanel];
|
|
1447
|
+
logger.info("Panels after open", panels);
|
|
1448
|
+
return uuid;
|
|
1449
|
+
};
|
|
1450
|
+
const close = (uuid) => {
|
|
1451
|
+
const panel = panels.find((item) => item.uuid === uuid);
|
|
1452
|
+
logger.log(`Close panel: "${uuid}"`);
|
|
1453
|
+
if (panels.length === 1 && isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1454
|
+
panel?.vnode.close();
|
|
1455
|
+
};
|
|
1456
|
+
const closeAll = () => {
|
|
1457
|
+
panels.forEach((panel) => {
|
|
1458
|
+
panel?.vnode.close();
|
|
1459
|
+
});
|
|
1460
|
+
if (isGlobalScrollLocked.value) unlockGlobalScroll();
|
|
1461
|
+
};
|
|
1462
|
+
const getInstance = (uuid) => {
|
|
1463
|
+
return panels.find((item) => item.uuid === uuid)?.vnode;
|
|
1464
|
+
};
|
|
1465
|
+
/**
|
|
1466
|
+
* Открытие панелей через hash
|
|
1467
|
+
*
|
|
1468
|
+
* Метод openByHash только дергает router и прокидывает в hash все необходимые данные.
|
|
1469
|
+
* Для полноценной работы на конкретной странице необходимо
|
|
1470
|
+
* для этого же компонента подключить watchHash
|
|
1471
|
+
*/
|
|
1472
|
+
const openByHash = ({ layer = 0, component, props }) => {
|
|
1473
|
+
const data = {
|
|
1474
|
+
name: component.name,
|
|
1475
|
+
layer,
|
|
1476
|
+
props
|
|
1477
|
+
};
|
|
1478
|
+
router.push({
|
|
1479
|
+
name: route.name || void 0,
|
|
1480
|
+
query: route.query,
|
|
1481
|
+
hash: `#${window.btoa(JSON.stringify(data))}`
|
|
1482
|
+
});
|
|
1483
|
+
};
|
|
1484
|
+
const watchHash = ({ component, events }) => {
|
|
1485
|
+
logger.info(`start watching route.hash for panel *${component.name}*`);
|
|
1486
|
+
const stopWatch = watch(() => route.hash, async (newHash) => {
|
|
1487
|
+
if (!newHash) {
|
|
1488
|
+
closeAll();
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
let dataFromHash;
|
|
1492
|
+
try {
|
|
1493
|
+
dataFromHash = JSON.parse(window.atob(newHash.slice(1)));
|
|
1494
|
+
} catch (_error) {
|
|
1495
|
+
logger.error("*watchHash* cant parse hash");
|
|
1496
|
+
}
|
|
1497
|
+
if (typeof dataFromHash !== "object") return;
|
|
1498
|
+
if (!dataFromHash.name) {
|
|
1499
|
+
logger.error("*watchHash* cant find component name in hash");
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
if (dataFromHash.name !== component.name) return;
|
|
1503
|
+
logger.info("*watchHash* data from hash", dataFromHash);
|
|
1504
|
+
await nextTick();
|
|
1505
|
+
open({
|
|
1506
|
+
component,
|
|
1507
|
+
layer: dataFromHash.layer || 0,
|
|
1508
|
+
props: {
|
|
1509
|
+
"onUpdate:modelValue": (value) => {
|
|
1510
|
+
if (value) return;
|
|
1511
|
+
router.push({
|
|
1512
|
+
name: route.name || void 0,
|
|
1513
|
+
query: route.query,
|
|
1514
|
+
hash: void 0
|
|
1515
|
+
});
|
|
1516
|
+
},
|
|
1517
|
+
...dataFromHash.props,
|
|
1518
|
+
...events
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
}, { immediate: true });
|
|
1522
|
+
const stopWatchHash = () => {
|
|
1523
|
+
logger.info(`stop watching route.hash for panel *${component.name}*`);
|
|
1524
|
+
stopWatch();
|
|
1525
|
+
};
|
|
1526
|
+
onBeforeUnmount(() => {
|
|
1527
|
+
stopWatchHash();
|
|
1528
|
+
});
|
|
1529
|
+
return stopWatchHash;
|
|
1530
|
+
};
|
|
1531
|
+
return {
|
|
1532
|
+
open,
|
|
1533
|
+
getInstance,
|
|
1534
|
+
close,
|
|
1535
|
+
closeAll,
|
|
1536
|
+
openByHash,
|
|
1537
|
+
watchHash
|
|
1538
|
+
};
|
|
1366
1539
|
}
|
|
1367
|
-
|
|
1540
|
+
//#endregion
|
|
1541
|
+
//#region src/validator/validatePhone.ts
|
|
1368
1542
|
function validatePhone(rule, value) {
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
return phoneNumber ? phoneNumber.isValid() : false;
|
|
1543
|
+
if (!value) return true;
|
|
1544
|
+
const phoneNumber = parsePhoneNumberFromString(value);
|
|
1545
|
+
return phoneNumber ? phoneNumber.isValid() : false;
|
|
1373
1546
|
}
|
|
1374
|
-
|
|
1547
|
+
//#endregion
|
|
1548
|
+
//#region src/validator/formRules.ts
|
|
1375
1549
|
function isRequired(value = true, message = "This field is required") {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1550
|
+
return {
|
|
1551
|
+
required: value,
|
|
1552
|
+
message
|
|
1553
|
+
};
|
|
1380
1554
|
}
|
|
1381
1555
|
function isMax(value = 255, message) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1556
|
+
return {
|
|
1557
|
+
max: value,
|
|
1558
|
+
message: message ?? `Length must be no more than ${value} characters`
|
|
1559
|
+
};
|
|
1386
1560
|
}
|
|
1387
1561
|
function isMin(value = 3, message) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1562
|
+
return {
|
|
1563
|
+
min: value,
|
|
1564
|
+
message: message ?? `Length must be at least ${value} characters`
|
|
1565
|
+
};
|
|
1392
1566
|
}
|
|
1393
1567
|
function isTypeEmail(message = "Invalid format") {
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1568
|
+
return {
|
|
1569
|
+
type: "email",
|
|
1570
|
+
message
|
|
1571
|
+
};
|
|
1398
1572
|
}
|
|
1399
1573
|
function isTypeUrl(message = "The url is invalid") {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1574
|
+
return {
|
|
1575
|
+
type: "url",
|
|
1576
|
+
message
|
|
1577
|
+
};
|
|
1404
1578
|
}
|
|
1405
1579
|
function isTypeNumber(value = 1, message) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1580
|
+
return {
|
|
1581
|
+
type: "number",
|
|
1582
|
+
min: value,
|
|
1583
|
+
message: message ?? `Must be at least ${value}`
|
|
1584
|
+
};
|
|
1411
1585
|
}
|
|
1412
1586
|
function isStrictLength(value = 3, message) {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1587
|
+
return {
|
|
1588
|
+
len: value,
|
|
1589
|
+
message: message ?? `Length must be exactly ${value} characters`
|
|
1590
|
+
};
|
|
1417
1591
|
}
|
|
1418
|
-
|
|
1419
|
-
export { AppComponentsResolver, UiComponentsResolver, camelizeKeys, convertEnumToOptions, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, isElementIgnored, isEmptyObject, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|
|
1592
|
+
//#endregion
|
|
1593
|
+
export { AppComponentsResolver, EnrichError, UiComponentsResolver, camelizeKeys, convertEnumToOptions, formatErrorDataMessage, formatErrorForNotify, formatMoney, genHash, genRandomNumber, genUUID, getCardNumber, getCountryFromPhone, getPaginationLimit, getPaginationOffset, getPaginationPages, getPaginationParams, getStatusMessage, isElementIgnored, isEmptyObject, isHtml, isMax, isMin, isRequired, isStrictLength, isTypeEmail, isTypeNumber, isTypeUrl, mapDataObjectForFilters, parsePhone, snakelizeKeys, unformatNumber, useAbortController, useAsyncItems, useAsyncMultiselect, useAsyncSelect, useBreakpoint, useClassName, useDayjs, useDetectBrowser, useDialog, useFilters, useGlobalScroll, useLogger, usePanel, validateNumber, validatePhone };
|