@hi-ui/grid 5.0.0-experimental.1 → 5.0.0-rc.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 CHANGED
@@ -1,16 +1,6 @@
1
1
  # @hi-ui/grid
2
2
 
3
- ## 5.0.0-experimental.1
4
-
5
- ### Patch Changes
6
-
7
- - c6197357f: 新增 AutoGrid 及 DynamicGrid 组件
8
- - Updated dependencies [eb17c4697]
9
- - Updated dependencies [c407744fe]
10
- - @hi-ui/core@5.0.0-experimental.1
11
- - @hi-ui/use-merge-semantic@5.0.0-experimental.0
12
-
13
- ## 5.0.0-experimental.0
3
+ ## 5.0.0-rc.0
14
4
 
15
5
  ### Major Changes
16
6
 
@@ -23,19 +13,26 @@
23
13
  ### Patch Changes
24
14
 
25
15
  - 9b34d99bc: chore: 将代码中 v4 改为 v5 (5.0)
16
+ - c6197357f: 新增 AutoGrid 及 DynamicGrid 组件
26
17
  - 2e56529f7: styles: 主题定制功能完善&&样式变量化写法改造&&兼容 RTL (5.0)
27
18
  - 33da3144e: build: 将 package.json 中 exports 配置中的 types 配置放在最上面 (5.0)
19
+ - Updated dependencies [eb17c4697]
28
20
  - Updated dependencies [8c0ee78f0]
29
21
  - Updated dependencies [8f3aa85e4]
30
22
  - Updated dependencies [fd4c20bbd]
31
23
  - Updated dependencies [79ea480f3]
32
24
  - Updated dependencies [f1ab51725]
25
+ - Updated dependencies [d91a8bb0f]
33
26
  - Updated dependencies [33da3144e]
34
27
  - Updated dependencies [58ad82e94]
35
- - @hi-ui/core@5.0.0-experimental.0
36
- - @hi-ui/classname@5.0.0-experimental.0
37
- - @hi-ui/env@5.0.0-experimental.0
38
- - @hi-ui/type-assertion@5.0.0-experimental.0
28
+ - Updated dependencies [95d930354]
29
+ - @hi-ui/core@5.0.0-rc.0
30
+ - @hi-ui/use-latest@5.0.0-rc.0
31
+ - @hi-ui/use-merge-refs@5.0.0-rc.0
32
+ - @hi-ui/classname@5.0.0-rc.0
33
+ - @hi-ui/env@5.0.0-rc.0
34
+ - @hi-ui/func-utils@5.0.0-rc.0
35
+ - @hi-ui/type-assertion@5.0.0-rc.0
39
36
 
40
37
  ## 4.0.9
41
38
 
@@ -15,7 +15,7 @@ Object.defineProperty(exports, '__esModule', {
15
15
  });
16
16
  var tslib = require('tslib');
17
17
  var React = require('react');
18
- var index = require('../hooks/use-merge-refs/lib/esm/index.js');
18
+ var useMergeRefs = require('@hi-ui/use-merge-refs');
19
19
  var useColumnCount = require('./use-column-count.js');
20
20
  var AutoGrid = require('./AutoGrid.js');
21
21
  var env = require('@hi-ui/env');
@@ -43,7 +43,7 @@ var DynamicGrid = /*#__PURE__*/React.forwardRef(function DynamicGrid(props, ref)
43
43
  breakpoints: breakpoints,
44
44
  sensitive: sensitive
45
45
  });
