musae 0.3.3 → 0.3.5

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 (149) hide show
  1. package/dist/components/button/button.cjs +11 -10
  2. package/dist/components/button/button.mjs +7 -6
  3. package/dist/components/calendar/contribution.cjs +251 -0
  4. package/dist/components/calendar/contribution.d.ts +13 -0
  5. package/dist/components/calendar/contribution.mjs +249 -0
  6. package/dist/components/calendar/index.d.ts +2 -1
  7. package/dist/components/config/provider.cjs +2 -2
  8. package/dist/components/config/provider.mjs +2 -2
  9. package/dist/components/drawer/popup.cjs +51 -17
  10. package/dist/components/drawer/popup.d.ts +1 -1
  11. package/dist/components/drawer/popup.mjs +51 -17
  12. package/dist/components/fab/floatable.d.ts +1 -1
  13. package/dist/components/icon/icons/action/delete.cjs +20 -0
  14. package/dist/components/icon/icons/action/delete.d.ts +3 -0
  15. package/dist/components/icon/icons/action/delete.mjs +18 -0
  16. package/dist/components/icon/icons/action/index.cjs +7 -1
  17. package/dist/components/icon/icons/action/index.d.ts +5 -1
  18. package/dist/components/icon/icons/action/index.mjs +6 -2
  19. package/dist/components/icon/icons/action/three-d-rotation.cjs +28 -0
  20. package/dist/components/icon/icons/action/three-d-rotation.d.ts +3 -0
  21. package/dist/components/icon/icons/action/three-d-rotation.mjs +26 -0
  22. package/dist/components/icon/icons/editor/attch-file.cjs +20 -0
  23. package/dist/components/icon/icons/editor/attch-file.d.ts +3 -0
  24. package/dist/components/icon/icons/editor/attch-file.mjs +18 -0
  25. package/dist/components/icon/icons/editor/index.cjs +4 -1
  26. package/dist/components/icon/icons/editor/index.d.ts +3 -1
  27. package/dist/components/icon/icons/editor/index.mjs +4 -2
  28. package/dist/components/icon/icons/index.cjs +6 -0
  29. package/dist/components/icon/icons/index.mjs +3 -0
  30. package/dist/components/menu/hooks.d.ts +1 -2
  31. package/dist/components/menu/item.d.ts +2 -3
  32. package/dist/components/pagination/pagination.cjs +1 -1
  33. package/dist/components/pagination/pagination.mjs +2 -2
  34. package/dist/components/popover/popover.cjs +1 -1
  35. package/dist/components/popover/popover.mjs +1 -1
  36. package/dist/components/popper/dropdown.cjs +44 -19
  37. package/dist/components/popper/dropdown.mjs +46 -21
  38. package/dist/components/popper/hooks.cjs +88 -89
  39. package/dist/components/popper/hooks.d.ts +7 -13
  40. package/dist/components/popper/hooks.mjs +91 -91
  41. package/dist/components/rich-text-editor/plugins/controlled-state/index.cjs +1 -2
  42. package/dist/components/rich-text-editor/plugins/controlled-state/index.mjs +1 -2
  43. package/dist/components/rich-text-editor/plugins/markdown-shortcut/index.cjs +5 -4
  44. package/dist/components/rich-text-editor/plugins/markdown-shortcut/index.d.ts +3 -3
  45. package/dist/components/rich-text-editor/plugins/markdown-shortcut/index.mjs +3 -4
  46. package/dist/components/rich-text-editor/rich-text-editor.cjs +5 -5
  47. package/dist/components/rich-text-editor/rich-text-editor.mjs +3 -3
  48. package/dist/components/select/utils.cjs +1 -3
  49. package/dist/components/select/utils.d.ts +1 -1
  50. package/dist/components/select/utils.mjs +2 -4
  51. package/dist/components/skeleton/skeleton.cjs +5 -48
  52. package/dist/components/skeleton/skeleton.d.ts +1 -1
  53. package/dist/components/skeleton/skeleton.mjs +5 -48
  54. package/dist/components/steps/context.d.ts +1 -1
  55. package/dist/components/steps/item.d.ts +1 -1
  56. package/dist/components/steps/steps.d.ts +1 -1
  57. package/dist/components/switch/switch.cjs +7 -6
  58. package/dist/components/switch/switch.d.ts +1 -1
  59. package/dist/components/switch/switch.mjs +8 -7
  60. package/dist/components/table/body.cjs +3 -1
  61. package/dist/components/table/body.mjs +3 -1
  62. package/dist/components/tabs/context.d.ts +1 -1
  63. package/dist/components/tabs/hooks.d.ts +2 -2
  64. package/dist/components/tabs/navigation.d.ts +1 -1
  65. package/dist/components/tabs/panels.d.ts +1 -1
  66. package/dist/components/tabs/tab.d.ts +1 -1
  67. package/dist/components/tabs/tabs.d.ts +1 -1
  68. package/dist/components/tag/tag.d.ts +1 -1
  69. package/dist/components/theme/hooks.cjs +6 -6
  70. package/dist/components/theme/hooks.d.ts +1 -1
  71. package/dist/components/theme/hooks.mjs +6 -6
  72. package/dist/components/theme/theme-provider.cjs +12 -6
  73. package/dist/components/theme/theme-provider.d.ts +2 -2
  74. package/dist/components/theme/theme-provider.mjs +12 -6
  75. package/dist/components/time-picker/hooks.d.ts +1 -1
  76. package/dist/components/time-picker/panel.d.ts +1 -1
  77. package/dist/components/time-picker/time-picker.d.ts +1 -1
  78. package/dist/components/timeline/context.d.ts +1 -1
  79. package/dist/components/timeline/item.d.ts +1 -1
  80. package/dist/components/timeline/timeline.d.ts +1 -1
  81. package/dist/components/tooltip/tooltip.d.ts +1 -1
  82. package/dist/components/transfer/context.d.ts +1 -1
  83. package/dist/components/transfer/hooks.d.ts +1 -1
  84. package/dist/components/transfer/item.d.ts +1 -1
  85. package/dist/components/transfer/list.d.ts +1 -1
  86. package/dist/components/transfer/transfer.d.ts +1 -1
  87. package/dist/components/upload/upload.cjs +31 -6
  88. package/dist/components/upload/upload.d.ts +2 -2
  89. package/dist/components/upload/upload.mjs +31 -6
  90. package/dist/components/upload/uploadeds.cjs +119 -55
  91. package/dist/components/upload/uploadeds.d.ts +1 -1
  92. package/dist/components/upload/uploadeds.mjs +121 -57
  93. package/dist/components/upload/utils.cjs +9 -0
  94. package/dist/components/upload/utils.d.ts +6 -0
  95. package/dist/components/upload/utils.mjs +9 -0
  96. package/dist/components/visually-hidden/visually-hidden.d.ts +1 -1
  97. package/dist/components/waterfall/sequential.d.ts +1 -1
  98. package/dist/components/waterfall/waterfall.d.ts +1 -1
  99. package/dist/components/watermark/hooks.d.ts +1 -1
  100. package/dist/components/watermark/watermark.d.ts +1 -1
  101. package/dist/hooks/use-class-names.d.ts +1 -0
  102. package/dist/hooks/use-closable.cjs +0 -8
  103. package/dist/hooks/use-closable.mjs +0 -8
  104. package/dist/hooks/use-container.d.ts +1 -1
  105. package/dist/hooks/use-lazy-boolean.cjs +2 -2
  106. package/dist/hooks/use-lazy-boolean.mjs +2 -2
  107. package/dist/index.cjs +2 -0
  108. package/dist/index.d.ts +1 -1
  109. package/dist/index.mjs +1 -0
  110. package/dist/locale/locales/en_US.cjs +5 -1
  111. package/dist/locale/locales/en_US.mjs +5 -1
  112. package/dist/locale/locales/zh_CN.cjs +5 -1
  113. package/dist/locale/locales/zh_CN.mjs +5 -1
  114. package/dist/styles.css +16 -7
  115. package/dist/types/drawer.d.ts +5 -0
  116. package/dist/types/element.d.ts +1 -56
  117. package/dist/types/form.d.ts +39 -1
  118. package/dist/types/locale.d.ts +6 -0
  119. package/dist/types/menu.d.ts +8 -3
  120. package/dist/types/popper.d.ts +1 -1
  121. package/dist/types/skeleton.d.ts +0 -7
  122. package/dist/{components/theme/types.d.ts → types/theme.d.ts} +1 -1
  123. package/dist/types/tree.d.ts +7 -2
  124. package/dist/{components/upload/types.d.ts → types/upload.d.ts} +59 -22
  125. package/dist/{components/waterfall/types.d.ts → types/waterfall.d.ts} +3 -3
  126. package/dist/utils/class-name.cjs +1 -1
  127. package/dist/utils/class-name.d.ts +3 -1
  128. package/dist/utils/class-name.mjs +1 -1
  129. package/dist/utils/colors.cjs +0 -10
  130. package/dist/utils/colors.d.ts +1 -4
  131. package/dist/utils/colors.mjs +1 -10
  132. package/dist/utils/component-token.cjs +1 -0
  133. package/dist/utils/component-token.d.ts +2 -1
  134. package/dist/utils/component-token.mjs +1 -0
  135. package/dist/utils/date.cjs +13 -0
  136. package/dist/utils/date.d.ts +6 -0
  137. package/dist/utils/date.mjs +13 -0
  138. package/package.json +25 -25
  139. package/dist/components/icon/icons/three-dimension-rotation.d.ts +0 -3
  140. /package/dist/{components/steps/types.d.ts → types/steps.d.ts} +0 -0
  141. /package/dist/{components/switch/types.d.ts → types/switch.d.ts} +0 -0
  142. /package/dist/{components/tabs/types.d.ts → types/tabs.d.ts} +0 -0
  143. /package/dist/{components/tag/types.d.ts → types/tag.d.ts} +0 -0
  144. /package/dist/{components/time-picker/types.d.ts → types/time-picker.d.ts} +0 -0
  145. /package/dist/{components/timeline/types.d.ts → types/timeline.d.ts} +0 -0
  146. /package/dist/{components/tooltip/types.d.ts → types/tooltip.d.ts} +0 -0
  147. /package/dist/{components/transfer/types.d.ts → types/transfer.d.ts} +0 -0
  148. /package/dist/{components/visually-hidden/types.d.ts → types/visually-hidden.d.ts} +0 -0
  149. /package/dist/{components/watermark/types.d.ts → types/watermark.d.ts} +0 -0
