@hsu-react/ui 0.0.22 → 0.0.24

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.
@@ -12,6 +12,7 @@ import { Button } from "@chakra-ui/react";
12
12
  import usePermissions from "../../../hooks/usePermissions";
13
13
  import styles from "./index.module.scss";
14
14
  import classNames from "classnames";
15
+ import ChakraRoot from "../../ChakraRoot";
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  import { Fragment as _Fragment } from "react/jsx-runtime";
17
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -32,7 +33,23 @@ var ChakraButton = function ChakraButton(props) {
32
33
  return null;
33
34
  }
34
35
  if (reRender) {
35
- return reRender( /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonConfig), {}, {
36
+ return /*#__PURE__*/_jsx(ChakraRoot, {
37
+ children: reRender( /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonConfig), {}, {
38
+ className: classNames(className, styles.button, _defineProperty({}, styles[iconPosition], iconPosition)),
39
+ children: /*#__PURE__*/_jsxs(_Fragment, {
40
+ children: [iconPosition === "start" && icon && /*#__PURE__*/_jsx("span", {
41
+ className: styles.icon,
42
+ children: icon
43
+ }), children !== null && children !== void 0 ? children : title, iconPosition === "end" && icon && /*#__PURE__*/_jsx("span", {
44
+ className: styles.icon,
45
+ children: icon
46
+ })]
47
+ })
48
+ })))
49
+ });
50
+ }
51
+ return /*#__PURE__*/_jsx(ChakraRoot, {
52
+ children: /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonConfig), {}, {
36
53
  className: classNames(className, styles.button, _defineProperty({}, styles[iconPosition], iconPosition)),
37
54
  children: /*#__PURE__*/_jsxs(_Fragment, {
38
55
  children: [iconPosition === "start" && icon && /*#__PURE__*/_jsx("span", {
@@ -43,19 +60,7 @@ var ChakraButton = function ChakraButton(props) {
43
60
  children: icon
44
61
  })]
45
62
  })
46
- })));
47
- }
48
- return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonConfig), {}, {
49
- className: classNames(className, styles.button, _defineProperty({}, styles[iconPosition], iconPosition)),
50
- children: /*#__PURE__*/_jsxs(_Fragment, {
51
- children: [iconPosition === "start" && icon && /*#__PURE__*/_jsx("span", {
52
- className: styles.icon,
53
- children: icon
54
- }), children !== null && children !== void 0 ? children : title, iconPosition === "end" && icon && /*#__PURE__*/_jsx("span", {
55
- className: styles.icon,
56
- children: icon
57
- })]
58
- })
59
- }));
63
+ }))
64
+ });
60
65
  };
61
66
  export default ChakraButton;
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ export interface ChakraRootProps {
3
+ children?: React.ReactNode;
4
+ }
5
+ declare const ChakraRoot: React.FC<ChakraRootProps>;
6
+ export default ChakraRoot;
@@ -0,0 +1,42 @@
1
+ import React from "react";
2
+ import { ChakraProvider, createSystem, defaultConfig } from "@chakra-ui/react";
3
+ import createCache from "@emotion/cache";
4
+ import { CacheProvider } from "@emotion/react";
5
+
6
+ /**
7
+ * Provider shell for chakra.
8
+ *
9
+ * These two providers used to be mounted by the consumer at the application entry, wrapping
10
+ * the whole tree — which pulled `@chakra-ui/react` + `@emotion/*` + zag-js (about 570 KB in
11
+ * total) into the initial bundle unconditionally, even though Button.Chakra is the only thing
12
+ * that actually uses chakra.
13
+ *
14
+ * Changed to "whoever uses it wraps it": ChakraButton wraps itself (it is already a lazy chunk,
15
+ * so chakra travels with it), and the consumer entry no longer needs a global provider, which
16
+ * takes chakra out of the initial bundle entirely.
17
+ *
18
+ * Both system and cache are module-level singletons, so wrapping in several places does not
19
+ * create duplicates; nested wrapping passes the very same instance and is idempotent. The cache
20
+ * keeps `prepend: true` so chakra's style tags are inserted near the top of head — lower
21
+ * priority than antd — matching the previous behaviour.
22
+ */
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ var cache = createCache({
25
+ key: "css",
26
+ prepend: true
27
+ });
28
+ var system = createSystem(defaultConfig, {
29
+ disableLayers: true,
30
+ preflight: false
31
+ });
32
+ var ChakraRoot = function ChakraRoot(_ref) {
33
+ var children = _ref.children;
34
+ return /*#__PURE__*/_jsx(CacheProvider, {
35
+ value: cache,
36
+ children: /*#__PURE__*/_jsx(ChakraProvider, {
37
+ value: system,
38
+ children: children
39
+ })
40
+ });
41
+ };
42
+ export default ChakraRoot;
@@ -4,7 +4,13 @@
4
4
  margin: 0px;
