@zuzjs/ui 0.8.1 → 0.8.3
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/cjs/comps/Accordion/index.js +1 -1
- package/dist/cjs/comps/Actionbar/index.js +1 -1
- package/dist/cjs/comps/Alert/index.js +1 -1
- package/dist/cjs/comps/AutoComplete/index.d.ts +1 -1
- package/dist/cjs/comps/AutoComplete/index.js +3 -2
- package/dist/cjs/comps/Avatar/index.js +5 -5
- package/dist/cjs/comps/Box/index.js +1 -1
- package/dist/cjs/comps/Button/index.js +1 -1
- package/dist/cjs/comps/CheckBox/index.d.ts +1 -0
- package/dist/cjs/comps/CheckBox/index.js +1 -1
- package/dist/cjs/comps/CheckBox/types.d.ts +1 -0
- package/dist/cjs/comps/ColorScheme/index.js +1 -1
- package/dist/cjs/comps/ContextMenu/index.d.ts +2 -0
- package/dist/cjs/comps/ContextMenu/index.js +6 -6
- package/dist/cjs/comps/ContextMenu/item.js +1 -1
- package/dist/cjs/comps/ContextMenu/types.d.ts +3 -1
- package/dist/cjs/comps/CookiesConsent/index.js +1 -1
- package/dist/cjs/comps/Cover/index.js +1 -1
- package/dist/cjs/comps/Cropper/index.d.ts +8 -0
- package/dist/cjs/comps/Cropper/index.js +20 -0
- package/dist/cjs/comps/Cropper/types.d.ts +14 -0
- package/dist/cjs/comps/Cropper/types.js +5 -0
- package/dist/cjs/comps/Crumb/index.d.ts +2 -1
- package/dist/cjs/comps/Crumb/index.js +13 -3
- package/dist/cjs/comps/Crumb/types.d.ts +1 -0
- package/dist/cjs/comps/Drawer/index.js +1 -1
- package/dist/cjs/comps/Fab/index.js +1 -1
- package/dist/cjs/comps/Filters/index.js +1 -1
- package/dist/cjs/comps/Form/index.js +22 -6
- package/dist/cjs/comps/Icon/index.js +1 -1
- package/dist/cjs/comps/Image/index.js +1 -1
- package/dist/cjs/comps/Input/index.d.ts +2 -2
- package/dist/cjs/comps/Input/index.js +1 -1
- package/dist/cjs/comps/KeyboardKeys/index.js +1 -1
- package/dist/cjs/comps/Label/index.js +1 -1
- package/dist/cjs/comps/List/index.d.ts +1 -1
- package/dist/cjs/comps/List/index.js +1 -1
- package/dist/cjs/comps/Network/index.js +1 -1
- package/dist/cjs/comps/Overlay/index.js +1 -1
- package/dist/cjs/comps/Pagination/index.js +1 -1
- package/dist/cjs/comps/Password/index.d.ts +6 -2
- package/dist/cjs/comps/Password/index.js +15 -5
- package/dist/cjs/comps/PinInput/index.d.ts +1 -1
- package/dist/cjs/comps/PinInput/index.js +8 -3
- package/dist/cjs/comps/ProgressBar/index.js +2 -2
- package/dist/cjs/comps/Radio/index.js +1 -1
- package/dist/cjs/comps/ScrollView/index.js +1 -1
- package/dist/cjs/comps/Search/index.d.ts +1 -1
- package/dist/cjs/comps/Search/index.js +1 -1
- package/dist/cjs/comps/Segmented/index.js +1 -1
- package/dist/cjs/comps/Select/index.d.ts +1 -0
- package/dist/cjs/comps/Select/index.js +3 -3
- package/dist/cjs/comps/Select/types.d.ts +6 -1
- package/dist/cjs/comps/Sheet/index.js +1 -1
- package/dist/cjs/comps/Sidebar/index.js +1 -1
- package/dist/cjs/comps/Slider/index.js +1 -1
- package/dist/cjs/comps/Span/index.js +1 -1
- package/dist/cjs/comps/Spinner/index.js +1 -1
- package/dist/cjs/comps/Switch/index.d.ts +1 -0
- package/dist/cjs/comps/Switch/index.js +1 -1
- package/dist/cjs/comps/TabView/body.js +1 -1
- package/dist/cjs/comps/TabView/index.js +1 -1
- package/dist/cjs/comps/TabView/tab.js +1 -1
- package/dist/cjs/comps/Table/col.js +1 -1
- package/dist/cjs/comps/Table/index.js +56 -2
- package/dist/cjs/comps/Table/row.js +1 -1
- package/dist/cjs/comps/Text/index.js +1 -1
- package/dist/cjs/comps/TextArea/index.js +1 -1
- package/dist/cjs/comps/TextWheel/index.js +3 -3
- package/dist/cjs/comps/Tooltip/index.js +1 -1
- package/dist/cjs/comps/Treeview/index.js +1 -1
- package/dist/cjs/comps/Treeview/item.js +1 -1
- package/dist/cjs/comps/VideoPlayer/index.js +1 -0
- package/dist/cjs/comps/index.d.ts +2 -0
- package/dist/cjs/comps/index.js +2 -0
- package/dist/cjs/funs/events.d.ts +31 -7
- package/dist/cjs/funs/events.js +57 -19
- package/dist/cjs/funs/index.d.ts +5 -3
- package/dist/cjs/funs/index.js +39 -84
- package/dist/cjs/hooks/index.d.ts +2 -0
- package/dist/cjs/hooks/index.js +2 -0
- package/dist/cjs/hooks/useDB.d.ts +5 -1
- package/dist/cjs/hooks/useDB.js +52 -4
- package/dist/cjs/hooks/useImage.js +2 -2
- package/dist/cjs/hooks/useImageCropper.d.ts +10 -0
- package/dist/cjs/hooks/useImageCropper.js +67 -0
- package/dist/cjs/hooks/useSlider.d.ts +1 -1
- package/dist/cjs/hooks/useUploader.d.ts +46 -0
- package/dist/cjs/hooks/useUploader.js +101 -0
- package/dist/cjs/hooks/useWebSocket.d.ts +2 -2
- package/dist/cjs/hooks/useWebSocket.js +13 -2
- package/dist/cjs/types/index.d.ts +3 -0
- package/dist/css/styles.css +1 -1
- package/dist/esm/comps/Accordion/index.js +1 -1
- package/dist/esm/comps/Actionbar/index.js +1 -1
- package/dist/esm/comps/Alert/index.js +1 -1
- package/dist/esm/comps/AutoComplete/index.d.ts +1 -1
- package/dist/esm/comps/AutoComplete/index.js +3 -2
- package/dist/esm/comps/Avatar/index.js +5 -5
- package/dist/esm/comps/Box/index.js +1 -1
- package/dist/esm/comps/Button/index.js +1 -1
- package/dist/esm/comps/CheckBox/index.d.ts +1 -0
- package/dist/esm/comps/CheckBox/index.js +1 -1
- package/dist/esm/comps/CheckBox/types.d.ts +1 -0
- package/dist/esm/comps/ColorScheme/index.js +1 -1
- package/dist/esm/comps/ContextMenu/index.d.ts +2 -0
- package/dist/esm/comps/ContextMenu/index.js +6 -6
- package/dist/esm/comps/ContextMenu/item.js +1 -1
- package/dist/esm/comps/ContextMenu/types.d.ts +3 -1
- package/dist/esm/comps/CookiesConsent/index.js +1 -1
- package/dist/esm/comps/Cover/index.js +1 -1
- package/dist/esm/comps/Cropper/index.d.ts +8 -0
- package/dist/esm/comps/Cropper/index.js +20 -0
- package/dist/esm/comps/Cropper/types.d.ts +14 -0
- package/dist/esm/comps/Cropper/types.js +5 -0
- package/dist/esm/comps/Crumb/index.d.ts +2 -1
- package/dist/esm/comps/Crumb/index.js +13 -3
- package/dist/esm/comps/Crumb/types.d.ts +1 -0
- package/dist/esm/comps/Drawer/index.js +1 -1
- package/dist/esm/comps/Fab/index.js +1 -1
- package/dist/esm/comps/Filters/index.js +1 -1
- package/dist/esm/comps/Form/index.js +22 -6
- package/dist/esm/comps/Icon/index.js +1 -1
- package/dist/esm/comps/Image/index.js +1 -1
- package/dist/esm/comps/Input/index.d.ts +2 -2
- package/dist/esm/comps/Input/index.js +1 -1
- package/dist/esm/comps/KeyboardKeys/index.js +1 -1
- package/dist/esm/comps/Label/index.js +1 -1
- package/dist/esm/comps/List/index.d.ts +1 -1
- package/dist/esm/comps/List/index.js +1 -1
- package/dist/esm/comps/Network/index.js +1 -1
- package/dist/esm/comps/Overlay/index.js +1 -1
- package/dist/esm/comps/Pagination/index.js +1 -1
- package/dist/esm/comps/Password/index.d.ts +6 -2
- package/dist/esm/comps/Password/index.js +15 -5
- package/dist/esm/comps/PinInput/index.d.ts +1 -1
- package/dist/esm/comps/PinInput/index.js +8 -3
- package/dist/esm/comps/ProgressBar/index.js +2 -2
- package/dist/esm/comps/Radio/index.js +1 -1
- package/dist/esm/comps/ScrollView/index.js +1 -1
- package/dist/esm/comps/Search/index.d.ts +1 -1
- package/dist/esm/comps/Search/index.js +1 -1
- package/dist/esm/comps/Segmented/index.js +1 -1
- package/dist/esm/comps/Select/index.d.ts +1 -0
- package/dist/esm/comps/Select/index.js +3 -3
- package/dist/esm/comps/Select/types.d.ts +6 -1
- package/dist/esm/comps/Sheet/index.js +1 -1
- package/dist/esm/comps/Sidebar/index.js +1 -1
- package/dist/esm/comps/Slider/index.js +1 -1
- package/dist/esm/comps/Span/index.js +1 -1
- package/dist/esm/comps/Spinner/index.js +1 -1
- package/dist/esm/comps/Switch/index.d.ts +1 -0
- package/dist/esm/comps/Switch/index.js +1 -1
- package/dist/esm/comps/TabView/body.js +1 -1
- package/dist/esm/comps/TabView/index.js +1 -1
- package/dist/esm/comps/TabView/tab.js +1 -1
- package/dist/esm/comps/Table/col.js +1 -1
- package/dist/esm/comps/Table/index.js +56 -2
- package/dist/esm/comps/Table/row.js +1 -1
- package/dist/esm/comps/Text/index.js +1 -1
- package/dist/esm/comps/TextArea/index.js +1 -1
- package/dist/esm/comps/TextWheel/index.js +3 -3
- package/dist/esm/comps/Tooltip/index.js +1 -1
- package/dist/esm/comps/Treeview/index.js +1 -1
- package/dist/esm/comps/Treeview/item.js +1 -1
- package/dist/esm/comps/VideoPlayer/index.js +1 -0
- package/dist/esm/comps/index.d.ts +2 -0
- package/dist/esm/comps/index.js +2 -0
- package/dist/esm/funs/events.d.ts +31 -7
- package/dist/esm/funs/events.js +57 -19
- package/dist/esm/funs/index.d.ts +5 -3
- package/dist/esm/funs/index.js +39 -84
- package/dist/esm/hooks/index.d.ts +2 -0
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/useDB.d.ts +5 -1
- package/dist/esm/hooks/useDB.js +52 -4
- package/dist/esm/hooks/useImage.js +2 -2
- package/dist/esm/hooks/useImageCropper.d.ts +10 -0
- package/dist/esm/hooks/useImageCropper.js +67 -0
- package/dist/esm/hooks/useSlider.d.ts +1 -1
- package/dist/esm/hooks/useUploader.d.ts +46 -0
- package/dist/esm/hooks/useUploader.js +101 -0
- package/dist/esm/hooks/useWebSocket.d.ts +2 -2
- package/dist/esm/hooks/useWebSocket.js +13 -2
- package/dist/esm/types/index.d.ts +3 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/cjs/funs/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import Hashids from "hashids";
|
|
3
|
-
import Cookies from "js-cookie";
|
|
4
2
|
import md5 from "md5";
|
|
5
3
|
import moment from "moment";
|
|
6
4
|
import { nanoid } from "nanoid";
|
|
@@ -205,88 +203,6 @@ export const removeDuplicatesFromArray = (array) => {
|
|
|
205
203
|
return accumulator;
|
|
206
204
|
}, []);
|
|
207
205
|
};
|
|
208
|
-
export const withPost = async (uri, data, timeout = 60, onProgress) => {
|
|
209
|
-
const _cookies = Cookies.get();
|
|
210
|
-
if (data instanceof FormData) {
|
|
211
|
-
for (const c in _cookies) {
|
|
212
|
-
data.append(c, _cookies[c]);
|
|
213
|
-
}
|
|
214
|
-
return new Promise((resolve, reject) => {
|
|
215
|
-
axios({
|
|
216
|
-
method: 'post',
|
|
217
|
-
url: uri,
|
|
218
|
-
data: data,
|
|
219
|
-
timeout: timeout * 1000,
|
|
220
|
-
headers: {
|
|
221
|
-
'Content-Type': 'multipart/form-data',
|
|
222
|
-
},
|
|
223
|
-
onUploadProgress: ev => onProgress && onProgress(ev)
|
|
224
|
-
})
|
|
225
|
-
.then(resp => {
|
|
226
|
-
if (resp.data && "kind" in resp.data) {
|
|
227
|
-
resolve(resp.data);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
reject(resp.data);
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
.catch(err => reject(err));
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
return new Promise((resolve, reject) => {
|
|
237
|
-
axios.post(uri, {
|
|
238
|
-
...data,
|
|
239
|
-
..._cookies,
|
|
240
|
-
__stmp: new Date().getTime() / 1000
|
|
241
|
-
}, {
|
|
242
|
-
timeout: 1000 * timeout,
|
|
243
|
-
headers: {
|
|
244
|
-
'Content-Type': 'application/json',
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
.then(resp => {
|
|
248
|
-
if (resp.data && "kind" in resp.data) {
|
|
249
|
-
resolve(resp.data);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
reject(resp.data);
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
.catch(err => {
|
|
256
|
-
if (err?.response?.data)
|
|
257
|
-
reject(err.response.data);
|
|
258
|
-
else
|
|
259
|
-
reject(err.code && err.code == `ERR_NETWORK` ? { error: err.code, message: navigator.onLine ? `Unable to connect to the server. It may be temporarily down.` : `Network error: Unable to connect. Please check your internet connection and try again.` } : err);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
};
|
|
263
|
-
export const withGet = async (uri, timeout = 60, ignoreKind = false) => {
|
|
264
|
-
return new Promise((resolve, reject) => {
|
|
265
|
-
axios
|
|
266
|
-
.get(uri, { timeout: timeout * 1000 })
|
|
267
|
-
.then((resp) => {
|
|
268
|
-
if (ignoreKind || (resp.data && "kind" in resp.data)) {
|
|
269
|
-
resolve(resp.data);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
reject(resp.data);
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
.catch((err) => {
|
|
276
|
-
if (err?.response?.data)
|
|
277
|
-
reject(err.response.data);
|
|
278
|
-
else
|
|
279
|
-
reject(err.code === `ERR_NETWORK`
|
|
280
|
-
? {
|
|
281
|
-
error: err.code,
|
|
282
|
-
message: navigator.onLine
|
|
283
|
-
? `Unable to connect to the server. It may be temporarily down.`
|
|
284
|
-
: `Network error: Unable to connect. Please check your internet connection and try again.`,
|
|
285
|
-
}
|
|
286
|
-
: err);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
206
|
export const withTime = (fun) => {
|
|
291
207
|
const start = new Date().getTime();
|
|
292
208
|
const result = fun();
|
|
@@ -546,3 +462,42 @@ export const truncate = (selector, lines = 2) => {
|
|
|
546
462
|
}
|
|
547
463
|
});
|
|
548
464
|
};
|
|
465
|
+
export const checkPasswordStrength = (password) => {
|
|
466
|
+
const suggestions = [];
|
|
467
|
+
let score = 0;
|
|
468
|
+
if (password.length >= 8) {
|
|
469
|
+
score++;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
suggestions.push("Use at least 8 characters");
|
|
473
|
+
}
|
|
474
|
+
if (/[a-z]/.test(password)) {
|
|
475
|
+
score++;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
suggestions.push("Add lowercase letters");
|
|
479
|
+
}
|
|
480
|
+
if (/[A-Z]/.test(password)) {
|
|
481
|
+
score++;
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
suggestions.push("Add uppercase letters");
|
|
485
|
+
}
|
|
486
|
+
if (/\d/.test(password)) {
|
|
487
|
+
score++;
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
suggestions.push("Include numbers");
|
|
491
|
+
}
|
|
492
|
+
if (/[^A-Za-z0-9]/.test(password)) {
|
|
493
|
+
score++;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
suggestions.push("Add special characters (e.g. !, @, #)");
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
score,
|
|
500
|
+
result: score <= 2 ? "Weak" : score == 3 ? "Moderate" : score == 4 ? "Strong" : "Excellent",
|
|
501
|
+
suggestion: suggestions
|
|
502
|
+
};
|
|
503
|
+
};
|
|
@@ -19,6 +19,7 @@ export { default as useFileManager } from './useFileManager';
|
|
|
19
19
|
export { default as useFacebookPixel } from './useFacebookPixel';
|
|
20
20
|
export { default as useGoogleTagManager } from './useGoogleTagManager';
|
|
21
21
|
export { default as useImage } from './useImage';
|
|
22
|
+
export { default as useImageCropper } from './useImageCropper';
|
|
22
23
|
export { default as useIntersectionObserver } from './useIntersectionObserver';
|
|
23
24
|
export { default as useScrollbar } from './useScrollbar';
|
|
24
25
|
export { default as useSheet } from './useSheet';
|
|
@@ -27,5 +28,6 @@ export { default as useNetworkStatus } from './useNetworkStatus';
|
|
|
27
28
|
export { default as useResizeObserver } from './useResizeObserver';
|
|
28
29
|
export { default as useSlider } from './useSlider';
|
|
29
30
|
export { default as useTruncateText } from './useTruncateText';
|
|
31
|
+
export { default as useUploader } from './useUploader';
|
|
30
32
|
export { default as useViewTransition } from './useViewTransition';
|
|
31
33
|
export { default as useWebSocket, type WebSocketOptions } from './useWebSocket';
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export { default as useFileManager } from './useFileManager';
|
|
|
20
20
|
export { default as useFacebookPixel } from './useFacebookPixel';
|
|
21
21
|
export { default as useGoogleTagManager } from './useGoogleTagManager';
|
|
22
22
|
export { default as useImage } from './useImage';
|
|
23
|
+
export { default as useImageCropper } from './useImageCropper';
|
|
23
24
|
export { default as useIntersectionObserver } from './useIntersectionObserver';
|
|
24
25
|
export { default as useScrollbar } from './useScrollbar';
|
|
25
26
|
export { default as useSheet } from './useSheet';
|
|
@@ -28,5 +29,6 @@ export { default as useNetworkStatus } from './useNetworkStatus';
|
|
|
28
29
|
export { default as useResizeObserver } from './useResizeObserver';
|
|
29
30
|
export { default as useSlider } from './useSlider';
|
|
30
31
|
export { default as useTruncateText } from './useTruncateText';
|
|
32
|
+
export { default as useUploader } from './useUploader';
|
|
31
33
|
export { default as useViewTransition } from './useViewTransition';
|
|
32
34
|
export { default as useWebSocket } from './useWebSocket';
|
|
@@ -17,10 +17,14 @@ export interface IDBSchema {
|
|
|
17
17
|
unique?: boolean;
|
|
18
18
|
}
|
|
19
19
|
declare const useDB: (options: IDBOptions) => {
|
|
20
|
+
getAll: <T>(storeName: string) => Promise<T>;
|
|
20
21
|
getByID: <T>(storeName: string, id: string | number) => Promise<T>;
|
|
21
22
|
getStore: <T>(storeName: string, id: string | number) => Promise<T>;
|
|
22
23
|
insert: <T>(storeName: string, value: T, key?: any) => Promise<number>;
|
|
23
|
-
update: <T>(storeName: string,
|
|
24
|
+
update: <T>(storeName: string, values: {
|
|
25
|
+
[x: string | number | symbol]: T;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
update_one: <T extends Object>(storeName: string, value: Partial<T>, key: IDBValidKey) => Promise<void>;
|
|
24
28
|
remove: (storeName: string, key: IDBValidKey) => Promise<void>;
|
|
25
29
|
error: string | null;
|
|
26
30
|
};
|
package/dist/cjs/hooks/useDB.js
CHANGED
|
@@ -65,6 +65,25 @@ const useDB = (options) => {
|
|
|
65
65
|
reject(err.message || 'Database either corrupted or not initialized');
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
const getAll = (storeName) => new Promise((resolve, reject) => {
|
|
69
|
+
connect().then((db) => {
|
|
70
|
+
const { store } = createTransaction(storeName, DBMode.readOnly);
|
|
71
|
+
const request = store.getAll();
|
|
72
|
+
request.onsuccess = (evt) => {
|
|
73
|
+
const result = evt.target.result;
|
|
74
|
+
if (undefined == result)
|
|
75
|
+
reject('Record not found');
|
|
76
|
+
resolve(evt.target.result);
|
|
77
|
+
};
|
|
78
|
+
request.onerror = (evt) => {
|
|
79
|
+
reject(`SELECT Failed. ${evt.target.result}`);
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
.catch(err => {
|
|
83
|
+
console.log(`[getAll]`, err);
|
|
84
|
+
reject('Database either corrupted or not initialized');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
68
87
|
const getByID = (storeName, id) => new Promise((resolve, reject) => {
|
|
69
88
|
connect().then((db) => {
|
|
70
89
|
const { store } = createTransaction(storeName, DBMode.readOnly);
|
|
@@ -80,7 +99,7 @@ const useDB = (options) => {
|
|
|
80
99
|
};
|
|
81
100
|
})
|
|
82
101
|
.catch(err => {
|
|
83
|
-
|
|
102
|
+
console.log(`[getByID]`, err);
|
|
84
103
|
reject('Database either corrupted or not initialized');
|
|
85
104
|
});
|
|
86
105
|
});
|
|
@@ -99,16 +118,43 @@ const useDB = (options) => {
|
|
|
99
118
|
reject(err.message || 'Database either corrupted or not initialized');
|
|
100
119
|
});
|
|
101
120
|
});
|
|
102
|
-
const
|
|
121
|
+
const update_one = (storeName, value, key) => new Promise((resolve, reject) => {
|
|
103
122
|
connect().then((db) => {
|
|
104
123
|
const { store } = createTransaction(storeName, DBMode.readWrite);
|
|
105
|
-
const
|
|
124
|
+
const getReq = store.get(key);
|
|
125
|
+
getReq.onsuccess = () => {
|
|
126
|
+
const existing = getReq.result;
|
|
127
|
+
if (!existing) {
|
|
128
|
+
reject(`Record with key ${key} not found.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const updateReq = store.put({ ...existing, ...value });
|
|
132
|
+
updateReq.onsuccess = () => resolve();
|
|
133
|
+
updateReq.onerror = (evt) => reject(`Update failed. ${evt.target.error}`);
|
|
134
|
+
};
|
|
135
|
+
getReq.onerror = (evt) => {
|
|
136
|
+
reject(`Failed to get existing record. ${evt.target.error}`);
|
|
137
|
+
};
|
|
138
|
+
})
|
|
139
|
+
.catch(err => {
|
|
140
|
+
reject('Database either corrupted or not initialized');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
const update = (storeName, values) => new Promise((resolve, reject) => {
|
|
144
|
+
connect().then((db) => {
|
|
145
|
+
const { store } = createTransaction(storeName, DBMode.readWrite);
|
|
146
|
+
let completed = 0;
|
|
147
|
+
const request = store.put(values);
|
|
106
148
|
request.onsuccess = (evt) => {
|
|
107
149
|
resolve();
|
|
108
150
|
};
|
|
151
|
+
request.onerror = (evt) => {
|
|
152
|
+
reject(`UPDATE Failed. ${evt.target.result}`);
|
|
153
|
+
};
|
|
109
154
|
})
|
|
110
155
|
.catch(err => {
|
|
111
|
-
reject(
|
|
156
|
+
reject(`UPDATE Failed. ${err}`);
|
|
157
|
+
// reject('Database either corrupted or not initialized');
|
|
112
158
|
});
|
|
113
159
|
});
|
|
114
160
|
const remove = (storeName, key) => new Promise((resolve, reject) => {
|
|
@@ -125,10 +171,12 @@ const useDB = (options) => {
|
|
|
125
171
|
});
|
|
126
172
|
});
|
|
127
173
|
return {
|
|
174
|
+
getAll,
|
|
128
175
|
getByID,
|
|
129
176
|
getStore,
|
|
130
177
|
insert,
|
|
131
178
|
update,
|
|
179
|
+
update_one,
|
|
132
180
|
remove,
|
|
133
181
|
error
|
|
134
182
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
const useImage = (url, crossOrigin, referrerPolicy) => {
|
|
4
|
-
const img = useRef(null);
|
|
5
4
|
const [state, setState] = useState({ loaded: false, error: null });
|
|
5
|
+
const img = useRef(null);
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (url && url !== ``) {
|
|
8
8
|
var _img = new Image();
|
|
@@ -17,7 +17,7 @@ const useImage = (url, crossOrigin, referrerPolicy) => {
|
|
|
17
17
|
};
|
|
18
18
|
_img.src = url;
|
|
19
19
|
}
|
|
20
|
-
}, []);
|
|
20
|
+
}, [url]);
|
|
21
21
|
return [img.current ? img.current.src : ``, state.loaded, state.error];
|
|
22
22
|
};
|
|
23
23
|
export default useImage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CropShape } from '..';
|
|
2
|
+
declare const useImageCropper: (imageUrl: string, cropSize: number, cropShape?: CropShape, scale?: number) => {
|
|
3
|
+
canvasRef: import("react").RefObject<HTMLCanvasElement | null>;
|
|
4
|
+
crop: () => string | null;
|
|
5
|
+
setScale: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
6
|
+
handleMouseDown: () => void;
|
|
7
|
+
handleMouseUp: () => void;
|
|
8
|
+
handleMouseMove: (e: React.MouseEvent<HTMLCanvasElement>) => void;
|
|
9
|
+
};
|
|
10
|
+
export default useImageCropper;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { CropShape } from '..';
|
|
3
|
+
const useImageCropper = (imageUrl, cropSize, cropShape = CropShape.Circle, scale = 1) => {
|
|
4
|
+
const [dragging, setDragging] = useState(false);
|
|
5
|
+
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
|
6
|
+
const [_scale, setScale] = useState(scale);
|
|
7
|
+
const imgRef = useRef(null);
|
|
8
|
+
const canvasRef = useRef(null);
|
|
9
|
+
const draw = () => {
|
|
10
|
+
const canvas = canvasRef.current;
|
|
11
|
+
const ctx = canvas?.getContext('2d');
|
|
12
|
+
const img = imgRef.current;
|
|
13
|
+
if (!canvas || !ctx || !img)
|
|
14
|
+
return;
|
|
15
|
+
canvas.width = cropSize;
|
|
16
|
+
canvas.height = cropSize;
|
|
17
|
+
ctx.clearRect(0, 0, cropSize, cropSize);
|
|
18
|
+
ctx.globalAlpha = 0.5;
|
|
19
|
+
ctx.drawImage(img, offset.x, offset.y, img.width * _scale, img.height * _scale);
|
|
20
|
+
ctx.globalAlpha = 1.0;
|
|
21
|
+
ctx.save();
|
|
22
|
+
if (cropShape === CropShape.Circle) {
|
|
23
|
+
ctx.beginPath();
|
|
24
|
+
ctx.arc(cropSize / 2, cropSize / 2, cropSize / 2, 0, Math.PI * 2);
|
|
25
|
+
ctx.closePath();
|
|
26
|
+
ctx.clip();
|
|
27
|
+
}
|
|
28
|
+
ctx.drawImage(img, offset.x, offset.y, img.width * _scale, img.height * _scale);
|
|
29
|
+
ctx.restore();
|
|
30
|
+
};
|
|
31
|
+
useEffect(draw, [_scale]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (imageUrl) {
|
|
34
|
+
const img = new Image();
|
|
35
|
+
img.onload = () => {
|
|
36
|
+
imgRef.current = img;
|
|
37
|
+
draw();
|
|
38
|
+
};
|
|
39
|
+
img.src = imageUrl;
|
|
40
|
+
}
|
|
41
|
+
}, [imageUrl, offset]);
|
|
42
|
+
const handleMouseDown = () => setDragging(true);
|
|
43
|
+
const handleMouseUp = () => setDragging(false);
|
|
44
|
+
const handleMouseMove = (e) => {
|
|
45
|
+
if (!dragging || !imgRef.current)
|
|
46
|
+
return;
|
|
47
|
+
setOffset(prev => ({
|
|
48
|
+
x: prev.x + e.movementX,
|
|
49
|
+
y: prev.y + e.movementY,
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
const crop = () => {
|
|
53
|
+
const canvas = canvasRef.current;
|
|
54
|
+
if (!canvas)
|
|
55
|
+
return null;
|
|
56
|
+
return canvas.toDataURL('image/png');
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
canvasRef,
|
|
60
|
+
crop,
|
|
61
|
+
setScale,
|
|
62
|
+
handleMouseDown,
|
|
63
|
+
handleMouseUp,
|
|
64
|
+
handleMouseMove,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export default useImageCropper;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CancelTokenSource } from "@zuzjs/core";
|
|
2
|
+
import { dynamic } from "..";
|
|
3
|
+
export declare enum Status {
|
|
4
|
+
Error = -1,
|
|
5
|
+
Idle = 0,
|
|
6
|
+
FetchingServer = 1,
|
|
7
|
+
Uploading = 2,
|
|
8
|
+
Saving = 3
|
|
9
|
+
}
|
|
10
|
+
export interface QueItem {
|
|
11
|
+
ID: string;
|
|
12
|
+
file: File;
|
|
13
|
+
dir: string;
|
|
14
|
+
remote: false;
|
|
15
|
+
progress: number;
|
|
16
|
+
speed: number;
|
|
17
|
+
eta: number;
|
|
18
|
+
bytes: number;
|
|
19
|
+
status: Status;
|
|
20
|
+
server?: Server | null;
|
|
21
|
+
}
|
|
22
|
+
export type Server = {
|
|
23
|
+
ID: string;
|
|
24
|
+
uri: string;
|
|
25
|
+
token: string;
|
|
26
|
+
rmf: string | null;
|
|
27
|
+
};
|
|
28
|
+
export type Uploadify = {
|
|
29
|
+
que: QueItem[];
|
|
30
|
+
index: number;
|
|
31
|
+
speed: number;
|
|
32
|
+
stamp: number | null;
|
|
33
|
+
token: string | null;
|
|
34
|
+
status: Status;
|
|
35
|
+
cancelToken?: CancelTokenSource | null;
|
|
36
|
+
};
|
|
37
|
+
export interface Uploader {
|
|
38
|
+
apiUrl: string;
|
|
39
|
+
onChange?: (file: QueItem | null) => void;
|
|
40
|
+
onQueFinished?: () => void;
|
|
41
|
+
}
|
|
42
|
+
declare const useUploader: (conf: Uploader) => {
|
|
43
|
+
getQue: () => QueItem[];
|
|
44
|
+
addToQue: (f: dynamic) => void;
|
|
45
|
+
};
|
|
46
|
+
export default useUploader;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getCancelToken, withPost } from "@zuzjs/core";
|
|
2
|
+
import { uuid } from "..";
|
|
3
|
+
export var Status;
|
|
4
|
+
(function (Status) {
|
|
5
|
+
Status[Status["Error"] = -1] = "Error";
|
|
6
|
+
Status[Status["Idle"] = 0] = "Idle";
|
|
7
|
+
Status[Status["FetchingServer"] = 1] = "FetchingServer";
|
|
8
|
+
Status[Status["Uploading"] = 2] = "Uploading";
|
|
9
|
+
Status[Status["Saving"] = 3] = "Saving";
|
|
10
|
+
})(Status || (Status = {}));
|
|
11
|
+
const useUploader = (conf) => {
|
|
12
|
+
const { apiUrl, onChange, onQueFinished } = conf;
|
|
13
|
+
const self = {
|
|
14
|
+
que: [],
|
|
15
|
+
index: -1,
|
|
16
|
+
speed: 0,
|
|
17
|
+
stamp: null,
|
|
18
|
+
token: null,
|
|
19
|
+
status: Status.Idle
|
|
20
|
+
};
|
|
21
|
+
const sync = () => onChange?.(currentFile());
|
|
22
|
+
const importFile = () => { };
|
|
23
|
+
const uploadFile = () => {
|
|
24
|
+
self.stamp = Date.now();
|
|
25
|
+
const file = currentFile();
|
|
26
|
+
const formData = new FormData();
|
|
27
|
+
formData.append("ID", file.ID);
|
|
28
|
+
formData.append("dir", file.dir);
|
|
29
|
+
formData.append("server", file.server.ID);
|
|
30
|
+
formData.append("token", file.server.token);
|
|
31
|
+
formData.append('file', file.file);
|
|
32
|
+
formData.append('fs', file.file.size.toString());
|
|
33
|
+
self.cancelToken = getCancelToken();
|
|
34
|
+
withPost(`${self.que[self.index].server.uri}/receive`, formData, 86400, true, (ev) => {
|
|
35
|
+
console.log(ev);
|
|
36
|
+
})
|
|
37
|
+
.catch(resp => {
|
|
38
|
+
console.log(`Uploaded`, resp);
|
|
39
|
+
})
|
|
40
|
+
.catch(err => {
|
|
41
|
+
self.que[self.index].status = Status.Error;
|
|
42
|
+
self.status = Status.Idle;
|
|
43
|
+
sync();
|
|
44
|
+
Que();
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const getServer = (force) => {
|
|
48
|
+
self.que[self.index].status = Status.FetchingServer;
|
|
49
|
+
sync();
|
|
50
|
+
withPost(`${apiUrl}get_server`, { size: currentFile().file.size })
|
|
51
|
+
.then((resp) => {
|
|
52
|
+
self.que[self.index].server = resp.server;
|
|
53
|
+
self.que[self.index].status = Status.Uploading;
|
|
54
|
+
sync();
|
|
55
|
+
uploadFile();
|
|
56
|
+
})
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
self.que[self.index].status = Status.Error;
|
|
59
|
+
self.status = Status.Idle;
|
|
60
|
+
sync();
|
|
61
|
+
Que();
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const currentFile = () => self.que[self.index];
|
|
65
|
+
const getQue = () => self.que;
|
|
66
|
+
const Que = () => {
|
|
67
|
+
if (self.status == Status.Idle &&
|
|
68
|
+
(self.que.length - 1) > self.index) {
|
|
69
|
+
self.status = Status.Uploading;
|
|
70
|
+
self.index++;
|
|
71
|
+
self.que[self.index].status = Status.Uploading;
|
|
72
|
+
sync();
|
|
73
|
+
if (self.que[self.index].remote)
|
|
74
|
+
importFile();
|
|
75
|
+
else
|
|
76
|
+
getServer(true);
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
onQueFinished?.();
|
|
80
|
+
};
|
|
81
|
+
const addToQue = (f) => {
|
|
82
|
+
self.que.push({
|
|
83
|
+
ID: uuid(),
|
|
84
|
+
file: f.file,
|
|
85
|
+
dir: f.dir,
|
|
86
|
+
remote: f.remote,
|
|
87
|
+
progress: 0,
|
|
88
|
+
speed: 0,
|
|
89
|
+
eta: 0,
|
|
90
|
+
bytes: 0,
|
|
91
|
+
status: Status.Idle,
|
|
92
|
+
server: null
|
|
93
|
+
});
|
|
94
|
+
Que();
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
getQue,
|
|
98
|
+
addToQue,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export default useUploader;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dynamic } from "..";
|
|
2
2
|
export type WebSocketOptions = {
|
|
3
3
|
onOpen?: (event: Event) => void;
|
|
4
4
|
onClose?: (event: CloseEvent) => void;
|
|
5
5
|
onRawMessage?: (event: MessageEvent) => void;
|
|
6
|
-
onMessage?: (data:
|
|
6
|
+
onMessage?: (data: dynamic) => void;
|
|
7
7
|
onError?: (event: Event) => void;
|
|
8
8
|
reconnect?: boolean;
|
|
9
9
|
};
|
|
@@ -18,8 +18,19 @@ const useWebSocket = (url, options) => {
|
|
|
18
18
|
reconnectIntervals.set(url, 2); // Reset to 1s on successful reconnect
|
|
19
19
|
};
|
|
20
20
|
const connect = useCallback(() => {
|
|
21
|
-
if (socketInstances.has(url))
|
|
21
|
+
if (socketInstances.has(url)) {
|
|
22
|
+
const Socket = socketInstances.get(url);
|
|
23
|
+
if (Socket) {
|
|
24
|
+
Socket.onmessage = (event) => {
|
|
25
|
+
setMessages((prev) => [...prev, event.data]);
|
|
26
|
+
onRawMessage?.(event);
|
|
27
|
+
const raw = JSON.parse(Buffer.isBuffer(event) ? event.toString(`utf8`) : `string` == typeof event ? event : event.data);
|
|
28
|
+
onMessage?.(raw);
|
|
29
|
+
listenersMap.get(url)?.forEach((listener) => listener(event));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
22
32
|
return; // Prevent duplicate connection
|
|
33
|
+
}
|
|
23
34
|
const socket = new WebSocket(url);
|
|
24
35
|
socketInstances.set(url, socket);
|
|
25
36
|
listenersMap.set(url, []);
|
|
@@ -79,7 +90,7 @@ const useWebSocket = (url, options) => {
|
|
|
79
90
|
socket.send(data);
|
|
80
91
|
}
|
|
81
92
|
else {
|
|
82
|
-
console.
|
|
93
|
+
console.log("WebSocket is not connected.");
|
|
83
94
|
}
|
|
84
95
|
}, [url]);
|
|
85
96
|
return { isConnected, messages, sendMessage };
|