Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Vue and Typescript? #73

Open
afnan opened this issue Jun 30, 2022 · 2 comments
Open

Support for Vue and Typescript? #73

afnan opened this issue Jun 30, 2022 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@afnan
Copy link

afnan commented Jun 30, 2022

Do you have any plans to support Vue3 and TS?

@rsimon
Copy link
Member

rsimon commented Jul 24, 2022

I know that some people have used Annotorious with Vue. RecogitoJS's API is almost identical, so it should be fairly straightforward to wrap. I'm not planning an offical wrapper which would expose RecogitoJS as a component though. (I'd certainly love to see it - but, as far as I'm concerned, not enough bandwidth to work on it I'm afraid.)

Likewise for TypeScript: I'd love to see type declarations! Currently can't take care of it myself, but would welcome a Pull Request, or a separate package on definitelytyped. We've been discussing the same thing for Annotorious here: annotorious/annotorious#204

@rsimon rsimon added the help wanted Extra attention is needed label Sep 3, 2022
@Revadike
Copy link

Revadike commented Jun 17, 2024

I wrote this wrapper for nuxt.js (vue3):

<!-- eslint-disable vue/no-v-html -->
<script setup>
  import { Recogito } from '@recogito/recogito-js'
  import '@recogito/recogito-js/dist/recogito.min.css'

  const content = ref(null)
  const props = defineProps({
    text: {
      type: String,
      required: true
    },
    annotations: {
      type: Array,
      default: () => []
    }
  })

  const emit = defineEmits(['update:annotations'])

  const initRecogito = () => {
    const r = new Recogito({
      content: content.value,
      locale: 'nl-NL',
      widgets: [{ widget: 'COMMENT' }]
    })

    const { user } = useAuthStore()
    r.setAuthInfo({
      id: user.uid,
      displayName: user.displayName
    })

    watch(() => props.annotations, (newAnnotations) => {
      r.setAnnotations(newAnnotations)
    }, { immediate: true })

    r.on('createAnnotation', () => {
      emit('update:annotations', r.getAnnotations())
    })

    r.on('updateAnnotation', () => {
      emit('update:annotations', r.getAnnotations())
    })

    r.on('deleteAnnotation', () => {
      emit('update:annotations', r.getAnnotations())
    })
  }

  onMounted(initRecogito)
</script>

<template>
  <div
    v-if="text"
    ref="content"
    v-html="text"
  />
</template>

Feel free to adapt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants