musae 1.0.27-beta.2 → 1.0.27-beta.21

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.
Files changed (77) hide show
  1. package/dist/components/calendar/calendar.cjs +2 -2
  2. package/dist/components/calendar/calendar.mjs +2 -2
  3. package/dist/components/calendar/hooks.cjs +17 -17
  4. package/dist/components/calendar/hooks.d.ts +2 -2
  5. package/dist/components/calendar/hooks.mjs +17 -17
  6. package/dist/components/checkbox/checkbox.cjs +5 -26
  7. package/dist/components/checkbox/checkbox.mjs +3 -24
  8. package/dist/components/icon/icons/action/calendar-today.cjs +22 -0
  9. package/dist/components/icon/icons/action/calendar-today.d.ts +3 -0
  10. package/dist/components/icon/icons/action/calendar-today.mjs +18 -0
  11. package/dist/components/icon/icons/action/index.cjs +2 -0
  12. package/dist/components/icon/icons/action/index.d.ts +2 -1
  13. package/dist/components/icon/icons/action/index.mjs +1 -0
  14. package/dist/components/icon/icons/communication/index.d.ts +2 -0
  15. package/dist/components/icon/icons/communication/location-on.cjs +25 -0
  16. package/dist/components/icon/icons/communication/location-on.d.ts +3 -0
  17. package/dist/components/icon/icons/communication/location-on.mjs +21 -0
  18. package/dist/components/icon/icons/content/add.cjs +22 -0
  19. package/dist/components/icon/icons/content/add.d.ts +3 -0
  20. package/dist/components/icon/icons/content/add.mjs +18 -0
  21. package/dist/components/icon/icons/content/clear.cjs +2 -2
  22. package/dist/components/icon/icons/content/clear.d.ts +2 -2
  23. package/dist/components/icon/icons/content/clear.mjs +2 -2
  24. package/dist/components/icon/icons/content/index.cjs +4 -0
  25. package/dist/components/icon/icons/content/index.d.ts +3 -1
  26. package/dist/components/icon/icons/content/index.mjs +2 -0
  27. package/dist/components/icon/icons/content/remove.cjs +22 -0
  28. package/dist/components/icon/icons/content/remove.d.ts +3 -0
  29. package/dist/components/icon/icons/content/remove.mjs +18 -0
  30. package/dist/components/icon/icons/index.cjs +10 -0
  31. package/dist/components/icon/icons/index.d.ts +2 -0
  32. package/dist/components/icon/icons/index.mjs +5 -0
  33. package/dist/components/icon/icons/social/index.d.ts +2 -0
  34. package/dist/components/icon/icons/social/share.cjs +22 -0
  35. package/dist/components/icon/icons/social/share.d.ts +3 -0
  36. package/dist/components/icon/icons/social/share.mjs +18 -0
  37. package/dist/components/progress/linear.cjs +2 -2
  38. package/dist/components/progress/linear.mjs +2 -2
  39. package/dist/components/rich-text-editor/plugins/controlled-state/index.cjs +12 -26
  40. package/dist/components/rich-text-editor/plugins/controlled-state/index.mjs +13 -27
  41. package/dist/components/rich-text-editor/rich-text-editor.cjs +3 -11
  42. package/dist/components/rich-text-editor/rich-text-editor.mjs +3 -11
  43. package/dist/components/tabs/context.cjs +1 -4
  44. package/dist/components/tabs/context.d.ts +2 -2
  45. package/dist/components/tabs/context.mjs +1 -4
  46. package/dist/components/tabs/hooks/use-navigation.cjs +87 -0
  47. package/dist/components/tabs/hooks/use-navigation.d.ts +12 -0
  48. package/dist/components/tabs/hooks/use-navigation.mjs +85 -0
  49. package/dist/components/tabs/hooks/use-tabs-context.cjs +18 -0
  50. package/dist/components/tabs/hooks/use-tabs-context.d.ts +7 -0
  51. package/dist/components/tabs/hooks/use-tabs-context.mjs +16 -0
  52. package/dist/components/tabs/hooks/use-tabs.cjs +46 -0
  53. package/dist/components/tabs/hooks/use-tabs.d.ts +17 -0
  54. package/dist/components/tabs/hooks/use-tabs.mjs +44 -0
  55. package/dist/components/tabs/navigation.cjs +48 -18
  56. package/dist/components/tabs/navigation.mjs +47 -17
  57. package/dist/components/tabs/panels.cjs +56 -39
  58. package/dist/components/tabs/panels.mjs +56 -39
  59. package/dist/components/tabs/tab.cjs +6 -4
  60. package/dist/components/tabs/tab.mjs +5 -3
  61. package/dist/components/tabs/tabs.cjs +11 -6
  62. package/dist/components/tabs/tabs.d.ts +1 -1
  63. package/dist/components/tabs/tabs.mjs +10 -5
  64. package/dist/components/tag/tag.cjs +51 -28
  65. package/dist/components/tag/tag.d.ts +1 -1
  66. package/dist/components/tag/tag.mjs +51 -28
  67. package/dist/components/theme/tokens.stylex.d.ts +2 -0
  68. package/dist/hooks/use-theme-color-vars.cjs +7 -9
  69. package/dist/hooks/use-theme-color-vars.d.ts +2 -1
  70. package/dist/hooks/use-theme-color-vars.mjs +6 -8
  71. package/dist/styles.css +37 -21
  72. package/dist/types/tabs.d.ts +18 -2
  73. package/dist/types/tag.d.ts +7 -0
  74. package/package.json +6 -6
  75. package/dist/components/tabs/hooks.cjs +0 -145
  76. package/dist/components/tabs/hooks.d.ts +0 -43
  77. package/dist/components/tabs/hooks.mjs +0 -140