5
5
  padding-block: 0px;
6
6
 
7
- overflow-x: hidden;
7
+ // 横向裁切用 clip 而不是 hidden:把手(36px 命中区)比轨道(32px)高 4px,靠
8
+ // overflow-y: visible 露出上下那点溢出。但按 CSS Overflow L3,visible 一旦与
9
+ // 「既非 visible 也非 clip」的值同时出现,就会被计算成 auto——写 hidden 时
10
+ // overflow-y 实际变成 auto,溢出的 4px 成了一条真能滚的区域:滚轮停在滑块上
11
+ // 滚的是它自己,把手还会跟着上下错位。
12
+ // clip 同样裁掉横向溢出,但不创建滚动容器,也不会把另一轴的 visible 拽下水。
13
+ overflow-x: clip;
8
14
  overflow-y: visible;
9
15
 
10
16
  :global(.ant-slider-step),
package/es/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export { default as Button } from "./components/Button";
10
10
  export * from "./components/Button";
11
11
  export { default as ChainGraph } from "./components/ChainGraph";
12
12
  export * from "./components/ChainGraph";
13
+ export { default as ChakraRoot } from "./components/ChakraRoot";
14
+ export * from "./components/ChakraRoot";
13
15
  export { default as Chart } from "./components/Chart";
14
16
  export * from "./components/Chart";
15
17
  export { default as Chat } from "./components/Chat";
package/es/index.js CHANGED
@@ -13,6 +13,8 @@ export { default as Button } from "./components/Button";
13
13
  export * from "./components/Button";
14
14
  export { default as ChainGraph } from "./components/ChainGraph";
15
15
  export * from "./components/ChainGraph";
16
+ export { default as ChakraRoot } from "./components/ChakraRoot";
17
+ export * from "./components/ChakraRoot";
16
18
  export { default as Chart } from "./components/Chart";
17
19
  export * from "./components/Chart";
18
20
  export { default as Chat } from "./components/Chat";
@@ -9,6 +9,7 @@ var _react2 = require("@chakra-ui/react");
9
9
  var _usePermissions = _interopRequireDefault(require("../../../hooks/usePermissions"));
10
10
  var _indexModule = _interopRequireDefault(require("./index.module.scss"));
11
11
  var _classnames = _interopRequireDefault(require("classnames"));
12
+ var _ChakraRoot = _interopRequireDefault(require("../../ChakraRoot"));
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  const ChakraButton = props => {
@@ -30,7 +31,26 @@ const ChakraButton = props => {
30
31
  return null;
31
32
  }
32
33
  if (reRender) {
33
- return reRender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Button, {
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChakraRoot.default, {
35
+ children: reRender( /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Button, {
36
+ ...buttonConfig,
37
+ className: (0, _classnames.default)(className, _indexModule.default.button, {
38
+ [_indexModule.default[iconPosition]]: iconPosition
39
+ }),
40
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
41
+ children: [iconPosition === "start" && icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
42
+ className: _indexModule.default.icon,
43
+ children: icon
44
+ }), children ?? title, iconPosition === "end" && icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
45
+ className: _indexModule.default.icon,
46
+ children: icon
47
+ })]
48
+ })
49
+ }))
50
+ });
51
+ }
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChakraRoot.default, {
53
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Button, {
34
54
  ...buttonConfig,
35
55
  className: (0, _classnames.default)(className, _indexModule.default.button, {
36
56
  [_indexModule.default[iconPosition]]: iconPosition
@@ -44,21 +64,6 @@ const ChakraButton = props => {
44
64
  children: icon
45
65
  })]
46
66
  })
