@bifrostui/react 2.0.0-beta.10 → 2.0.0-beta.11

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 (211) hide show
  1. package/dist/Calendar/Calendar.js +5 -1
  2. package/dist/Calendar/Calendar.types.d.ts +5 -0
  3. package/dist/Collapse/Collapse.css +0 -1
  4. package/dist/Collapse/Collapse.d.ts +1 -1
  5. package/dist/Collapse/Collapse.js +11 -8
  6. package/dist/Collapse/Collapse.miniapp.d.ts +5 -0
  7. package/dist/Collapse/Collapse.miniapp.js +177 -0
  8. package/dist/CollapsePanel/CollapsePanel.css +4 -2
  9. package/dist/DatePicker/DatePicker.d.ts +4 -0
  10. package/dist/DatePicker/DatePicker.js +335 -0
  11. package/dist/DatePicker/DatePicker.types.d.ts +36 -0
  12. package/dist/DatePicker/DatePicker.types.js +15 -0
  13. package/dist/DatePicker/constants.d.ts +9 -0
  14. package/dist/DatePicker/constants.js +37 -0
  15. package/dist/DatePicker/index.d.ts +3 -0
  16. package/dist/DatePicker/index.js +44 -0
  17. package/dist/DesktopDatePicker/DesktopDatePicker.d.ts +5 -0
  18. package/dist/DesktopDatePicker/DesktopDatePicker.js +280 -0
  19. package/dist/DesktopDatePicker/DesktopDatePicker.types.d.ts +163 -0
  20. package/dist/DesktopDatePicker/DesktopDatePicker.types.js +15 -0
  21. package/dist/DesktopDatePicker/deskTopPickerContainer.css +100 -0
  22. package/dist/DesktopDatePicker/index.css +61 -0
  23. package/dist/DesktopDatePicker/index.d.ts +2 -0
  24. package/dist/DesktopDatePicker/index.js +41 -0
  25. package/dist/DesktopDatePicker/useGetDatePickerContent.d.ts +6 -0
  26. package/dist/DesktopDatePicker/useGetDatePickerContent.js +343 -0
  27. package/dist/DesktopDateTimePicker/DesktopDateTimePicker.d.ts +5 -0
  28. package/dist/DesktopDateTimePicker/DesktopDateTimePicker.js +322 -0
  29. package/dist/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +163 -0
  30. package/dist/DesktopDateTimePicker/DesktopDateTimePicker.types.js +15 -0
  31. package/dist/DesktopDateTimePicker/index.css +66 -0
  32. package/dist/DesktopDateTimePicker/index.d.ts +2 -0
  33. package/dist/DesktopDateTimePicker/index.js +41 -0
  34. package/dist/DesktopPicker/DesktopPicker.d.ts +5 -0
  35. package/dist/DesktopPicker/DesktopPicker.js +243 -0
  36. package/dist/DesktopPicker/DesktopPicker.types.d.ts +61 -0
  37. package/dist/DesktopPicker/DesktopPicker.types.js +15 -0
  38. package/dist/DesktopPicker/index.css +39 -0
  39. package/dist/DesktopPicker/index.d.ts +2 -0
  40. package/dist/DesktopPicker/index.js +41 -0
  41. package/dist/DesktopPicker/utils/calcAfterMounted.d.ts +2 -0
  42. package/dist/{Tabs/utils/bound.js → DesktopPicker/utils/calcAfterMounted.js} +7 -14
  43. package/dist/DesktopPicker/utils/calcAfterMounted.miniapp.d.ts +2 -0
  44. package/dist/DesktopPicker/utils/calcAfterMounted.miniapp.js +38 -0
  45. package/dist/DesktopTimePicker/DesktopTimePicker.d.ts +5 -0
  46. package/dist/DesktopTimePicker/DesktopTimePicker.js +288 -0
  47. package/dist/DesktopTimePicker/DesktopTimePicker.types.d.ts +182 -0
  48. package/dist/DesktopTimePicker/DesktopTimePicker.types.js +15 -0
  49. package/dist/DesktopTimePicker/DesktopTimePickerList.d.ts +4 -0
  50. package/dist/DesktopTimePicker/DesktopTimePickerList.js +111 -0
  51. package/dist/DesktopTimePicker/index.css +170 -0
  52. package/dist/DesktopTimePicker/index.d.ts +2 -0
  53. package/dist/DesktopTimePicker/index.js +41 -0
  54. package/dist/DesktopTimePicker/useGetTimePickerContent.d.ts +6 -0
  55. package/dist/DesktopTimePicker/useGetTimePickerContent.js +249 -0
  56. package/dist/DesktopTimePicker/utils/scrollUtil.d.ts +2 -0
  57. package/dist/DesktopTimePicker/utils/scrollUtil.js +27 -0
  58. package/dist/DesktopTimePicker/utils/scrollUtil.miniapp.d.ts +2 -0
  59. package/dist/DesktopTimePicker/utils/scrollUtil.miniapp.js +51 -0
  60. package/dist/DesktopTimePicker/utils/utils.d.ts +28 -0
  61. package/dist/DesktopTimePicker/utils/utils.js +408 -0
  62. package/dist/Dialog/Dialog.types.d.ts +5 -0
  63. package/dist/Dialog/FunctionalDialog.js +13 -2
  64. package/dist/Input/Input.css +0 -2
  65. package/dist/Modal/Modal.miniapp.d.ts +1 -1
  66. package/dist/Picker/Picker.css +5 -0
  67. package/dist/Picker/Picker.js +27 -5
  68. package/dist/Picker/Picker.types.d.ts +15 -2
  69. package/dist/Picker/PickerPanel.css +4 -0
  70. package/dist/Picker/PickerPanel.js +7 -6
  71. package/dist/Popover/Popover.js +70 -27
  72. package/dist/Portal/Portal.miniapp.js +7 -4
  73. package/dist/ScrollView/ScrollView.js +24 -11
  74. package/dist/ScrollView/ScrollView.types.d.ts +0 -1
  75. package/dist/Select/Select.css +1 -4
  76. package/dist/Select/Select.js +62 -37
  77. package/dist/Slider/Slider.js +13 -5
  78. package/dist/SwipeAction/SwipeAction.css +79 -0
  79. package/dist/SwipeAction/SwipeAction.d.ts +5 -0
  80. package/dist/SwipeAction/SwipeAction.js +349 -0
  81. package/dist/SwipeAction/SwipeAction.types.d.ts +75 -0
  82. package/dist/SwipeAction/SwipeAction.types.js +15 -0
  83. package/dist/SwipeAction/SwipeActionContext.d.ts +4 -0
  84. package/dist/SwipeAction/SwipeActionContext.js +30 -0
  85. package/dist/SwipeAction/SwipeActionItem.css +31 -0
  86. package/dist/SwipeAction/SwipeActionItem.d.ts +5 -0
  87. package/dist/SwipeAction/SwipeActionItem.js +105 -0
  88. package/dist/SwipeAction/constants.d.ts +9 -0
  89. package/dist/SwipeAction/constants.js +39 -0
  90. package/dist/SwipeAction/index.d.ts +5 -0
  91. package/dist/SwipeAction/index.js +50 -0
  92. package/dist/Tabs/Tabs.js +29 -14
  93. package/dist/Tabs/utils/scroll.d.ts +2 -0
  94. package/dist/Tabs/utils/scroll.js +55 -0
  95. package/dist/Toast/FunctionalToast.js +13 -2
  96. package/dist/Toast/Toast.css +0 -1
  97. package/dist/Toast/Toast.types.d.ts +5 -0
  98. package/dist/Tooltip/Tooltip.js +70 -27
  99. package/dist/index.d.ts +6 -0
  100. package/dist/index.js +13 -1
  101. package/dist/locales/base.d.ts +11 -0
  102. package/dist/locales/en-US.js +24 -0
  103. package/dist/locales/zh-CN.js +24 -0
  104. package/dist/locales/zh-TW.js +24 -0
  105. package/es/Calendar/Calendar.js +5 -1
  106. package/es/Calendar/Calendar.types.d.ts +5 -0
  107. package/es/Collapse/Collapse.css +0 -1
  108. package/es/Collapse/Collapse.d.ts +1 -1
  109. package/es/Collapse/Collapse.js +11 -8
  110. package/es/Collapse/Collapse.miniapp.d.ts +5 -0
  111. package/es/Collapse/Collapse.miniapp.js +157 -0
  112. package/es/CollapsePanel/CollapsePanel.css +4 -2
  113. package/es/DatePicker/DatePicker.d.ts +4 -0
  114. package/es/DatePicker/DatePicker.js +308 -0
  115. package/es/DatePicker/DatePicker.types.d.ts +36 -0
  116. package/es/DatePicker/DatePicker.types.js +1 -0
  117. package/es/DatePicker/constants.d.ts +9 -0
  118. package/es/DatePicker/constants.js +14 -0
  119. package/es/DatePicker/index.d.ts +3 -0
  120. package/es/DatePicker/index.js +8 -0
  121. package/es/DesktopDatePicker/DesktopDatePicker.d.ts +5 -0
  122. package/es/DesktopDatePicker/DesktopDatePicker.js +253 -0
  123. package/es/DesktopDatePicker/DesktopDatePicker.types.d.ts +163 -0
  124. package/es/DesktopDatePicker/DesktopDatePicker.types.js +1 -0
  125. package/es/DesktopDatePicker/deskTopPickerContainer.css +100 -0
  126. package/es/DesktopDatePicker/index.css +61 -0
  127. package/es/DesktopDatePicker/index.d.ts +2 -0
  128. package/es/DesktopDatePicker/index.js +6 -0
  129. package/es/DesktopDatePicker/useGetDatePickerContent.d.ts +6 -0
  130. package/es/DesktopDatePicker/useGetDatePickerContent.js +316 -0
  131. package/es/DesktopDateTimePicker/DesktopDateTimePicker.d.ts +5 -0
  132. package/es/DesktopDateTimePicker/DesktopDateTimePicker.js +295 -0
  133. package/es/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +163 -0
  134. package/es/DesktopDateTimePicker/DesktopDateTimePicker.types.js +1 -0
  135. package/es/DesktopDateTimePicker/index.css +66 -0
  136. package/es/DesktopDateTimePicker/index.d.ts +2 -0
  137. package/es/DesktopDateTimePicker/index.js +9 -0
  138. package/es/DesktopPicker/DesktopPicker.d.ts +5 -0
  139. package/es/DesktopPicker/DesktopPicker.js +226 -0
  140. package/es/DesktopPicker/DesktopPicker.types.d.ts +61 -0
  141. package/es/DesktopPicker/DesktopPicker.types.js +1 -0
  142. package/es/DesktopPicker/index.css +39 -0
  143. package/es/DesktopPicker/index.d.ts +2 -0
  144. package/es/DesktopPicker/index.js +6 -0
  145. package/es/DesktopPicker/utils/calcAfterMounted.d.ts +2 -0
  146. package/es/DesktopPicker/utils/calcAfterMounted.js +6 -0
  147. package/es/DesktopPicker/utils/calcAfterMounted.miniapp.d.ts +2 -0
  148. package/es/DesktopPicker/utils/calcAfterMounted.miniapp.js +9 -0
  149. package/es/DesktopTimePicker/DesktopTimePicker.d.ts +5 -0
  150. package/es/DesktopTimePicker/DesktopTimePicker.js +261 -0
  151. package/es/DesktopTimePicker/DesktopTimePicker.types.d.ts +182 -0
  152. package/es/DesktopTimePicker/DesktopTimePicker.types.js +1 -0
  153. package/es/DesktopTimePicker/DesktopTimePickerList.d.ts +4 -0
  154. package/es/DesktopTimePicker/DesktopTimePickerList.js +84 -0
  155. package/es/DesktopTimePicker/index.css +170 -0
  156. package/es/DesktopTimePicker/index.d.ts +2 -0
  157. package/es/DesktopTimePicker/index.js +6 -0
  158. package/es/DesktopTimePicker/useGetTimePickerContent.d.ts +6 -0
  159. package/es/DesktopTimePicker/useGetTimePickerContent.js +226 -0
  160. package/es/DesktopTimePicker/utils/scrollUtil.d.ts +2 -0
  161. package/es/DesktopTimePicker/utils/scrollUtil.js +8 -0
  162. package/es/DesktopTimePicker/utils/scrollUtil.miniapp.d.ts +2 -0
  163. package/es/DesktopTimePicker/utils/scrollUtil.miniapp.js +22 -0
  164. package/es/DesktopTimePicker/utils/utils.d.ts +28 -0
  165. package/es/DesktopTimePicker/utils/utils.js +365 -0
  166. package/es/Dialog/Dialog.types.d.ts +5 -0
  167. package/es/Dialog/FunctionalDialog.js +14 -3
  168. package/es/Input/Input.css +0 -2
  169. package/es/Picker/Picker.css +5 -0
  170. package/es/Picker/Picker.js +27 -5
  171. package/es/Picker/Picker.types.d.ts +15 -2
  172. package/es/Picker/PickerPanel.css +4 -0
  173. package/es/Picker/PickerPanel.js +7 -6
  174. package/es/Popover/Popover.js +73 -29
  175. package/es/Portal/Portal.miniapp.js +8 -5
  176. package/es/ScrollView/ScrollView.js +24 -11
  177. package/es/ScrollView/ScrollView.types.d.ts +0 -1
  178. package/es/Select/Select.css +1 -4
  179. package/es/Select/Select.js +62 -38
  180. package/es/Slider/Slider.js +16 -6
  181. package/es/SwipeAction/SwipeAction.css +79 -0
  182. package/es/SwipeAction/SwipeAction.d.ts +5 -0
  183. package/es/SwipeAction/SwipeAction.js +334 -0
  184. package/es/SwipeAction/SwipeAction.types.d.ts +75 -0
  185. package/es/SwipeAction/SwipeAction.types.js +1 -0
  186. package/es/SwipeAction/SwipeActionContext.d.ts +4 -0
  187. package/es/SwipeAction/SwipeActionContext.js +11 -0
  188. package/es/SwipeAction/SwipeActionItem.css +31 -0
  189. package/es/SwipeAction/SwipeActionItem.d.ts +5 -0
  190. package/es/SwipeAction/SwipeActionItem.js +78 -0
  191. package/es/SwipeAction/constants.d.ts +9 -0
  192. package/es/SwipeAction/constants.js +15 -0
  193. package/es/SwipeAction/index.d.ts +5 -0
  194. package/es/SwipeAction/index.js +12 -0
  195. package/es/Tabs/Tabs.js +29 -14
  196. package/es/Tabs/utils/scroll.d.ts +2 -0
  197. package/es/Tabs/utils/scroll.js +36 -0
  198. package/es/Toast/FunctionalToast.js +14 -3
  199. package/es/Toast/Toast.css +0 -1
  200. package/es/Toast/Toast.types.d.ts +5 -0
  201. package/es/Tooltip/Tooltip.js +73 -29
  202. package/es/index.d.ts +6 -0
  203. package/es/index.js +6 -0
  204. package/es/locales/base.d.ts +11 -0
  205. package/es/locales/en-US.js +24 -0
  206. package/es/locales/zh-CN.js +24 -0
  207. package/es/locales/zh-TW.js +24 -0
  208. package/package.json +5 -5
  209. package/dist/Tabs/utils/bound.d.ts +0 -1
  210. package/es/Tabs/utils/bound.d.ts +0 -1
  211. package/es/Tabs/utils/bound.js +0 -13
