clxx 2.1.5 → 2.1.7

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 (74) hide show
  1. package/AGENTS.md +2 -0
  2. package/README.md +827 -420
  3. package/build/Ago/index.js +14 -8
  4. package/build/Alert/Wrapper.js +13 -10
  5. package/build/Alert/index.js +17 -11
  6. package/build/Alert/style.js +44 -58
  7. package/build/AutoGrid/index.js +66 -48
  8. package/build/AutoGrid/style.d.ts +3 -4
  9. package/build/AutoGrid/style.js +13 -22
  10. package/build/CarouselNotice/index.js +22 -19
  11. package/build/CarouselNotice/style.js +12 -14
  12. package/build/CitySelect/data.d.ts +3 -0
  13. package/build/CitySelect/data.js +2355 -0
  14. package/build/CitySelect/index.d.ts +17 -0
  15. package/build/CitySelect/index.js +300 -0
  16. package/build/CitySelect/search.d.ts +2 -0
  17. package/build/CitySelect/search.js +70 -0
  18. package/build/CitySelect/style.d.ts +4 -0
  19. package/build/CitySelect/style.js +237 -0
  20. package/build/CitySelect/type.d.ts +17 -0
  21. package/build/CitySelect/type.js +2 -0
  22. package/build/Clickable/index.d.ts +1 -0
  23. package/build/Clickable/index.js +113 -31
  24. package/build/Container/index.js +62 -47
  25. package/build/Countdowner/index.js +50 -14
  26. package/build/Dialog/Wrapper.js +13 -10
  27. package/build/Dialog/index.js +18 -12
  28. package/build/Dialog/style.js +29 -25
  29. package/build/Effect/useInterval.js +7 -4
  30. package/build/Effect/useTick.js +9 -6
  31. package/build/Effect/useUpdate.js +6 -3
  32. package/build/Effect/useViewport.js +15 -8
  33. package/build/Effect/useWindowResize.js +7 -4
  34. package/build/Fixed/index.d.ts +5 -0
  35. package/build/Fixed/index.js +40 -0
  36. package/build/Flex/Col.js +23 -15
  37. package/build/Flex/Row.js +23 -15
  38. package/build/Flex/index.js +9 -5
  39. package/build/Indicator/index.js +24 -18
  40. package/build/Indicator/style.js +6 -3
  41. package/build/Loading/Wrapper.js +14 -11
  42. package/build/Loading/index.js +17 -10
  43. package/build/Loading/style.js +25 -23
  44. package/build/Overlay/index.js +15 -31
  45. package/build/SafeArea/index.js +8 -5
  46. package/build/ScrollView/index.js +24 -21
  47. package/build/ScrollView/style.js +16 -14
  48. package/build/Toast/Toast.js +53 -17
  49. package/build/Toast/index.js +21 -14
  50. package/build/Toast/style.js +31 -30
  51. package/build/index.d.ts +2 -2
  52. package/build/index.js +102 -36
  53. package/build/utils/Countdown.js +7 -3
  54. package/build/utils/ago.js +10 -4
  55. package/build/utils/calendarTable.js +9 -3
  56. package/build/utils/createApp.d.ts +1 -2
  57. package/build/utils/createApp.js +35 -31
  58. package/build/utils/cssUtil.d.ts +0 -9
  59. package/build/utils/cssUtil.js +10 -43
  60. package/build/utils/defaultScroll.js +4 -1
  61. package/build/utils/dom.js +6 -3
  62. package/build/utils/is.js +6 -2
  63. package/build/utils/jsonp.js +4 -1
  64. package/build/utils/request.js +40 -27
  65. package/build/utils/tick.js +4 -1
  66. package/build/utils/uniqKey.js +4 -1
  67. package/build/utils/wait.js +8 -4
  68. package/package.json +1 -1
  69. package/test/src/city-select/index.jsx +21 -0
  70. package/test/src/dialog/index.module.css +1 -1
  71. package/test/src/index/index.jsx +1 -0
  72. package/test/vite.config.js +6 -2
  73. package/build/context.d.ts +0 -15
  74. package/build/context.js +0 -24
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,20 +8,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
11
- import { Wrapper } from './Wrapper';
12
- import { createPortalDOM } from '../utils/dom';
13
- import isPlainObject from 'lodash/isPlainObject';
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.showLoading = showLoading;
16
+ exports.showLoadingAtLeast = showLoadingAtLeast;
17
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
18
+ const Wrapper_1 = require("./Wrapper");
19
+ const dom_1 = require("../utils/dom");
20
+ const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
14
21
  /**
15
22
  * 显示loading
16
23
  * @param hint 提示文字
17
24
  * @param option
18
25
  * @returns
19
26
  */
