Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:acdh-oeaw/vicav-vue3 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mau Zsofia Abraham committed Oct 3, 2024
2 parents 540377a + 71508d1 commit 8989ff5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 212 deletions.
5 changes: 3 additions & 2 deletions components/corpus-query-window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function searchCorpus() {
const openNewWindowFromAnchor = useAnchorClickHandler();
const { data: config } = useProjectInfo();
const specialCharacters = config.value?.projectConfig?.specialCharacters as Array<string>;
const specialCharacters = config.value?.projectConfig?.specialCharacters;
</script>

<template>
Expand All @@ -38,10 +38,11 @@ const specialCharacters = config.value?.projectConfig?.specialCharacters as Arra
class="block w-full rounded border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder:text-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
>
<InputExtended
v-if="specialCharacters"
v-model="queryString"
aria-label="Search"
placeholder="Search in corpus ..."
:string-snippets="specialCharacters"
:special-characters="specialCharacters"
@submit="searchCorpus"
/>
<button
Expand Down
10 changes: 7 additions & 3 deletions components/dict-query-window-content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const myDict = await dictStore.getDictById(params.value.textId);
const formId = `dictQueryForm-${params.value.textId}`;
/* data fetch parameters editing copies */
const q = ref<string | undefined>(params.value.queryParams?.q ?? "");
const q = ref<string>(params.value.queryParams?.q ?? "");
const page = ref<number>(params.value.queryParams?.page ?? 1);
const pageSize = ref<number | undefined>(params.value.queryParams?.pageSize);
const id = ref<string | null | undefined>(params.value.queryParams?.id);
Expand Down Expand Up @@ -165,18 +165,22 @@ const api = useApiClient();
</label>
</div>
<div v-if="isTextInputManual">
<InputBuilder v-model="q" :button-labels="myDict.specChars" @submit="updateQueryParams" />
<InputBuilder
v-model="q"
:special-characters="myDict.specialCharacters"
@submit="updateQueryParams"
/>
</div>
<div v-else>
<div>
<InputBuilder
v-model="textInput"
v-model:select-value="queryTemplate"
aria-label="Search"
:button-labels="myDict.specChars"
class="mb-3"
placeholder="Filter by&hellip;"
:select-options="myDict.queryTemplates"
:special-characters="myDict.specialCharacters"
submit-button-label="+"
@submit="addFilter"
/>
Expand Down
32 changes: 21 additions & 11 deletions components/input-builder.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<script setup lang="ts">
const props = defineProps({
modelValue: { type: String, default: "" },
selectValue: { type: String },
buttonLabels: { type: Array<string>, default: [] },
selectOptions: { type: Map<string, string>, default: new Map([]) },
placeholder: { type: String, default: "" },
submitButtonLabel: { type: String },
});
import type { SpecialCharacters } from "@/lib/api-client";
const props = withDefaults(
defineProps<{
modelValue: string;
selectValue?: string;
specialCharacters: SpecialCharacters;
selectOptions?: Map<string, string>;
placeholder?: string;
submitButtonLabel?: string;
}>(),
{
selectValue: "",
selectOptions: () => new Map<string, string>([]),
placeholder: "",
submitButtonLabel: "",
},
);
const emit = defineEmits(["update:modelValue", "update:selectValue", "submit"]);
const inputElement = ref();
Expand Down Expand Up @@ -82,10 +92,10 @@ watch(
<div class="ib">
<div class="ib-buttons">
<button
v-for="(c, i) in buttonLabels"
v-for="(c, i) in specialCharacters"
:key="i"
@click.prevent="InsertSnippet(c)"
v-text="c"
@click.prevent="InsertSnippet(c.value)"
v-html="c.text ? c.text : c.value"
></button>
</div>
<div class="ib-input-row">
Expand Down
18 changes: 10 additions & 8 deletions components/input-extended.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup lang="ts">
const props = defineProps({
modelValue: String,
stringSnippets: Array<string>,
placeholder: String,
});
import type { SpecialCharacters } from "@/lib/api-client";
const props = defineProps<{
modelValue: string;
specialCharacters: SpecialCharacters;
placeholder: string;
}>();
const emit = defineEmits(["update:modelValue", "submit"]);
const inputElement = ref();
Expand Down Expand Up @@ -51,10 +53,10 @@ const restoreCursorPosition = (pos: number) => {
<div class="ie-buttons">
<!-- @ts-expect-error -->
<button
v-for="(c, i) in stringSnippets"
v-for="(c, i) in specialCharacters"
:key="i"
@click.prevent="InsertSnippet(c)"
v-html="c"
@click.prevent="InsertSnippet(c.value)"
v-html="c.text ? c.text : c.value"
></button>
</div>
<div class="ie-textinput">
Expand Down
195 changes: 8 additions & 187 deletions stores/use-dict-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,186 +2,6 @@ import { Dict } from "@/types/global.d";

type DictIndex = Set<Zod.infer<typeof Dict>["id"]>;

const dictDataExtra = {
specChars: new Map<Zod.infer<typeof Dict>["id"], Zod.infer<typeof Dict>["specChars"]>([
[
"dc_tunico",
[
"’",
"ʔ",
"ā",
"ḅ",
"ʕ",
"ḏ",
"ḏ",
"ē",
"ġ",
"ǧ",
"ḥ",
"ī",
"ᴵ",
"ḷ",
"ṃ",
"ō",
"ṛ",
"ṣ",
"s̠",
"š",
"ṭ",
"ṯ",
"ū",
"ẓ",
"ž",
],
],
[
"dc_apc_eng_publ",
[
"ʕ",
"ʔ",
"ā",
"ḅ",
"ʕ",
"ḍ",
"ḏ",
"ǝ",
"ᵊ",
"ē",
"ġ",
"ǧ",
"ḥ",
"ī",
"ḷ",
"ṃ",
"ō",
"ṛ",
"ṣ",
"š",
"ṭ",
"ṯ",
"ū",
"ẓ",
"ž",
],
],
[
"dc_arz_eng_publ",
[
"’",
"ʔ",
"ā",
"ḅ",
"ʕ",
"ḏ",
"ḏ",
"ē",
"ġ",
"ǧ",
"ḥ",
"ī",
"ᴵ",
"ḷ",
"ṃ",
"ō",
"ṛ",
"ṣ",
"s̠",
"š",
"ṭ",
"ṯ",
"ū",
"ẓ",
"ž",
],
],
[
"dc_acm_baghdad_eng_publ",
[
"ʔ",
"ʕ",
"ā",
"b",
"č",
"d",
"ḍ",
"ḓ",
"ḏ",
"e",
"ē",
"ǝ",
"ġ",
"ǧ",
"ḥ",
"ī",
"ḷ",
"ṃ",
"ō",
"ṛ",
"š",
"ṣ",
"ṭ",
"ṯ",
"ū",
"ẓ",
],
],
[
"dc_ar_en_publ",
[
"ˀ",
"ˁ",
"ā",
"ḍ",
"ḏ",
"ē",
"ġ",
"ǧ",
"ḥ",
"ī",
"ḷ",
"ṣ",
"s̠",
"š",
"ṭ",
"ṯ",
"ū",
"ẓ",
"ʔ",
],
],
[
"dc_shawi_eng",
[
"ʕ",
"ʔ",
"ā",
"ḅ",
"ʕ",
"ḍ",
"ḏ",
"ǝ",
"ᵊ",
"ē",
"ġ",
"ǧ",
"ḥ",
"ī",
"ḷ",
"ṃ",
"ō",
"ṛ",
"ṣ",
"š",
"ṭ",
"ṯ",
"ū",
"ẓ",
"ž",
],
],
]),
};

export const useDictStore = defineStore("dict", () => {
const { data: dictData, suspense } = useDicts();

Expand Down Expand Up @@ -212,24 +32,25 @@ export const useDictStore = defineStore("dict", () => {
const { data, suspense: suspense } = useDictsDict({ id });
await suspense();
//TODO: refine response types in API definition
//eslint-disable-next-line @typescript-eslint/no-explicit-any
const dataObject: Record<string, any> | undefined = data.value!._embedded._.find(

const dataObject = data.value!._embedded._.find(
//eslint-disable-next-line @typescript-eslint/no-explicit-any
(obj) => (obj as Record<string, any>).note === "all entries",
);
if (dataObject === undefined) {
return;
}
const specChars = dictDataExtra.specChars.get(id); // TODO: this is obsolete, and is inserted here temporarily
if (specChars === undefined) {

if (dataObject.specialCharacters === undefined) {
throw new Error("Missing virtual keyboard definition!");
}

const dict: Zod.infer<typeof Dict> = {
id,
//TODO refine response types in API definition
queryTemplates: new Map((dataObject.queryTemplates as Array<string>).map((e) => [e, e])),
dbNames: dataObject.dbNames as Array<string>,
specChars,
queryTemplates: new Map(dataObject.queryTemplates!.map((e) => [e, e])),
dbNames: dataObject.dbNames!,
specialCharacters: dataObject.specialCharacters,
};
return dict;
};
Expand Down
2 changes: 1 addition & 1 deletion types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Dict = z.object({
id: z.string(),
queryTemplates: z.map(z.string(), z.string()),
dbNames: z.array(z.string()),
specChars: z.array(z.string()),
specialCharacters: z.array(z.object({ value: z.string(), text: z.string().optional() })),
});
export const DictQuerySchema = z.object({
targetType: z.literal("DictQuery"),
Expand Down

0 comments on commit 8989ff5

Please sign in to comment.