@@ -0,0 +1,85 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { useEvent, clamp, useResize, useMount, useMounted } from '@aiszlab/relax';
3
+ import { useRef, useState, useMemo } from 'react';
4
+
5
+ /**
6
+ * @description
7
+ * count dom ele size
8
+ */
9
+ var useNavigation = function useNavigation() {
10
+ var navigatorRef = useRef(null);
11
+ var tabsRef = useRef(null);
12
+ var _useState = useState(0),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ offset = _useState2[0],
15
+ setOffset = _useState2[1];
16
+ // navigator size
17
+ var _useState3 = useState(0),
18
+ _useState4 = _slicedToArray(_useState3, 2),
19
+ navigatorSize = _useState4[0],
20
+ setNavigatorSize = _useState4[1];
21
+ // tabs size
22
+ var _useState5 = useState(0),
23
+ _useState6 = _slicedToArray(_useState5, 2),
24
+ tabsSize = _useState6[0],
25
+ setTabsSize = _useState6[1];
26
+ var _useMemo = useMemo(function () {
27
+ return {
28
+ maxOffset: Math.max(0, tabsSize - navigatorSize),
29
+ minOffset: 0
30
+ };
31
+ }, [navigatorSize, tabsSize]),
32
+ maxOffset = _useMemo.maxOffset,
33
+ minOffset = _useMemo.minOffset;
34
+ // handle scroll
35
+ var scrollNavigation = useEvent(function (delta) {
36
+ setOffset(clamp(delta, minOffset, maxOffset));
37
+ });
38
+ var resize = useEvent(function () {
39
+ var _navigatorRef$current, _navigatorRef$current2, _tabsRef$current$getB, _tabsRef$current;
40
+ var _navigatorSize = (_navigatorRef$current = (_navigatorRef$current2 = navigatorRef.current) === null || _navigatorRef$current2 === void 0 ? void 0 : _navigatorRef$current2.getBoundingClientRect().width) !== null && _navigatorRef$current !== void 0 ? _navigatorRef$current : 0;
41
+ var _tabsSize = (_tabsRef$current$getB = (_tabsRef$current = tabsRef.current) === null || _tabsRef$current === void 0 ? void 0 : _tabsRef$current.getBoundingClientRect().width) !== null && _tabsRef$current$getB !== void 0 ? _tabsRef$current$getB : 0;
42
+ setNavigatorSize(_navigatorSize);
43
+ setTabsSize(_tabsSize);
44
+ scrollNavigation(0);
45
+ });
46
+ var _useMemo2 = useMemo(function () {
47
+ return {
48
+ isLeadingOverflow: offset > minOffset,
49
+ isTrailingOverflow: offset < maxOffset
50
+ };
51
+ }, [minOffset, maxOffset, offset]),
52
+ isLeadingOverflow = _useMemo2.isLeadingOverflow,
53
+ isTrailingOverflow = _useMemo2.isTrailingOverflow;
54
+ // if window resize
55
+ // re-calculate offsets range
56
+ useResize(resize);
57
+ // mouse wheel
58
+ var scrollByWheel = useEvent(function (event) {
59
+ event.preventDefault();
60
+ var deltaY = event.deltaY;
61
+ scrollNavigation(offset + deltaY);
62
+ });
63
+ // calculate size once at mounting step
64
+ useMount(function () {
65
+ resize();
66
+ });
67
+ useMounted(function () {
68
+ var _navigatorRef$current3;
69
+ (_navigatorRef$current3 = navigatorRef.current) === null || _navigatorRef$current3 === void 0 || _navigatorRef$current3.addEventListener("wheel", scrollByWheel);
70
+ return function () {
71
+ var _navigatorRef$current4;
72
+ (_navigatorRef$current4 = navigatorRef.current) === null || _navigatorRef$current4 === void 0 || _navigatorRef$current4.removeEventListener("wheel", scrollByWheel);
73
+ };
74
+ });
75
+ return {
76
+ navigatorRef: navigatorRef,
77
+ tabsRef: tabsRef,
78
+ offset: offset,
79
+ isLeadingOverflow: isLeadingOverflow,
80
+ isTrailingOverflow: isTrailingOverflow,
81
+ scrollNavigation: scrollNavigation
82
+ };
83
+ };
84
+
85
+ export { useNavigation };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var context = require('../context.cjs');
5
+
6
+ /**
7
+ * @description
8
+ * use tab context
9
+ */
10
+ var useTabsContext = function useTabsContext() {
11
+ var context$1 = React.useContext(context.Context);
12
+ if (!context$1) {
13
+ throw new Error("useTabsContext must be used within a Tabs component");
14
+ }
15
+ return context$1;
16
+ };
17
+
18
+ exports.useTabsContext = useTabsContext;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description
3
+ * use tab context
4
+ */
5
+ export declare const useTabsContext: () => import("../../../types/tabs").ContextValue & {
6
+ classNames: typeof import("../context").CLASS_NAMES;
7
+ };
@@ -0,0 +1,16 @@
1
+ import { useContext } from 'react';
2
+ import { Context } from '../context.mjs';
3
+
4
+ /**
5
+ * @description
6
+ * use tab context
7
+ */
8
+ var useTabsContext = function useTabsContext() {
9
+ var context = useContext(Context);
10
+ if (!context) {
11
+ throw new Error("useTabsContext must be used within a Tabs component");
12
+ }
13
+ return context;
14
+ };
15
+
16
+ export { useTabsContext };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var React = require('react');
5
+ var relax = require('@aiszlab/relax');
6
+
7
+ /**
8
+ * @description
9
+ * tabs
10
+ */
11
+ var useTabs = function useTabs(_ref) {
12
+ var _items$at;
13
+ var _activeKey = _ref.activeKey,
14
+ items = _ref.items,
15
+ defaultActiveKey = _ref.defaultActiveKey,
16
+ onChange = _ref.onChange;
17
+ var _useControlledState = relax.useControlledState(_activeKey, {
18
+ defaultState: defaultActiveKey !== null && defaultActiveKey !== void 0 ? defaultActiveKey : (_items$at = items.at(0)) === null || _items$at === void 0 ? void 0 : _items$at.key,
19
+ onChange: relax.useEvent(function (selectedKey) {
20
+ if (relax.isUndefined(selectedKey)) return;
21
+ onChange === null || onChange === void 0 || onChange(selectedKey);
22
+ })
23
+ }),
24
+ _useControlledState2 = _slicedToArray(_useControlledState, 2),
25
+ activeKey = _useControlledState2[0],
26
+ setActiveKey = _useControlledState2[1];
27
+ var _useState = React.useState(function () {
28
+ return new Set(relax.isUndefined(activeKey) ? void 0 : [activeKey]);
29
+ }),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ activatedKeys = _useState2[0],
32
+ setActivatedKeys = _useState2[1];
33
+ var changeActiveKey = relax.useEvent(function (key) {
34
+ setActiveKey(key);
35
+ setActivatedKeys(function (prev) {
36
+ return new Set(prev).add(key);
37
+ });
38
+ });
39
+ return {
40
+ activeKey: activeKey,
41
+ activatedKeys: activatedKeys,
42
+ changeActiveKey: changeActiveKey
43
+ };
44
+ };
45
+
46
+ exports.useTabs = useTabs;
@@ -0,0 +1,17 @@
1
+ import { type Key } from "react";
2
+ import { type TabItem, type TabsProps } from "../../../types/tabs";
3
+ import type { Partialable } from "@aiszlab/relax/types";
4
+ /**
5
+ * @description
6
+ * tabs
7
+ */
8
+ export declare const useTabs: ({ activeKey: _activeKey, items, defaultActiveKey, onChange, }: {
9
+ activeKey?: Key;
10
+ items: TabItem[];
11
+ defaultActiveKey?: Key;
12
+ onChange?: TabsProps["onChange"];
13
+ }) => {
14
+ activeKey: Partialable<Key>;
15
+ activatedKeys: Set<Key>;
16
+ changeActiveKey: (key: Key) => void;
17
+ };
@@ -0,0 +1,44 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
+ import { useState } from 'react';
3
+ import { useControlledState, useEvent, isUndefined } from '@aiszlab/relax';
4
+
5
+ /**
6
+ * @description
7
+ * tabs
8
+ */
9
+ var useTabs = function useTabs(_ref) {
10
+ var _items$at;
11
+ var _activeKey = _ref.activeKey,
12
+ items = _ref.items,
13
+ defaultActiveKey = _ref.defaultActiveKey,
14
+ onChange = _ref.onChange;
15
+ var _useControlledState = useControlledState(_activeKey, {
16
+ defaultState: defaultActiveKey !== null && defaultActiveKey !== void 0 ? defaultActiveKey : (_items$at = items.at(0)) === null || _items$at === void 0 ? void 0 : _items$at.key,
17
+ onChange: useEvent(function (selectedKey) {
18
+ if (isUndefined(selectedKey)) return;
19
+ onChange === null || onChange === void 0 || onChange(selectedKey);
20
+ })
21
+ }),
22
+ _useControlledState2 = _slicedToArray(_useControlledState, 2),
23
+ activeKey = _useControlledState2[0],
24
+ setActiveKey = _useControlledState2[1];
25
+ var _useState = useState(function () {
26
+ return new Set(isUndefined(activeKey) ? void 0 : [activeKey]);
27
+ }),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ activatedKeys = _useState2[0],
30
+ setActivatedKeys = _useState2[1];
31
+ var changeActiveKey = useEvent(function (key) {
32
+ setActiveKey(key);
33
+ setActivatedKeys(function (prev) {
34
+ return new Set(prev).add(key);
35
+ });
36
+ });
37
+ return {
38
+ activeKey: activeKey,
39
+ activatedKeys: activatedKeys,
40
+ changeActiveKey: changeActiveKey
41
+ };
42
+ };
43
+
44
+ export { useTabs };
@@ -4,34 +4,56 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
6
  var React = require('react');