@@ -7,7 +7,7 @@ import { useClassNames } from '../../hooks/use-class-names.mjs';
7
7
  import { PaginationClassToken } from '../../utils/class-name.mjs';
8
8
  import { ComponentToken } from '../../utils/component-token.mjs';
9
9
  import { useLocale } from '../../locale/use-locale.mjs';
10
- import { toFunction, clsx } from '@aiszlab/relax';
10
+ import { unique, toFunction, clsx } from '@aiszlab/relax';
11
11
 
12
12
  var Pagination = function Pagination(_ref) {
13
13
  var _ref$total = _ref.total,
@@ -53,7 +53,7 @@ var Pagination = function Pagination(_ref) {
53
53
  }
54
54
  };
55
55
  var sizeOptions = useMemo(function () {
56
- return Array.from(new Set(pageSizes)).map(function (size) {
56
+ return unique(pageSizes).map(function (size) {
57
57
  return {
58
58
  value: size,
59
59
  label: toFunction(locale.size)(size)
@@ -96,7 +96,7 @@ var Popover = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
96
96
  return relax.chain(_children.props.onFocus, turnOn)(event);
97
97
  },
98
98
  onBlur: function onBlur(event) {
99
- return relax.chain(_children.props.onBlur)(event);
99
+ return relax.chain(_children.props.onBlur, disappear)(event);
100
100
  }
101
101
  }),
102
102
  _useFocus2 = _slicedToArray(_useFocus, 2),
@@ -94,7 +94,7 @@ var Popover = /*#__PURE__*/forwardRef(function (_ref2, ref) {
94
94
  return chain(_children.props.onFocus, turnOn)(event);
95
95
  },
96
96
  onBlur: function onBlur(event) {
97
- return chain(_children.props.onBlur)(event);
97
+ return chain(_children.props.onBlur, disappear)(event);
98
98
  }
99
99
  }),
100
100
  _useFocus2 = _slicedToArray(_useFocus, 2),
@@ -15,6 +15,25 @@ var dom = require('@aiszlab/relax/dom');
15
15
 
16
16
  var _excluded = ["open", "children", "placement", "style", "className", "onExit", "onExited", "onEntered", "trigger", "offset", "overlay", "arrow", "disappearable"];
17
17
  var styles = {
18
+ portal: {
19
+ "default": {
20
+ position: "musaex-ixxii4",
21
+ overflow: "musaex-b3r6kr",
22
+ overflowX: null,
23
+ overflowY: null,
24
+ pointerEvents: "musaex-47corl",
25
+ inset: "musaex-10a8y8t",
26
+ insetInline: null,
27
+ insetInlineStart: null,
28
+ insetInlineEnd: null,
29
+ left: null,
30
+ right: null,
31
+ insetBlock: null,
32
+ top: null,
33
+ bottom: null,
34
+ $$css: true
35
+ }
36
+ },
18
37
  dropdown: {
19
38
  "default": function _default(props) {
20
39
  return [{
@@ -35,7 +54,12 @@ var styles = {
35
54
  borderTopRightRadius: null,
36
55
  borderBottomLeftRadius: null,
37
56
  borderBottomRightRadius: null,
38
- willChange: "musaex-19wnzia",
57
+ pointerEvents: "musaex-67bb7w",
58
+ willChange: "musaex-1enemt",
59
+ transitionProperty: "musaex-qzan4j",
60
+ transitionDuration: "musaex-1g2r6go",
61
+ display: "musaex-1s85apg",
62
+ opacity: "musaex-g01cxk",
39
63
  $$css: true
40
64
  }, {
41
65
  "--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial"
@@ -72,7 +96,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
72
96
  onExited = _ref.onExited,
73
97
  onEntered = _ref.onEntered,
74
98
  trigger = _ref.trigger,
75
- _offset = _ref.offset,
99
+ offset = _ref.offset,
76
100
  _ref$overlay = _ref.overlay,
77
101
  overlay = _ref$overlay === void 0 ? false : _ref$overlay,
78
102
  _ref$arrow = _ref.arrow,
@@ -84,26 +108,23 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
84
108
  var theme = hooks.useTheme();
85
109
  var _useFloating = hooks$1.useFloating({
86
110
  arrowable: arrowable,
87
- offset: _offset,
111
+ offset: offset,
88
112
  placement: placement,
89
113
  open: open,
90
- trigger: trigger
91
- }),
92
- floatableRef = _useFloating.floatableRef,
93
- arrowRef = _useFloating.arrowRef;
94
- var _useAnimation = hooks$1.useAnimation({
95
- open: open,
96
- disappearable: disappearable,
114
+ trigger: trigger,
97
115
  onEntered: onEntered,
98
116
  onExit: onExit,
99
- onExited: onExited
117
+ onExited: onExited,
118
+ disappearable: disappearable
100
119
  }),
101
- disappear = _useAnimation.disappear,
102
- animatableRef = _useAnimation.animatableRef;
103
- var refs = relax.useRefs(floatableRef, animatableRef);
120
+ floatableRef = _useFloating.floatableRef,
121
+ arrowRef = _useFloating.arrowRef,
122
+ _disappear = _useFloating.disappear;
104
123
  React.useImperativeHandle(ref, function () {
105
124
  return {
106
- disappear: disappear,
125
+ disappear: function disappear() {
126
+ return _disappear(true);
127
+ },
107
128
  contains: function contains(node) {
108
129
  return dom.contains(floatableRef.current, node);
109
130
  }
@@ -115,10 +136,14 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
115
136
  }), overlay && styles.dropdown.overlay),
116
137
  arrow: stylex.default.props(styles.arrow["default"]({
117
138
  backgroundColor: theme.colors[colors.ColorToken.SurfaceContainer]
118
- }))
139
+ })),
140
+ portal: stylex.default.props(styles.portal["default"])
119
141
  };
120
- return /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({
121
- ref: refs
142
+ return /*#__PURE__*/React.createElement("div", {
143
+ className: styled.portal.className,
144
+ style: styled.portal.style
145
+ }, /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({
146
+ ref: floatableRef
122
147
  }, props), {}, {
123
148
  className: relax.clsx(classNames[className.PopperClassToken.Dropdown], className$1, styled.dropdown.className),
124
149
  style: _objectSpread(_objectSpread({}, styled.dropdown.style), style)
@@ -126,7 +151,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
126
151
  ref: arrowRef,
127
152
  className: styled.arrow.className,
128
153
  style: styled.arrow.style
129
- })));
154
+ }))));
130
155
  });