46
- var mergedRef = index.useMergeRefs(wrapperElRefProp !== null && wrapperElRefProp !== void 0 ? wrapperElRefProp : wrapperRef, ref);
46
+ var mergedRef = useMergeRefs.useMergeRefs(wrapperElRefProp !== null && wrapperElRefProp !== void 0 ? wrapperElRefProp : wrapperRef, ref);
47
47
  return /*#__PURE__*/React__default["default"].createElement("div", {
48
48
  ref: mergedRef,
49
49
  style: {
@@ -13,8 +13,8 @@ Object.defineProperty(exports, '__esModule', {
13
13
  value: true
14
14
  });
15
15
  var React = require('react');
16
- var index = require('../hooks/use-latest/lib/esm/index.js');
17
- var index$1 = require('../utils/func-utils/lib/esm/index.js');
16
+ var useLatest = require('@hi-ui/use-latest');
17
+ var funcUtils = require('@hi-ui/func-utils');
18
18
  var types = require('../types.js');
19
19
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
20
20
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
@@ -55,27 +55,19 @@ var MAX_EL_READY_POLL_DURATION = 3000;
55
55
  /** 轮询检查元素的间隔(ms) */
56
56
  var EL_READY_POLL_INTERVAL = 50;
57
57
  // 根据容器宽度动态计算列数(与 GridResponsiveSize 断点一致)
58
- var DEFAULT_BREAKPOINTS = [[types.GRID_VIEWPORT_BREAKPOINTS.sm, 1],
59
- // xs: 宽度 < 576px 时,1 列
60
- [types.GRID_VIEWPORT_BREAKPOINTS.md, 2],
61
- // sm: 576px~768px,2 列
62
- [types.GRID_VIEWPORT_BREAKPOINTS.lg, 3],
63
- // md: 768px~992px,3 列
64
- [types.GRID_VIEWPORT_BREAKPOINTS.xl, 4],
65
- // lg: 992px~1200px,4 列
66
- [Infinity, 4] // xl: 宽度 >= 1200px,4 列
58
+ var DEFAULT_BREAKPOINTS = [[types.GRID_VIEWPORT_BREAKPOINTS.sm, 1], [types.GRID_VIEWPORT_BREAKPOINTS.md, 2], [types.GRID_VIEWPORT_BREAKPOINTS.lg, 3], [types.GRID_VIEWPORT_BREAKPOINTS.xl, 4], [Infinity, 4] // xl: 宽度 >= 1200px,4 列
67
59
  ];
68
60
 
69
61
  function useColumnCount(ctx) {
70
62
  var _a, _b;
71
- var ctxRef = index.useLatestRef(ctx);
63
+ var ctxRef = useLatest.useLatestRef(ctx);
72
64
  var _useState = React.useState((_b = (_a = ctx.columnCount) !== null && _a !== void 0 ? _a : ctx.defaultColumnCount) !== null && _b !== void 0 ? _b : DEFAULT_COLUMN_COUNT),
73
65
  columnCount = _useState[0],
74
66
  _setColumnCount = _useState[1];
75
- var columnCountRef = index.useLatestRef(columnCount);
76
- var onColumnCountChangeRef = index.useLatestRef(ctx.onColumnCountChange);
67
+ var columnCountRef = useLatest.useLatestRef(columnCount);
68
+ var onColumnCountChangeRef = useLatest.useLatestRef(ctx.onColumnCountChange);
77
69
  var setColumnCount = React.useMemo(function () {
78
- return index$1.debounce(function (next) {
70
+ return funcUtils.debounce(function (next) {
79
71
  var prev = columnCountRef.current;
80
72
  _setColumnCount(next);
81
73
  // 如果外部有传入,并且实际可视列数变化了,则触发回调
@@ -84,7 +76,7 @@ function useColumnCount(ctx) {
84
76
  }, 32);
85
77
  }, [columnCountRef, onColumnCountChangeRef]);
86
78
  var isFirstCalcRef = React.useRef(true);
87
- var breakpointsRef = index.useLatestRef(ctx.breakpoints);
79
+ var breakpointsRef = useLatest.useLatestRef(ctx.breakpoints);
88
80
  var pollTimerRef = React.useRef(null);
89
81
  var observerRef = React.useRef(null);
90
82
  React.useEffect(function () {
@@ -34,13 +34,13 @@ function isInvalidGridEl(el) {
34
34
  return false;
35
35
  }
36
36
  function getGridElSpan(el) {
37
- var _a;
37
+ var _a, _b;
38
38
  try {
39
- var props = el === null || el === void 0 ? void 0 : el.props;
40
- var span = (_a = props === null || props === void 0 ? void 0 : props.span) !== null && _a !== void 0 ? _a : props === null || props === void 0 ? void 0 : props['data-span'];
39
+ var props = (_a = el) === null || _a === void 0 ? void 0 : _a.props;
40
+ var span = (_b = props === null || props === void 0 ? void 0 : props.span) !== null && _b !== void 0 ? _b : props === null || props === void 0 ? void 0 : props['data-span'];
41
41
  if (typeof span === 'number' && !isNaN(span) && span >= 0) return span;
42
42
  return null;
43
- } catch (_b) {
43
+ } catch (_c) {
44
44
  return null;
45
45
  }
46
46
  }
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { __rest } from 'tslib';
11
11
  import React, { forwardRef, useRef } from 'react';
12
- import { useMergeRefs } from '../hooks/use-merge-refs/lib/esm/index.js';
12
+ import { useMergeRefs } from '@hi-ui/use-merge-refs';
13
13
  import { useColumnCount } from './use-column-count.js';
14
14
  import { AutoGrid } from './AutoGrid.js';
15
15
  import { __DEV__ } from '@hi-ui/env';
@@ -8,8 +8,8 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import { useState, useMemo, useRef, useEffect } from 'react';
11
- import { useLatestRef } from '../hooks/use-latest/lib/esm/index.js';
12
- import { debounce } from '../utils/func-utils/lib/esm/index.js';
11
+ import { useLatestRef } from '@hi-ui/use-latest';
12
+ import { debounce } from '@hi-ui/func-utils';
13
13
  import { GRID_VIEWPORT_BREAKPOINTS } from '../types.js';
14
14
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
15
15
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
@@ -50,15 +50,7 @@ var MAX_EL_READY_POLL_DURATION = 3000;
50
50
  /** 轮询检查元素的间隔(ms) */
51
51
  var EL_READY_POLL_INTERVAL = 50;
52
52
  // 根据容器宽度动态计算列数(与 GridResponsiveSize 断点一致)
53
- var DEFAULT_BREAKPOINTS = [[GRID_VIEWPORT_BREAKPOINTS.sm, 1],
54
- // xs: 宽度 < 576px 时,1 列
55
- [GRID_VIEWPORT_BREAKPOINTS.md, 2],
56
- // sm: 576px~768px,2 列
57
- [GRID_VIEWPORT_BREAKPOINTS.lg, 3],
58
- // md: 768px~992px,3 列
59
- [GRID_VIEWPORT_BREAKPOINTS.xl, 4],
60
- // lg: 992px~1200px,4 列
61
- [Infinity, 4] // xl: 宽度 >= 1200px,4 列
53
+ var DEFAULT_BREAKPOINTS = [[GRID_VIEWPORT_BREAKPOINTS.sm, 1], [GRID_VIEWPORT_BREAKPOINTS.md, 2], [GRID_VIEWPORT_BREAKPOINTS.lg, 3], [GRID_VIEWPORT_BREAKPOINTS.xl, 4], [Infinity, 4] // xl: 宽度 >= 1200px,4 列
62
54
  ];
63
55
 
64
56
  function useColumnCount(ctx) {
@@ -22,13 +22,13 @@ function isInvalidGridEl(el) {
22
22
  return false;
23
23
  }
24
24
  function getGridElSpan(el) {
25
- var _a;
25
+ var _a, _b;
26
26
  try {
27
- var props = el === null || el === void 0 ? void 0 : el.props;
28
- var span = (_a = props === null || props === void 0 ? void 0 : props.span) !== null && _a !== void 0 ? _a : props === null || props === void 0 ? void 0 : props['data-span'];
27
+ var props = (_a = el) === null || _a === void 0 ? void 0 : _a.props;
28
+ var span = (_b = props === null || props === void 0 ? void 0 : props.span) !== null && _b !== void 0 ? _b : props === null || props === void 0 ? void 0 : props['data-span'];
29
29
  if (typeof span === 'number' && !isNaN(span) && span >= 0) return span;
30
30
  return null;
31
- } catch (_b) {
31
+ } catch (_c) {
32
32
  return null;
33
33
  }
34
34
  }
@@ -8,7 +8,7 @@ export interface AutoGridNodeType {
8
8
  columnCount: number;
9
9
  }) => ColProps);
10
10
  }
11
- export type AutoGridProps = RowProps & {
11
+ export declare type AutoGridProps = RowProps & {
12
12
  /** 列元素清单 */
13
13
  nodes?: AutoGridNodeType[];
14
14
  /**
@@ -22,13 +22,13 @@ export type AutoGridProps = RowProps & {
22
22
  };
23
23
  export declare const AutoGrid: React.ForwardRefExoticComponent<RowProps & {
24
24
  /** 列元素清单 */
25
- nodes?: AutoGridNodeType[];
25
+ nodes?: AutoGridNodeType[] | undefined;
26
26
  /**
27
27
  * 子元素清单
28
28
  * - 存在子元素时,会自动按照默认的配置增加网格包裹
29
29
  * - 如需控制子元素占据的网格数,请在元素上增加 span 或者 data-span 属性
30
30
  */
31
- children?: React.ReactNode[];
31
+ children?: React.ReactNode[] | undefined;
32
32
  /** 列数 */
33
- columnCount?: number;
33
+ columnCount?: number | undefined;
34
34
  } & React.RefAttributes<HTMLDivElement | null>>;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import type { UseColumnCountCtxType } from './use-column-count';
3
3
  import type { AutoGridProps } from './AutoGrid';
4
- export type DynamicGridProps = AutoGridProps & UseColumnCountCtxType;
4
+ export declare type DynamicGridProps = AutoGridProps & UseColumnCountCtxType;
5
5
  export declare const DynamicGrid: React.ForwardRefExoticComponent<import("..").RowProps & {
6
- nodes?: import("./AutoGrid").AutoGridNodeType[];
7
- children?: React.ReactNode[];
8
- columnCount?: number;
6
+ nodes?: import("./AutoGrid").AutoGridNodeType[] | undefined;
7
+ children?: React.ReactNode[] | undefined;
8
+ columnCount?: number | undefined;
9
9
  } & UseColumnCountCtxType & React.RefAttributes<HTMLDivElement | null>>;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- export type BreakpointType = [width: number, column: number];
3
- export type UseColumnCountCtxType = {
2
+ export declare type BreakpointType = [width: number, column: number];
3
+ export declare type UseColumnCountCtxType = {
4
4
  /**
5
5
  * 列数,表示一行包含元素的数量
6
6
  * @default 3
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  interface GridContext {
2
3
  columns?: number;
3
4
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import './styles/index.scss';
2
3
  declare const Grid: {
3
4
  Row: import("react").ForwardRefExoticComponent<import("./Grid").RowProps & import("react").RefAttributes<HTMLDivElement | null>>;
@@ -13,8 +13,8 @@ export declare const GRID_VIEWPORT_BREAKPOINTS: {
13
13
  readonly lg: 992;
14
14
  readonly xl: 1200;
15
15
  };
16
- export type GridJustifyEnum = 'flex-start' | 'flex-end' | 'center' | 'space-around' | 'space-between';
17
- export type GridAlignEnum = 'flex-start' | 'flex-end' | 'center' | 'stretch';
16
+ export declare type GridJustifyEnum = 'flex-start' | 'flex-end' | 'center' | 'space-around' | 'space-between';
17
+ export declare type GridAlignEnum = 'flex-start' | 'flex-end' | 'center' | 'stretch';
18
18
  export interface GridResponsiveSize<T> {
19
19
  /**
20
20
  * 设置屏幕 < 576px 时响应式栅格数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/grid",
3
- "version": "5.0.0-experimental.1",
3
+ "version": "5.0.0-rc.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -44,19 +44,21 @@
44
44
  "url": "https://github.com/XiaoMi/hiui/issues"
45
45
  },
46
46
  "dependencies": {
47
- "@hi-ui/classname": "^5.0.0-experimental.0",
48
- "@hi-ui/env": "^5.0.0-experimental.0",
49
- "@hi-ui/type-assertion": "^5.0.0-experimental.0",
50
- "@hi-ui/use-merge-semantic": "^5.0.0-experimental.0"
47
+ "@hi-ui/classname": "^5.0.0-rc.0",
48
+ "@hi-ui/env": "^5.0.0-rc.0",
49
+ "@hi-ui/func-utils": "^5.0.0-rc.0",
50
+ "@hi-ui/type-assertion": "^5.0.0-rc.0",
51
+ "@hi-ui/use-latest": "^5.0.0-rc.0",
52
+ "@hi-ui/use-merge-refs": "^5.0.0-rc.0"
51
53
  },
52
54
  "peerDependencies": {
53
- "@hi-ui/core": ">=5.0.0-experimental.1",
55
+ "@hi-ui/core": ">=5.0.0-rc.0",
54
56
  "react": ">=16.8.6",
55
57
  "react-dom": ">=16.8.6"
56
58
  },
57
59
  "devDependencies": {
58
- "@hi-ui/core": "^5.0.0-experimental.1",
59
- "@hi-ui/core-css": "^5.0.0-experimental.2",
60
+ "@hi-ui/core": "^5.0.0-rc.0",
61
+ "@hi-ui/core-css": "^5.0.0-rc.0",
60
62
  "react": "^17.0.1",
61
63
  "react-dom": "^17.0.1"
62
64
  }
@@ -1,38 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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
- exports.useLatestRef = useLatestRef;
@@ -1,68 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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-merge-refs
19
- * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-merge-refs#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
- * A hook to merge multiple refs into a single function ref.
29
- *
30
- * @param refs
31
- */
32
- var useMergeRefs = function useMergeRefs() {
33
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
34
- refs[_key] = arguments[_key];
35
- }
36
- return React.useMemo(function () {
37
- return mergeRefs.apply(void 0, refs);
38
- }, refs);
39
- };
40
- /**
41
- * Merges multiple refs into a single function ref.
42
- *
43
- * @param refs
44
- * @returns
45
- */
46
- function mergeRefs() {
47
- for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
48
- refs[_key2] = arguments[_key2];
49
- }
50
- // Empty check
51
- if (refs.some(function (ref) {
52
- return ref;
53
- }) === false) return null;
54
- return function (value) {
55
- refs.forEach(function (ref) {
56
- setRef(ref, value);
57
- });
58
- };
59
- }
60
- function setRef(ref, value) {
61
- if (typeof ref === 'function') {
62
- ref(value);
63
- } else if (ref) {
64
- ref.current = value;
65
- }
66
- }
67
- exports.mergeRefs = mergeRefs;
68
- exports.useMergeRefs = useMergeRefs;
@@ -1,60 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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
- require('@hi-ui/type-assertion');
16
-
17
- /** @LICENSE
18
- * @hi-ui/func-utils
19
- * https://github.com/XiaoMi/hiui/tree/master/packages/utils/func-utils#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
- * @param func 被优化函数
29
- * @param delay 抖动间隔
30
- * @returns
31
- */
32
- var debounce = function debounce(func, delay) {
33
- if (delay === void 0) {
34
- delay = 150;
35
- }
36
- var timer = 0;
37
- var cancel = function cancel() {
38
- if (timer) {
39
- window.clearTimeout(timer);
40
- timer = 0;
41
- }
42
- };
43
- var debounceFn = function debounceFn() {
44
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
45
- args[_key4] = arguments[_key4];
46
- }
47
- if (timer) {
48
- cancel();
49
- }
50
- if (func) {
51
- timer = window.setTimeout(function () {
52
- func.apply(null, args);
53
- timer = 0;
54
- }, delay);
55
- }
56
- };
57
- debounceFn.cancel = cancel;
58
- return debounceFn;
59
- };
60
- exports.debounce = debounce;
@@ -1,33 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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
- import { useRef } from 'react';
11
-
12
- /** @LICENSE
13
- * @hi-ui/use-latest
14
- * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-latest#readme
15
- *
16
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- */
21
-
22
- /**
23
- * Keep value up-to-date if it changes.
24
- *
25
- * @param value
26
- * @returns
27
- */
28
- var useLatestRef = function useLatestRef(value) {
29
- var ref = useRef(value);
30
- ref.current = value;
31
- return ref;
32
- };
33
- export { useLatestRef };
@@ -1,62 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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
- import { useMemo } from 'react';
11
-
12
- /** @LICENSE
13
- * @hi-ui/use-merge-refs
14
- * https://github.com/XiaoMi/hiui/tree/master/packages/hooks/use-merge-refs#readme
15
- *
16
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- */
21
-
22
- /**
23
- * A hook to merge multiple refs into a single function ref.
24
- *
25
- * @param refs
26
- */
27
- var useMergeRefs = function useMergeRefs() {
28
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
29
- refs[_key] = arguments[_key];
30
- }
31
- return useMemo(function () {
32
- return mergeRefs.apply(void 0, refs);
33
- }, refs);
34
- };
35
- /**
36
- * Merges multiple refs into a single function ref.
37
- *
38
- * @param refs
39
- * @returns
40
- */
41
- function mergeRefs() {
42
- for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
43
- refs[_key2] = arguments[_key2];
44
- }
45
- // Empty check
46
- if (refs.some(function (ref) {
47
- return ref;
48
- }) === false) return null;
49
- return function (value) {
50
- refs.forEach(function (ref) {
51
- setRef(ref, value);
52
- });
53
- };
54
- }
55
- function setRef(ref, value) {
56
- if (typeof ref === 'function') {
57
- ref(value);
58
- } else if (ref) {
59
- ref.current = value;
60
- }
61
- }
62
- export { mergeRefs, useMergeRefs };
@@ -1,55 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/grid
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/grid#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
- import '@hi-ui/type-assertion';
11
-
12
- /** @LICENSE
13
- * @hi-ui/func-utils
14
- * https://github.com/XiaoMi/hiui/tree/master/packages/utils/func-utils#readme
15
- *
16
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- */
21
- /**
22
- * 函数防抖优化
23
- * @param func 被优化函数
24
- * @param delay 抖动间隔
25
- * @returns
26
- */
27
- var debounce = function debounce(func, delay) {
28
- if (delay === void 0) {
29
- delay = 150;
30
- }
31
- var timer = 0;
32
- var cancel = function cancel() {
33
- if (timer) {
34
- window.clearTimeout(timer);
35
- timer = 0;
36
- }
37
- };
38
- var debounceFn = function debounceFn() {
39
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
40
- args[_key4] = arguments[_key4];
41
- }
42
- if (timer) {
43
- cancel();
44
- }
45
- if (func) {
46
- timer = window.setTimeout(function () {
47
- func.apply(null, args);
48
- timer = 0;
49
- }, delay);
50
- }
51
- };
52
- debounceFn.cancel = cancel;
53
- return debounceFn;
54
- };
55
- export { debounce };