7
+ var stylex = require('../../node_modules/.pnpm/@stylexjs_stylex@0.17.5/node_modules/@stylexjs/stylex/lib/es/stylex.cjs');
7
8
  var tab = require('./tab.cjs');
8
9
  var react = require('motion/react');
9
10
  var relax = require('@aiszlab/relax');
10
- var hooks = require('./hooks.cjs');
11
11
  var className = require('@aiszlab/relax/class-name');
12
12
  var useThemeColorVars = require('../../hooks/use-theme-color-vars.cjs');
13
+ var useTabsContext = require('./hooks/use-tabs-context.cjs');
14
+ var useNavigation = require('./hooks/use-navigation.cjs');
13
15
 
16
+ var styles = {
17
+ indicator: {
18
+ "default": {
19
+ kWkggS: "musaex-19fix8x",
20
+ kVAEAm: "musaex-10l6tqk",
21
+ krVfgx: "musaex-1c1gxxa",
22
+ kIxVMA: "musaex-421gk9",
23
+ ksF3WI: "musaex-4izuhl",
24
+ $$css: true
25
+ },
26
+ medium: {
27
+ kZKoxP: "musaex-rftw1c",
28
+ $$css: true
29
+ },
30
+ small: {
31
+ kZKoxP: "musaex-12yrczq",
32
+ $$css: true
33
+ },
34
+ large: {
35
+ kZKoxP: "musaex-rntz3j",
36
+ $$css: true
37
+ }
38
+ }
39
+ };
14
40
  var Navigation = function Navigation(_ref) {
15
41
  var onChange = _ref.onChange;
16
- var _useTabsContext = hooks.useTabsContext(),
42
+ var _useTabsContext = useTabsContext.useTabsContext(),
17
43
  activeKey = _useTabsContext.activeKey,
18
44
  items = _useTabsContext.items,
19
- classNames = _useTabsContext.classNames;
45
+ classNames = _useTabsContext.classNames,
46
+ size = _useTabsContext.size;
20
47
  var indicatorRef = React.useRef(null);
21
48
  var tabItemsRef = React.useRef(new Map());
22
- var _useNavigation = hooks.useNavigation(),
49
+ var _useNavigation = useNavigation.useNavigation(),
23
50
  navigatorRef = _useNavigation.navigatorRef,
24
51
  tabsRef = _useNavigation.tabsRef,
25
- scroll = _useNavigation.scroll,
26
52
  offset = _useNavigation.offset,
53
+ scrollNavigation = _useNavigation.scrollNavigation,
27
54
  isLeadingOverflow = _useNavigation.isLeadingOverflow,
28
55
  isTrailingOverflow = _useNavigation.isTrailingOverflow;
29
56
  var _themeColorVars = useThemeColorVars.useThemeColorVars(["outline-variant", "primary"]);
30
- // control tabs scroll
31
- hooks.useNavigatorScroll({
32
- navigatorRef: navigatorRef,
33
- scroll: scroll
34
- });
35
57
  var styled = {
36
58
  navigation: {
37
59
  className: "musaex-quqrak musaex-d1xpcx musaex-1q0q8m5"
@@ -51,13 +73,11 @@ var Navigation = function Navigation(_ref) {
51
73
  }
52
74
  }[!!isLeadingOverflow << 1 | !!isTrailingOverflow << 0],
53
75
  list: {
54
- className: "musaex-78zum5 musaex-eq5yr9 musaex-o9m17b"
76
+ className: "musaex-78zum5 musaex-eq5yr9 musaex-12eyqs9 musaex-bngzmg"
55
77
  },
56
- indicator: {
57
- className: "musaex-rftw1c musaex-19fix8x musaex-10l6tqk musaex-1c1gxxa"
58
- }
78
+ indicator: stylex.props(styles.indicator["default"], styles.indicator[size])
59
79
  };
60
- // repaint indicator when activeKey changed
80
+ // repaint indicator when activeKey or size changed
61
81
  // animate indicator to correct position & width
62
82
  React.useEffect(function () {
63
83
  var indicator = indicatorRef.current;
@@ -68,12 +88,22 @@ var Navigation = function Navigation(_ref) {
68
88
  left: tabItem === null || tabItem === void 0 ? void 0 : tabItem.offsetLeft,
69
89
  width: tabItem === null || tabItem === void 0 ? void 0 : tabItem.clientWidth
70
90
  });
71
- }, [activeKey]);
91
+ }, [activeKey, size]);
92
+ // 用户手动切换`tab`选项
93
+ // 1. 切换`tab`后,尝试滚动`tab`到中间为止
94
+ var changeTabItem = relax.useEvent(function (key) {
95
+ var tabItem = tabItemsRef.current.get(key);
96
+ if (tabItem) {
97
+ var _navigatorRef$current, _navigatorRef$current2;
98
+ scrollNavigation(tabItem.offsetLeft - ((_navigatorRef$current = (_navigatorRef$current2 = navigatorRef.current) === null || _navigatorRef$current2 === void 0 ? void 0 : _navigatorRef$current2.clientWidth) !== null && _navigatorRef$current !== void 0 ? _navigatorRef$current : 0) / 2);
99
+ }
100
+ onChange(key);
101
+ });
72
102
  return /*#__PURE__*/React.createElement("div", {
73
103
  role: "tablist",
74
104
  className: className.stringify(classNames.navigation, styled.navigation.className),
75
105
  style: _objectSpread(_objectSpread(_objectSpread({}, styled.navigation.style), _themeColorVars), {}, {
76
- "--offset": offset
106
+ "--offset": offset + "px"
77
107
  })
78
108
  }, /*#__PURE__*/React.createElement("div", {
79
109
  ref: navigatorRef,
@@ -88,7 +118,7 @@ var Navigation = function Navigation(_ref) {
88
118
  key: item.key,
89
119
  value: item.key,
90
120
  label: item.label,
91
- onClick: onChange,
121
+ onClick: changeTabItem,
92
122
  ref: function ref(_tab) {
93
123
  tabItemsRef.current.set(item.key, _tab);
94
124
  }
@@ -1,33 +1,55 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import React, { useRef, useEffect } from 'react';
3
+ import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.17.5/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
3
4
  import Tab from './tab.mjs';
4
5
  import { animate } from 'motion/react';
5
- import { isUndefined } from '@aiszlab/relax';
6
- import { useTabsContext, useNavigation, useNavigatorScroll } from './hooks.mjs';
6
+ import { isUndefined, useEvent } from '@aiszlab/relax';
7
7
  import { stringify } from '@aiszlab/relax/class-name';
8
8
  import { useThemeColorVars } from '../../hooks/use-theme-color-vars.mjs';
9
+ import { useTabsContext } from './hooks/use-tabs-context.mjs';
10
+ import { useNavigation } from './hooks/use-navigation.mjs';
9
11
 
12
+ var styles = {
13
+ indicator: {
14
+ "default": {
15
+ kWkggS: "musaex-19fix8x",
16
+ kVAEAm: "musaex-10l6tqk",
17
+ krVfgx: "musaex-1c1gxxa",
18
+ kIxVMA: "musaex-421gk9",
19
+ ksF3WI: "musaex-4izuhl",
20
+ $$css: true
21
+ },
22
+ medium: {
23
+ kZKoxP: "musaex-rftw1c",
24
+ $$css: true
25
+ },
26
+ small: {
27
+ kZKoxP: "musaex-12yrczq",
28
+ $$css: true
29
+ },
30
+ large: {
31
+ kZKoxP: "musaex-rntz3j",
32
+ $$css: true
33
+ }
34
+ }
35
+ };
10
36
  var Navigation = function Navigation(_ref) {
11
37
  var onChange = _ref.onChange;
12
38
  var _useTabsContext = useTabsContext(),
13
39
  activeKey = _useTabsContext.activeKey,
14
40
  items = _useTabsContext.items,
15
- classNames = _useTabsContext.classNames;
41
+ classNames = _useTabsContext.classNames,
42
+ size = _useTabsContext.size;
16
43
  var indicatorRef = useRef(null);
17
44
  var tabItemsRef = useRef(new Map());
18
45
  var _useNavigation = useNavigation(),
19
46
  navigatorRef = _useNavigation.navigatorRef,
20
47
  tabsRef = _useNavigation.tabsRef,
21
- scroll = _useNavigation.scroll,
22
48
  offset = _useNavigation.offset,
49
+ scrollNavigation = _useNavigation.scrollNavigation,
23
50
  isLeadingOverflow = _useNavigation.isLeadingOverflow,
24
51
  isTrailingOverflow = _useNavigation.isTrailingOverflow;
25
52
  var _themeColorVars = useThemeColorVars(["outline-variant", "primary"]);
26
- // control tabs scroll
27
- useNavigatorScroll({
28
- navigatorRef: navigatorRef,
29
- scroll: scroll
30
- });
31
53
  var styled = {
32
54
  navigation: {
33
55
  className: "musaex-quqrak musaex-d1xpcx musaex-1q0q8m5"
@@ -47,13 +69,11 @@ var Navigation = function Navigation(_ref) {
47
69
  }
48
70
  }[!!isLeadingOverflow << 1 | !!isTrailingOverflow << 0],
49
71
  list: {
50
- className: "musaex-78zum5 musaex-eq5yr9 musaex-o9m17b"
72
+ className: "musaex-78zum5 musaex-eq5yr9 musaex-12eyqs9 musaex-bngzmg"
51
73
  },
52
- indicator: {
53
- className: "musaex-rftw1c musaex-19fix8x musaex-10l6tqk musaex-1c1gxxa"
54
- }
74
+ indicator: props(styles.indicator["default"], styles.indicator[size])
55
75
  };
56
- // repaint indicator when activeKey changed
76
+ // repaint indicator when activeKey or size changed
57
77
  // animate indicator to correct position & width
58
78
  useEffect(function () {
59
79
  var indicator = indicatorRef.current;
@@ -64,12 +84,22 @@ var Navigation = function Navigation(_ref) {
64
84
  left: tabItem === null || tabItem === void 0 ? void 0 : tabItem.offsetLeft,
65
85
  width: tabItem === null || tabItem === void 0 ? void 0 : tabItem.clientWidth
66
86
  });
67
- }, [activeKey]);
87
+ }, [activeKey, size]);
88
+ // 用户手动切换`tab`选项
89
+ // 1. 切换`tab`后,尝试滚动`tab`到中间为止
90
+ var changeTabItem = useEvent(function (key) {
91
+ var tabItem = tabItemsRef.current.get(key);
92
+ if (tabItem) {
93
+ var _navigatorRef$current, _navigatorRef$current2;
94
+ scrollNavigation(tabItem.offsetLeft - ((_navigatorRef$current = (_navigatorRef$current2 = navigatorRef.current) === null || _navigatorRef$current2 === void 0 ? void 0 : _navigatorRef$current2.clientWidth) !== null && _navigatorRef$current !== void 0 ? _navigatorRef$current : 0) / 2);
95
+ }
96
+ onChange(key);
97
+ });
68
98
  return /*#__PURE__*/React.createElement("div", {
69
99
  role: "tablist",
70
100
  className: stringify(classNames.navigation, styled.navigation.className),
71
101
  style: _objectSpread(_objectSpread(_objectSpread({}, styled.navigation.style), _themeColorVars), {}, {
72
- "--offset": offset
102
+ "--offset": offset + "px"
73
103
  })
74
104
  }, /*#__PURE__*/React.createElement("div", {
75
105
  ref: navigatorRef,
@@ -84,7 +114,7 @@ var Navigation = function Navigation(_ref) {
84
114
  key: item.key,
85
115
  value: item.key,
86
116
  label: item.label,
87
- onClick: onChange,
117
+ onClick: changeTabItem,
88
118
  ref: function ref(_tab) {
89
119
  tabItemsRef.current.set(item.key, _tab);
90
120
  }
@@ -2,67 +2,84 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
+ var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
6
6
  var React = require('react');
7
7
  var className = require('@aiszlab/relax/class-name');
8
8
  var relax = require('@aiszlab/relax');
9
- var hooks = require('./hooks.cjs');
9
+ var useTabsContext = require('./hooks/use-tabs-context.cjs');
10
10
 
11
11
  var Panels = function Panels(_ref) {
12
12
  var forceRender = _ref.forceRender,
13
13
  destroyable = _ref.destroyable,
14
14
  activatedKeys = _ref.activatedKeys;
15
- var _useTabsContext = hooks.useTabsContext(),
15
+ var _useTabsContext = useTabsContext.useTabsContext(),
16
16
  items = _useTabsContext.items,
17
17
  activeKey = _useTabsContext.activeKey,
18
18
  classNames = _useTabsContext.classNames;
19
- var styled = {
20
- panels: {
21
- className: "musaex-bvu51n"
22
- },
23
- panel: {
24
- active: {},
25
- hidden: {
26
- className: "musaex-1s85apg"
27
- }
28
- }
29
- };
19
+ // 收集需要渲染的面板内容
30
20
  var panels = React.useMemo(function () {
21
+ var renderedPanels = [];
31
22
  if (relax.isUndefined(activeKey)) {
32
- return [];
23
+ return renderedPanels;
33
24
  }
34
- if (destroyable) {
35
- var _items$find;
36
- return [[activeKey, (_items$find = items.find(function (item) {
37
- return item.key === activeKey;
38
- })) === null || _items$find === void 0 ? void 0 : _items$find.children]];
39
- }
40
- if (forceRender) {
41
- return items.map(function (item) {
42
- return [item.key, item.children];
43
- });
25
+ var _iterator = _createForOfIteratorHelper(items),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var item = _step.value;
30
+ if (destroyable) {
31
+ if (item.key !== activeKey) {
32
+ continue;
33
+ }
34
+ if (item.children) {
35
+ renderedPanels.push({
36
+ key: item.key,
37
+ children: item.children
38
+ });
39
+ }
40
+ break;
41
+ }
42
+ if (forceRender || activatedKeys.has(item.key)) {
43
+ if (item.children) {
44
+ renderedPanels.push({
45
+ key: item.key,
46
+ children: item.children
47
+ });
48
+ }
49
+ }
50
+ }
51
+ } catch (err) {
52
+ _iterator.e(err);
53
+ } finally {
54
+ _iterator.f();
44
55
  }
45
- return items.map(function (item) {
46
- return [item.key, activatedKeys.has(item.key) ? item.children : null];
47
- });
56
+ return renderedPanels;
48
57
  }, [destroyable, forceRender, items, activeKey, activatedKeys]);
58
+ var styled = {
59
+ panels: {
60
+ 0: {},
61
+ 1: {
62
+ className: "musaex-1y9dh0z"
63
+ }
64
+ }[!!(panels.length > 0) << 0]
65
+ };
49
66
  return /*#__PURE__*/React.createElement("div", {
50
67
  className: className.stringify(classNames.panels, styled.panels.className),
51
68
  style: styled.panels.style
52
69
  }, panels.map(function (_ref2) {
53
- var _ref3 = _slicedToArray(_ref2, 2),
54
- key = _ref3[0],
55
- children = _ref3[1];
56
- var _ref4 = key === activeKey ? styled.panel.active : styled.panel.hidden,
57
- className$1 = _ref4.className,
58
- style = _ref4.style;
59
- if (relax.isVoid(children)) {
60
- return null;
61
- }
70
+ var key = _ref2.key,
71
+ children = _ref2.children;
72
+ var isActive = key === activeKey;
73
+ var panelStyled = {
74
+ 0: {},
75
+ 1: {
76
+ className: "musaex-1s85apg"
77
+ }
78
+ }[!!!isActive << 0];
62
79
  return /*#__PURE__*/React.createElement("div", {
63
80
  key: key,
64
- className: className.stringify(classNames.panel, className$1),
65
- style: style
81
+ className: className.stringify(classNames.panel, panelStyled.className),
82
+ style: panelStyled.style
66
83
  }, children);
67
84
  }));
68
85
  };