131
156
 
132
157
  exports.default = Dropdown;
@@ -4,8 +4,8 @@ import React, { forwardRef, useImperativeHandle } from 'react';
4
4
  import { PopperClassToken } from '../../utils/class-name.mjs';
5
5
  import { useClassNames } from '../../hooks/use-class-names.mjs';
6
6
  import _stylex from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.mjs';
7
- import { useRefs, clsx } from '@aiszlab/relax';
8
- import { useFloating, useAnimation } from './hooks.mjs';
7
+ import { clsx } from '@aiszlab/relax';
8
+ import { useFloating } from './hooks.mjs';
9
9
  import { useTheme } from '../theme/hooks.mjs';
10
10
  import { ColorToken } from '../../utils/colors.mjs';
11
11
  import { ComponentToken } from '../../utils/component-token.mjs';
@@ -13,6 +13,25 @@ import { contains } from '@aiszlab/relax/dom';
13
13
 
14
14
  var _excluded = ["open", "children", "placement", "style", "className", "onExit", "onExited", "onEntered", "trigger", "offset", "overlay", "arrow", "disappearable"];
15
15
  var styles = {
16
+ portal: {
17
+ "default": {
18
+ position: "musaex-ixxii4",
19
+ overflow: "musaex-b3r6kr",
20
+ overflowX: null,
21
+ overflowY: null,
22
+ pointerEvents: "musaex-47corl",
23
+ inset: "musaex-10a8y8t",
24
+ insetInline: null,
25
+ insetInlineStart: null,
26
+ insetInlineEnd: null,
27
+ left: null,
28
+ right: null,
29
+ insetBlock: null,
30
+ top: null,
31
+ bottom: null,
32
+ $$css: true
33
+ }
34
+ },
16
35
  dropdown: {
17
36
  "default": function _default(props) {
18
37
  return [{
@@ -33,7 +52,12 @@ var styles = {
33
52
  borderTopRightRadius: null,
34
53
  borderBottomLeftRadius: null,
35
54
  borderBottomRightRadius: null,
36
- willChange: "musaex-19wnzia",
55
+ pointerEvents: "musaex-67bb7w",
56
+ willChange: "musaex-1enemt",
57
+ transitionProperty: "musaex-qzan4j",
58
+ transitionDuration: "musaex-1g2r6go",
59
+ display: "musaex-1s85apg",
60
+ opacity: "musaex-g01cxk",
37
61
  $$css: true
38
62
  }, {
39
63
  "--backgroundColor": props.backgroundColor != null ? props.backgroundColor : "initial"
@@ -70,7 +94,7 @@ var Dropdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
70
94
  onExited = _ref.onExited,
71
95
  onEntered = _ref.onEntered,
72
96
  trigger = _ref.trigger,
73
- _offset = _ref.offset,
97
+ offset = _ref.offset,
74
98
  _ref$overlay = _ref.overlay,
75
99
  overlay = _ref$overlay === void 0 ? false : _ref$overlay,
76
100
  _ref$arrow = _ref.arrow,
@@ -82,26 +106,23 @@ var Dropdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
82
106
  var theme = useTheme();
83
107
  var _useFloating = useFloating({
84
108
  arrowable: arrowable,
85
- offset: _offset,
109
+ offset: offset,
86
110
  placement: placement,
87
111
  open: open,
88
- trigger: trigger
89
- }),
90
- floatableRef = _useFloating.floatableRef,
91
- arrowRef = _useFloating.arrowRef;
92
- var _useAnimation = useAnimation({
93
- open: open,
94
- disappearable: disappearable,
112
+ trigger: trigger,
95
113
  onEntered: onEntered,
96
114
  onExit: onExit,
97
- onExited: onExited
115
+ onExited: onExited,
116
+ disappearable: disappearable
98
117
  }),
99
- disappear = _useAnimation.disappear,
100
- animatableRef = _useAnimation.animatableRef;
101
- var refs = useRefs(floatableRef, animatableRef);
118
+ floatableRef = _useFloating.floatableRef,
119
+ arrowRef = _useFloating.arrowRef,
120
+ _disappear = _useFloating.disappear;
102
121
  useImperativeHandle(ref, function () {
103
122
  return {
104
- disappear: disappear,
123
+ disappear: function disappear() {
124
+ return _disappear(true);
125
+ },
105
126
  contains: function contains$1(node) {
106
127
  return contains(floatableRef.current, node);
107
128
  }
@@ -113,10 +134,14 @@ var Dropdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
113
134
  }), overlay && styles.dropdown.overlay),
114
135
  arrow: _stylex.props(styles.arrow["default"]({
115
136
  backgroundColor: theme.colors[ColorToken.SurfaceContainer]
116
- }))
137
+ })),
138
+ portal: _stylex.props(styles.portal["default"])
117
139
  };
118
- return /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({
119
- ref: refs
140
+ return /*#__PURE__*/React.createElement("div", {
141
+ className: styled.portal.className,
142
+ style: styled.portal.style
143
+ }, /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({
144
+ ref: floatableRef
120
145
  }, props), {}, {
121
146
  className: clsx(classNames[PopperClassToken.Dropdown], className, styled.dropdown.className),
122
147
  style: _objectSpread(_objectSpread({}, styled.dropdown.style), style)
@@ -124,7 +149,7 @@ var Dropdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
124
149
  ref: arrowRef,
125
150
  className: styled.arrow.className,
126
151
  style: styled.arrow.style
127
- })));
152
+ }))));
128
153
  });
