You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

1 month ago
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var core = require('@vueuse/core');
  5. var lodashUnified = require('lodash-unified');
  6. var dom = require('@floating-ui/dom');
  7. var objects = require('../../utils/objects.js');
  8. var runtime = require('../../utils/vue/props/runtime.js');
  9. const useFloatingProps = runtime.buildProps({});
  10. const unrefReference = (elRef) => {
  11. if (!core.isClient)
  12. return;
  13. if (!elRef)
  14. return elRef;
  15. const unrefEl = core.unrefElement(elRef);
  16. if (unrefEl)
  17. return unrefEl;
  18. return vue.isRef(elRef) ? unrefEl : elRef;
  19. };
  20. const getPositionDataWithUnit = (record, key) => {
  21. const value = record == null ? void 0 : record[key];
  22. return lodashUnified.isNil(value) ? "" : `${value}px`;
  23. };
  24. const useFloating = ({
  25. middleware,
  26. placement,
  27. strategy
  28. }) => {
  29. const referenceRef = vue.ref();
  30. const contentRef = vue.ref();
  31. const x = vue.ref();
  32. const y = vue.ref();
  33. const middlewareData = vue.ref({});
  34. const states = {
  35. x,
  36. y,
  37. placement,
  38. strategy,
  39. middlewareData
  40. };
  41. const update = async () => {
  42. if (!core.isClient)
  43. return;
  44. const referenceEl = unrefReference(referenceRef);
  45. const contentEl = core.unrefElement(contentRef);
  46. if (!referenceEl || !contentEl)
  47. return;
  48. const data = await dom.computePosition(referenceEl, contentEl, {
  49. placement: vue.unref(placement),
  50. strategy: vue.unref(strategy),
  51. middleware: vue.unref(middleware)
  52. });
  53. objects.keysOf(states).forEach((key) => {
  54. states[key].value = data[key];
  55. });
  56. };
  57. vue.onMounted(() => {
  58. vue.watchEffect(() => {
  59. update();
  60. });
  61. });
  62. return {
  63. ...states,
  64. update,
  65. referenceRef,
  66. contentRef
  67. };
  68. };
  69. const arrowMiddleware = ({
  70. arrowRef,
  71. padding
  72. }) => {
  73. return {
  74. name: "arrow",
  75. options: {
  76. element: arrowRef,
  77. padding
  78. },
  79. fn(args) {
  80. const arrowEl = vue.unref(arrowRef);
  81. if (!arrowEl)
  82. return {};
  83. return dom.arrow({
  84. element: arrowEl,
  85. padding
  86. }).fn(args);
  87. }
  88. };
  89. };
  90. exports.arrowMiddleware = arrowMiddleware;
  91. exports.getPositionDataWithUnit = getPositionDataWithUnit;
  92. exports.useFloating = useFloating;
  93. exports.useFloatingProps = useFloatingProps;
  94. //# sourceMappingURL=index.js.map