@@ -29,13 +29,32 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
32
52
  import { CaretDownIcon, CaretUpIcon } from "@bifrostui/icons";
33
53
  import {
34
54
  getStylesAndLocation,
35
55
  isMini,
36
56
  throttle,
37
57
  useForkRef,
38
- useUniqueId,
39
58
  useValue
40
59
  } from "@bifrostui/utils";
41
60
  import clsx from "clsx";
@@ -100,38 +119,36 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
100
119
  const isOpen = open !== void 0 ? open : internalOpen;
101
120
  const locatorRef = useRef(null);
102
121
  const rootRef = useForkRef(ref, locatorRef);
103
- const ttId = useUniqueId();
104
- const dataId = `${prefixCls}-tt-${ttId}`;
105
- const updateOptionStyle = throttle(() => {
122
+ const optionContainerRef = useRef(null);
123
+ const optionMainRef = useRef(null);
124
+ const updateOptionStyle = () => __async(void 0, null, function* () {
106
125
  const curScrollRoot = scrollContainer();
107
- if (!isMini && curScrollRoot) {
108
- const result = getStylesAndLocation({
109
- scrollRoot: curScrollRoot,
110
- childrenRef: locatorRef,
111
- arrowDirection: defaultPlacement,
112
- arrowLocation: "none",
113
- selector: `[data-id="${dataId}"]`,
114
- offsetSpacing: 0
115
- });
116
- if (!result)
117
- return;
118
- const { styles, childrenStyle, newArrowDirection } = result;
119
- setPlacement(newArrowDirection);
120
- setOptionStyle(__spreadProps(__spreadValues({}, styles), { width: childrenStyle.width }));
121
- }
122
- }, 100);
123
- const changeOpen = (newOpen) => {
126
+ const result = yield getStylesAndLocation({
127
+ scrollRoot: curScrollRoot,
128
+ childrenRef: locatorRef,
129
+ tipRef: optionContainerRef,
130
+ arrowDirection: defaultPlacement,
131
+ arrowLocation: "none",
132
+ offsetSpacing: 0
133
+ });
134
+ if (!result)
135
+ return;
136
+ const { styles, childrenStyle, newArrowDirection } = result;
137
+ optionMainRef.current.style.transition = "none";
138
+ optionMainRef.current.style.transform = `translateY(${newArrowDirection === "bottom" ? "-100%" : "100%"})`;
139
+ setPlacement(newArrowDirection);
140
+ setOptionStyle(__spreadProps(__spreadValues({}, styles), { width: childrenStyle == null ? void 0 : childrenStyle.width }));
141
+ });
142
+ const changeOpen = (newOpen) => __async(void 0, null, function* () {
124
143
  if (newOpen) {
125
- updateOptionStyle();
126
- setTimeout(() => {
127
- setInternalOpen(newOpen);
128
- onOpen == null ? void 0 : onOpen();
129
- }, 100);
144
+ yield updateOptionStyle();
145
+ setInternalOpen(newOpen);
146
+ onOpen == null ? void 0 : onOpen();
130
147
  } else {
131
148
  onClose == null ? void 0 : onClose();
132
149
  setInternalOpen(newOpen);
133
150
  }
134
- };
151
+ });
135
152
  const handleSelectClick = (e) => {
136
153
  if (disabled)
137
154
  return;
@@ -156,10 +173,11 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
156
173
  [selectValue, onChange, setRenderValue]
157
174
  );