129
154
 
130
155
  export { Dropdown as default };
@@ -28,132 +28,125 @@ var useOffsets = function useOffsets(_ref) {
28
28
  };
29
29
  /**
30
30
  * @description
31
- * use animation
31
+ * floating position
32
32
  */
33
- var useAnimation = function useAnimation(_ref2) {
33
+ var useFloating = function useFloating(_ref2) {
34
34
  var open = _ref2.open,
35
- disappearable = _ref2.disappearable,
35
+ _trigger = _ref2.trigger,
36
+ placement = _ref2.placement,
37
+ arrowable = _ref2.arrowable,
38
+ _offset = _ref2.offset,
36
39
  onEntered = _ref2.onEntered,
37
40
  onExit = _ref2.onExit,
38
- onExited = _ref2.onExited;
41
+ onExited = _ref2.onExited,
42
+ disappearable = _ref2.disappearable;
39
43
  var _useAnimate = framerMotion.useAnimate(),
40
44
  _useAnimate2 = _slicedToArray(_useAnimate, 2),
41
- animatableRef = _useAnimate2[0],
45
+ floatableRef = _useAnimate2[0],
42
46
  animate = _useAnimate2[1];
47
+ var arrowRef = React.useRef(null);
48
+ var _useContainer = useContainer.useContainer({
49
+ container: _trigger,
50
+ useBody: false
51
+ }, [open]),
52
+ trigger = _useContainer.container;
53
+ var _isOpen = React.useRef(false);
54
+ // appear animation
55
+ // prevent open again when opened
56
+ // first remove `display: none` style
57
+ // then animate
43
58
  var appear = relax.useEvent(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
44
59
  return _regeneratorRuntime().wrap(function _callee$(_context) {
45
60
  while (1) switch (_context.prev = _context.next) {
46
61
  case 0:
47
- animatableRef.current.style.display = "";
48
- _context.next = 3;
49
- return animate(animatableRef.current, {
50
- opacity: 1,
51
- transform: "scale(1, 1)"
62
+ if (!_isOpen.current) {
63
+ _context.next = 2;
64
+ break;
65
+ }
66
+ return _context.abrupt("return");
67
+ case 2:
68
+ _isOpen.current = true;
69
+ floatableRef.current.style.display = "unset";
70
+ _context.next = 6;
71
+ return animate(floatableRef.current, {
72
+ opacity: 1
52
73
  }, {
53
74
  duration: 0.2
54
75
  });
55
- case 3:
56
- _context.next = 5;
76
+ case 6:
77
+ _context.next = 8;
57
78
  return onEntered === null || onEntered === void 0 ? void 0 : onEntered();
58
- case 5:
79
+ case 8:
59
80
  case "end":
60
81
  return _context.stop();
61
82
  }
62
83
  }, _callee);
63
84
  })));
85
+ // disappear animation
86
+ // prevent disappear again when disappeared
87
+ // when using force disappear, it will be forced to disappear
64
88
  var disappear = relax.useEvent(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
89
+ var force,
90
+ _args2 = arguments;
65
91
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
66
92
  while (1) switch (_context2.prev = _context2.next) {
67
93
  case 0:
68
- _context2.next = 2;
69
- return Promise.all([onExit === null || onExit === void 0 ? void 0 : onExit(), animate(animatableRef.current, {
70
- opacity: 0,
71
- transform: "scale(0, 0)"
94
+ force = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : false;
95
+ if (_isOpen.current) {
96
+ _context2.next = 3;
97
+ break;
98
+ }
99
+ return _context2.abrupt("return");
100
+ case 3:
101
+ if (!(!force && !disappearable)) {
102
+ _context2.next = 5;
103
+ break;
104
+ }
105
+ return _context2.abrupt("return");
106
+ case 5:
107
+ _isOpen.current = false;
108
+ _context2.next = 8;
109
+ return Promise.all([onExit === null || onExit === void 0 ? void 0 : onExit(), animate(floatableRef.current, {
110
+ opacity: 0
72
111
  }, {
73
112
  duration: 0.2
74
113
  }).then(function () {
75
- if (!animatableRef.current) return;
76
- animatableRef.current.style.display = "none";
114
+ floatableRef.current.style.display = "none";
77
115
  })]);
78
- case 2:
79
- _context2.next = 4;
116
+ case 8:
117
+ _context2.next = 10;
80
118
  return onExited === null || onExited === void 0 ? void 0 : onExited();
81
- case 4:
119
+ case 10:
82
120
  case "end":
83
121
  return _context2.stop();
84
122
  }
85
123
  }, _callee2);
86
124
  })));
