useInstanceBoundingClientRect.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { __awaiter, __generator } from "tslib";
  2. import { useComponent } from 'functional-mini/component';
  3. import { getInstanceBoundingClientRect } from '../jsapi/get-instance-bounding-client-rect';
  4. export var useInstanceBoundingClientRect = function () {
  5. var instance = useComponent();
  6. function getInstance() {
  7. if (instance.$id) {
  8. return my;
  9. }
  10. return instance;
  11. }
  12. function getBoundingClientRectWithId(prefix) {
  13. return __awaiter(this, void 0, void 0, function () {
  14. return __generator(this, function (_a) {
  15. switch (_a.label) {
  16. case 0: return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "".concat(prefix).concat(instance.$id ? "-".concat(instance.$id) : ''))];
  17. case 1: return [2 /*return*/, _a.sent()];
  18. }
  19. });
  20. });
  21. }
  22. function getBoundingClientRect(query) {
  23. return __awaiter(this, void 0, void 0, function () {
  24. return __generator(this, function (_a) {
  25. switch (_a.label) {
  26. case 0: return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), query)];
  27. case 1: return [2 /*return*/, _a.sent()];
  28. }
  29. });
  30. });
  31. }
  32. function getBoundingClientRectWithBuilder(builder) {
  33. return __awaiter(this, void 0, void 0, function () {
  34. return __generator(this, function (_a) {
  35. switch (_a.label) {
  36. case 0: return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), builder(instance.$id ? "-".concat(instance.$id) : ''))];
  37. case 1: return [2 /*return*/, _a.sent()];
  38. }
  39. });
  40. });
  41. }
  42. return {
  43. getBoundingClientRect: getBoundingClientRect,
  44. getBoundingClientRectWithId: getBoundingClientRectWithId,
  45. getBoundingClientRectWithBuilder: getBoundingClientRectWithBuilder,
  46. };
  47. };