158
175
  useEffect(() => {
176
+ const resizeCb = throttle(updateOptionStyle, 100);
159
177
  if (!isMini) {
160
- window.addEventListener("resize", updateOptionStyle);
178
+ window.addEventListener("resize", resizeCb);
161
179
  return () => {
162
- window.removeEventListener("resize", updateOptionStyle);
180
+ window.removeEventListener("resize", resizeCb);
163
181
  };
164
182
  }
165
183
  }, []);
@@ -177,8 +195,8 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
177
195
  {
178
196
  in: isOpen,
179
197
  timeout: {
180
- enter: 150,
181
- exit: 150
198
+ enter: 167,
199
+ exit: 167
182
200
  }
183
201
  },
184
202
  /* @__PURE__ */ React.createElement(
@@ -192,7 +210,7 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
192
210
  [`${prefixCls}-option-container-hide`]: !isOpen
193
211
  }
194
212
  ),
195
- "data-id": dataId,
213
+ ref: optionContainerRef,
196
214
  style: optionStyle
197
215
  },
198
216
  /* @__PURE__ */ React.createElement(
@@ -201,11 +219,18 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
201
219
  in: isOpen,
202
220
  direction: placement === "bottom" ? "down" : "up",
203
221
  timeout: {
204
- enter: 150,
205
- exit: 150
222
+ enter: 167,
223
+ exit: 167
206
224
  }
207
225
  },
