index.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { __awaiter, __generator } from "tslib";
  2. import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
  3. import { PopoverDefaultProps } from './props';
  4. import mixinValue from '../mixins/value';
  5. import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
  6. import { getSystemInfo } from '../_util/jsapi/get-system-info';
  7. import { getPopoverStyle } from './utils';
  8. Component(PopoverDefaultProps, {
  9. getInstance: function () {
  10. if (this.$id) {
  11. return my;
  12. }
  13. return this;
  14. },
  15. updatePopover: function () {
  16. return __awaiter(this, void 0, void 0, function () {
  17. var _a, placement, autoAdjustOverflow, _b, containerRect, childrenRect, contentRect, systemInfo, _c, popoverContentStyle, adjustedPlacement;
  18. return __generator(this, function (_d) {
  19. switch (_d.label) {
  20. case 0:
  21. _a = getValueFromProps(this, [
  22. 'placement',
  23. 'autoAdjustOverflow',
  24. ]), placement = _a[0], autoAdjustOverflow = _a[1];
  25. return [4 /*yield*/, Promise.all([
  26. getInstanceBoundingClientRect(this.getInstance(), "#ant-popover-children".concat(this.$id ? "-".concat(this.$id) : '')),
  27. getInstanceBoundingClientRect(this.getInstance(), this.$id
  28. ? "#ant-popover-children-".concat(this.$id, " > *")
  29. : "#ant-popover-children-container"),
  30. getInstanceBoundingClientRect(this.getInstance(), this.$id
  31. ? "#ant-popover-content-".concat(this.$id)
  32. : '#ant-popover-content'),
  33. getSystemInfo(),
  34. ])];
  35. case 1:
  36. _b = _d.sent(), containerRect = _b[0], childrenRect = _b[1], contentRect = _b[2], systemInfo = _b[3];
  37. _c = getPopoverStyle(placement, autoAdjustOverflow, {
  38. containerRect: containerRect,
  39. childrenRect: childrenRect,
  40. contentRect: contentRect,
  41. systemInfo: systemInfo,
  42. }), popoverContentStyle = _c.popoverContentStyle, adjustedPlacement = _c.adjustedPlacement;
  43. this.setData({
  44. popoverContentStyle: popoverContentStyle,
  45. adjustedPlacement: adjustedPlacement,
  46. });
  47. return [2 /*return*/];
  48. }
  49. });
  50. });
  51. },
  52. onVisibleChange: function (e) {
  53. if (!this.getValue() &&
  54. e.target.id &&
  55. e.target.id.indexOf('ant-popover-') === 0) {
  56. return;
  57. }
  58. var value = !this.getValue();
  59. if (!this.isControlled()) {
  60. this.update(value);
  61. }
  62. triggerEvent(this, 'visibleChange', value, e);
  63. },
  64. }, {
  65. adjustedPlacement: '',
  66. popoverContentStyle: '',
  67. }, [
  68. mixinValue({
  69. valueKey: 'visible',
  70. defaultValueKey: 'defaultVisible',
  71. transformValue: function (value) {
  72. if (value) {
  73. this.updatePopover();
  74. }
  75. else {
  76. this.setData({
  77. adjustedPlacement: '',
  78. });
  79. }
  80. return {
  81. needUpdate: true,
  82. value: value,
  83. };
  84. },
  85. }),
  86. ], {
  87. didUpdate: function (prevProps) {
  88. var _a = getValueFromProps(this, [
  89. 'placement',
  90. 'autoAdjustOverflow',
  91. ]), placement = _a[0], autoAdjustOverflow = _a[1];
  92. if ((prevProps.placement !== placement ||
  93. prevProps.autoAdjustOverflow !== autoAdjustOverflow) &&
  94. this.getValue()) {
  95. this.updatePopover();
  96. }
  97. },
  98. });