-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #81, resolves #52 --------- Co-authored-by: Robin Kaggl <[email protected]>
- Loading branch information
Showing
22 changed files
with
835 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<script lang="ts" setup> | ||
import { | ||
Combobox, | ||
ComboboxButton, | ||
ComboboxInput, | ||
ComboboxOption, | ||
ComboboxOptions, | ||
} from "@headlessui/vue"; | ||
import { useQuery } from "@tanstack/vue-query"; | ||
import { Search } from "lucide-vue-next"; | ||
import type { ModelRef } from "vue"; | ||
import type { HierarchyNode } from "@/lib/types"; | ||
const query = ref( | ||
useQuery({ | ||
queryKey: ["autocomplete"], | ||
queryFn: async () => { | ||
const data = await fetch( | ||
"https://viecpro.acdh-dev.oeaw.ac.at/visualisations/entityautocomplete/", | ||
); | ||
const ret = await data.json(); | ||
return ret.context as Array<HierarchyNode>; | ||
}, | ||
}), | ||
); | ||
const selection: ModelRef<HierarchyNode | null> = defineModel({ | ||
default: null, | ||
}); | ||
const input = ref(""); | ||
const filtered = computed(() => { | ||
if (!query.value.data) return null; | ||
return input.value === "" | ||
? query.value.data | ||
: query.value.data.filter((entity) => { | ||
return entity.label.toLowerCase().includes(input.value.toLowerCase()); | ||
}); | ||
}); | ||
defineEmits(["change", "input"]); | ||
</script> | ||
|
||
<template> | ||
<Combobox | ||
v-model="selection" | ||
as="div" | ||
class="relative" | ||
@update:model-value="$emit('change', selection)" | ||
> | ||
<div | ||
v-if="!query.isFetching" | ||
class="relative m-2 flex cursor-default overflow-hidden rounded border bg-white text-left shadow-lg" | ||
> | ||
<ComboboxInput | ||
class="w-96 truncate p-2" | ||
:display-value="(entity) => (entity as HierarchyNode)?.label" | ||
@change=" | ||
$emit('input', $event.target.value); | ||
input = $event.target.value; | ||
" | ||
/> | ||
<ComboboxButton class="inset-y-0 right-0 flex items-center px-3 text-gray-500"> | ||
<Search class="h-5 w-5" /> | ||
</ComboboxButton> | ||
</div> | ||
<div v-else class="m-2 h-11 w-96 animate-pulse rounded bg-gray-300 shadow-lg" /> | ||
<MenuTransition> | ||
<ComboboxOptions | ||
v-if="filtered" | ||
as="div" | ||
class="absolute ml-2 flex flex-col divide-y overflow-auto rounded border bg-white text-base shadow" | ||
> | ||
<ComboboxOption | ||
v-for="entity in filtered.slice(0, 10)" | ||
:key="entity.pk" | ||
:value="entity" | ||
as="div" | ||
class="cursor-pointer p-2 ui-active:bg-primary-300" | ||
> | ||
{{ entity.label }} | ||
</ComboboxOption> | ||
</ComboboxOptions> | ||
</MenuTransition> | ||
</Combobox> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script lang="ts" setup> | ||
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "@headlessui/vue"; | ||
import { ChevronsUpDown } from "lucide-vue-next"; | ||
import type { ModelRef } from "vue"; | ||
const model: ModelRef<{ label: string; value: string } | null> = defineModel({ | ||
default: null, | ||
}); | ||
defineProps<{ | ||
items: Array<{ label: string; value: string }>; | ||
}>(); | ||
defineEmits(["change"]); | ||
</script> | ||
|
||
<template> | ||
<Listbox | ||
v-model="model" | ||
as="div" | ||
class="relative" | ||
@update:model-value="(to) => $emit('change', to)" | ||
> | ||
<ListboxButton | ||
class="flex h-11 w-full items-center justify-between gap-2 rounded border bg-white p-2 shadow-lg" | ||
as="button" | ||
> | ||
<span>{{ model?.label || model }}</span> | ||
<ChevronsUpDown class="h-5 w-5 text-gray-500" /> | ||
</ListboxButton> | ||
<MenuTransition> | ||
<ListboxOptions | ||
v-if="items.length != 0" | ||
as="div" | ||
class="absolute mt-2 flex w-full flex-col divide-y rounded border bg-white shadow-xl" | ||
> | ||
<ListboxOption | ||
v-for="item in items" | ||
:key="item.value" | ||
class="cursor-pointer list-none p-2 first-of-type:rounded-t last-of-type:rounded-b ui-selected:bg-primary-300 ui-active:bg-primary-300" | ||
:value="item" | ||
> | ||
<span>{{ item.label }}</span> | ||
</ListboxOption> | ||
</ListboxOptions> | ||
</MenuTransition> | ||
</Listbox> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<script lang="ts" setup> | ||
import { hierarchy } from "d3"; | ||
import type { TreeEntity } from "@/lib/get-tree-data"; | ||
import { Tree } from "@/lib/tree"; | ||
const router = useRouter(); | ||
const locale = useLocale(); | ||
const props = defineProps<{ | ||
data: TreeEntity; | ||
width: number; | ||
}>(); | ||
const hierarchyRef = ref<SVGElement | null>(null); | ||
onMounted(() => { | ||
updateTree(props.data, props.width); | ||
}); | ||
watch( | ||
() => [props.data, props.width], | ||
([to, newWidth]) => { | ||
updateTree(to as TreeEntity, newWidth as number); | ||
}, | ||
{ deep: true }, | ||
); | ||
interface Node { | ||
data: { | ||
children: Array<Node>; | ||
name: string; | ||
meta: { | ||
end: string; | ||
entity_type: string; | ||
label: string; | ||
pk: number; | ||
rel_end: string; | ||
rel_start: string; | ||
start: string; | ||
url: string; | ||
}; | ||
}; | ||
depth: number; | ||
height: number; | ||
parent?: Node; | ||
} | ||
function updateTree(data: TreeEntity, width: number) { | ||
const options = { | ||
label: (d: Node) => d.data.meta.label, | ||
link: (d: Node) => | ||
`/${locale.value}/hierarchy?id=${d.data.meta.pk}&model=${d.data.meta.entity_type}&label=${d.data.meta.label}`, | ||
width, | ||
r: 7, | ||
fontSize: "medium", | ||
padding: 2, | ||
}; | ||
hierarchyRef.value = Tree(hierarchy(data), options); | ||
} | ||
</script> | ||
|
||
<template> | ||
<!-- eslint-disable vuejs-accessibility/no-static-element-interactions --> | ||
<!-- eslint-disable vuejs-accessibility/click-events-have-key-events --> | ||
<div | ||
class="w-full" | ||
@click.prevent=" | ||
(event) => | ||
event.target?.parentNode?.href ? router.push(event.target.parentNode.href.baseVal) : null | ||
" | ||
v-html="hierarchyRef?.outerHTML" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
<Transition | ||
enter-active-class="transition duration-100 ease-out" | ||
enter-from-class="transform scale-95 -translate-y-8 opacity-0" | ||
enter-to-class="transform scale-100 translate-y-0 opacity-100" | ||
leave-active-class="transition duration-75 ease-in" | ||
leave-from-class="transform scale-100 opacity-100" | ||
leave-to-class="transform scale-95 opacity-0" | ||
> | ||
<slot /> | ||
</Transition> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.