@ozen-ui/responsive 0.84.0 → 0.84.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__inner__/cjs/ui/ResponsiveProps/ResponsiveProps.js +12 -6
- package/__inner__/cjs/ui/utils/utils.js +7 -7
- package/__inner__/cjs/user-agent/user-agent-parser.js +5 -10
- package/__inner__/esm/ui/ResponsiveProps/ResponsiveProps.js +12 -6
- package/__inner__/esm/ui/utils/utils.js +7 -7
- package/__inner__/esm/user-agent/user-agent-parser.js +5 -10
- package/__inner__/types/ui/ResponsiveProps/ResponsiveProps.d.ts +1 -1
- package/__inner__/types/ui/ResponsiveProps/types.d.ts +2 -1
- package/__inner__/types/ui/utils/utils.d.ts +2 -2
- package/package.json +2 -2
|
@@ -8,8 +8,8 @@ var hooks_1 = require("../../hooks");
|
|
|
8
8
|
var provider_1 = require("../../provider");
|
|
9
9
|
var utils_2 = require("../utils");
|
|
10
10
|
var ResponsiveProps = function (_a) {
|
|
11
|
-
var _b;
|
|
12
|
-
var component = _a.component, props = _a.props, sharedPropsProp = _a.sharedProps, fallback = _a.fallback;
|
|
11
|
+
var _b, _c, _d;
|
|
12
|
+
var component = _a.component, props = _a.props, sharedPropsProp = _a.sharedProps, fallback = _a.fallback, childrenProp = _a.children;
|
|
13
13
|
var store = (0, provider_1.useResponsiveContext)().store;
|
|
14
14
|
var breakpoint = (0, hooks_1.useBreakpoint)();
|
|
15
15
|
var type = (0, hooks_1.useDeviceType)();
|
|
@@ -19,9 +19,6 @@ var ResponsiveProps = function (_a) {
|
|
|
19
19
|
};
|
|
20
20
|
var Fallback = fallback !== null && fallback !== void 0 ? fallback : (function () { return null; });
|
|
21
21
|
var rawNeededProps = (_b = (0, utils_2.resolveBreakpoints)(store.scope, props, device)) === null || _b === void 0 ? void 0 : _b.value;
|
|
22
|
-
if (!rawNeededProps) {
|
|
23
|
-
return react_1.default.createElement(Fallback, null);
|
|
24
|
-
}
|
|
25
22
|
var sharedProps = (function () {
|
|
26
23
|
if (!sharedPropsProp) {
|
|
27
24
|
return null;
|
|
@@ -34,7 +31,16 @@ var ResponsiveProps = function (_a) {
|
|
|
34
31
|
var neededProps = (0, utils_1.isFunction)(rawNeededProps)
|
|
35
32
|
? rawNeededProps()
|
|
36
33
|
: rawNeededProps;
|
|
34
|
+
var isNullProps = neededProps === null;
|
|
35
|
+
var isWithoutProps = rawNeededProps === undefined && !sharedProps && !childrenProp;
|
|
36
|
+
if (isNullProps || isWithoutProps) {
|
|
37
|
+
return react_1.default.createElement(Fallback, null);
|
|
38
|
+
}
|
|
37
39
|
var Component = component;
|
|
38
|
-
|
|
40
|
+
var children = (_d = (_c = neededProps === null || neededProps === void 0 ? void 0 : neededProps.children) !== null && _c !== void 0 ? _c : sharedProps === null || sharedProps === void 0 ? void 0 : sharedProps.children) !== null && _d !== void 0 ? _d : childrenProp;
|
|
41
|
+
return (
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
react_1.default.createElement(Component, tslib_1.__assign({}, sharedProps, neededProps), children));
|
|
39
45
|
};
|
|
40
46
|
exports.ResponsiveProps = ResponsiveProps;
|
|
@@ -13,8 +13,8 @@ var resolveBreakpoints = function (scope, by, device) {
|
|
|
13
13
|
var bestMixed = null;
|
|
14
14
|
try {
|
|
15
15
|
for (var _c = tslib_1.__values(Object.entries(by)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
16
|
-
var _e = tslib_1.__read(_d.value, 2), rawKey = _e[0],
|
|
17
|
-
if (!
|
|
16
|
+
var _e = tslib_1.__read(_d.value, 2), rawKey = _e[0], value = _e[1];
|
|
17
|
+
if (!value && value !== null) {
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
var key = rawKey;
|
|
@@ -31,7 +31,7 @@ var resolveBreakpoints = function (scope, by, device) {
|
|
|
31
31
|
}
|
|
32
32
|
var rank = SIZE_RANK[size];
|
|
33
33
|
if (rank <= currentRank && (!bestMixed || rank > bestMixed.rank)) {
|
|
34
|
-
bestMixed = { key: key, rank: rank, value:
|
|
34
|
+
bestMixed = { key: key, rank: rank, value: value };
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -46,7 +46,7 @@ var resolveBreakpoints = function (scope, by, device) {
|
|
|
46
46
|
return { key: bestMixed.key, value: bestMixed.value };
|
|
47
47
|
}
|
|
48
48
|
var typeOnly = by[device.type];
|
|
49
|
-
if (typeOnly) {
|
|
49
|
+
if (typeOnly || typeOnly === null) {
|
|
50
50
|
return { key: device.type, value: typeOnly };
|
|
51
51
|
}
|
|
52
52
|
var bestSize = null;
|
|
@@ -54,12 +54,12 @@ var resolveBreakpoints = function (scope, by, device) {
|
|
|
54
54
|
for (var _g = tslib_1.__values(scope.sizesAscending), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
55
55
|
var size = _h.value;
|
|
56
56
|
var value = by[size];
|
|
57
|
-
if (!value) {
|
|
57
|
+
if (!value && value !== null) {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
60
|
var rank = SIZE_RANK[size];
|
|
61
61
|
if (rank <= currentRank && (!bestSize || rank > bestSize.rank)) {
|
|
62
|
-
bestSize = { key: size, rank: rank, value: value };
|
|
62
|
+
bestSize = { key: size, rank: rank, value: value !== null && value !== void 0 ? value : null };
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -73,6 +73,6 @@ var resolveBreakpoints = function (scope, by, device) {
|
|
|
73
73
|
if (bestSize) {
|
|
74
74
|
return { key: bestSize.key, value: bestSize.value };
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return undefined;
|
|
77
77
|
};
|
|
78
78
|
exports.resolveBreakpoints = resolveBreakpoints;
|
|
@@ -18,18 +18,13 @@ var UserAgentParser = /** @class */ (function () {
|
|
|
18
18
|
if (!rawType) {
|
|
19
19
|
return 'desktop';
|
|
20
20
|
}
|
|
21
|
-
var _loop_1 = function (rawType_1, uaTypes) {
|
|
22
|
-
var type = rawType_1;
|
|
23
|
-
if (uaTypes.some(function (type) { return type === rawType_1; })) {
|
|
24
|
-
return { value: type };
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
21
|
try {
|
|
28
22
|
for (var _b = tslib_1.__values(Object.entries(constants_1.USER_AGENT_PARSER_TYPE_TO_INTERNAL_TYPE)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
29
|
-
var _d = tslib_1.__read(_c.value, 2),
|
|
30
|
-
var
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
23
|
+
var _d = tslib_1.__read(_c.value, 2), _type = _d[0], uaTypes = _d[1];
|
|
24
|
+
var type = _type;
|
|
25
|
+
if (uaTypes.some(function (type) { return type === rawType; })) {
|
|
26
|
+
return type;
|
|
27
|
+
}
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -5,8 +5,8 @@ import { useBreakpoint, useDeviceType } from '../../hooks';
|
|
|
5
5
|
import { useResponsiveContext } from '../../provider';
|
|
6
6
|
import { resolveBreakpoints } from '../utils';
|
|
7
7
|
export var ResponsiveProps = function (_a) {
|
|
8
|
-
var _b;
|
|
9
|
-
var component = _a.component, props = _a.props, sharedPropsProp = _a.sharedProps, fallback = _a.fallback;
|
|
8
|
+
var _b, _c, _d;
|
|
9
|
+
var component = _a.component, props = _a.props, sharedPropsProp = _a.sharedProps, fallback = _a.fallback, childrenProp = _a.children;
|
|
10
10
|
var store = useResponsiveContext().store;
|
|
11
11
|
var breakpoint = useBreakpoint();
|
|
12
12
|
var type = useDeviceType();
|
|
@@ -16,9 +16,6 @@ export var ResponsiveProps = function (_a) {
|
|
|
16
16
|
};
|
|
17
17
|
var Fallback = fallback !== null && fallback !== void 0 ? fallback : (function () { return null; });
|
|
18
18
|
var rawNeededProps = (_b = resolveBreakpoints(store.scope, props, device)) === null || _b === void 0 ? void 0 : _b.value;
|
|
19
|
-
if (!rawNeededProps) {
|
|
20
|
-
return React.createElement(Fallback, null);
|
|
21
|
-
}
|
|
22
19
|
var sharedProps = (function () {
|
|
23
20
|
if (!sharedPropsProp) {
|
|
24
21
|
return null;
|
|
@@ -31,6 +28,15 @@ export var ResponsiveProps = function (_a) {
|
|
|
31
28
|
var neededProps = isFunction(rawNeededProps)
|
|
32
29
|
? rawNeededProps()
|
|
33
30
|
: rawNeededProps;
|
|
31
|
+
var isNullProps = neededProps === null;
|
|
32
|
+
var isWithoutProps = rawNeededProps === undefined && !sharedProps && !childrenProp;
|
|
33
|
+
if (isNullProps || isWithoutProps) {
|
|
34
|
+
return React.createElement(Fallback, null);
|
|
35
|
+
}
|
|
34
36
|
var Component = component;
|
|
35
|
-
|
|
37
|
+
var children = (_d = (_c = neededProps === null || neededProps === void 0 ? void 0 : neededProps.children) !== null && _c !== void 0 ? _c : sharedProps === null || sharedProps === void 0 ? void 0 : sharedProps.children) !== null && _d !== void 0 ? _d : childrenProp;
|
|
38
|
+
return (
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
React.createElement(Component, __assign({}, sharedProps, neededProps), children));
|
|
36
42
|
};
|
|
@@ -10,8 +10,8 @@ export var resolveBreakpoints = function (scope, by, device) {
|
|
|
10
10
|
var bestMixed = null;
|
|
11
11
|
try {
|
|
12
12
|
for (var _c = __values(Object.entries(by)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
13
|
-
var _e = __read(_d.value, 2), rawKey = _e[0],
|
|
14
|
-
if (!
|
|
13
|
+
var _e = __read(_d.value, 2), rawKey = _e[0], value = _e[1];
|
|
14
|
+
if (!value && value !== null) {
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
var key = rawKey;
|
|
@@ -28,7 +28,7 @@ export var resolveBreakpoints = function (scope, by, device) {
|
|
|
28
28
|
}
|
|
29
29
|
var rank = SIZE_RANK[size];
|
|
30
30
|
if (rank <= currentRank && (!bestMixed || rank > bestMixed.rank)) {
|
|
31
|
-
bestMixed = { key: key, rank: rank, value:
|
|
31
|
+
bestMixed = { key: key, rank: rank, value: value };
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -43,7 +43,7 @@ export var resolveBreakpoints = function (scope, by, device) {
|
|
|
43
43
|
return { key: bestMixed.key, value: bestMixed.value };
|
|
44
44
|
}
|
|
45
45
|
var typeOnly = by[device.type];
|
|
46
|
-
if (typeOnly) {
|
|
46
|
+
if (typeOnly || typeOnly === null) {
|
|
47
47
|
return { key: device.type, value: typeOnly };
|
|
48
48
|
}
|
|
49
49
|
var bestSize = null;
|
|
@@ -51,12 +51,12 @@ export var resolveBreakpoints = function (scope, by, device) {
|
|
|
51
51
|
for (var _g = __values(scope.sizesAscending), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
52
52
|
var size = _h.value;
|
|
53
53
|
var value = by[size];
|
|
54
|
-
if (!value) {
|
|
54
|
+
if (!value && value !== null) {
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
57
|
var rank = SIZE_RANK[size];
|
|
58
58
|
if (rank <= currentRank && (!bestSize || rank > bestSize.rank)) {
|
|
59
|
-
bestSize = { key: size, rank: rank, value: value };
|
|
59
|
+
bestSize = { key: size, rank: rank, value: value !== null && value !== void 0 ? value : null };
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -70,5 +70,5 @@ export var resolveBreakpoints = function (scope, by, device) {
|
|
|
70
70
|
if (bestSize) {
|
|
71
71
|
return { key: bestSize.key, value: bestSize.value };
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return undefined;
|
|
74
74
|
};
|
|
@@ -15,18 +15,13 @@ var UserAgentParser = /** @class */ (function () {
|
|
|
15
15
|
if (!rawType) {
|
|
16
16
|
return 'desktop';
|
|
17
17
|
}
|
|
18
|
-
var _loop_1 = function (rawType_1, uaTypes) {
|
|
19
|
-
var type = rawType_1;
|
|
20
|
-
if (uaTypes.some(function (type) { return type === rawType_1; })) {
|
|
21
|
-
return { value: type };
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
18
|
try {
|
|
25
19
|
for (var _b = __values(Object.entries(USER_AGENT_PARSER_TYPE_TO_INTERNAL_TYPE)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
26
|
-
var _d = __read(_c.value, 2),
|
|
27
|
-
var
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
20
|
+
var _d = __read(_c.value, 2), _type = _d[0], uaTypes = _d[1];
|
|
21
|
+
var type = _type;
|
|
22
|
+
if (uaTypes.some(function (type) { return type === rawType; })) {
|
|
23
|
+
return type;
|
|
24
|
+
}
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2,4 +2,4 @@ import type { ElementType } from 'react';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { Breakpoints } from '../../entities';
|
|
4
4
|
import type { ResponsivePropsProps } from './types';
|
|
5
|
-
export declare const ResponsiveProps: <TBreakpoints extends Breakpoints, Component extends ElementType>({ component, props, sharedProps: sharedPropsProp, fallback, }: ResponsivePropsProps<TBreakpoints, Component>) => React.JSX.Element;
|
|
5
|
+
export declare const ResponsiveProps: <TBreakpoints extends Breakpoints, Component extends ElementType>({ component, props, sharedProps: sharedPropsProp, fallback, children: childrenProp, }: ResponsivePropsProps<TBreakpoints, Component>) => React.JSX.Element;
|
|
@@ -3,6 +3,7 @@ import type { Breakpoints, ByBreakpoints } from '../../entities';
|
|
|
3
3
|
export type ResponsivePropsProps<TBreakpoints extends Breakpoints, Component extends ElementType> = {
|
|
4
4
|
fallback?: () => ReactNode;
|
|
5
5
|
component: Component;
|
|
6
|
-
props: ByBreakpoints<TBreakpoints, ComponentProps<Component
|
|
6
|
+
props: ByBreakpoints<TBreakpoints, Partial<ComponentProps<Component>> | null | (() => Partial<ComponentProps<Component>> | null)>;
|
|
7
7
|
sharedProps?: Partial<ComponentProps<Component>> | (() => Partial<ComponentProps<Component>>);
|
|
8
|
+
children?: 'children' extends keyof ComponentProps<Component> ? ComponentProps<Component>['children'] : never;
|
|
8
9
|
};
|
|
@@ -2,5 +2,5 @@ import type { BreakpointKey, Breakpoints, Scope } from '../../entities';
|
|
|
2
2
|
import type { BreakpointMap, DeviceInfo } from './types';
|
|
3
3
|
export declare const resolveBreakpoints: <TBreakpoints extends Breakpoints, Value>(scope: Scope<TBreakpoints>, by: BreakpointMap<TBreakpoints, Value>, device: DeviceInfo<TBreakpoints>) => {
|
|
4
4
|
key: BreakpointKey<TBreakpoints>;
|
|
5
|
-
value: Value;
|
|
6
|
-
} |
|
|
5
|
+
value: Value | null;
|
|
6
|
+
} | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozen-ui/responsive",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.2",
|
|
4
4
|
"description": "React component library",
|
|
5
5
|
"files": [
|
|
6
6
|
"*"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"ua-parser-js": "2.0.8",
|
|
22
|
-
"@ozen-ui/kit": "0.84.
|
|
22
|
+
"@ozen-ui/kit": "0.84.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/lodash.isequal": "^4.5.0"
|