208
- /* @__PURE__ */ React.createElement("div", { className: clsx(`${prefixCls}-option-main`) }, children)
226
+ /* @__PURE__ */ React.createElement(
227
+ "div",
228
+ {
229
+ className: clsx(`${prefixCls}-option-main`),
230
+ ref: optionMainRef
231
+ },
232
+ children
233
+ )
209
234
  )
210
235
  )
211
236
  );
@@ -233,9 +258,8 @@ const Select = /* @__PURE__ */ React.forwardRef((props, ref) => {
233
258
  [inputProps == null ? void 0 : inputProps.className]: inputProps == null ? void 0 : inputProps.className
234
259
  })
235
260
  })
236
- ), icon || defaultIcon),
237
- isMini && renderOptions()
238
- ), !isMini && /* @__PURE__ */ React.createElement(Portal, { onRootElementMouted: updateOptionStyle }, renderOptions()), /* @__PURE__ */ React.createElement(
261
+ ), icon || defaultIcon)
262
+ ), /* @__PURE__ */ React.createElement(Portal, { onRootElementMouted: updateOptionStyle }, renderOptions()), /* @__PURE__ */ React.createElement(
239
263
  Backdrop,
240
264
  __spreadProps(__spreadValues({
241
265
  open: isOpen,
@@ -50,7 +50,9 @@ import { GripperBarVerticalIcon } from "@bifrostui/icons";
50
50
  import {
51
51
  isMini,
52
52
  useForkRef,
53
- useTouchEmulator,
53
+ emulateTouchStart,
54
+ emulateTouchMove,
55
+ emulateTouchEnd,
54
56
  useValue,
55
57
  getBoundingClientRect
56
58
  } from "@bifrostui/utils";
@@ -110,7 +112,6 @@ const Slider = /* @__PURE__ */ React.forwardRef((props, ref) => {
110
112
  const value = shouldProtection ? latestVal.current : valueProp;
111
113
  const [rootRef, setRootRef] = useState(null);
112
114
  const handleRef = useForkRef(ref, setRootRef);
113
- useTouchEmulator(rootRef);
114
115
  const sliderRect = useRef();
115
116
  const touchStartPageX = useRef();
116
117
  const touchStartLeft = useRef();
@@ -181,9 +182,7 @@ const Slider = /* @__PURE__ */ React.forwardRef((props, ref) => {
181
182
  return;
182
183
  beforeMoveValue.current = internalValue;
183
184
  tooltipRef.current = internalValue;
184
- if (!sliderRect.current.width) {
185
- getLineWidth();
186
- }
185
+ getLineWidth();
187
186
  const currentTarget = isMini ? e.mpEvent.currentTarget : e.currentTarget;
188
187
  touchStartPageX.current = e.touches[0].pageX;
189
188
  touchStartLeft.current = currentTarget == null ? void 0 : currentTarget.offsetLeft;
@@ -242,6 +241,16 @@ const Slider = /* @__PURE__ */ React.forwardRef((props, ref) => {
242
241
  setFrontTooltipVisible(false);
243
242
  setEndTooltipVisible(false);
244
243
  };
244
+ const onMouseUp = (e) => {
245
+ emulateTouchEnd(e);
246
+ document.removeEventListener("mousemove", emulateTouchMove);
247
+ document.removeEventListener("mouseup", onMouseUp);
248
+ };
249
+ const onMouseDown = (e) => {
250
+ emulateTouchStart(e);
251
+ document.addEventListener("mousemove", emulateTouchMove);
252
+ document.addEventListener("mouseup", onMouseUp);
253
+ };
245
254
  const renderButton = (index) => {
246
255
  const valuenow = internalValue[index];
247
256
  return /* @__PURE__ */ React.createElement(
@@ -264,7 +273,8 @@ const Slider = /* @__PURE__ */ React.forwardRef((props, ref) => {
264
273
  },
265
274
  onTouchMove,
266
275
  onTouchEnd,
267
- onTouchCancel: onTouchEnd
276
+ onTouchCancel: onTouchEnd,
277
+ onMouseDown
268
278
  },
269
279
  index === SLIDER_BUTTON.FRONT ? startIcon || defaultIcon : endIcon || defaultIcon
270
280
  );
@@ -0,0 +1,79 @@
1
+ :root,
2
+ page,
3
+ xhs-page {
4
+ --bui-swipe-action-container-padding: 10px;
5
+ --bui-swipe-action-container-color: var(--bui-color-black);
6
+ }
7
+ .bui-swipe-action {
8
+ background: var(--bui-color-bg-view);
9
+ font-family: var(--bui-font-family);
10
+ overflow: hidden;
11
+ touch-action: pan-x;
12
+ }
13
+ .bui-swipe-action-track {
14
+ position: relative;
15
+ transition: transform 200ms ease;
16
+ }
17
+ .bui-swipe-action-actions {
18
+ position: absolute;
19
+ top: 0;
20
+ display: flex;
21
+ width: auto;
22
+ white-space: nowrap;
23
+ }
24
+ .bui-swipe-action-actions-right {
25
+ left: 100%;
26
+ height: 100%;
27
+ cursor: pointer;
28
+ margin-left: 1px;
29
+ user-select: none;
30
+ display: flex;
31
+ align-items: center;
32
+ box-sizing: content-box;
33
+ }
34
+ .bui-swipe-action-actions-left {
35
+ margin-right: 1px;
36
+ right: 100%;
37
+ height: 100%;
38
+ cursor: pointer;
39
+ box-sizing: content-box;
40
+ user-select: none;
41
+ display: flex;
42
+ align-items: center;
43
+ }
44
+ .bui-swipe-action-button {
45
+ padding: 0 15px;
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ height: 100%;
50
+ width: 100%;
51
+ color: #fff;
52
+ box-sizing: content-box;
53
+ white-space: nowrap;
54
+ }
55
+ .bui-swipe-action-content-container {
56
+ overflow: hidden;
57
+ position: relative;
58
+ cursor: grab;
59
+ user-select: none;
60
+ padding: var(--bui-swipe-action-container-padding);
61
+ color: var(--bui-swipe-action-container-color);
62
+ }
63
+ .bui-swipe-action-content-container:active {
64
+ cursor: grabbing;
65
+ }
66
+ .bui-swipe-action-content-mask {
67
+ position: absolute;
68
+ left: 0;
69
+ top: 0;
70
+ width: 100%;
71
+ height: 100%;
72
+ }
73
+ .bui-swipe-action-action {
74
+ display: flex;
75
+ align-items: center;
76
+ justify-content: center;
77
+ padding: 0 10px;
78
+ height: 100%;
79
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { SwipeActionProps, SwipeActionRef } from './SwipeAction.types';
3
+ import './SwipeAction.less';
4
+ declare const SwipeAction: React.ForwardRefExoticComponent<Omit<SwipeActionProps<"div", {}>, "ref"> & React.RefAttributes<SwipeActionRef>>;
5
+ export default SwipeAction;
@@ -0,0 +1,334 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+ import React, {
50
+ useImperativeHandle,
51
+ useRef,
52
+ useState,
53
+ useEffect,
54
+ useMemo
55
+ } from "react";
56
+ import clsx from "clsx";
57
+ import {
58
+ useTouch,
59
+ touchEmulator,
60
+ isMini,
61
+ getBoundingClientRect,
62
+ throttle
63
+ } from "@bifrostui/utils";
64
+ import BuiSwipeActionContext from "./SwipeActionContext";
65
+ import { DragPhaseEnum, SideTypeEnum } from "./constants";
66
+ import "./SwipeAction.css";
67
+ const classPrefix = "bui-swipe-action";
68
+ const SwipeAction = /* @__PURE__ */ React.forwardRef(
69
+ (props, ref) => {
70
+ const _a = props, {
71
+ className,
72
+ children,
73
+ rightActions,
74
+ leftActions,
75
+ disabled,
76
+ closeOnClickActionItem = true,
77
+ closeOnClickContainer = false,
78
+ onActionsReveal
79
+ } = _a, others = __objRest(_a, [
80
+ "className",
81
+ "children",
82
+ "rightActions",
83
+ "leftActions",
84
+ "disabled",
85
+ "closeOnClickActionItem",
86
+ "closeOnClickContainer",
87
+ "onActionsReveal"
88
+ ]);
89
+ const touch = useTouch();
90
+ const rootRef = useRef(null);
91
+ const leftRef = useRef(null);
92
+ const rightRef = useRef(null);
93
+ const contentRef = useRef(null);
94
+ const [translateX, setTranslateX] = useState(0);
95
+ const [isOpen, setIsOpen] = useState(false);
96
+ const startingX = useRef(0);
97
+ const currentX = useRef(0);
98
+ const isDragging = useRef(false);
99
+ let pretranslateX = 0;
100
+ let dragPhase = DragPhaseEnum.START;
101
+ const dragThreshold = 5;
102
+ const leftWidthCache = useRef(0);
103
+ const rightWidthCache = useRef(0);
104
+ const getWidth = (_ref) => {
105
+ if (!_ref.current)
106
+ return Promise.resolve(0);
107
+ return new Promise((resolve) => {
108
+ if (isMini) {
109
+ getBoundingClientRect(_ref.current).then((rect) => {
110
+ if (rect) {
111
+ resolve(rect.width || 0);
112
+ }
113
+ });
114
+ } else {
115
+ resolve(_ref.current.offsetWidth);
116
+ }
117
+ });
118
+ };
119
+ const getLefRefWidth = () => __async(void 0, null, function* () {
120
+ if (leftRef.current && leftActions && !leftWidthCache.current) {
121
+ leftWidthCache.current = yield getWidth(leftRef);
122
+ }
123
+ return leftWidthCache.current;
124
+ });
125
+ const getRightRefWidth = () => __async(void 0, null, function* () {
126
+ if (rightRef.current && rightActions && !rightWidthCache.current) {
127
+ rightWidthCache.current = yield getWidth(rightRef);
128
+ }
129
+ return rightWidthCache.current;
130
+ });
131
+ const initRefWidth = () => {
132
+ getLefRefWidth();
133
+ getRightRefWidth();
134
+ };
135
+ const handleTouchStart = (e) => {
136
+ dragPhase = DragPhaseEnum.START;
137
+ const isMaskEle = e.target.id === "content-mask";
138
+ if (isDragging.current || disabled || isMaskEle)
139
+ return;
140
+ touch.start(e);
141
+ isDragging.current = true;
142
+ startingX.current = touch.deltaX.current - translateX;
143
+ };
144
+ const handleTouchMove = throttle(
145
+ (e) => __async(void 0, null, function* () {
146
+ if (!isDragging.current || disabled)
147
+ return;
148
+ if (dragPhase === DragPhaseEnum.START) {
149
+ dragPhase = DragPhaseEnum.MOVE;
150
+ }
151
+ touch.move(e);
152
+ currentX.current = touch.deltaX.current - startingX.current;
153
+ if (Math.abs(currentX.current) < dragThreshold)
154
+ return;
155
+ const leftWidth = yield getLefRefWidth();
156
+ const rightWidth = yield getRightRefWidth();
157
+ currentX.current = Math.max(
158
+ -rightWidth,
159
+ Math.min(leftWidth, currentX.current)
160
+ );
161
+ setTranslateX(currentX.current);
162
+ }),
163
+ 100
164
+ );
165
+ const emitActionsReveal = (targetX, stop = false) => {
166
+ const isSpecial = targetX === pretranslateX && targetX !== 0;
167
+ if (targetX === pretranslateX && !isSpecial || stop)
168
+ return;
169
+ let resStr = null;
170
+ const shouldOpen = targetX > 0 && pretranslateX <= 0 || targetX < 0 && pretranslateX >= 0 || isSpecial;
171
+ if (shouldOpen) {
172
+ if (targetX > 0) {
173
+ resStr = SideTypeEnum.LEFT;
174
+ } else if (targetX < 0) {
175
+ resStr = SideTypeEnum.RIGHT;
176
+ }
177
+ setIsOpen(true);
178
+ } else {
179
+ setIsOpen(false);
180
+ }
181
+ if (resStr) {
182
+ onActionsReveal == null ? void 0 : onActionsReveal({ side: resStr });
183
+ }
184
+ };
185
+ const handleTouchEnd = (e) => __async(void 0, null, function* () {
186
+ if (!isDragging.current)
187
+ return;
188
+ if (dragPhase === DragPhaseEnum.MOVE) {
189
+ dragPhase = DragPhaseEnum.END;
190
+ }
191
+ const leftWidth = yield getLefRefWidth();
192
+ const rightWidth = yield getRightRefWidth();
193
+ const threshold = 0.5;
194
+ let targetX = 0;
195
+ isDragging.current = false;
196
+ if (Math.abs(currentX.current) < dragThreshold)
197
+ return;
198
+ if (currentX.current > leftWidth * threshold) {
199
+ targetX = leftWidth;
200
+ } else if (currentX.current < -rightWidth * threshold) {
201
+ targetX = -rightWidth;
202
+ }
203
+ if (dragPhase === DragPhaseEnum.END || isMini) {
204
+ emitActionsReveal(targetX);
205
+ console.log("handleTouchEnd\uFF1A", targetX, e);
206
+ setTranslateX(targetX);
207
+ pretranslateX = targetX;
208
+ }
209
+ currentX.current = 0;
210
+ });
211
+ const close = () => {
212
+ setTranslateX(0);
213
+ pretranslateX = 0;
214
+ setIsOpen(false);
215
+ };
216
+ useEffect(() => {
217
+ initRefWidth();
218
+ if (!contentRef.current)
219
+ return;
220
+ const removeTouchEmulator = touchEmulator(contentRef.current);
221
+ return () => {
222
+ removeTouchEmulator();
223
+ };
224
+ }, []);
225
+ useEffect(() => {
226
+ var _a2, _b, _c, _d;
227
+ (_a2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _a2.addEventListener("touchstart", handleTouchStart);
228
+ (_b = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _b.addEventListener("touchmove", handleTouchMove);
229
+ (_c = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _c.addEventListener("touchend", handleTouchEnd);
230
+ (_d = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _d.addEventListener("touchcancel", handleTouchEnd);
231
+ if (!isMini && document) {
232
+ document.addEventListener("mouseup", handleTouchEnd);
233
+ }
234
+ return () => {
235
+ var _a3, _b2, _c2, _d2;
236
+ (_a3 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _a3.removeEventListener(
237
+ "touchstart",
238
+ handleTouchStart
239
+ );
240
+ (_b2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _b2.removeEventListener("touchmove", handleTouchMove);
241
+ (_c2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _c2.removeEventListener("touchend", handleTouchEnd);
242
+ (_d2 = contentRef == null ? void 0 : contentRef.current) == null ? void 0 : _d2.removeEventListener("touchcancel", handleTouchEnd);
243
+ if (!isMini && document) {
244
+ document.removeEventListener("mouseup", handleTouchEnd);
245
+ }
246
+ };
247
+ }, []);
248
+ useImperativeHandle(ref, () => ({
249
+ show: (params) => __async(void 0, null, function* () {
250
+ let targetX = 0;
251
+ if (params && params.side === SideTypeEnum.RIGHT) {
252
+ targetX = -(yield getRightRefWidth());
253
+ } else {
254
+ targetX = yield getLefRefWidth();
255
+ }
256
+ setTranslateX(targetX);
257
+ pretranslateX = targetX;
258
+ emitActionsReveal(targetX);
259
+ }),
260
+ close,
261
+ // 获取当前是否打开
262
+ open: isOpen,
263
+ ref: rootRef.current
264
+ }));
265
+ const outClickHandle = (e) => {
266
+ e.preventDefault();
267
+ e.stopPropagation();
268
+ if (translateX !== 0 && closeOnClickContainer) {
269
+ close();
270
+ }
271
+ };
272
+ const SwipeActionContext = useMemo(
273
+ () => ({ closeOnClickActionItem, close }),
274
+ [closeOnClickActionItem]
275
+ );
276
+ return /* @__PURE__ */ React.createElement(BuiSwipeActionContext.Provider, { value: SwipeActionContext }, /* @__PURE__ */ React.createElement(
277
+ "div",
278
+ __spreadValues({
279
+ className: clsx(`${classPrefix}`, className),
280
+ ref: rootRef
281
+ }, others),
282
+ /* @__PURE__ */ React.createElement(
283
+ "div",
284
+ {
285
+ className: `${classPrefix}-track`,
286
+ style: {
287
+ transform: `translate3d(${translateX}px, 0, 0)`
288
+ }
289
+ },
290
+ /* @__PURE__ */ React.createElement(
291
+ "div",
292
+ {
293
+ className: `${classPrefix}-actions ${classPrefix}-actions-left`,
294
+ ref: leftRef
295
+ },
296
+ leftActions
297
+ ),
298
+ /* @__PURE__ */ React.createElement(
299
+ "div",
300
+ {
301
+ className: `${classPrefix}-content-container`,
302
+ ref: contentRef,
303
+ onTouchStart: handleTouchStart,
304
+ onTouchMove: handleTouchMove,
305
+ onTouchEnd: handleTouchEnd,
306
+ onTouchCancel: handleTouchEnd
307
+ },
308
+ isOpen && closeOnClickContainer && /* @__PURE__ */ React.createElement(
309
+ "div",
310
+ {
311
+ className: `${classPrefix}-content-mask`,
312
+ id: "content-mask",
313
+ onClick: outClickHandle
314
+ }
315
+ ),
316
+ children
317
+ ),
318
+ /* @__PURE__ */ React.createElement(
319
+ "div",
320
+ {
321
+ className: `${classPrefix}-actions ${classPrefix}-actions-right`,
322
+ ref: rightRef
323
+ },
324
+ rightActions
325
+ )
326
+ )
327
+ ));
328
+ }
329
+ );
330
+ SwipeAction.displayName = "BuiSwipeAction";
331
+ var SwipeAction_default = SwipeAction;
332
+ export {
333
+ SwipeAction_default as default
334
+ };