index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { __awaiter, __generator } from "tslib";
  2. import { useMemo, useState } from 'functional-mini/compat';
  3. import { useComponent, useEvent } from 'functional-mini/component';
  4. import { mountComponent } from '../_util/component';
  5. import { useEvent as useStableCallback } from '../_util/hooks/useEvent';
  6. import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
  7. import { PaginationDefaultProps } from './props';
  8. var Pagination = function () {
  9. var componentInstance = useComponent();
  10. var _a = useState(0), pageDeg = _a[0], setPageDeg = _a[1];
  11. function getInstance() {
  12. if (componentInstance.$id) {
  13. return my;
  14. }
  15. return componentInstance;
  16. }
  17. var clacWidth = useStableCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
  18. var instance, rect;
  19. return __generator(this, function (_a) {
  20. switch (_a.label) {
  21. case 0:
  22. instance = getInstance();
  23. return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "#ant-pageInfinite-".concat(instance.$id ? "-".concat(instance.$id) : ''))];
  24. case 1:
  25. rect = _a.sent();
  26. if (rect) {
  27. return [2 /*return*/, rect.width];
  28. }
  29. return [2 /*return*/, 0];
  30. }
  31. });
  32. }); });
  33. useEvent('onScroll', function (e) { return __awaiter(void 0, void 0, void 0, function () {
  34. var _a, scrollLeft, scrollWidth, viewWidth;
  35. return __generator(this, function (_b) {
  36. switch (_b.label) {
  37. case 0:
  38. _a = e.detail, scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth;
  39. return [4 /*yield*/, clacWidth()];
  40. case 1:
  41. viewWidth = _b.sent();
  42. if (viewWidth) {
  43. setPageDeg(Math.ceil((scrollLeft / (scrollWidth - viewWidth)) * 100));
  44. }
  45. return [2 /*return*/];
  46. }
  47. });
  48. }); });
  49. var supportSjs = useMemo(function () {
  50. if (typeof my === 'undefined') {
  51. return true;
  52. }
  53. return my.canIUse('sjs.event');
  54. }, []);
  55. return {
  56. pageDeg: pageDeg,
  57. supportSjs: supportSjs,
  58. };
  59. };
  60. mountComponent(Pagination, PaginationDefaultProps);