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

fix: dynamically load pdf component #265

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions ui/src/core_components/embed/CorePDF.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ export default {
</script>

<script setup lang="ts">
import { inject, ref, watch, computed } from "vue";
import { VuePDF, usePDF } from "@tato30/vue-pdf";
import { inject, ref, watch, computed, onMounted } from "vue";
import injectionKeys from "../../injectionKeys";
import "@tato30/vue-pdf/style.css";

type MatchType = { str: string; page: number; index: number };

const fields = inject(injectionKeys.evaluatedFields);

const { pdf, pages } = usePDF(fields.source);
let pdf, pages, VuePDF;

const highlightText = computed(() => {
return fields.highlights.value
Expand All @@ -136,6 +135,14 @@ const loading = ref(false);
const pagesLoaded = ref(0);
const highlightsList = ref([]);

onMounted(async () => {
const VuePDFLib = await import("@tato30/vue-pdf");
VuePDF = VuePDFLib.VuePDF;
const usePDF = VuePDFLib.usePDF;
({ pdf, pages } = usePDF(fields.source));
reload();
});

const reload = () => {
loading.value = true;
pagesLoaded.value = 0;
Expand Down Expand Up @@ -218,6 +225,7 @@ const gotoHighlight = (matchIdx: number) => {
return;
}
const match = matches.value[matchIdx - 1];
if (!match) return;
const matchEls = rootEl.value.querySelectorAll(
`div[page='${match.page}'] span.highlight`,
);
Expand Down
Loading