ag-common 0.0.295 → 0.0.298
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/common/helpers/object.d.ts +1 -0
- package/dist/common/helpers/object.js +4 -1
- package/dist/ui/components/UserImage/index.d.ts +2 -1
- package/dist/ui/components/UserImage/index.js +5 -8
- package/dist/ui/helpers/index.d.ts +1 -0
- package/dist/ui/helpers/index.js +1 -0
- package/dist/ui/helpers/useGranularHook.d.ts +5 -0
- package/dist/ui/helpers/useGranularHook.js +14 -0
- package/package.json +2 -2
|
@@ -51,3 +51,4 @@ export declare const removeUndefValuesFromObject: <T>(orig: Record<string, T>, .
|
|
|
51
51
|
* @returns
|
|
52
52
|
*/
|
|
53
53
|
export declare const castStringlyObject: (orig: Record<string, string | string[] | undefined>) => Record<string, string>;
|
|
54
|
+
export declare const isObject: (o: any) => any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.castStringlyObject = exports.removeUndefValuesFromObject = exports.castObject = exports.objectToString = exports.paramsToObject = exports.objectAlphaSort = exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
|
|
3
|
+
exports.isObject = exports.castStringlyObject = exports.removeUndefValuesFromObject = exports.castObject = exports.objectToString = exports.paramsToObject = exports.objectAlphaSort = exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const tryJsonParse = (str, defaultValue) => {
|
|
6
6
|
if (!str) {
|
|
@@ -156,3 +156,6 @@ const castStringlyObject = (orig) => {
|
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
158
|
exports.castStringlyObject = castStringlyObject;
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
160
|
+
const isObject = (o) => o && typeof o === 'object' && !Array.isArray(o);
|
|
161
|
+
exports.isObject = isObject;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { User } from '../../helpers/jwt';
|
|
3
3
|
export declare const UserImageIcon: JSX.Element;
|
|
4
|
-
export declare const UserImage: ({ image, className, }: {
|
|
4
|
+
export declare const UserImage: ({ image, className, title, }: {
|
|
5
5
|
image?: string | undefined;
|
|
6
6
|
className?: string | undefined;
|
|
7
|
+
title?: string | undefined;
|
|
7
8
|
}) => JSX.Element;
|
|
8
9
|
export declare const UserProfileImage: ({ className, user, }: {
|
|
9
10
|
className?: string | undefined;
|
|
@@ -48,12 +48,11 @@ const Img = styled_components_1.default.img `
|
|
|
48
48
|
const images = {
|
|
49
49
|
domains: ['platform-lookaside.fbsbx.com', 'lh3.googleusercontent.com'],
|
|
50
50
|
};
|
|
51
|
-
const UserImage = ({ image, className, }) => {
|
|
51
|
+
const UserImage = ({ image, className, title = 'user image', }) => {
|
|
52
52
|
const [fallback, setFallback] = (0, react_1.useState)(false);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
!showImage && exports.UserImageIcon));
|
|
53
|
+
return (react_1.default.createElement(Base, { className: className, title: title },
|
|
54
|
+
image && !fallback && (react_1.default.createElement(Img, { alt: "user", src: image, onError: () => setFallback(true) })),
|
|
55
|
+
(!image || fallback) && exports.UserImageIcon));
|
|
57
56
|
};
|
|
58
57
|
exports.UserImage = UserImage;
|
|
59
58
|
const UserProfileImage = ({ className, user, }) => {
|
|
@@ -65,8 +64,6 @@ const UserProfileImage = ({ className, user, }) => {
|
|
|
65
64
|
}
|
|
66
65
|
const titleA = [user === null || user === void 0 ? void 0 : user.fullname, user === null || user === void 0 ? void 0 : user.userId].filter(array_1.notEmpty);
|
|
67
66
|
const title = titleA.length === 0 ? '' : titleA.join(' - ');
|
|
68
|
-
return
|
|
69
|
-
image && react_1.default.createElement(Img, { alt: "user", src: image }),
|
|
70
|
-
!image && exports.UserImageIcon));
|
|
67
|
+
return react_1.default.createElement(exports.UserImage, { image: image, title: title, className: className });
|
|
71
68
|
};
|
|
72
69
|
exports.UserProfileImage = UserProfileImage;
|
|
@@ -12,6 +12,7 @@ export * from './plural';
|
|
|
12
12
|
export * from './routes';
|
|
13
13
|
export * from './serviceWorker';
|
|
14
14
|
export * from './useContextMenu';
|
|
15
|
+
export * from './useGranularHook';
|
|
15
16
|
export * from './useLocalStorage';
|
|
16
17
|
export * from './useLockBodyScroll';
|
|
17
18
|
export * from './useOnClickOutside';
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __exportStar(require("./plural"), exports);
|
|
|
28
28
|
__exportStar(require("./routes"), exports);
|
|
29
29
|
__exportStar(require("./serviceWorker"), exports);
|
|
30
30
|
__exportStar(require("./useContextMenu"), exports);
|
|
31
|
+
__exportStar(require("./useGranularHook"), exports);
|
|
31
32
|
__exportStar(require("./useLocalStorage"), exports);
|
|
32
33
|
__exportStar(require("./useLockBodyScroll"), exports);
|
|
33
34
|
__exportStar(require("./useOnClickOutside"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DependencyList, EffectCallback } from 'react';
|
|
2
|
+
declare type HookWithDependencies<C, R> = (callback: C, deps: DependencyList) => R;
|
|
3
|
+
export declare const useGranularHook: <T extends HookWithDependencies<C, ReturnType<T>>, C>(hook: T, callback: C, primaryDeps: DependencyList, secondaryDeps: DependencyList) => ReturnType<T>;
|
|
4
|
+
export declare const useGranularEffect: (effect: EffectCallback, primaryDeps: DependencyList, secondaryDeps: DependencyList) => void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useGranularEffect = exports.useGranularHook = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useGranularHook = (hook, callback, primaryDeps, secondaryDeps) => {
|
|
6
|
+
const ref = (0, react_1.useRef)();
|
|
7
|
+
if (!ref.current ||
|
|
8
|
+
!primaryDeps.every((w, i) => { var _a; return Object.is(w, (_a = ref.current) === null || _a === void 0 ? void 0 : _a[i]); }))
|
|
9
|
+
ref.current = [...primaryDeps, ...secondaryDeps];
|
|
10
|
+
return hook(callback, ref.current);
|
|
11
|
+
};
|
|
12
|
+
exports.useGranularHook = useGranularHook;
|
|
13
|
+
const useGranularEffect = (effect, primaryDeps, secondaryDeps) => (0, exports.useGranularHook)(react_1.useEffect, effect, primaryDeps, secondaryDeps);
|
|
14
|
+
exports.useGranularEffect = useGranularEffect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.298",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@storybook/react": "6.5.9",
|
|
43
43
|
"@storybook/theming": "6.5.9",
|
|
44
44
|
"@types/jsonwebtoken": "8.5.8",
|
|
45
|
-
"@types/node": "18.6.
|
|
45
|
+
"@types/node": "18.6.2",
|
|
46
46
|
"@types/react": "18.0.15",
|
|
47
47
|
"@types/react-dom": "18.0.6",
|
|
48
48
|
"@types/styled-components": "5.1.25",
|