87
- var _disappear = React.useCallback(function () {
88
- if (!disappearable) return;
89
- disappear();
90
- }, [disappear, disappearable]);
91
- React.useLayoutEffect(function () {
92
- if (open) {
93
- appear();
94
- return;
95
- }
96
- _disappear();
97
- // eslint-disable-next-line react-hooks/exhaustive-deps
98
- }, [open]);
99
- return {
100
- animatableRef: animatableRef,
101
- disappear: disappear
102
- };
103
- };
104
- /**
105
- * @description
106
- * floating position
107
- */
108
- var useFloating = function useFloating(_ref5) {
109
- var open = _ref5.open,
110
- _trigger = _ref5.trigger,
111
- placement = _ref5.placement,
112
- arrowable = _ref5.arrowable,
113
- _offset = _ref5.offset;
114
- var floatableRef = React.useRef(null);
115
- var _useContainer = useContainer.useContainer({
116
- container: _trigger,
117
- useBody: false
118
- }, [open]),
119
- trigger = _useContainer.container;
120
- var arrowRef = React.useRef(null);
121
125
  // memorized offsets
122
126
  var offsets = useOffsets({
123
127
  offset: _offset,
124
128
  arrowable: arrowable
125
129
  });
126
- // auto update: calc trigger dom to get position
127
- // if trigger changed, re-relate
128
- React.useLayoutEffect(function () {
129
- var floatable = floatableRef.current;
130
+ // position listener
131
+ var position = relax.useEvent(function () {
130
132
  if (!trigger) return;
131
- if (!floatable) return;
132
- var cleanup = dom.autoUpdate(trigger, floatable, function () {
133
- dom.computePosition(trigger, floatable, {
133
+ var cleanup = dom.autoUpdate(trigger, floatableRef.current, function () {
134
+ dom.computePosition(trigger, floatableRef.current, {
134
135
  placement: placement,
135
- middleware: [dom.flip(), dom.offset(offsets), arrowable && !!arrowRef.current && dom.arrow({
136
+ middleware: [dom.flip(), dom.shift(), dom.offset(offsets), arrowable && !!arrowRef.current && dom.arrow({
136
137
  element: arrowRef.current,
137
138
  padding: 16
138
- }), dom.size({
139
- apply: function apply(_ref6) {
140
- var availableWidth = _ref6.availableWidth,
141
- availableHeight = _ref6.availableHeight,
142
- floating = _ref6.elements.floating;
143
- floating.style.maxWidth = "".concat(availableWidth, "px");
144
- floating.style.maxHeight = "".concat(availableHeight, "px");
145
- }
146
139
  })]
147
- }).then(function (_ref7) {
148
- var x = _ref7.x,
149
- y = _ref7.y,
150
- middlewareData = _ref7.middlewareData,
151
- _placement = _ref7.placement;
140
+ }).then(function (_ref5) {
141
+ var x = _ref5.x,
142
+ y = _ref5.y,
143
+ middlewareData = _ref5.middlewareData,
144
+ _placement = _ref5.placement;
152
145
  var _placement$split = _placement.split("-"),
153
146
  _placement$split2 = _slicedToArray(_placement$split, 1),
154
147
  side = _placement$split2[0];
155
148
  // set float element styles
156
- floatable.style.translate = "".concat(x, "px ").concat(y, "px");
149
+ floatableRef.current.style.translate = "".concat(x, "px ").concat(y, "px");
157
150
  // set arrow styles
158
151
  if (middlewareData.arrow && !!arrowRef.current) {
159
152
  var _middlewareData$arrow, _middlewareData$arrow2;
@@ -163,25 +156,31 @@ var useFloating = function useFloating(_ref5) {
163
156
  side === "top" && (arrowRef.current.style.insetBlockEnd = offsetY);
164
157
  side === "bottom" && (arrowRef.current.style.insetBlockStart = offsetY);
165
158
  }
159
+ // use appear animation
160
+ appear();
166
161
  })["catch"](function () {
167
162
  return null;
168
- }).then(function () {
169
- requestAnimationFrame(function () {
170
- floatable.style.transitionProperty = "translate";
171
- floatable.style.transitionDuration = "0.1s";
172
- });
173
163
  });
174
164
  });
175
- return function () {
176
- cleanup();
177
- };
178
- }, [placement, trigger, offsets, arrowable]);
165
+ return cleanup;
166
+ });
167
+ // auto update: calc trigger dom to get position
168
+ // if trigger changed, re-relate
169
+ React.useEffect(function () {
170
+ if (open) {
171
+ var cleanup = position();
172
+ return function () {
173
+ cleanup === null || cleanup === void 0 || cleanup();
174
+ };
175
+ }
176
+ disappear();
177
+ }, [disappear, open, position]);
179
178
  return {
180
179
  floatableRef: floatableRef,
181
- arrowRef: arrowRef
180
+ arrowRef: arrowRef,
181
+ disappear: disappear
182
182
  };
183
183
  };
184
184
 
185
- exports.useAnimation = useAnimation;
186
185
  exports.useFloating = useFloating;
187
186
  exports.useOffsets = useOffsets;
@@ -11,28 +11,22 @@ export declare const useOffsets: ({ offset, arrowable, }: {
11
11
  crossAxis?: number;
12
12
  alignmentAxis?: number | null;
13
13
  };
14
- /**
15
- * @description
16
- * use animation
17
- */
18
- export declare const useAnimation: ({ open, disappearable, onEntered, onExit, onExited, }: {
19
- open: boolean;
20
- disappearable: boolean;
21
- } & Pick<PopperProps, "onEntered" | "onExit" | "onExited">) => {
22
- animatableRef: import("framer-motion").AnimationScope<HTMLDivElement>;
23
- disappear: () => Promise<void>;
24
- };
25
14
  /**
26
15
  * @description
27
16
  * floating position
28
17
  */
29
- export declare const useFloating: ({ open, trigger: _trigger, placement, arrowable, offset: _offset, }: {
18
+ export declare const useFloating: ({ open, trigger: _trigger, placement, arrowable, offset: _offset, onEntered, onExit, onExited, disappearable, }: {
30
19
  open: boolean;
31
20
  trigger: DropdownProps["trigger"];
32
21
  placement: DropdownProps["placement"];
33
22
  arrowable: boolean;
34
23
  offset: DropdownProps["offset"];
24
+ onEntered?: () => Promise<void> | void;
25
+ onExit?: () => Promise<void> | void;
26
+ onExited?: () => Promise<void> | void;
27
+ disappearable: boolean;
35
28
  }) => {
36
- floatableRef: import("react").RefObject<HTMLDivElement>;
29
+ floatableRef: import("framer-motion").AnimationScope<HTMLDivElement>;
37
30
  arrowRef: import("react").RefObject<HTMLDivElement>;
31
+ disappear: (force?: boolean) => Promise<void>;
38
32
  };