Open Craft editors in standalone tabs and improve addon settings

This commit is contained in:
SantaSpeen committed 2026-10-22 19:02:35 +03:00
1 parent 5cb1b463ea
commit bc9709e500
16 files changed
+277 -162

No files matched your search

+69 -83
View File
@@ -1,72 +1,68 @@
<template>
<div class="craft-editor">
<header-bar
><Action
icon="close"
:label="t('buttons.close')"
@action="close"
/><title>{{ currentName }}</title></header-bar
>
<div class="craft-status" role="status">
<strong>{{ title }}</strong
><span>{{
saving
? t("addons.saving")
: pending
? t("addons.unsaved")
: frameDirty
<div v-if="pending || error || saving || saveAs" class="craft-feedback">
<div class="craft-status" role="status">
<strong>{{ title }}</strong
><span>{{
saving
? t("addons.saving")
: pending
? t("addons.unsaved")
: status
}}</span
><button
v-if="pending && !saveAs && !saving"
type="button"
class="button button--flat"
@click="persist"
>
{{ t("addons.retrySave") }}</button
><button
v-if="pending && !saveAs && !saving"
type="button"
class="button button--flat"
@click="
newName = pending.name;
saveAs = true;
"
>
{{ t("addons.saveAs") }}</button
><button
v-if="pending"
type="button"
class="button button--flat"
@click="downloadCopy"
>
{{ t("addons.downloadCopy") }}
</button>
: frameDirty
? t("addons.unsaved")
: status
}}</span
><button
v-if="pending && !saveAs && !saving"
type="button"
class="button button--flat"
@click="persist"
>
{{ t("addons.retrySave") }}</button
><button
v-if="pending && !saveAs && !saving"
type="button"
class="button button--flat"
@click="
newName = pending.name;
saveAs = true;
"
>
{{ t("addons.saveAs") }}</button
><button
v-if="pending"
type="button"
class="button button--flat"
@click="downloadCopy"
>
{{ t("addons.downloadCopy") }}
</button>
</div>
<p v-if="error" class="craft-error" role="alert">
{{ error }}
<a
v-if="authExpired"
:href="baseURL + '/auth/login'"
target="_blank"
rel="noopener noreferrer"
>{{ t("sidebar.login") }}</a
>
</p>
<form v-if="saveAs" class="craft-save-as" @submit.prevent="confirmSaveAs">
<label
>{{ t("addons.saveAs")
}}<input class="input" v-model.trim="newName" required /></label
><button class="button" :disabled="saving">
{{ t("buttons.save") }}</button
><button
type="button"
class="button button--flat"
@click="saveAs = false"
>
{{ t("buttons.cancel") }}
</button>
</form>
</div>
<p v-if="error" class="craft-error" role="alert">
{{ error }}
<a
v-if="authExpired"
:href="baseURL + '/auth/login'"
target="_blank"
rel="noopener noreferrer"
>{{ t("sidebar.login") }}</a
>
</p>
<form v-if="saveAs" class="craft-save-as" @submit.prevent="confirmSaveAs">
<label
>{{ t("addons.saveAs")
}}<input class="input" v-model.trim="newName" required /></label
><button class="button" :disabled="saving">{{ t("buttons.save") }}</button
><button
type="button"
class="button button--flat"
@click="saveAs = false"
>
{{ t("buttons.cancel") }}
</button>
</form>
<iframe
v-if="frameURL"
ref="frame"
@@ -82,15 +78,8 @@
</template>
<script setup lang="ts">
import { computed, ref, onMounted, onBeforeUnmount } from "vue";
import {
useRoute,
useRouter,
onBeforeRouteLeave,
onBeforeRouteUpdate,
} from "vue-router";
import { useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
import { useI18n } from "vue-i18n";
import HeaderBar from "@/components/header/HeaderBar.vue";
import Action from "@/components/header/Action.vue";
import { useFileStore } from "@/stores/file";
import { useAuthStore } from "@/stores/auth";
import { useAddonsStore } from "@/stores/addons";
@@ -98,17 +87,18 @@ import { baseURL } from "@/utils/constants";
import { fetchURL, StatusError } from "@/api/utils";
import { craftMessage, safeCraftName } from "@/utils/craft";
const route = useRoute(),
router = useRouter(),
store = useAddonsStore(),
files = useFileStore(),
auth = useAuthStore(),
{ t } = useI18n();
// Bind the editor to the file opened at mount; later store navigation must not redirect a save.
const file = files.req,
id = String(route.query.craft || ""),
sourcePath = file?.path || "";
id = String(route.params.addon || route.query.craft || ""),
sourcePath = route.params.addon
? String(route.query.path || "")
: file?.path || "";
const currentPath = ref(sourcePath),
currentName = ref(file?.name || "");
currentName = ref(sourcePath.split("/").pop() || "");
const title = computed(
() => store.items.find((item) => item.id === id)?.name || id
);
@@ -193,11 +183,6 @@ onBeforeRouteUpdate(mayLeave);
function beforeUnload(event: BeforeUnloadEvent) {
if (unsaved.value) event.preventDefault();
}
function close() {
router.push({
path: file?.url.slice(0, file.url.lastIndexOf("/") + 1) || "/files/",
});
}
async function persist() {
const payload = pending.value;
if (!payload || saving.value) return;
@@ -292,7 +277,7 @@ function receive(event: MessageEvent) {
opened = true;
clearTimeout(startup);
frame.value!.contentWindow!.postMessage(
{ type: id + ":open", name: file!.name, bytes: original },
{ type: id + ":open", name: currentName.value, bytes: original },
window.location.origin,
[original]
);
@@ -340,6 +325,7 @@ onMounted(async () => {
window.addEventListener("message", receive);
window.addEventListener("beforeunload", beforeUnload);
try {
document.title = currentName.value;
await store.refresh();
const addon = store.items.find(
(item) => item.id === id && item.enabled && item.build
+3
View File
@@ -271,6 +271,7 @@
</template>
<script setup lang="ts">
import { useAddonsStore } from "@/stores/addons";
import { useAuthStore } from "@/stores/auth";
import { useClipboardStore } from "@/stores/clipboard";
import { useFileStore } from "@/stores/file";
@@ -318,6 +319,7 @@ const $showError = inject<IToastError>("$showError")!;
const clipboardStore = useClipboardStore();
const authStore = useAuthStore();
const addons = useAddonsStore();
const fileStore = useFileStore();
const layoutStore = useLayoutStore();
@@ -442,6 +444,7 @@ watch(req, () => {
});
onMounted(() => {
if (authStore.isLoggedIn) addons.refresh().catch(() => {});
// Check the columns size for the first time.
columnsResize();
@@ -18,6 +18,12 @@ const harness = vi.hoisted(() => ({
},
}));
vi.mock("@/stores/addons", () => ({
useAddonsStore: () => ({
items: [],
refresh: vi.fn().mockResolvedValue(undefined),
}),
}));
vi.mock("@/stores/auth", () => ({
useAuthStore: () => ({ user: null }),
}));