20
- export function showLoading(hint, option) {
21
- const { mount, unmount } = createPortalDOM();
27
+ function showLoading(hint, option) {
28
+ const { mount, unmount } = (0, dom_1.createPortalDOM)();
22
29
  let props = { hint, status: 'show' };
23
- if (isPlainObject(option)) {
30
+ if ((0, isPlainObject_1.default)(option)) {
24
31
  delete option.status;
25
32
  props = Object.assign(Object.assign({}, props), option);
26
33
  }
@@ -28,10 +35,10 @@ export function showLoading(hint, option) {
28
35
  const closeLoading = () => __awaiter(this, void 0, void 0, function* () {
29
36
  props.status = 'hide';
30
37
  props.onHide = unmount;
31
- yield mount(_jsx(Wrapper, Object.assign({}, props)));
38
+ yield mount((0, jsx_runtime_1.jsx)(Wrapper_1.Wrapper, Object.assign({}, props)));
32
39
  });
33
40
  // 显示loading
34
- const mountShow = mount(_jsx(Wrapper, Object.assign({}, props)));
41
+ const mountShow = mount((0, jsx_runtime_1.jsx)(Wrapper_1.Wrapper, Object.assign({}, props)));
35
42
  // 关闭loading
36
43
  return () => __awaiter(this, void 0, void 0, function* () {
37
44
  yield mountShow;
@@ -45,7 +52,7 @@ export function showLoading(hint, option) {
45
52
  * @param option 各种可定制的选项
46
53
  * @returns
47
54
  */
48
- export function showLoadingAtLeast(atLeast = 300, hint, option) {
55
+ function showLoadingAtLeast(atLeast = 300, hint, option) {
49
56
  const closeLoading = showLoading(hint, option);
50
57
  // 记录开始展示的时间
51
58
  const start = Date.now();
@@ -1,6 +1,8 @@
1
- import { keyframes } from "@emotion/react";
2
- import { adaptive } from "../utils/cssUtil";
3
- export const LoadingShow = keyframes `
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.style = exports.LoadingHide = exports.LoadingShow = void 0;
4
+ const react_1 = require("@emotion/react");
5
+ exports.LoadingShow = (0, react_1.keyframes) `
4
6
  from {
5
7
  opacity: 0;
6
8
  }
@@ -8,7 +10,7 @@ export const LoadingShow = keyframes `
8
10
  opacity: 1;
9
11
  }
10
12
  `;
11
- export const LoadingHide = keyframes `
13
+ exports.LoadingHide = (0, react_1.keyframes) `
12
14
  from {
13
15
  opacity: 1;
14
16
  }
@@ -16,34 +18,34 @@ export const LoadingHide = keyframes `
16
18
  opacity: 0;
17
19
  }
18
20
  `;
19
- export const style = {
20
- boxCommon: adaptive({
21
+ exports.style = {
22
+ boxCommon: {
21
23
  backgroundColor: `rgba(0, 0, 0, .8)`,
22
- borderRadius: 16,
23
- }),
24
- box: adaptive({
25
- width: 160,
26
- height: 160,
27
- }),
24
+ borderRadius: '.16rem',
25
+ },
26
+ box: {
27
+ width: '1.6rem',
28
+ height: '1.6rem',
29
+ },
28
30
  boxShow: {
29
- animation: `${LoadingShow} 200ms`,
31
+ animation: `${exports.LoadingShow} 200ms`,
30
32
  },
31
33
  boxHide: {
32
- animation: `${LoadingHide} 200ms`,
34
+ animation: `${exports.LoadingHide} 200ms`,
33
35
  },
34
36
  boxWithExtra: [
35
- adaptive({ padding: 30 }),
37
+ { padding: '.3rem' },
36
38
  {
37
- "> div:first-of-type": adaptive({
38
- width: 48,
39
- height: 48,
40
- }),
39
+ "> div:first-of-type": {
40
+ width: '.48rem',
41
+ height: '.48rem',
42
+ },
41
43
  },
42
44
  ],
43
- hint: adaptive({
45
+ hint: {
44
46
  color: "#f5f5f5dd",
45
47
  whiteSpace: "nowrap",
46
- fontSize: 28,
47
- marginLeft: 20,
48
- }),
48
+ fontSize: '.28rem',
49
+ marginLeft: '.2rem',
50
+ },
49
51
  };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __rest = (this && this.__rest) || function (s, e) {
2
3
  var t = {};
3
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -9,21 +10,20 @@ var __rest = (this && this.__rest) || function (s, e) {
9
10
  }
10
11
  return t;
11
12
  };
12
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
13
- import { useLayoutEffect, useMemo, useState } from "react";
14
- import { createPortal } from "react-dom";
15
- import { getContextValue } from "../context";
16
- import { useWindowResize } from "../Effect/useWindowResize";
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Overlay = Overlay;
15
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
16
+ const react_1 = require("react");
17
+ const react_dom_1 = require("react-dom");
17
18
  /**
18
19
  * 覆盖层,可以作为通用遮罩
19
20
  * @param props
20
21
  * @returns
21
22
  */
22
- export function Overlay(props) {
23
+ function Overlay(props) {
23
24
  const { children, outside = false, centerContent = true, fullScreen = true, maskColor = "rgba(0, 0, 0, .6)" } = props, extra = __rest(props, ["children", "outside", "centerContent", "fullScreen", "maskColor"]);
24
- const [mount, setMount] = useState(null);
25
- const [innerWidth, setInnerWidth] = useState(window.innerWidth);
26
- useLayoutEffect(() => {
25
+ const [mount, setMount] = (0, react_1.useState)(null);
26
+ (0, react_1.useLayoutEffect)(() => {
27
27
  if (outside) {
28
28
  const div = document.createElement("div");
29
29
  document.body.appendChild(div);
@@ -33,34 +33,18 @@ export function Overlay(props) {
33
33
  };
34
34
  }
35
35
  }, [outside]);
36
- // 页面大小变化时,innerWidth 也会更新
37
- useWindowResize(() => {
38
- setInnerWidth(window.innerWidth);
39
- });
40
- const ctx = getContextValue();
41
36
  // 使用 useMemo 缓存样式计算,避免每次渲染都重新计算
42
- const style = useMemo(() => {
37
+ const style = (0, react_1.useMemo)(() => {
43
38
  const styles = [];
44
39
  // 如果是全屏,设置全屏样式
45
40
  if (fullScreen) {
46
- // 获取宽度
47
- let width = innerWidth;
48
- if (width >= ctx.maxDocWidth) {
49
- width = ctx.maxDocWidth;
50
- }
51
- else if (width <= ctx.minDocWidth) {
52
- width = ctx.minDocWidth;
53
- }
54
41
  styles.push({
55
42
  zIndex: 9999,
56
43
  position: "fixed",
57
44
  top: 0,
58
- left: "50%",
59
- marginLeft: `-${width / 2}px`,
60
- width: `${width}px`,
45
+ left: 0,
46
+ width: "100%",
61
47
  height: "100%",
62
- maxWidth: `${ctx.maxDocWidth}px`,
63
- minWidth: `${ctx.minDocWidth}px`,
64
48
  backgroundColor: maskColor,
65
49
  });
66
50
  }
@@ -73,8 +57,8 @@ export function Overlay(props) {
73
57
  });
74
58
  }
75
59
  return styles;
76
- }, [fullScreen, innerWidth, ctx.maxDocWidth, ctx.minDocWidth, maskColor, centerContent]);
77
- const content = (_jsx("div", Object.assign({ css: style }, extra, { children: children })));
60
+ }, [fullScreen, maskColor, centerContent]);
61
+ const content = ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: style }, extra, { children: children })));
78
62
  /**
79
63
  * 如果是挂载到当前位置,直接返回
80
64
  */
@@ -90,5 +74,5 @@ export function Overlay(props) {
90
74
  /**
91
75
  * 挂载到外部,且挂载点已经准备好
92
76
  */
93
- return createPortal(content, mount);
77
+ return (0, react_dom_1.createPortal)(content, mount);
94
78
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __rest = (this && this.__rest) || function (s, e) {
2
3
  var t = {};
3
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -9,11 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
9
10
  }
10
11
  return t;
11
12
  };
12
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
13
- import { useViewport } from "../Effect/useViewport";
14
- export function SafeArea(props) {
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.SafeArea = SafeArea;
15
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
16
+ const useViewport_1 = require("../Effect/useViewport");
17
+ function SafeArea(props) {
15
18
  const { children, type = "bottom" } = props, extra = __rest(props, ["children", "type"]);
16
- useViewport({ viewportFit: "cover" });
19
+ (0, useViewport_1.useViewport)({ viewportFit: "cover" });
17
20
  let boxCss = {};
18
21
  if (type === "top") {
19
22
  boxCss = {
@@ -31,5 +34,5 @@ export function SafeArea(props) {
31
34
  ],
32
35
  };
33
36
  }
34
- return (_jsx("div", Object.assign({ css: boxCss }, extra, { children: children })));
37
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: boxCss }, extra, { children: children })));
35
38
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __rest = (this && this.__rest) || function (s, e) {
2
3
  var t = {};
3
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -9,12 +10,14 @@ var __rest = (this && this.__rest) || function (s, e) {
9
10
  }
10
11
  return t;
11
12
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
13
- import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
14
- import { Indicator } from "../Indicator";
15
- import { RowCenter } from "../Flex/Row";
16
- import { style } from "./style";
17
- export function ScrollView(props) {
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ScrollView = ScrollView;
15
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
16
+ const react_1 = require("react");
17
+ const Indicator_1 = require("../Indicator");
18
+ const Row_1 = require("../Flex/Row");
19
+ const style_1 = require("./style");
20
+ function ScrollView(props) {
18
21
  const { children, height, reachTopThreshold = 50, onReachTop, reachBottomThreshold = 50, onReachBottom, showLoading = true, loadingContent, onScroll, scrollThrottle = 16, containerStyle, wrapperStyle, loadingStyle } = props, attrs = __rest(props, ["children", "height", "reachTopThreshold", "onReachTop", "reachBottomThreshold", "onReachBottom", "showLoading", "loadingContent", "onScroll", "scrollThrottle", "containerStyle", "wrapperStyle", "loadingStyle"]);
19
22
  // 容器高度
20
23
  const heightStyle = {};
@@ -22,17 +25,17 @@ export function ScrollView(props) {
22
25
  heightStyle.height = height;
23
26
  }
24
27
  // 滚动容器
25
- const container = useRef(null);
28
+ const container = (0, react_1.useRef)(null);
26
29
  // 当前滚动到顶部的距离
27
- const lastScrollTop = useRef(0);
30
+ const lastScrollTop = (0, react_1.useRef)(0);
28
31
  // 防止重复触发的标记
29
- const hasReachedTop = useRef(false);
30
- const hasReachedBottom = useRef(false);
32
+ const hasReachedTop = (0, react_1.useRef)(false);
33
+ const hasReachedBottom = (0, react_1.useRef)(false);
31
34
  // 节流控制
32
- const throttleTimer = useRef(undefined);
33
- const lastCallTime = useRef(0);
35
+ const throttleTimer = (0, react_1.useRef)(undefined);
36
+ const lastCallTime = (0, react_1.useRef)(0);
34
37
  // 使用 ref 保存所有滚动处理需要的 props,彻底消除陈旧闭包
35
- const propsRef = useRef({
38
+ const propsRef = (0, react_1.useRef)({
36
39
  onScroll,
37
40
  onReachTop,
38
41
  onReachBottom,
@@ -47,16 +50,16 @@ export function ScrollView(props) {
47
50
  reachBottomThreshold,
48
51
  };
49
52
  // container 是否有滚动条
50
- const [hasScrollBar, setHasScrollBar] = useState(false);
53
+ const [hasScrollBar, setHasScrollBar] = (0, react_1.useState)(false);
51
54
  // 检查是否有滚动条
52
- const checkScrollBar = useCallback(() => {
55
+ const checkScrollBar = (0, react_1.useCallback)(() => {
53
56
  if (container.current) {
54
57
  const hasScroll = container.current.scrollHeight > container.current.clientHeight;
55
58
  setHasScrollBar(hasScroll);
56
59
  }
57
60
  }, []);
58
61
  // 使用 ResizeObserver 监听内容高度变化
59
- useLayoutEffect(() => {
62
+ (0, react_1.useLayoutEffect)(() => {
60
63
  const containerEl = container.current;
61
64
  if (!containerEl)
62
65
  return;
@@ -77,7 +80,7 @@ export function ScrollView(props) {
77
80
  }, [checkScrollBar]);
78
81
  // 核心滚动处理逻辑
79
82
  // 所有外部值从 ref 读取,deps 为空,引用永远稳定,不存在闭包过期问题
80
- const processScroll = useCallback((rawEvent) => {
83
+ const processScroll = (0, react_1.useCallback)((rawEvent) => {
81
84
  const box = container.current;
82
85
  if (!box)
83
86
  return;
@@ -129,7 +132,7 @@ export function ScrollView(props) {
129
132
  lastScrollTop.current = scrollTop;
130
133
  }, []);
131
134
  // 节流滚动回调(leading + trailing)
132
- const scrollCallback = useCallback((rawEvent) => {
135
+ const scrollCallback = (0, react_1.useCallback)((rawEvent) => {
133
136
  // 不节流时直接执行
134
137
  if (scrollThrottle <= 0) {
135
138
  processScroll(rawEvent);
@@ -161,7 +164,7 @@ export function ScrollView(props) {
161
164
  }
162
165
  }, [scrollThrottle, processScroll]);
163
166
  // 清理节流定时器
164
- useEffect(() => {
167
+ (0, react_1.useEffect)(() => {
165
168
  return () => {
166
169
  if (throttleTimer.current !== undefined) {
167
170
  clearTimeout(throttleTimer.current);
@@ -172,11 +175,11 @@ export function ScrollView(props) {
172
175
  let showLoadingContent = null;
173
176
  if (showLoading) {
174
177
  if (!loadingContent) {
175
- showLoadingContent = (_jsxs(RowCenter, { css: [style.loading, loadingStyle], children: [_jsx(Indicator, { barColor: "#333", barCount: 12 }), _jsx("p", { children: "\u6570\u636E\u52A0\u8F7D\u4E2D..." })] }));
178
+ showLoadingContent = ((0, jsx_runtime_1.jsxs)(Row_1.RowCenter, { css: [style_1.style.loading, loadingStyle], children: [(0, jsx_runtime_1.jsx)(Indicator_1.Indicator, { barColor: "#333", barCount: 12 }), (0, jsx_runtime_1.jsx)("p", { children: "\u6570\u636E\u52A0\u8F7D\u4E2D..." })] }));
176
179
  }
177
180
  else {
178
181
  showLoadingContent = loadingContent;
179
182
  }
180
183
  }
181
- return (_jsxs("div", Object.assign({ css: [style.container, heightStyle, containerStyle], onScroll: scrollCallback, ref: container }, attrs, { children: [_jsx("div", { css: wrapperStyle, children: children }), hasScrollBar && showLoadingContent] })));
184
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: [style_1.style.container, heightStyle, containerStyle], onScroll: scrollCallback, ref: container }, attrs, { children: [(0, jsx_runtime_1.jsx)("div", { css: wrapperStyle, children: children }), hasScrollBar && showLoadingContent] })));
182
185
  }
@@ -1,29 +1,31 @@
1
- import { adaptive } from "../utils/cssUtil";
2
- export const style = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.style = void 0;
4
+ exports.style = {
3
5
  container: {
4
6
  overflow: "auto",
5
7
  height: "100%",
6
8
  WebkitOverflowScrolling: "touch",
7
9
  },
8
10
  loading: [
9
- adaptive({
10
- paddingTop: 15,
11
- paddingBottom: 15,
12
- }),
13
11
  {
14
- "> div": adaptive({
15
- width: 30,
16
- height: 30,
17
- }),
12
+ paddingTop: '.15rem',
13
+ paddingBottom: '.15rem',
14
+ },
15
+ {
16
+ "> div": {
17
+ width: '.3rem',
18
+ height: '.3rem',
19
+ },
18
20
  "> p": [
19
21
  {
20
22
  color: "#666",
21
23
  lineHeight: 1,
22
24
  },
23
- adaptive({
24
- marginLeft: 16,
25
- fontSize: 24,
26
- }),
25
+ {
26
+ marginLeft: '.16rem',
27
+ fontSize: '.24rem',
28
+ },
27
29
  ],
28
30
  },
29
31
  ],
@@ -1,3 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
1
35
  var __rest = (this && this.__rest) || function (s, e) {
2
36
  var t = {};
3
37
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -9,17 +43,19 @@ var __rest = (this && this.__rest) || function (s, e) {
9
43
  }
10
44
  return t;
11
45
  };
12
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
13
- import React, { useState, useEffect } from "react";
14
- import { style, getAnimation } from "./style";
15
- export function Toast(props) {
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.Toast = Toast;
48
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
49
+ const react_1 = __importStar(require("react"));
50
+ const style_1 = require("./style");
51
+ function Toast(props) {
16
52
  const { content = "", position = "middle", duration = 2000, radius = 16, offsetTop = 50, offsetBottom = 50, onHide = () => undefined, containerStyle, contentStyle } = props, attributes = __rest(props, ["content", "position", "duration", "radius", "offsetTop", "offsetBottom", "onHide", "containerStyle", "contentStyle"]);
17
53
  // 初始化显示的动画
18
- const getResult = getAnimation(position, "show");
19
- const [animation, setAnimation] = useState(getResult.animation);
20
- useEffect(() => {
54
+ const getResult = (0, style_1.getAnimation)(position, "show");
55
+ const [animation, setAnimation] = (0, react_1.useState)(getResult.animation);
56
+ (0, react_1.useEffect)(() => {
21
57
  const timer = window.setTimeout(() => {
22
- const { animation } = getAnimation(position, "hide");
58
+ const { animation } = (0, style_1.getAnimation)(position, "hide");
23
59
  setAnimation(animation);
24
60
  }, duration);
25
61
  return () => {
@@ -27,29 +63,29 @@ export function Toast(props) {
27
63
  };
28
64
  }, [position, duration]);
29
65
  let showContent;
30
- const middleStyle = position === "middle" ? style.contentMiddle : undefined;
31
- if (React.isValidElement(content)) {
32
- showContent = _jsx("div", { css: [middleStyle, contentStyle], children: content });
66
+ const middleStyle = position === "middle" ? style_1.style.contentMiddle : undefined;
67
+ if (react_1.default.isValidElement(content)) {
68
+ showContent = (0, jsx_runtime_1.jsx)("div", { css: [middleStyle, contentStyle], children: content });
33
69
  }
34
70
  else {
35
- showContent = (_jsx("p", { css: [style.content(radius), middleStyle, contentStyle], children: content }));
71
+ showContent = ((0, jsx_runtime_1.jsx)("p", { css: [style_1.style.content(radius), middleStyle, contentStyle], children: content }));
36
72
  }
37
73
  // toast消失动画结束触发
38
74
  const animationEnd = (event) => {
39
- const { keyframes } = getAnimation(position, "hide");
75
+ const { keyframes } = (0, style_1.getAnimation)(position, "hide");
40
76
  if (event.animationName === keyframes.name) {
41
77
  onHide === null || onHide === void 0 ? void 0 : onHide();
42
78
  }
43
79
  };
44
80
  let positionStyle;
45
81
  if (position === "top") {
46
- positionStyle = style.top(offsetTop);
82
+ positionStyle = style_1.style.top(offsetTop);
47
83
  }
48
84
  else if (position === "bottom") {
49
- positionStyle = style.bottom(offsetBottom);
85
+ positionStyle = style_1.style.bottom(offsetBottom);
50
86
  }
51
87
  else {
52
- positionStyle = style.middle;
88
+ positionStyle = style_1.style.middle;
53
89
  }
54
- return (_jsx("div", Object.assign({ css: [style.container(), positionStyle, animation, containerStyle], onAnimationEnd: animationEnd }, attributes, { children: showContent })));
90
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: [style_1.style.container(), positionStyle, animation, containerStyle], onAnimationEnd: animationEnd }, attributes, { children: showContent })));
55
91
  }
@@ -1,39 +1,46 @@
1
- import { createElement as _createElement } from "@emotion/react";
2
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
3
- import React from 'react';
4
- import { uniqKey } from '../utils/uniqKey';
5
- import { createPortalDOM } from '../utils/dom';
6
- import { Toast as ToastComponent } from './Toast';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.showToast = showToast;
7
+ exports.showUniqToast = showUniqToast;
8
+ const react_1 = require("@emotion/react");
9
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
10
+ const react_2 = __importDefault(require("react"));
11
+ const uniqKey_1 = require("../utils/uniqKey");
12
+ const dom_1 = require("../utils/dom");
13
+ const Toast_1 = require("./Toast");
7
14
  /**
8
15
  * 显示一个全局的轻提示,这个toast不是唯一的
9
16
  * @param option 可以是一个字符串,也可以是一个React组件
10
17
  */
11
- export function showToast(option) {
12
- const { mount, unmount } = createPortalDOM();
18
+ function showToast(option) {
19
+ const { mount, unmount } = (0, dom_1.createPortalDOM)();
13
20
  let props = {};
14
- if (React.isValidElement(option) || typeof option !== 'object') {
21
+ if (react_2.default.isValidElement(option) || typeof option !== 'object') {
15
22
  props.content = option;
16
23
  }
17
24
  else {
18
25
  props = option;
19
26
  }
20
27
  props.onHide = unmount;
21
- mount(_jsx(ToastComponent, Object.assign({}, props)));
28
+ mount((0, jsx_runtime_1.jsx)(Toast_1.Toast, Object.assign({}, props)));
22
29
  }
23
30
  /**
24
31
  * 生成一个全局唯一的Toast
25
32
  * @param option
26
33
  */
27
34
  let portalDOM = null;
28
- export function showUniqToast(option) {
35
+ function showUniqToast(option) {
29
36
  // 先清理上一个 Toast 的 DOM 容器,避免快速连续调用时旧容器泄漏
30
37
  if (portalDOM) {
31
38
  portalDOM.unmount();
32
39
  portalDOM = null;
33
40
  }
34
- portalDOM = createPortalDOM();
41
+ portalDOM = (0, dom_1.createPortalDOM)();
35
42
  let props = {};
36
- if (React.isValidElement(option) || typeof option !== 'object') {
43
+ if (react_2.default.isValidElement(option) || typeof option !== 'object') {
37
44
  props.content = option;
38
45
  }
39
46
  else {
@@ -44,5 +51,5 @@ export function showUniqToast(option) {
44
51
  portalDOM = null;
45
52
  };
46
53
  props.onHide = onHide;
47
- portalDOM.mount(_createElement(ToastComponent, Object.assign({}, props, { key: uniqKey() })));
54
+ portalDOM.mount((0, react_1.createElement)(Toast_1.Toast, Object.assign({}, props, { key: (0, uniqKey_1.uniqKey)() })));
48
55
  }