@hi-ui/layout 4.0.0 → 5.0.0-alpha.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/CHANGELOG.md +51 -0
- package/lib/cjs/AppList.js +163 -0
- package/lib/cjs/CollapseIcon.js +56 -0
- package/lib/cjs/Content.js +1 -4
- package/lib/cjs/FloatMenuContainer.js +93 -0
- package/lib/cjs/Footer.js +45 -0
- package/lib/cjs/Header.js +45 -0
- package/lib/cjs/Layout.js +4 -2
- package/lib/cjs/Profile.js +165 -0
- package/lib/cjs/SearchTrigger.js +71 -8
- package/lib/cjs/Sider.js +32 -18
- package/lib/cjs/index.js +26 -3
- package/lib/cjs/packages/hooks/use-id/lib/esm/index.js +51 -0
- package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +16 -0
- package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +33 -0
- package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +41 -0
- package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +33 -0
- package/lib/cjs/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +19 -0
- package/lib/cjs/packages/hooks/use-latest/lib/esm/index.js +56 -0
- package/lib/cjs/packages/hooks/use-timeout/lib/esm/index.js +50 -0
- package/lib/cjs/packages/hooks/use-toggle/lib/esm/index.js +71 -0
- package/lib/cjs/packages/hooks/use-unmount-effect/lib/esm/index.js +44 -0
- package/lib/cjs/packages/icons/lib/esm/components/alert/check-outlined.js +65 -0
- package/lib/cjs/packages/icons/lib/esm/components/direction/right-outlined.js +65 -0
- package/lib/cjs/packages/ui/popover/lib/esm/Popover.js +111 -0
- package/lib/cjs/packages/ui/popover/lib/esm/index.js +31 -0
- package/lib/cjs/packages/ui/popover/lib/esm/styles/index.scss.js +35 -0
- package/lib/cjs/packages/ui/popover/lib/esm/types.js +31 -0
- package/lib/cjs/packages/ui/popover/lib/esm/use-popover.js +187 -0
- package/lib/cjs/packages/ui/popover/lib/esm/utils/container/lib/esm/index.js +67 -0
- package/lib/cjs/packages/ui/popover/lib/esm/with-api.js +84 -0
- package/lib/cjs/packages/utils/array-utils/lib/esm/index.js +33 -0
- package/lib/cjs/packages/utils/dom-utils/lib/esm/index.js +47 -0
- package/lib/cjs/packages/utils/react-utils/lib/esm/index.js +72 -0
- package/lib/cjs/packages/utils/type-assertion/lib/esm/index.js +36 -0
- package/lib/cjs/styles/index.scss.js +1 -1
- package/lib/esm/AppList.js +149 -0
- package/lib/esm/CollapseIcon.js +44 -0
- package/lib/esm/Content.js +1 -4
- package/lib/esm/FloatMenuContainer.js +81 -0
- package/lib/esm/Footer.js +33 -0
- package/lib/esm/Header.js +33 -0
- package/lib/esm/Layout.js +4 -2
- package/lib/esm/Profile.js +152 -0
- package/lib/esm/SearchTrigger.js +70 -8
- package/lib/esm/Sider.js +32 -18
- package/lib/esm/index.js +22 -4
- package/lib/esm/packages/hooks/use-id/lib/esm/index.js +45 -0
- package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/regex.js +11 -0
- package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/rng.js +27 -0
- package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/stringify.js +36 -0
- package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/v4.js +28 -0
- package/lib/esm/packages/hooks/use-id/node_modules/uuid/dist/esm-browser/validate.js +14 -0
- package/lib/esm/packages/hooks/use-latest/lib/esm/index.js +50 -0
- package/lib/esm/packages/hooks/use-timeout/lib/esm/index.js +45 -0
- package/lib/esm/packages/hooks/use-toggle/lib/esm/index.js +66 -0
- package/lib/esm/packages/hooks/use-unmount-effect/lib/esm/index.js +39 -0
- package/lib/esm/packages/icons/lib/esm/components/alert/check-outlined.js +53 -0
- package/lib/esm/packages/icons/lib/esm/components/direction/right-outlined.js +53 -0
- package/lib/esm/packages/ui/popover/lib/esm/Popover.js +97 -0
- package/lib/esm/packages/ui/popover/lib/esm/index.js +25 -0
- package/lib/esm/packages/ui/popover/lib/esm/styles/index.scss.js +23 -0
- package/lib/esm/packages/ui/popover/lib/esm/types.js +25 -0
- package/lib/esm/packages/ui/popover/lib/esm/use-popover.js +175 -0
- package/lib/esm/packages/ui/popover/lib/esm/utils/container/lib/esm/index.js +60 -0
- package/lib/esm/packages/ui/popover/lib/esm/with-api.js +79 -0
- package/lib/esm/packages/utils/array-utils/lib/esm/index.js +28 -0
- package/lib/esm/packages/utils/dom-utils/lib/esm/index.js +42 -0
- package/lib/esm/packages/utils/react-utils/lib/esm/index.js +65 -0
- package/lib/esm/packages/utils/type-assertion/lib/esm/index.js +29 -0
- package/lib/esm/styles/index.scss.js +1 -1
- package/lib/types/AppList.d.ts +71 -0
- package/lib/types/CollapseIcon.d.ts +1 -0
- package/lib/types/Content.d.ts +0 -3
- package/lib/types/FloatMenuContainer.d.ts +28 -0
- package/lib/types/Footer.d.ts +5 -0
- package/lib/types/Header.d.ts +5 -0
- package/lib/types/Layout.d.ts +4 -0
- package/lib/types/Profile.d.ts +24 -0
- package/lib/types/SearchTrigger.d.ts +11 -0
- package/lib/types/Sider.d.ts +21 -0
- package/lib/types/index.d.ts +17 -1
- package/package.json +9 -7
package/lib/cjs/SearchTrigger.js
CHANGED
|
@@ -17,14 +17,18 @@ var tslib = require('tslib');
|
|
|
17
17
|
var React = require('react');
|
|
18
18
|
var classname = require('@hi-ui/classname');
|
|
19
19
|
var env = require('@hi-ui/env');
|
|
20
|
+
var core = require('@hi-ui/core');
|
|
20
21
|
require('./packages/icons/lib/esm/styles/index.scss.js');
|
|
21
22
|
var searchOutlined = require('./packages/icons/lib/esm/components/common/search-outlined.js');
|
|
23
|
+
var Popper = require('@hi-ui/popper');
|
|
24
|
+
var menu = require('@hi-ui/menu');
|
|
22
25
|
function _interopDefaultCompat(e) {
|
|
23
26
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
|
24
27
|
'default': e
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
31
|
+
var Popper__default = /*#__PURE__*/_interopDefaultCompat(Popper);
|
|
28
32
|
var SEARCH_TRIGGER_PREFIX = classname.getPrefixCls('search-trigger');
|
|
29
33
|
/**
|
|
30
34
|
* 搜索触发器组件
|
|
@@ -37,17 +41,76 @@ var SearchTrigger = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
37
41
|
role = _a$role === void 0 ? 'search-trigger' : _a$role,
|
|
38
42
|
className = _a.className,
|
|
39
43
|
mini = _a.mini,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
placeholder = _a.placeholder,
|
|
45
|
+
data = _a.data,
|
|
46
|
+
onClick = _a.onClick,
|
|
47
|
+
rest = tslib.__rest(_a, ["prefixCls", "role", "className", "mini", "placeholder", "data", "onClick"]);
|
|
48
|
+
var i18n = core.useLocaleContext();
|
|
49
|
+
var _React$useState = React__default["default"].useState(false),
|
|
50
|
+
visible = _React$useState[0],
|
|
51
|
+
setVisible = _React$useState[1];
|
|
52
|
+
var _React$useState2 = React__default["default"].useState(''),
|
|
53
|
+
value = _React$useState2[0],
|
|
54
|
+
setValue = _React$useState2[1];
|
|
55
|
+
var innerRef = React__default["default"].useRef(null);
|
|
56
|
+
var searchRef = React__default["default"].useRef(null);
|
|
43
57
|
var cls = classname.cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--mini"] = mini, _cx));
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
var handleClick = function handleClick(evt) {
|
|
59
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(evt);
|
|
60
|
+
if (evt.defaultPrevented) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setVisible(!visible);
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
|
|
66
|
+
ref: innerRef,
|
|
46
67
|
role: role,
|
|
47
|
-
className: cls
|
|
48
|
-
|
|
68
|
+
className: cls,
|
|
69
|
+
onClick: handleClick
|
|
70
|
+
}, rest), /*#__PURE__*/React__default["default"].createElement(searchOutlined.SearchOutlined, null), !mini && ( /*#__PURE__*/React__default["default"].createElement("span", {
|
|
49
71
|
className: prefixCls + "__placeholder"
|
|
50
|
-
}, placeholder))
|
|
72
|
+
}, placeholder || i18n.menuSearch.search))), /*#__PURE__*/React__default["default"].createElement(Popper__default["default"], {
|
|
73
|
+
classNames: {
|
|
74
|
+
container: prefixCls + "__popper-container"
|
|
75
|
+
},
|
|
76
|
+
visible: visible,
|
|
77
|
+
attachEl: innerRef.current,
|
|
78
|
+
gutterGap: -32,
|
|
79
|
+
unmountOnClose: false,
|
|
80
|
+
onOutsideClick: function onOutsideClick() {
|
|
81
|
+
var _a;
|
|
82
|
+
setVisible(false);
|
|
83
|
+
(_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.hide();
|
|
84
|
+
},
|
|
85
|
+
onEntered: function onEntered() {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (visible) {
|
|
88
|
+
(_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
89
|
+
if (value) {
|
|
90
|
+
(_b = searchRef.current) === null || _b === void 0 ? void 0 : _b.show();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, /*#__PURE__*/React__default["default"].createElement(menu.MenuSearch, {
|
|
95
|
+
innerRef: searchRef,
|
|
96
|
+
width: 360,
|
|
97
|
+
value: value,
|
|
98
|
+
onChange: setValue,
|
|
99
|
+
data: data,
|
|
100
|
+
placeholder: i18n.menuSearch.placeholder,
|
|
101
|
+
onSelect: function onSelect(id, item) {
|
|
102
|
+
setVisible(false);
|
|
103
|
+
},
|
|
104
|
+
onClear: function onClear() {
|
|
105
|
+
setValue('');
|
|
106
|
+
},
|
|
107
|
+
onClose: function onClose() {
|
|
108
|
+
setVisible(false);
|
|
109
|
+
},
|
|
110
|
+
onEsc: function onEsc() {
|
|
111
|
+
setVisible(false);
|
|
112
|
+
}
|
|
113
|
+
})));
|
|
51
114
|
});
|
|
52
115
|
if (env.__DEV__) {
|
|
53
116
|
SearchTrigger.displayName = 'SearchTrigger';
|
package/lib/cjs/Sider.js
CHANGED
|
@@ -26,6 +26,10 @@ function _interopDefaultCompat(e) {
|
|
|
26
26
|
}
|
|
27
27
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
28
28
|
var SIDER_PREFIX = classname.getPrefixCls('sider');
|
|
29
|
+
var DEFAULT_SIDER_WIDTH = 180;
|
|
30
|
+
var SIDER_WIDTH_MIN = 60;
|
|
31
|
+
var SIDER_WIDTH_MIN_COLLAPSED = 150;
|
|
32
|
+
var SIDER_WIDTH_MAX = 360;
|
|
29
33
|
/**
|
|
30
34
|
* 侧边栏组件
|
|
31
35
|
*/
|
|
@@ -36,31 +40,40 @@ var Sider = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
36
40
|
_a$role = _a.role,
|
|
37
41
|
role = _a$role === void 0 ? 'sider' : _a$role,
|
|
38
42
|
className = _a.className,
|
|
43
|
+
widthProp = _a.width,
|
|
44
|
+
maxWidthProp = _a.maxWidth,
|
|
45
|
+
_a$resizable = _a.resizable,
|
|
46
|
+
resizable = _a$resizable === void 0 ? true : _a$resizable,
|
|
39
47
|
collapsedProp = _a.collapsed,
|
|
40
48
|
onCollapse = _a.onCollapse,
|
|
41
49
|
children = _a.children,
|
|
42
|
-
rest = tslib.__rest(_a, ["prefixCls", "role", "className", "collapsed", "onCollapse", "children"]);
|
|
50
|
+
rest = tslib.__rest(_a, ["prefixCls", "role", "className", "width", "maxWidth", "resizable", "collapsed", "onCollapse", "children"]);
|
|
43
51
|
var _useUncontrolledState = useUncontrolledState.useUncontrolledState(false, collapsedProp, onCollapse),
|
|
44
52
|
collapsed = _useUncontrolledState[0],
|
|
45
53
|
setCollapsed = _useUncontrolledState[1];
|
|
46
|
-
var
|
|
54
|
+
var siderWidth = widthProp || DEFAULT_SIDER_WIDTH;
|
|
55
|
+
var _useState = React.useState(collapsedProp ? SIDER_WIDTH_MIN : siderWidth),
|
|
47
56
|
width = _useState[0],
|
|
48
57
|
setWidth = _useState[1];
|
|
58
|
+
var maxWidth = maxWidthProp || SIDER_WIDTH_MAX;
|
|
49
59
|
var handleResize = function handleResize(evt, options) {
|
|
50
60
|
var _a;
|
|
51
61
|
var width = (_a = options === null || options === void 0 ? void 0 : options.size) === null || _a === void 0 ? void 0 : _a.width;
|
|
52
|
-
if (!collapsed && width <
|
|
53
|
-
width =
|
|
62
|
+
if (!collapsed && width < SIDER_WIDTH_MIN_COLLAPSED) {
|
|
63
|
+
width = SIDER_WIDTH_MIN;
|
|
54
64
|
setCollapsed(true);
|
|
55
65
|
}
|
|
56
|
-
if (collapsed && width >
|
|
57
|
-
width =
|
|
66
|
+
if (collapsed && width > SIDER_WIDTH_MIN) {
|
|
67
|
+
width = siderWidth;
|
|
58
68
|
setTimeout(function () {
|
|
59
69
|
setCollapsed(false);
|
|
60
70
|
}, 300);
|
|
61
71
|
}
|
|
62
|
-
if (width
|
|
63
|
-
width =
|
|
72
|
+
if (width <= SIDER_WIDTH_MIN) {
|
|
73
|
+
width = SIDER_WIDTH_MIN;
|
|
74
|
+
}
|
|
75
|
+
if (width > maxWidth) {
|
|
76
|
+
width = maxWidth;
|
|
64
77
|
}
|
|
65
78
|
setWidth(width);
|
|
66
79
|
};
|
|
@@ -71,7 +84,16 @@ var Sider = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
71
84
|
document.body.style.userSelect = 'auto';
|
|
72
85
|
}, []);
|
|
73
86
|
var cls = classname.cx(prefixCls, className, (_cx = {}, _cx[prefixCls + "--collapsed"] = collapsed, _cx));
|
|
74
|
-
|
|
87
|
+
var Content = /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
|
|
88
|
+
ref: ref,
|
|
89
|
+
role: role,
|
|
90
|
+
className: cls
|
|
91
|
+
}, rest, {
|
|
92
|
+
style: Object.assign({
|
|
93
|
+
width: width
|
|
94
|
+
}, rest.style)
|
|
95
|
+
}), children);
|
|
96
|
+
return resizable ? ( /*#__PURE__*/React__default["default"].createElement(index.Resizable, {
|
|
75
97
|
className: prefixCls + "__resizable",
|
|
76
98
|
draggableOpts: {
|
|
77
99
|
enableUserSelectHack: false
|
|
@@ -84,15 +106,7 @@ var Sider = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
84
106
|
onResize: handleResize,
|
|
85
107
|
onResizeStart: handleResizeStart,
|
|
86
108
|
onResizeStop: handleResizeStop
|
|
87
|
-
},
|
|
88
|
-
ref: ref,
|
|
89
|
-
role: role,
|
|
90
|
-
className: cls
|
|
91
|
-
}, rest, {
|
|
92
|
-
style: Object.assign({
|
|
93
|
-
width: width
|
|
94
|
-
}, rest.style)
|
|
95
|
-
}), children));
|
|
109
|
+
}, Content)) : Content;
|
|
96
110
|
});
|
|
97
111
|
if (env.__DEV__) {
|
|
98
112
|
Sider.displayName = 'Sider';
|
package/lib/cjs/index.js
CHANGED
|
@@ -13,12 +13,35 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
13
13
|
value: true
|
|
14
14
|
});
|
|
15
15
|
require('./styles/index.scss.js');
|
|
16
|
-
var Layout = require('./Layout.js');
|
|
16
|
+
var Layout$1 = require('./Layout.js');
|
|
17
|
+
var Header = require('./Header.js');
|
|
17
18
|
var Sider = require('./Sider.js');
|
|
18
19
|
var Content = require('./Content.js');
|
|
20
|
+
var Footer = require('./Footer.js');
|
|
19
21
|
var SearchTrigger = require('./SearchTrigger.js');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
var FloatMenuContainer = require('./FloatMenuContainer.js');
|
|
23
|
+
var AppList = require('./AppList.js');
|
|
24
|
+
var Profile = require('./Profile.js');
|
|
25
|
+
var Layout = Object.assign(Layout$1.Layout, {
|
|
26
|
+
Header: Header.Header,
|
|
27
|
+
Sider: Sider.Sider,
|
|
28
|
+
Content: Content.Content,
|
|
29
|
+
Footer: Footer.Footer,
|
|
30
|
+
SearchTrigger: SearchTrigger.SearchTrigger,
|
|
31
|
+
FloatMenuContainer: FloatMenuContainer.FloatMenuContainer,
|
|
32
|
+
AppListPopover: AppList.AppListPopover,
|
|
33
|
+
ProfilePopover: Profile.ProfilePopover
|
|
34
|
+
});
|
|
35
|
+
exports.Layout = Layout$1.Layout;
|
|
36
|
+
exports.Header = Header.Header;
|
|
22
37
|
exports.Sider = Sider.Sider;
|
|
23
38
|
exports.Content = Content.Content;
|
|
39
|
+
exports.Footer = Footer.Footer;
|
|
24
40
|
exports.SearchTrigger = SearchTrigger.SearchTrigger;
|
|
41
|
+
exports.FloatMenuContainer = FloatMenuContainer.FloatMenuContainer;
|
|
42
|
+
exports.AppList = AppList.AppList;
|
|
43
|
+
exports.AppListPopover = AppList.AppListPopover;
|
|
44
|
+
exports.IconBgColorMap = AppList.IconBgColorMap;
|
|
45
|
+
exports.Profile = Profile.Profile;
|
|
46
|
+
exports.ProfilePopover = Profile.ProfilePopover;
|
|
47
|
+
exports["default"] = Layout;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var React = require('react');
|
|
16
|
+
var v4 = require('../../node_modules/uuid/dist/esm-browser/v4.js');
|
|
17
|
+
|
|
18
|
+
/** @LICENSE
|
|
19
|
+
* @hi-ui/use-id
|
|
20
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-id#readme
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generate a uuid.
|
|
30
|
+
*/
|
|
31
|
+
var uuid = function uuid() {
|
|
32
|
+
return v4["default"]();
|
|
33
|
+
};
|
|
34
|
+
var IdGenerator = function IdGenerator() {
|
|
35
|
+
var _this = this;
|
|
36
|
+
this.id = 0;
|
|
37
|
+
this.next = function () {
|
|
38
|
+
return ++_this.id;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
var idGenerator = new IdGenerator();
|
|
42
|
+
/**
|
|
43
|
+
* A hook to generate a uid
|
|
44
|
+
*/
|
|
45
|
+
var useUID = function useUID(prefix) {
|
|
46
|
+
return React.useMemo(function () {
|
|
47
|
+
return prefix + '-' + idGenerator.next();
|
|
48
|
+
}, [prefix]);
|
|
49
|
+
};
|
|
50
|
+
exports.useUID = useUID;
|
|
51
|
+
exports.uuid = uuid;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
16
|
+
exports["default"] = REGEX;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
17
|
+
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
18
|
+
// generators (like Math.random()).
|
|
19
|
+
var getRandomValues;
|
|
20
|
+
var rnds8 = new Uint8Array(16);
|
|
21
|
+
function rng() {
|
|
22
|
+
// lazy load so that environments that need to polyfill have a chance to do so
|
|
23
|
+
if (!getRandomValues) {
|
|
24
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
|
25
|
+
// find the complete implementation of crypto (msCrypto) on IE11.
|
|
26
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|
27
|
+
if (!getRandomValues) {
|
|
28
|
+
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return getRandomValues(rnds8);
|
|
32
|
+
}
|
|
33
|
+
exports["default"] = rng;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var validate = require('./validate.js');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
19
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var byteToHex = [];
|
|
23
|
+
for (var i = 0; i < 256; ++i) {
|
|
24
|
+
byteToHex.push((i + 0x100).toString(16).substr(1));
|
|
25
|
+
}
|
|
26
|
+
function stringify(arr) {
|
|
27
|
+
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
28
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
29
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
30
|
+
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
|
31
|
+
// of the following:
|
|
32
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
33
|
+
// "undefined" in the uuid)
|
|
34
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
35
|
+
|
|
36
|
+
if (!validate["default"](uuid)) {
|
|
37
|
+
throw TypeError('Stringified UUID is invalid');
|
|
38
|
+
}
|
|
39
|
+
return uuid;
|
|
40
|
+
}
|
|
41
|
+
exports["default"] = stringify;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var rng = require('./rng.js');
|
|
16
|
+
var stringify = require('./stringify.js');
|
|
17
|
+
function v4(options, buf, offset) {
|
|
18
|
+
options = options || {};
|
|
19
|
+
var rnds = options.random || (options.rng || rng["default"])(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
20
|
+
|
|
21
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
22
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
23
|
+
|
|
24
|
+
if (buf) {
|
|
25
|
+
offset = offset || 0;
|
|
26
|
+
for (var i = 0; i < 16; ++i) {
|
|
27
|
+
buf[offset + i] = rnds[i];
|
|
28
|
+
}
|
|
29
|
+
return buf;
|
|
30
|
+
}
|
|
31
|
+
return stringify["default"](rnds);
|
|
32
|
+
}
|
|
33
|
+
exports["default"] = v4;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var regex = require('./regex.js');
|
|
16
|
+
function validate(uuid) {
|
|
17
|
+
return typeof uuid === 'string' && regex["default"].test(uuid);
|
|
18
|
+
}
|
|
19
|
+
exports["default"] = validate;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var React = require('react');
|
|
16
|
+
|
|
17
|
+
/** @LICENSE
|
|
18
|
+
* @hi-ui/use-latest
|
|
19
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-latest#readme
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Keep value up-to-date if it changes.
|
|
29
|
+
*
|
|
30
|
+
* @param value
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
var useLatestRef = function useLatestRef(value) {
|
|
34
|
+
var ref = React.useRef(value);
|
|
35
|
+
ref.current = value;
|
|
36
|
+
return ref;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Keep callback function up-to-date if it changes.
|
|
40
|
+
*
|
|
41
|
+
* @param callback
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
var useLatestCallback = function useLatestCallback(callback) {
|
|
45
|
+
var ref = useLatestRef(callback);
|
|
46
|
+
return React.useCallback(function () {
|
|
47
|
+
var _a2;
|
|
48
|
+
var _a;
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
return (_a = ref.current) === null || _a === void 0 ? void 0 : (_a2 = _a).call.apply(_a2, [ref].concat(args));
|
|
53
|
+
}, []);
|
|
54
|
+
};
|
|
55
|
+
exports.useLatestCallback = useLatestCallback;
|
|
56
|
+
exports.useLatestRef = useLatestRef;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var React = require('react');
|
|
16
|
+
var index = require('../../../use-latest/lib/esm/index.js');
|
|
17
|
+
|
|
18
|
+
/** @LICENSE
|
|
19
|
+
* @hi-ui/use-timeout
|
|
20
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-timeout#readme
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* TODO: What is useTimeout
|
|
30
|
+
* 1. 负责props变化需要取消定时器以及页面卸载时取消定时器这一套逻辑
|
|
31
|
+
* 2. 处理 window 支持 SSR
|
|
32
|
+
*/
|
|
33
|
+
var useTimeout = function useTimeout(callback, timeoutDelayMs) {
|
|
34
|
+
var timerRef = React.useRef(undefined);
|
|
35
|
+
var callbackLatest = index.useLatestCallback(callback);
|
|
36
|
+
var clear = React.useCallback(function () {
|
|
37
|
+
if (timerRef.current === undefined) return;
|
|
38
|
+
window.clearTimeout(timerRef.current);
|
|
39
|
+
timerRef.current = undefined;
|
|
40
|
+
}, []);
|
|
41
|
+
var start = React.useCallback(function () {
|
|
42
|
+
if (typeof timeoutDelayMs !== 'number' || timeoutDelayMs < 0) return;
|
|
43
|
+
timerRef.current = window.setTimeout(callbackLatest, timeoutDelayMs);
|
|
44
|
+
}, [callbackLatest, timeoutDelayMs]);
|
|
45
|
+
return {
|
|
46
|
+
start: start,
|
|
47
|
+
clear: clear
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.useTimeout = useTimeout;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var React = require('react');
|
|
16
|
+
var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
|
|
17
|
+
var index = require('../../../use-latest/lib/esm/index.js');
|
|
18
|
+
|
|
19
|
+
/** @LICENSE
|
|
20
|
+
* @hi-ui/use-toggle
|
|
21
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-toggle#readme
|
|
22
|
+
*
|
|
23
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
24
|
+
*
|
|
25
|
+
* This source code is licensed under the MIT license found in the
|
|
26
|
+
* LICENSE file in the root directory of this source tree.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Handles uncontrolled boolean switching by `on`, `off`, `not`
|
|
30
|
+
*/
|
|
31
|
+
function useUncontrolledToggle(_ref) {
|
|
32
|
+
var _ref$defaultVisible = _ref.defaultVisible,
|
|
33
|
+
defaultVisible = _ref$defaultVisible === void 0 ? false : _ref$defaultVisible,
|
|
34
|
+
visibleProp = _ref.visible,
|
|
35
|
+
onClose = _ref.onClose,
|
|
36
|
+
onOpen = _ref.onOpen,
|
|
37
|
+
onToggle = _ref.onToggle,
|
|
38
|
+
isEqual = _ref.isEqual,
|
|
39
|
+
_ref$disabled = _ref.disabled,
|
|
40
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
41
|
+
var onVisibleChange = index.useLatestCallback(function (nextVisible) {
|
|
42
|
+
var callback = nextVisible ? onOpen : onClose;
|
|
43
|
+
callback === null || callback === void 0 ? void 0 : callback();
|
|
44
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(nextVisible);
|
|
45
|
+
});
|
|
46
|
+
var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultVisible, visibleProp, onVisibleChange, isEqual),
|
|
47
|
+
bool = _useUncontrolledState[0],
|
|
48
|
+
setBool = _useUncontrolledState[1];
|
|
49
|
+
var proxySetBool = index.useLatestCallback(function (stateOrFunction) {
|
|
50
|
+
if (disabled) return;
|
|
51
|
+
setBool(stateOrFunction);
|
|
52
|
+
});
|
|
53
|
+
var toggle = React.useMemo(function () {
|
|
54
|
+
return {
|
|
55
|
+
set: proxySetBool,
|
|
56
|
+
on: function on() {
|
|
57
|
+
proxySetBool(true);
|
|
58
|
+
},
|
|
59
|
+
off: function off() {
|
|
60
|
+
proxySetBool(false);
|
|
61
|
+
},
|
|
62
|
+
not: function not() {
|
|
63
|
+
proxySetBool(function (prev) {
|
|
64
|
+
return !prev;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, [proxySetBool]);
|
|
69
|
+
return [bool, toggle];
|
|
70
|
+
}
|
|
71
|
+
exports.useUncontrolledToggle = useUncontrolledToggle;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/layout
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var React = require('react');
|
|
16
|
+
var index = require('../../../use-latest/lib/esm/index.js');
|
|
17
|
+
|
|
18
|
+
/** @LICENSE
|
|
19
|
+
* @hi-ui/use-unmount-effect
|
|
20
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-unmount-effect#readme
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A hook for running when component unmount, will return unmountRef sign
|
|
30
|
+
*/
|
|
31
|
+
var useUnmountEffect = function useUnmountEffect(cleanup) {
|
|
32
|
+
var cleanupLatest = index.useLatestCallback(cleanup);
|
|
33
|
+
var unmountRef = React.useRef(false);
|
|
34
|
+
React.useEffect(function () {
|
|
35
|
+
return function () {
|
|
36
|
+
unmountRef.current = true;
|
|
37
|
+
cleanupLatest();
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
[]);
|
|
42
|
+
return unmountRef;
|
|
43
|
+
};
|
|
44
|
+
exports.useUnmountEffect = useUnmountEffect;
|