Skip to content

Commit

Permalink
Merge branch 'dev' into config-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jul 18, 2024
2 parents f36bfe8 + 9e3d6e5 commit b3ed3fe
Show file tree
Hide file tree
Showing 11 changed files with 813 additions and 746 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ As this project is a user-facing application, the places in the semantic version
### Added

- Code highlighting for XML and YAML [#30](https://github.com/spraakbanken/mink-frontend/issues/30)
- HTTP compression

### Changed

- Drop unnecessary async usage of the `js-yaml` package
- The FormKit and Highlight.js libs are imported dynamically to allow for a smaller main asset chunk

### Fixed

Expand Down
10 changes: 9 additions & 1 deletion public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>
</IfModule>

AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE image/svg+xml
17 changes: 17 additions & 0 deletions src/components/FormKitWrapper.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
/** Wrap any FormKit forms with this to provide our custom config and sync locale. */
import { watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { changeLocale, FormKitProvider } from "@formkit/vue";
import { formkitConfig } from "@/formkit";
const { locale } = useI18n();
watchEffect(() => changeLocale(locale.value));
</script>

<template>
<FormKitProvider :config="formkitConfig">
<slot />
</FormKitProvider>
</template>
9 changes: 8 additions & 1 deletion src/components/SyntaxHighlight.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<script setup lang="ts">
import { defineAsyncComponent } from "vue";
// Import lib dynamically for chunking
const Highlightjs = defineAsyncComponent(
async () => (await import("@/highlight")).default.component,
);
defineProps<{
code: string;
language?: string;
}>();
</script>

<template>
<highlightjs
<Highlightjs
:code
:language
:autodetect="false"
Expand Down
100 changes: 52 additions & 48 deletions src/corpus/CreateCorpus.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { FormKit } from "@formkit/vue";
import PageTitle from "@/components/PageTitle.vue";
import LayoutSection from "@/components/LayoutSection.vue";
import useSpin from "@/spin/spin.composable";
Expand All @@ -9,6 +10,7 @@ import { FORMATS_EXT, type FileFormat } from "@/api/corpusConfig";
import { useAuth } from "@/auth/auth.composable";
import useCreateCorpus from "@/corpus/createCorpus.composable";
import HelpBox from "@/components/HelpBox.vue";
import FormKitWrapper from "@/components/FormKitWrapper.vue";
const { requireAuthentication } = useAuth();
const { createFromConfig } = useCreateCorpus();
Expand Down Expand Up @@ -51,60 +53,62 @@ async function submit(fields: Form) {
<HelpBox>{{ $t("corpus.create.help") }}</HelpBox>

<PendingContent on="create">
<FormKit
id="create-corpus"
v-slot="{ value }"
type="form"
:submit-label="$t('create')"
:submit-attrs="{
inputClass: 'mink-button button-primary',
}"
@submit="submit"
>
<FormKitWrapper>
<FormKit
:label="$t('name')"
type="text"
validation="required:trim"
name="name"
input-class="w-72"
:help="$t('metadata.name.help')"
/>
id="create-corpus"
v-slot="{ value }"
type="form"
:submit-label="$t('create')"
:submit-attrs="{
inputClass: 'mink-button button-primary',
}"
@submit="submit"
>
<FormKit
:label="$t('name')"
type="text"
validation="required:trim"
name="name"
input-class="w-72"
:help="$t('metadata.name.help')"
/>

<FormKit
:label="$t('description')"
type="textarea"
name="description"
:help="$t('metadata.description.help')"
input-class="block w-full h-20"
/>
<FormKit
:label="$t('description')"
type="textarea"
name="description"
:help="$t('metadata.description.help')"
input-class="block w-full h-20"
/>

<FormKit
name="format"
:label="$t('fileFormat')"
type="select"
input-class="w-72"
:help="$t('config.format.help')"
:options="formatOptions"
validate="required"
/>
<FormKit
name="format"
:label="$t('fileFormat')"
type="select"
input-class="w-72"
:help="$t('config.format.help')"
:options="formatOptions"
validate="required"
/>

<HelpBox v-if="value!.format === 'pdf'" important>
<icon :icon="['far', 'lightbulb']" class="mr-1" />
{{ $t("config.format.note.pdf") }}
</HelpBox>
<HelpBox v-if="value!.format === 'pdf'" important>
<icon :icon="['far', 'lightbulb']" class="mr-1" />
{{ $t("config.format.note.pdf") }}
</HelpBox>

<FormKit
v-if="value!.format === 'xml'"
name="textAnnotation"
:label="$t('config.text_annotation')"
validation="required:trim|matches:/^[^<>\s]*$/"
input-class="w-40 font-mono"
:help="$t('config.text_annotation.help')"
>
<template #prefix>&lt;</template>
<template #suffix>&gt;</template>
<FormKit
v-if="value!.format === 'xml'"
name="textAnnotation"
:label="$t('config.text_annotation')"
validation="required:trim|matches:/^[^<>\s]*$/"
input-class="w-40 font-mono"
:help="$t('config.text_annotation.help')"
>
<template #prefix>&lt;</template>
<template #suffix>&gt;</template>
</FormKit>
</FormKit>
</FormKit>
</FormKitWrapper>
</PendingContent>
</LayoutSection>
</template>
Loading

0 comments on commit b3ed3fe

Please sign in to comment.