context.js 591 B

12345678910111213141516171819
  1. import { computed, inject, provide } from 'vue';
  2. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  3. function noop() {}
  4. export const AnchorContextKey = Symbol('anchorContextKey');
  5. const useProvideAnchor = state => {
  6. provide(AnchorContextKey, state);
  7. };
  8. const useInjectAnchor = () => {
  9. return inject(AnchorContextKey, {
  10. registerLink: noop,
  11. unregisterLink: noop,
  12. scrollTo: noop,
  13. activeLink: computed(() => ''),
  14. handleClick: noop,
  15. direction: computed(() => 'vertical')
  16. });
  17. };
  18. export { useInjectAnchor, useProvideAnchor };
  19. export default useProvideAnchor;