47
- }));
48
- }
49
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Button, {
50
- ...buttonConfig,
51
- className: (0, _classnames.default)(className, _indexModule.default.button, {
52
- [_indexModule.default[iconPosition]]: iconPosition
53
- }),
54
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
55
- children: [iconPosition === "start" && icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
56
- className: _indexModule.default.icon,
57
- children: icon
58
- }), children ?? title, iconPosition === "end" && icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
59
- className: _indexModule.default.icon,
60
- children: icon
61
- })]
62
67
  })
63
68
  });
64
69
  };
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ export interface ChakraRootProps {
3
+ children?: React.ReactNode;
4
+ }
5
+ declare const ChakraRoot: React.FC<ChakraRootProps>;
6
+ export default ChakraRoot;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _react2 = require("@chakra-ui/react");
9
+ var _cache = _interopRequireDefault(require("@emotion/cache"));
10
+ var _react3 = require("@emotion/react");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /**
14
+ * Provider shell for chakra.
15
+ *
16
+ * These two providers used to be mounted by the consumer at the application entry, wrapping
17
+ * the whole tree — which pulled `@chakra-ui/react` + `@emotion/*` + zag-js (about 570 KB in
18
+ * total) into the initial bundle unconditionally, even though Button.Chakra is the only thing
19
+ * that actually uses chakra.
20
+ *
21
+ * Changed to "whoever uses it wraps it": ChakraButton wraps itself (it is already a lazy chunk,
22
+ * so chakra travels with it), and the consumer entry no longer needs a global provider, which
23
+ * takes chakra out of the initial bundle entirely.
24
+ *
25
+ * Both system and cache are module-level singletons, so wrapping in several places does not
26
+ * create duplicates; nested wrapping passes the very same instance and is idempotent. The cache
27
+ * keeps `prepend: true` so chakra's style tags are inserted near the top of head — lower
28
+ * priority than antd — matching the previous behaviour.
29
+ */const cache = (0, _cache.default)({
30
+ key: "css",
31
+ prepend: true
32
+ });
33
+ const system = (0, _react2.createSystem)(_react2.defaultConfig, {
34
+ disableLayers: true,
35
+ preflight: false
36
+ });
37
+ const ChakraRoot = ({
38
+ children
39
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_react3.CacheProvider, {
40
+ value: cache,
41
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.ChakraProvider, {
42
+ value: system,
43
+ children: children
44
+ })
45
+ });
46
+ var _default = exports.default = ChakraRoot;
@@ -4,7 +4,13 @@
4
4
  margin: 0px;
5
5
  padding-block: 0px;
6
6
 
7
- overflow-x: hidden;
7
+ // 横向裁切用 clip 而不是 hidden:把手(36px 命中区)比轨道(32px)高 4px,靠
8
+ // overflow-y: visible 露出上下那点溢出。但按 CSS Overflow L3,visible 一旦与
9
+ // 「既非 visible 也非 clip」的值同时出现,就会被计算成 auto——写 hidden 时
10
+ // overflow-y 实际变成 auto,溢出的 4px 成了一条真能滚的区域:滚轮停在滑块上
11
+ // 滚的是它自己,把手还会跟着上下错位。
12
+ // clip 同样裁掉横向溢出,但不创建滚动容器,也不会把另一轴的 visible 拽下水。
13
+ overflow-x: clip;
8
14
  overflow-y: visible;
9
15
 
10
16
  :global(.ant-slider-step),
package/lib/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export { default as Button } from "./components/Button";
10
10
  export * from "./components/Button";
11
11
  export { default as ChainGraph } from "./components/ChainGraph";
12
12
  export * from "./components/ChainGraph";
13
+ export { default as ChakraRoot } from "./components/ChakraRoot";
14
+ export * from "./components/ChakraRoot";
13
15
  export { default as Chart } from "./components/Chart";
14
16
  export * from "./components/Chart";
15
17
  export { default as Chat } from "./components/Chat";
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ var _exportNames = {
21
21
  defaultPrimaryColor: true,
22
22
  Button: true,
23
23
  ChainGraph: true,
24
+ ChakraRoot: true,
24
25
  Chart: true,
25
26
  Chat: true,
26
27
  Checkbox: true,
@@ -65,6 +66,12 @@ Object.defineProperty(exports, "ChainGraph", {
65
66
  return _ChainGraph.default;
66
67
  }
67
68
  });
