@willphan1712000/frontend 1.1.0 → 1.3.0
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/README.md +8 -1
- package/dist/index.d.mts +80 -4
- package/dist/index.d.ts +80 -4
- package/dist/index.js +34 -7
- package/dist/index.mjs +26 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
<img style="width: 15%" src="./will.png">
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Frontend package developed by Will Phan that makes Fronted development easy with pre-built UI components
|
|
4
4
|
|
|
5
5
|
## UI Components
|
|
6
|
+
- DropdownSelect, type Options
|
|
7
|
+
- RangeSlider
|
|
8
|
+
- OptionSlider, type SliderOptions
|
|
9
|
+
- ColorPickerSlider
|
|
10
|
+
- MultiSelect
|
|
11
|
+
- Button
|
|
12
|
+
- Avatar
|
|
6
13
|
|
|
7
14
|
## Technology
|
|
8
15
|
|
package/dist/index.d.mts
CHANGED
|
@@ -9,17 +9,15 @@ interface Props$b {
|
|
|
9
9
|
options: Options$2;
|
|
10
10
|
value: string;
|
|
11
11
|
onChange: (value: string) => void;
|
|
12
|
-
width?: string;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* Dropdown Select component, allowing users to select options from dropdown menu
|
|
16
15
|
* @param options - list of options, which is an array of object [{ label: string, value: string }]
|
|
17
16
|
* @param value - a chosen value
|
|
18
17
|
* @param onChange - a function to set a value
|
|
19
|
-
* @param width - specify the width of the component
|
|
20
18
|
* @returns
|
|
21
19
|
*/
|
|
22
|
-
declare const DropdownSelect: ({ options, value, onChange
|
|
20
|
+
declare const DropdownSelect: ({ options, value, onChange }: Props$b) => react_jsx_runtime.JSX.Element;
|
|
23
21
|
|
|
24
22
|
interface Props$a {
|
|
25
23
|
value: string;
|
|
@@ -377,4 +375,82 @@ declare class Transform {
|
|
|
377
375
|
private transform;
|
|
378
376
|
}
|
|
379
377
|
|
|
380
|
-
|
|
378
|
+
/**
|
|
379
|
+
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
380
|
+
* - Copyright: Will Phan
|
|
381
|
+
*/
|
|
382
|
+
interface AuthInterface<User = any> {
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
* @param redirect: route that will be returned after successful authentication
|
|
386
|
+
* @param client_id: oauth client id
|
|
387
|
+
* @param callback_api: api route for callback
|
|
388
|
+
* @returns sign in url
|
|
389
|
+
*/
|
|
390
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
391
|
+
redirect?: string;
|
|
392
|
+
client_id?: string;
|
|
393
|
+
callback_api?: string;
|
|
394
|
+
}): string;
|
|
395
|
+
/**
|
|
396
|
+
* Authenticate a user
|
|
397
|
+
*/
|
|
398
|
+
signin({ username, email, password, redirect, }: {
|
|
399
|
+
username: string;
|
|
400
|
+
email?: string;
|
|
401
|
+
password: string;
|
|
402
|
+
redirect?: string;
|
|
403
|
+
}): Promise<void>;
|
|
404
|
+
/**
|
|
405
|
+
* Validate user authentication
|
|
406
|
+
*/
|
|
407
|
+
validate({ state }: {
|
|
408
|
+
state?: string;
|
|
409
|
+
}): Promise<User>;
|
|
410
|
+
/**
|
|
411
|
+
* Sign a user out
|
|
412
|
+
*/
|
|
413
|
+
signout({ state }: {
|
|
414
|
+
state?: string;
|
|
415
|
+
}): Promise<void>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
type SessionType = {
|
|
419
|
+
username?: string;
|
|
420
|
+
email?: string;
|
|
421
|
+
role?: string;
|
|
422
|
+
} | undefined;
|
|
423
|
+
type SessionContextType = {
|
|
424
|
+
isLoading: boolean;
|
|
425
|
+
session: SessionType;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
430
|
+
* - Copyright: Will Phan
|
|
431
|
+
*/
|
|
432
|
+
interface StorageInterface {
|
|
433
|
+
getToken(): string | null;
|
|
434
|
+
getUser(): SessionType | null;
|
|
435
|
+
setToken({ token }: {
|
|
436
|
+
token: string;
|
|
437
|
+
}): void;
|
|
438
|
+
removeToken(): void;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Will-Auth - retrieve session
|
|
443
|
+
* @returns session context
|
|
444
|
+
*/
|
|
445
|
+
declare function useSession(): SessionContextType;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Custom Session Provider using React Context
|
|
449
|
+
* - Copyright: Will Phan
|
|
450
|
+
*/
|
|
451
|
+
declare const SessionProvider: ({ value, children, }: {
|
|
452
|
+
value: SessionContextType;
|
|
453
|
+
children: ReactNode;
|
|
454
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
455
|
+
|
|
456
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, useSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,17 +9,15 @@ interface Props$b {
|
|
|
9
9
|
options: Options$2;
|
|
10
10
|
value: string;
|
|
11
11
|
onChange: (value: string) => void;
|
|
12
|
-
width?: string;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
14
|
* Dropdown Select component, allowing users to select options from dropdown menu
|
|
16
15
|
* @param options - list of options, which is an array of object [{ label: string, value: string }]
|
|
17
16
|
* @param value - a chosen value
|
|
18
17
|
* @param onChange - a function to set a value
|
|
19
|
-
* @param width - specify the width of the component
|
|
20
18
|
* @returns
|
|
21
19
|
*/
|
|
22
|
-
declare const DropdownSelect: ({ options, value, onChange
|
|
20
|
+
declare const DropdownSelect: ({ options, value, onChange }: Props$b) => react_jsx_runtime.JSX.Element;
|
|
23
21
|
|
|
24
22
|
interface Props$a {
|
|
25
23
|
value: string;
|
|
@@ -377,4 +375,82 @@ declare class Transform {
|
|
|
377
375
|
private transform;
|
|
378
376
|
}
|
|
379
377
|
|
|
380
|
-
|
|
378
|
+
/**
|
|
379
|
+
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
380
|
+
* - Copyright: Will Phan
|
|
381
|
+
*/
|
|
382
|
+
interface AuthInterface<User = any> {
|
|
383
|
+
/**
|
|
384
|
+
*
|
|
385
|
+
* @param redirect: route that will be returned after successful authentication
|
|
386
|
+
* @param client_id: oauth client id
|
|
387
|
+
* @param callback_api: api route for callback
|
|
388
|
+
* @returns sign in url
|
|
389
|
+
*/
|
|
390
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
391
|
+
redirect?: string;
|
|
392
|
+
client_id?: string;
|
|
393
|
+
callback_api?: string;
|
|
394
|
+
}): string;
|
|
395
|
+
/**
|
|
396
|
+
* Authenticate a user
|
|
397
|
+
*/
|
|
398
|
+
signin({ username, email, password, redirect, }: {
|
|
399
|
+
username: string;
|
|
400
|
+
email?: string;
|
|
401
|
+
password: string;
|
|
402
|
+
redirect?: string;
|
|
403
|
+
}): Promise<void>;
|
|
404
|
+
/**
|
|
405
|
+
* Validate user authentication
|
|
406
|
+
*/
|
|
407
|
+
validate({ state }: {
|
|
408
|
+
state?: string;
|
|
409
|
+
}): Promise<User>;
|
|
410
|
+
/**
|
|
411
|
+
* Sign a user out
|
|
412
|
+
*/
|
|
413
|
+
signout({ state }: {
|
|
414
|
+
state?: string;
|
|
415
|
+
}): Promise<void>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
type SessionType = {
|
|
419
|
+
username?: string;
|
|
420
|
+
email?: string;
|
|
421
|
+
role?: string;
|
|
422
|
+
} | undefined;
|
|
423
|
+
type SessionContextType = {
|
|
424
|
+
isLoading: boolean;
|
|
425
|
+
session: SessionType;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
430
|
+
* - Copyright: Will Phan
|
|
431
|
+
*/
|
|
432
|
+
interface StorageInterface {
|
|
433
|
+
getToken(): string | null;
|
|
434
|
+
getUser(): SessionType | null;
|
|
435
|
+
setToken({ token }: {
|
|
436
|
+
token: string;
|
|
437
|
+
}): void;
|
|
438
|
+
removeToken(): void;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Will-Auth - retrieve session
|
|
443
|
+
* @returns session context
|
|
444
|
+
*/
|
|
445
|
+
declare function useSession(): SessionContextType;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Custom Session Provider using React Context
|
|
449
|
+
* - Copyright: Will Phan
|
|
450
|
+
*/
|
|
451
|
+
declare const SessionProvider: ({ value, children, }: {
|
|
452
|
+
value: SessionContextType;
|
|
453
|
+
children: ReactNode;
|
|
454
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
455
|
+
|
|
456
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, useSession };
|
package/dist/index.js
CHANGED
|
@@ -397,6 +397,9 @@ __export(index_exports, {
|
|
|
397
397
|
RangeSlider: function() {
|
|
398
398
|
return RangeSlider_default;
|
|
399
399
|
},
|
|
400
|
+
SessionProvider: function() {
|
|
401
|
+
return SessionProvider_default;
|
|
402
|
+
},
|
|
400
403
|
TextArea: function() {
|
|
401
404
|
return TextArea_default;
|
|
402
405
|
},
|
|
@@ -405,6 +408,9 @@ __export(index_exports, {
|
|
|
405
408
|
},
|
|
406
409
|
UploadImage: function() {
|
|
407
410
|
return UploadImage_default;
|
|
411
|
+
},
|
|
412
|
+
useSession: function() {
|
|
413
|
+
return useSession;
|
|
408
414
|
}
|
|
409
415
|
});
|
|
410
416
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -422,6 +428,10 @@ function useMyContext() {
|
|
|
422
428
|
var import_react2 = require("react");
|
|
423
429
|
// src/components/DropdownSelect/styles.ts
|
|
424
430
|
var styles = {
|
|
431
|
+
container: {
|
|
432
|
+
width: "100%",
|
|
433
|
+
position: "relative"
|
|
434
|
+
},
|
|
425
435
|
select_box: {
|
|
426
436
|
borderRadius: "10px",
|
|
427
437
|
border: "solid 1px #dadada",
|
|
@@ -498,7 +508,7 @@ var Search = function(param) {
|
|
|
498
508
|
name: "search",
|
|
499
509
|
onChange: function(e) {
|
|
500
510
|
return onSearch(options.filter(function(ele) {
|
|
501
|
-
return ele.
|
|
511
|
+
return ele.label.toLowerCase().includes(e.target.value.toLowerCase());
|
|
502
512
|
}));
|
|
503
513
|
}
|
|
504
514
|
})
|
|
@@ -572,7 +582,7 @@ var Dropdown_default = Dropdown;
|
|
|
572
582
|
var import_io = require("react-icons/io");
|
|
573
583
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
574
584
|
var DropdownSelect = function(param) {
|
|
575
|
-
var options = param.options, value = param.value, onChange = param.onChange
|
|
585
|
+
var options = param.options, value = param.value, onChange = param.onChange;
|
|
576
586
|
var _ref = _sliced_to_array((0, import_react3.useState)(false), 2), open = _ref[0], setOpen = _ref[1];
|
|
577
587
|
var _ref1 = _sliced_to_array((0, import_react3.useState)(false), 2), isHoverClose = _ref1[0], setHoverClose = _ref1[1];
|
|
578
588
|
var selectRef = (0, import_react3.useRef)(null);
|
|
@@ -596,10 +606,7 @@ var DropdownSelect = function(param) {
|
|
|
596
606
|
setOpen: setOpen
|
|
597
607
|
},
|
|
598
608
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", {
|
|
599
|
-
style:
|
|
600
|
-
width: "".concat(width, "px"),
|
|
601
|
-
position: "relative"
|
|
602
|
-
},
|
|
609
|
+
style: styles_default.container,
|
|
603
610
|
ref: selectRef,
|
|
604
611
|
children: [
|
|
605
612
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", {
|
|
@@ -3007,6 +3014,24 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
3007
3014
|
]);
|
|
3008
3015
|
return Transform;
|
|
3009
3016
|
}();
|
|
3017
|
+
// src/auth/react/context.tsx
|
|
3018
|
+
var import_react15 = require("react");
|
|
3019
|
+
var SessionContext = (0, import_react15.createContext)(void 0);
|
|
3020
|
+
function useSession() {
|
|
3021
|
+
var data = (0, import_react15.useContext)(SessionContext);
|
|
3022
|
+
if (data === void 0) throw new Error("Session context is undefined");
|
|
3023
|
+
return data;
|
|
3024
|
+
}
|
|
3025
|
+
// src/auth/react/SessionProvider.tsx
|
|
3026
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3027
|
+
var SessionProvider = function(param) {
|
|
3028
|
+
var value = param.value, children = param.children;
|
|
3029
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SessionContext.Provider, {
|
|
3030
|
+
value: value,
|
|
3031
|
+
children: children
|
|
3032
|
+
});
|
|
3033
|
+
};
|
|
3034
|
+
var SessionProvider_default = SessionProvider;
|
|
3010
3035
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3011
3036
|
0 && (module.exports = {
|
|
3012
3037
|
Avatar: Avatar,
|
|
@@ -3022,7 +3047,9 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
3022
3047
|
MultiSelect: MultiSelect,
|
|
3023
3048
|
OptionSlider: OptionSlider,
|
|
3024
3049
|
RangeSlider: RangeSlider,
|
|
3050
|
+
SessionProvider: SessionProvider,
|
|
3025
3051
|
TextArea: TextArea,
|
|
3026
3052
|
Transform: Transform,
|
|
3027
|
-
UploadImage: UploadImage
|
|
3053
|
+
UploadImage: UploadImage,
|
|
3054
|
+
useSession: useSession
|
|
3028
3055
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -306,6 +306,10 @@ function useMyContext() {
|
|
|
306
306
|
import { useEffect, useRef, useState } from "react";
|
|
307
307
|
// src/components/DropdownSelect/styles.ts
|
|
308
308
|
var styles = {
|
|
309
|
+
container: {
|
|
310
|
+
width: "100%",
|
|
311
|
+
position: "relative"
|
|
312
|
+
},
|
|
309
313
|
select_box: {
|
|
310
314
|
borderRadius: "10px",
|
|
311
315
|
border: "solid 1px #dadada",
|
|
@@ -382,7 +386,7 @@ var Search = function(param) {
|
|
|
382
386
|
name: "search",
|
|
383
387
|
onChange: function(e) {
|
|
384
388
|
return onSearch(options.filter(function(ele) {
|
|
385
|
-
return ele.
|
|
389
|
+
return ele.label.toLowerCase().includes(e.target.value.toLowerCase());
|
|
386
390
|
}));
|
|
387
391
|
}
|
|
388
392
|
})
|
|
@@ -456,7 +460,7 @@ var Dropdown_default = Dropdown;
|
|
|
456
460
|
import { IoMdClose } from "react-icons/io";
|
|
457
461
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
458
462
|
var DropdownSelect = function(param) {
|
|
459
|
-
var options = param.options, value = param.value, onChange = param.onChange
|
|
463
|
+
var options = param.options, value = param.value, onChange = param.onChange;
|
|
460
464
|
var _useState2 = _sliced_to_array(useState2(false), 2), open = _useState2[0], setOpen = _useState2[1];
|
|
461
465
|
var _useState21 = _sliced_to_array(useState2(false), 2), isHoverClose = _useState21[0], setHoverClose = _useState21[1];
|
|
462
466
|
var selectRef = useRef2(null);
|
|
@@ -480,10 +484,7 @@ var DropdownSelect = function(param) {
|
|
|
480
484
|
setOpen: setOpen
|
|
481
485
|
},
|
|
482
486
|
children: /* @__PURE__ */ jsxs2("div", {
|
|
483
|
-
style:
|
|
484
|
-
width: "".concat(width, "px"),
|
|
485
|
-
position: "relative"
|
|
486
|
-
},
|
|
487
|
+
style: styles_default.container,
|
|
487
488
|
ref: selectRef,
|
|
488
489
|
children: [
|
|
489
490
|
/* @__PURE__ */ jsxs2("div", {
|
|
@@ -2894,4 +2895,22 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
2894
2895
|
]);
|
|
2895
2896
|
return Transform;
|
|
2896
2897
|
}();
|
|
2897
|
-
|
|
2898
|
+
// src/auth/react/context.tsx
|
|
2899
|
+
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
2900
|
+
var SessionContext = createContext4(void 0);
|
|
2901
|
+
function useSession() {
|
|
2902
|
+
var data = useContext4(SessionContext);
|
|
2903
|
+
if (data === void 0) throw new Error("Session context is undefined");
|
|
2904
|
+
return data;
|
|
2905
|
+
}
|
|
2906
|
+
// src/auth/react/SessionProvider.tsx
|
|
2907
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2908
|
+
var SessionProvider = function(param) {
|
|
2909
|
+
var value = param.value, children = param.children;
|
|
2910
|
+
return /* @__PURE__ */ jsx20(SessionContext.Provider, {
|
|
2911
|
+
value: value,
|
|
2912
|
+
children: children
|
|
2913
|
+
});
|
|
2914
|
+
};
|
|
2915
|
+
var SessionProvider_default = SessionProvider;
|
|
2916
|
+
export { Avatar_default as Avatar, Button_default as Button, Canvas, ColorPickerSlider_default as ColorPickerSlider, DropdownSelect_default as DropdownSelect, Image_default as Image, ImageEditor_default as ImageEditor, Image_default2 as ImageUtilities, InputFile_default as InputFile, InputGoogle_default as InputGoogle, MultiSelect_default as MultiSelect, OptionSlider_default as OptionSlider, RangeSlider_default as RangeSlider, SessionProvider_default as SessionProvider, TextArea_default as TextArea, Transform, UploadImage_default as UploadImage, useSession };
|