73 lines
2.0 KiB
Vue
73 lines
2.0 KiB
Vue
<template>
|
|
<button
|
|
v-for="template in templates"
|
|
:key="template.id"
|
|
type="button"
|
|
class="action"
|
|
@click="open('newFile', template.id)"
|
|
>
|
|
<img
|
|
v-if="template.craft"
|
|
class="create-app-icon"
|
|
:src="baseURL + '/static/img/artcraft/' + template.craft + '.webp'"
|
|
alt=""
|
|
/><AppIcon v-else :name="template.icon" /><span>{{
|
|
template.craft
|
|
? (addons.items.find((item) => item.id === template.craft)?.name ||
|
|
template.craft) +
|
|
" (" +
|
|
template.extension +
|
|
")"
|
|
: t("createTypes." + template.id)
|
|
}}</span>
|
|
</button>
|
|
<CreateMenu v-if="!craftOnly && hasCraftTemplates" craft-only />
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { useI18n } from "vue-i18n";
|
|
import { useLayoutStore } from "@/stores/layout";
|
|
import { fileTemplates } from "@/utils/file-templates";
|
|
import { computed, onMounted } from "vue";
|
|
import { useAddonsStore } from "@/stores/addons";
|
|
import { useAuthStore } from "@/stores/auth";
|
|
import CreateMenu from "./CreateMenu.vue";
|
|
import { baseURL } from "@/utils/constants";
|
|
const props = defineProps<{ craftOnly?: boolean }>();
|
|
const addons = useAddonsStore(),
|
|
auth = useAuthStore();
|
|
const availableTemplates = computed(() =>
|
|
fileTemplates.filter(
|
|
(template) =>
|
|
!template.craft ||
|
|
(addons.available(template.craft) &&
|
|
auth.user?.perm.modify &&
|
|
auth.user?.perm.download)
|
|
)
|
|
);
|
|
const templates = computed(() =>
|
|
availableTemplates.value.filter(
|
|
(template) => !!template.craft === !!props.craftOnly
|
|
)
|
|
);
|
|
const hasCraftTemplates = computed(() =>
|
|
availableTemplates.value.some((template) => template.craft)
|
|
);
|
|
onMounted(() => {
|
|
addons.refresh().catch(() => {});
|
|
});
|
|
const { t } = useI18n(),
|
|
layout = useLayoutStore();
|
|
function open(prompt: string, template?: string) {
|
|
if (layout.currentPromptName === "create") layout.closeHovers();
|
|
layout.showHover({ prompt, props: { template } });
|
|
}
|
|
</script>
|
|
<style scoped>
|
|
.create-app-icon {
|
|
width: 20px;
|
|
height: 20px;
|
|
object-fit: contain;
|
|
flex-shrink: 0;
|
|
}
|
|
</style>
|