69
+ Object.defineProperty(exports, "ChakraRoot", {
70
+ enumerable: true,
71
+ get: function () {
72
+ return _ChakraRoot.default;
73
+ }
74
+ });
68
75
  Object.defineProperty(exports, "Chart", {
69
76
  enumerable: true,
70
77
  get: function () {
@@ -370,6 +377,18 @@ Object.keys(_ChainGraph).forEach(function (key) {
370
377
  }
371
378
  });
372
379
  });
380
+ var _ChakraRoot = _interopRequireWildcard(require("./components/ChakraRoot"));
381
+ Object.keys(_ChakraRoot).forEach(function (key) {
382
+ if (key === "default" || key === "__esModule") return;
383
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
384
+ if (key in exports && exports[key] === _ChakraRoot[key]) return;
385
+ Object.defineProperty(exports, key, {
386
+ enumerable: true,
387
+ get: function () {
388
+ return _ChakraRoot[key];
389
+ }
390
+ });
391
+ });
373
392
  var _Chart = _interopRequireWildcard(require("./components/Chart"));
374
393
  Object.keys(_Chart).forEach(function (key) {
375
394
  if (key === "default" || key === "__esModule") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hsu-react/ui",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "一套基于 React + Ant Design 的中后台业务组件库",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3,6 +3,7 @@ import { Button, ButtonProps } from "@chakra-ui/react";
3
3
  import usePermissions from "../../../hooks/usePermissions";
4
4
  import styles from "./index.module.scss";
5
5
  import classNames from "classnames";
6
+ import ChakraRoot from "../../ChakraRoot";
6
7
 
7
8
  export interface ChakraButtonProps extends ButtonProps {
8
9
  hasPermi?: string[];
@@ -31,7 +32,33 @@ const ChakraButton: React.FC<ChakraButtonProps> = (props) => {
31
32
  }
32
33
 
33
34
  if (reRender) {
34
- return reRender(
35
+ return (
36
+ <ChakraRoot>
37
+ {reRender(
38
+ <Button
39
+ {...buttonConfig}
40
+ className={classNames(className, styles.button, {
41
+ [styles[iconPosition]]: iconPosition,
42
+ })}
43
+ children={
44
+ <>
45
+ {iconPosition === "start" && icon && (
46
+ <span className={styles.icon}>{icon}</span>
47
+ )}
48
+ {children ?? title}
49
+ {iconPosition === "end" && icon && (
50
+ <span className={styles.icon}>{icon}</span>
51
+ )}
52
+ </>
53
+ }
54
+ />,
55
+ )}
56
+ </ChakraRoot>
57
+ );
58
+ }
59
+
60
+ return (
61
+ <ChakraRoot>
35
62
  <Button
36
63
  {...buttonConfig}
37
64
  className={classNames(className, styles.button, {
@@ -48,28 +75,8 @@ const ChakraButton: React.FC<ChakraButtonProps> = (props) => {
48
75
  )}
49
76
  </>
50
77
  }
51
- />,
52
- );
53
- }
54
-
55
- return (
56
- <Button
57
- {...buttonConfig}
58
- className={classNames(className, styles.button, {
59
- [styles[iconPosition]]: iconPosition,
60
- })}
61
- children={
62
- <>
63
- {iconPosition === "start" && icon && (
64
- <span className={styles.icon}>{icon}</span>
65
- )}
66
- {children ?? title}
67
- {iconPosition === "end" && icon && (
68
- <span className={styles.icon}>{icon}</span>
69
- )}
70
- </>
71
- }
72
- />
78
+ />
79
+ </ChakraRoot>
73
80
  );
74
81
  };
75
82
 
@@ -37,7 +37,11 @@ export default () => (
37
37
 
38
38
  ## Chakra 按钮
39
39
 
40
- 基于 Chakra UI 的按钮,支持 `hasPermi`、`hidden`、`iconPosition`、`icon` 等扩展属性(Chakra system 由文档站全局提供)。
40
+ 基于 Chakra UI 的按钮,支持 `hasPermi`、`hidden`、`iconPosition`、`icon` 等扩展属性。
41
+
42
+ Chakra 的 system 与 emotion cache 由组件**自带**(内部包了一层 `ChakraRoot`),消费方**不需要**在应用入口挂全局 `ChakraProvider` / `CacheProvider`。这样 `@chakra-ui/react` + `@emotion/*` + zag-js(合计约 570 KB)只存在于 `Button.Chakra` 的异步 chunk 里,不进首屏。
43
+
44
+ > 从 `0.0.23` 起:入口若仍留着全局 Provider,不会出错,但那 570 KB 会照旧留在首屏——要拿到收益需把它删掉。若页面要**直接**使用 chakra 组件(不经 `Button.Chakra`),用库导出的 `ChakraRoot` 自行包一层即可。
41
45
 
42
46
  ```tsx
43
47
  import React from "react";
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import { ChakraProvider, createSystem, defaultConfig } from "@chakra-ui/react";
3
+ import createCache from "@emotion/cache";
4
+ import { CacheProvider } from "@emotion/react";
5
+
6
+ /**
7
+ * Provider shell for chakra.
8
+ *
9
+ * These two providers used to be mounted by the consumer at the application entry, wrapping
10
+ * the whole tree — which pulled `@chakra-ui/react` + `@emotion/*` + zag-js (about 570 KB in
11
+ * total) into the initial bundle unconditionally, even though Button.Chakra is the only thing
12
+ * that actually uses chakra.
13
+ *
14
+ * Changed to "whoever uses it wraps it": ChakraButton wraps itself (it is already a lazy chunk,
15
+ * so chakra travels with it), and the consumer entry no longer needs a global provider, which
16
+ * takes chakra out of the initial bundle entirely.
17
+ *
18
+ * Both system and cache are module-level singletons, so wrapping in several places does not
19
+ * create duplicates; nested wrapping passes the very same instance and is idempotent. The cache
20
+ * keeps `prepend: true` so chakra's style tags are inserted near the top of head — lower
21
+ * priority than antd — matching the previous behaviour.
22
+ */
23
+ const cache = createCache({
24
+ key: "css",
25
+ prepend: true,
26
+ });
27
+
28
+ const system = createSystem(defaultConfig, {
29
+ disableLayers: true,
30
+ preflight: false,
31
+ });
32
+
33
+ export interface ChakraRootProps {
34
+ children?: React.ReactNode;
35
+ }
36
+
37
+ const ChakraRoot: React.FC<ChakraRootProps> = ({ children }) => (
38
+ <CacheProvider value={cache}>
39
+ <ChakraProvider value={system}>{children}</ChakraProvider>
40
+ </CacheProvider>
41
+ );
42
+
43
+ export default ChakraRoot;
@@ -4,7 +4,13 @@
4
4
  margin: 0px;
5
5
  padding-block: 0px;
6
6
 
7
- overflow-x: hidden;
7
+ // 横向裁切用 clip 而不是 hidden:把手(36px 命中区)比轨道(32px)高 4px,靠
8
+ // overflow-y: visible 露出上下那点溢出。但按 CSS Overflow L3,visible 一旦与
9
+ // 「既非 visible 也非 clip」的值同时出现,就会被计算成 auto——写 hidden 时
10
+ // overflow-y 实际变成 auto,溢出的 4px 成了一条真能滚的区域:滚轮停在滑块上
11
+ // 滚的是它自己,把手还会跟着上下错位。
12
+ // clip 同样裁掉横向溢出,但不创建滚动容器,也不会把另一轴的 visible 拽下水。
13
+ overflow-x: clip;
8
14
  overflow-y: visible;
9
15
 
10
16
  :global(.ant-slider-step),
package/src/index.ts CHANGED
@@ -25,6 +25,8 @@ export { default as Button } from "./components/Button";
25
25
  export * from "./components/Button";
26
26
  export { default as ChainGraph } from "./components/ChainGraph";
27
27
  export * from "./components/ChainGraph";
28
+ export { default as ChakraRoot } from "./components/ChakraRoot";
29
+ export * from "./components/ChakraRoot";
28
30
  export { default as Chart } from "./components/Chart";
29
31
  export * from "./components/Chart";
30
32
  export { default as Chat } from "./components/Chat";