Open Craft editors in standalone tabs and improve addon settings
This commit is contained in:
1 parent
5cb1b463ea
commit
bc9709e500
16 files changed
+277
-162
No files matched your search
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
Для HTML, JS и WASM создаются gzip-копии; корректные MIME, CSP для WASM и same-origin iframe задаются только страницам аддонов. Основная CSP File Browser не ослабляется. Старые версии остаются на диске: открытые редакторы продолжают загружать свои файлы. Удалять старые версии и оставшиеся после аварийной остановки `.install-*` можно вручную при остановленном сервере. Каталог `addons` закрыт от чтения/изменения через обычный файловый API, включая псевдонимы через ссылки и операции над родительскими папками.
|
Для HTML, JS и WASM создаются gzip-копии; корректные MIME, CSP для WASM и same-origin iframe задаются только страницам аддонов. Основная CSP File Browser не ослабляется. Старые версии остаются на диске: открытые редакторы продолжают загружать свои файлы. Удалять старые версии и оставшиеся после аварийной остановки `.install-*` можно вручную при остановленном сервере. Каталог `addons` закрыт от чтения/изменения через обычный файловый API, включая псевдонимы через ссылки и операции над родительскими папками.
|
||||||
|
|
||||||
В ПКМ и панели предпросмотра появляется «Открыть в GridCraft/PdfCraft». В «Создать» — XLSX/PDF, если соответствующий аддон установлен и включён; сервер генерирует корректные пустые документы. Предпросмотр PDF остаётся прежним быстрым просмотрщиком.
|
В ПКМ и панели предпросмотра появляется «Открыть в GridCraft/PdfCraft». В «Создать» — XLSX/PDF, если соответствующий аддон установлен и включён; сервер генерирует корректные пустые документы. Двойной клик по PDF/XLSX сразу открывает включённый установленный редактор в отдельной вкладке без панелей File Browser. Команда «Открыть в…» и создание документов также открывают отдельную вкладку. Для остальных файлов сохраняется обычное открытие.
|
||||||
|
|
||||||
Обмен идёт через официальный `?host=parent`/`postMessage`: проверяются origin и конкретное окно iframe. Данные передаются без токенов SSO. Файлы загружаются и сохраняются через собственный API File Browser, с проверкой области доступа, правил и текущих разрешений. Размер документа ограничен 64 МиБ; XLSX дополнительно ограничен 4096 записями и суммарно 256 МиБ заявленного распакованного содержимого. Одновременно обрабатываются не более двух запросов документов.
|
Обмен идёт через официальный `?host=parent`/`postMessage`: проверяются origin и конкретное окно iframe. Данные передаются без токенов SSO. Файлы загружаются и сохраняются через собственный API File Browser, с проверкой области доступа, правил и текущих разрешений. Размер документа ограничен 64 МиБ; XLSX дополнительно ограничен 4096 записями и суммарно 256 МиБ заявленного распакованного содержимого. Одновременно обрабатываются не более двух запросов документов.
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
v-if="tool"
|
v-if="tool"
|
||||||
icon="edit_note"
|
icon="edit_note"
|
||||||
:label="t('addons.openWith', { name: tool.name })"
|
:label="t('addons.openWith', { name: tool.name })"
|
||||||
@action="router.push({ path: file!.url, query: { craft: tool!.id } })"
|
@action="openCraftTab(router, tool!.id, file!.url)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { openCraftTab } from "@/utils/craft";
|
||||||
import { computed, onMounted } from "vue";
|
import { computed, onMounted } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
@@ -21,7 +22,10 @@ const store = useAddonsStore(),
|
|||||||
router = useRouter(),
|
router = useRouter(),
|
||||||
{ t } = useI18n();
|
{ t } = useI18n();
|
||||||
const tool = computed(() =>
|
const tool = computed(() =>
|
||||||
!props.file?.isDir && auth.user?.perm.download && auth.user?.perm.modify
|
props.file &&
|
||||||
|
!props.file.isDir &&
|
||||||
|
auth.user?.perm.download &&
|
||||||
|
auth.user?.perm.modify
|
||||||
? store.items.find(
|
? store.items.find(
|
||||||
(item) =>
|
(item) =>
|
||||||
item.enabled &&
|
item.enabled &&
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useAddonsStore } from "@/stores/addons";
|
||||||
|
import { openCraftTab } from "@/utils/craft";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { useFileStore } from "@/stores/file";
|
import { useFileStore } from "@/stores/file";
|
||||||
import { useLayoutStore } from "@/stores/layout";
|
import { useLayoutStore } from "@/stores/layout";
|
||||||
@@ -87,6 +89,7 @@ const props = defineProps<{
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
const addons = useAddonsStore();
|
||||||
const fileStore = useFileStore();
|
const fileStore = useFileStore();
|
||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
|
|
||||||
@@ -327,9 +330,12 @@ const click = (event: Event | KeyboardEvent) => {
|
|||||||
touches.value = 0;
|
touches.value = 0;
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
touches.value++;
|
if (!(event instanceof MouseEvent) || event.button === 0) {
|
||||||
if (touches.value > 1) {
|
touches.value++;
|
||||||
open();
|
if (touches.value > 1) {
|
||||||
|
touches.value = 0;
|
||||||
|
open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileStore.selected.indexOf(props.index) !== -1) {
|
if (fileStore.selected.indexOf(props.index) !== -1) {
|
||||||
@@ -377,6 +383,22 @@ const click = (event: Event | KeyboardEvent) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const open = () => {
|
const open = () => {
|
||||||
|
const tool =
|
||||||
|
!props.readOnly &&
|
||||||
|
!props.isDir &&
|
||||||
|
authStore.user?.perm.modify &&
|
||||||
|
authStore.user?.perm.download
|
||||||
|
? addons.items.find(
|
||||||
|
(item) =>
|
||||||
|
item.enabled &&
|
||||||
|
item.build &&
|
||||||
|
props.name.toLowerCase().endsWith(item.extension)
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
if (tool) {
|
||||||
|
openCraftTab(router, tool.id, props.url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.push({ path: props.url });
|
router.push({ path: props.url });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { craftLocation } from "@/utils/craft";
|
||||||
import { computed, inject, ref, watch } from "vue";
|
import { computed, inject, ref, watch } from "vue";
|
||||||
import { fileTemplate, templateFileName } from "@/utils/file-templates";
|
import { fileTemplate, templateFileName } from "@/utils/file-templates";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
@@ -88,8 +89,12 @@ const submit = async (event: Event) => {
|
|||||||
uri += encodeURIComponent(fullName.value);
|
uri += encodeURIComponent(fullName.value);
|
||||||
uri = uri.replace("//", "/");
|
uri = uri.replace("//", "/");
|
||||||
|
|
||||||
|
let editorTab: Window | null = null;
|
||||||
try {
|
try {
|
||||||
if (template.value.craft) {
|
if (template.value.craft) {
|
||||||
|
editorTab = window.open("about:blank", "_blank");
|
||||||
|
if (!editorTab) throw new Error(t("addons.popupBlocked"));
|
||||||
|
editorTab.opener = null;
|
||||||
await fetchURL(
|
await fetchURL(
|
||||||
"/api/craft/" +
|
"/api/craft/" +
|
||||||
template.value.craft +
|
template.value.craft +
|
||||||
@@ -102,16 +107,19 @@ const submit = async (event: Event) => {
|
|||||||
uri,
|
uri,
|
||||||
new Blob([template.value.content], { type: "text/plain;charset=utf-8" })
|
new Blob([template.value.content], { type: "text/plain;charset=utf-8" })
|
||||||
);
|
);
|
||||||
await router.push({
|
if (template.value.craft && editorTab) {
|
||||||
path: uri,
|
editorTab.location.replace(
|
||||||
query: template.value.craft
|
router.resolve(craftLocation(template.value.craft, uri)).href
|
||||||
? { craft: template.value.craft }
|
);
|
||||||
: template.value.id === "other"
|
fileStore.reload = true;
|
||||||
? {}
|
} else
|
||||||
: { edit: "true" },
|
await router.push({
|
||||||
});
|
path: uri,
|
||||||
|
query: template.value.id === "other" ? {} : { edit: "true" },
|
||||||
|
});
|
||||||
layoutStore.closeHovers();
|
layoutStore.closeHovers();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
editorTab?.close();
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
$showError(e);
|
$showError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,40 +3,51 @@
|
|||||||
<h2><AppIcon name="package" />{{ t("addons.title") }}</h2>
|
<h2><AppIcon name="package" />{{ t("addons.title") }}</h2>
|
||||||
<p class="field-hint">{{ t("addons.description") }}</p>
|
<p class="field-hint">{{ t("addons.description") }}</p>
|
||||||
<p v-if="error" class="document-error" role="alert">{{ error }}</p>
|
<p v-if="error" class="document-error" role="alert">{{ error }}</p>
|
||||||
<div v-for="addon in store.items" :key="addon.id" class="addon-row">
|
<div class="addon-grid">
|
||||||
<div>
|
<article v-for="addon in store.items" :key="addon.id" class="addon-card">
|
||||||
<strong>{{ addon.name }}</strong
|
<div class="addon-details">
|
||||||
><small
|
<AppIcon :name="addon.id === 'gridcraft' ? 'table' : 'description'" />
|
||||||
>{{ addon.version || t("addons.notInstalled") }} ·
|
<div>
|
||||||
{{ addon.extension }}</small
|
<strong>{{ addon.name }}</strong
|
||||||
><small v-if="busy(addon)"
|
><small
|
||||||
>{{ t("addons.states." + addon.state)
|
>{{ addon.version || t("addons.notInstalled") }} ·
|
||||||
}}<template v-if="addon.total">
|
{{ addon.extension }}</small
|
||||||
·
|
><small v-if="busy(addon)"
|
||||||
{{ Math.round((addon.downloaded / addon.total) * 100) }}%</template
|
>{{ t("addons.states." + addon.state)
|
||||||
></small
|
}}<template v-if="addon.total">
|
||||||
><small v-if="addon.error" role="alert" class="document-error">{{
|
·
|
||||||
addon.error
|
{{
|
||||||
}}</small>
|
Math.round((addon.downloaded / addon.total) * 100)
|
||||||
</div>
|
}}%</template
|
||||||
<label v-if="addon.build" class="addon-enabled"
|
></small
|
||||||
><input
|
><small v-if="addon.error" role="alert" class="document-error">{{
|
||||||
type="checkbox"
|
addon.error
|
||||||
:checked="addon.enabled"
|
}}</small>
|
||||||
:disabled="changing === addon.id"
|
</div>
|
||||||
@change="toggle(addon, ($event.target as HTMLInputElement).checked)"
|
</div>
|
||||||
/>{{ t("addons.enabled") }}</label
|
<div class="addon-controls">
|
||||||
>
|
<label v-if="addon.build" class="settings-toggle"
|
||||||
<button
|
><span>{{ t("addons.enabled") }}</span
|
||||||
type="button"
|
><input
|
||||||
class="button"
|
type="checkbox"
|
||||||
:disabled="busy(addon) || changing === addon.id"
|
:checked="addon.enabled"
|
||||||
@click="install(addon)"
|
:disabled="changing === addon.id"
|
||||||
>
|
@change="
|
||||||
<AppIcon :name="addon.build ? 'refresh' : 'download'" />{{
|
toggle(addon, ($event.target as HTMLInputElement).checked)
|
||||||
addon.build ? t("addons.update") : t("addons.install")
|
"
|
||||||
}}
|
/></label>
|
||||||
</button>
|
<button
|
||||||
|
type="button"
|
||||||
|
class="button"
|
||||||
|
:disabled="busy(addon) || changing === addon.id"
|
||||||
|
@click="install(addon)"
|
||||||
|
>
|
||||||
|
<AppIcon :name="addon.build ? 'refresh' : 'download'" />{{
|
||||||
|
addon.build ? t("addons.update") : t("addons.install")
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<p class="field-hint">{{ t("addons.directory") }} <code>./addons</code></p>
|
<p class="field-hint">{{ t("addons.directory") }} <code>./addons</code></p>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -389,38 +389,62 @@
|
|||||||
padding: 14px;
|
padding: 14px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.addon-row {
|
.addons-settings .addon-grid {
|
||||||
display: flex;
|
display: grid;
|
||||||
align-items: center;
|
grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
padding: 16px 0;
|
margin: 20px 0;
|
||||||
border-top: 1px solid var(--borderPrimary);
|
|
||||||
}
|
}
|
||||||
.addon-row > div {
|
.addons-settings .addon-card {
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid var(--borderPrimary);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--surfaceSecondary);
|
||||||
}
|
}
|
||||||
.addon-row strong,
|
.addon-details {
|
||||||
.addon-row small {
|
display: flex;
|
||||||
|
gap: 14px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
.addon-details > .app-icon {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--blue);
|
||||||
|
}
|
||||||
|
.addon-details > div {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.addon-details strong,
|
||||||
|
.addon-details small {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
|
||||||
.addon-row small {
|
|
||||||
margin-top: 5px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--textSecondary);
|
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
.addon-enabled {
|
.addon-details small {
|
||||||
display: flex;
|
margin-top: 6px;
|
||||||
align-items: center;
|
color: var(--textSecondary);
|
||||||
gap: 8px;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
.addon-row .button {
|
.addons-settings .addon-controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 14px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.addons-settings .addon-controls .settings-toggle {
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
.addon-controls .button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
white-space: nowrap;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.craft-editor {
|
.craft-editor {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -428,7 +452,7 @@
|
|||||||
z-index: 9000;
|
z-index: 9000;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-top: 64px;
|
padding: 0;
|
||||||
background: var(--background);
|
background: var(--background);
|
||||||
}
|
}
|
||||||
.craft-frame {
|
.craft-frame {
|
||||||
@@ -476,17 +500,32 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
}
|
}
|
||||||
|
.craft-feedback {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 16px;
|
||||||
|
left: 16px;
|
||||||
|
right: 16px;
|
||||||
|
z-index: 2;
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow: auto;
|
||||||
|
background: var(--surfacePrimary);
|
||||||
|
border: 1px solid var(--borderPrimary);
|
||||||
|
border-radius: 14px;
|
||||||
|
box-shadow: 0 8px 32px #0003;
|
||||||
|
}
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
.addon-row {
|
.addons-settings .addon-card {
|
||||||
flex-wrap: wrap;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
.addon-row > div {
|
.addon-controls .button {
|
||||||
flex-basis: 100%;
|
flex: 1;
|
||||||
}
|
|
||||||
.addon-row .button {
|
|
||||||
margin-inline-start: auto;
|
|
||||||
}
|
}
|
||||||
.craft-status {
|
.craft-status {
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
.craft-feedback {
|
||||||
|
bottom: 8px;
|
||||||
|
left: 8px;
|
||||||
|
right: 8px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -415,6 +415,7 @@
|
|||||||
"pdf": "PDF document"
|
"pdf": "PDF document"
|
||||||
},
|
},
|
||||||
"addons": {
|
"addons": {
|
||||||
|
"popupBlocked": "Allow new tabs in your browser.",
|
||||||
"title": "Addons",
|
"title": "Addons",
|
||||||
"description": "Editors run in your browser. Install official Artcraft releases with SHA-256 verification.",
|
"description": "Editors run in your browser. Install official Artcraft releases with SHA-256 verification.",
|
||||||
"notInstalled": "Not installed",
|
"notInstalled": "Not installed",
|
||||||
|
|||||||
@@ -412,6 +412,7 @@
|
|||||||
"pdf": "Документ PDF"
|
"pdf": "Документ PDF"
|
||||||
},
|
},
|
||||||
"addons": {
|
"addons": {
|
||||||
|
"popupBlocked": "Разрешите открытие новых вкладок в браузере.",
|
||||||
"title": "Аддоны",
|
"title": "Аддоны",
|
||||||
"description": "Редакторы работают в браузере. Установка и обновление — из официальных релизов Artcraft с проверкой SHA-256.",
|
"description": "Редакторы работают в браузере. Установка и обновление — из официальных релизов Artcraft с проверкой SHA-256.",
|
||||||
"notInstalled": "Не установлен",
|
"notInstalled": "Не установлен",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import i18n from "@/i18n";
|
|||||||
import { validateLogin } from "@/utils/auth";
|
import { validateLogin } from "@/utils/auth";
|
||||||
|
|
||||||
const titles = {
|
const titles = {
|
||||||
|
CraftEditor: "addons.title",
|
||||||
Login: "sidebar.login",
|
Login: "sidebar.login",
|
||||||
Share: "buttons.share",
|
Share: "buttons.share",
|
||||||
Files: "files.files",
|
Files: "files.files",
|
||||||
@@ -31,6 +32,12 @@ const titles = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
|
{
|
||||||
|
path: "/editor/:addon(gridcraft|pdfcraft)",
|
||||||
|
name: "CraftEditor",
|
||||||
|
component: () => import("@/views/files/CraftEditor.vue"),
|
||||||
|
meta: { requiresAuth: true },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/login",
|
path: "/login",
|
||||||
name: "Login",
|
name: "Login",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { expect, it } from "vitest";
|
import { expect, it } from "vitest";
|
||||||
import { craftMessage, safeCraftName } from "../craft";
|
import { craftLocation, craftMessage, safeCraftName } from "../craft";
|
||||||
it("accepts messages only from the specific same-origin editor frame", () => {
|
it("accepts messages only from the specific same-origin editor frame", () => {
|
||||||
const frame = {} as Window,
|
const frame = {} as Window,
|
||||||
origin = "https://files.test";
|
origin = "https://files.test";
|
||||||
@@ -56,3 +56,13 @@ it("validates save-as filenames without allowing paths or another file type", ()
|
|||||||
])
|
])
|
||||||
expect(safeCraftName(name, ".xlsx")).toBeNull();
|
expect(safeCraftName(name, ".xlsx")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves encoded names in standalone editor links", () => {
|
||||||
|
const location = craftLocation(
|
||||||
|
"gridcraft",
|
||||||
|
"/files/folder%20name/report%20%231%25.xlsx"
|
||||||
|
);
|
||||||
|
expect(location.name).toBe("CraftEditor");
|
||||||
|
expect(location.query.path).toBe("/folder name/report #1%.xlsx");
|
||||||
|
expect(location.params.addon).toBe("gridcraft");
|
||||||
|
});
|
||||||
@@ -1,3 +1,20 @@
|
|||||||
|
import type { Router } from "vue-router";
|
||||||
|
|
||||||
|
export function craftLocation(id: string, fileURL: string) {
|
||||||
|
return {
|
||||||
|
name: "CraftEditor",
|
||||||
|
params: { addon: id },
|
||||||
|
query: { path: decodeURIComponent(fileURL.replace(/^\/files/, "")) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export function openCraftTab(router: Router, id: string, fileURL: string) {
|
||||||
|
window.open(
|
||||||
|
router.resolve(craftLocation(id, fileURL)).href,
|
||||||
|
"_blank",
|
||||||
|
"noopener,noreferrer"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function safeCraftName(name: unknown, extension: string): string | null {
|
export function safeCraftName(name: unknown, extension: string): string | null {
|
||||||
if (
|
if (
|
||||||
typeof name !== "string" ||
|
typeof name !== "string" ||
|
||||||
|
|||||||
@@ -1,72 +1,68 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="craft-editor">
|
<div class="craft-editor">
|
||||||
<header-bar
|
<div v-if="pending || error || saving || saveAs" class="craft-feedback">
|
||||||
><Action
|
<div class="craft-status" role="status">
|
||||||
icon="close"
|
<strong>{{ title }}</strong
|
||||||
:label="t('buttons.close')"
|
><span>{{
|
||||||
@action="close"
|
saving
|
||||||
/><title>{{ currentName }}</title></header-bar
|
? t("addons.saving")
|
||||||
>
|
: pending
|
||||||
<div class="craft-status" role="status">
|
|
||||||
<strong>{{ title }}</strong
|
|
||||||
><span>{{
|
|
||||||
saving
|
|
||||||
? t("addons.saving")
|
|
||||||
: pending
|
|
||||||
? t("addons.unsaved")
|
|
||||||
: frameDirty
|
|
||||||
? t("addons.unsaved")
|
? t("addons.unsaved")
|
||||||
: status
|
: frameDirty
|
||||||
}}</span
|
? t("addons.unsaved")
|
||||||
><button
|
: status
|
||||||
v-if="pending && !saveAs && !saving"
|
}}</span
|
||||||
type="button"
|
><button
|
||||||
class="button button--flat"
|
v-if="pending && !saveAs && !saving"
|
||||||
@click="persist"
|
type="button"
|
||||||
>
|
class="button button--flat"
|
||||||
{{ t("addons.retrySave") }}</button
|
@click="persist"
|
||||||
><button
|
>
|
||||||
v-if="pending && !saveAs && !saving"
|
{{ t("addons.retrySave") }}</button
|
||||||
type="button"
|
><button
|
||||||
class="button button--flat"
|
v-if="pending && !saveAs && !saving"
|
||||||
@click="
|
type="button"
|
||||||
newName = pending.name;
|
class="button button--flat"
|
||||||
saveAs = true;
|
@click="
|
||||||
"
|
newName = pending.name;
|
||||||
>
|
saveAs = true;
|
||||||
{{ t("addons.saveAs") }}</button
|
"
|
||||||
><button
|
>
|
||||||
v-if="pending"
|
{{ t("addons.saveAs") }}</button
|
||||||
type="button"
|
><button
|
||||||
class="button button--flat"
|
v-if="pending"
|
||||||
@click="downloadCopy"
|
type="button"
|
||||||
>
|
class="button button--flat"
|
||||||
{{ t("addons.downloadCopy") }}
|
@click="downloadCopy"
|
||||||
</button>
|
>
|
||||||
|
{{ 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>
|
</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
|
<iframe
|
||||||
v-if="frameURL"
|
v-if="frameURL"
|
||||||
ref="frame"
|
ref="frame"
|
||||||
@@ -82,15 +78,8 @@
|
|||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, onMounted, onBeforeUnmount } from "vue";
|
import { computed, ref, onMounted, onBeforeUnmount } from "vue";
|
||||||
import {
|
import { useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
|
||||||
useRoute,
|
|
||||||
useRouter,
|
|
||||||
onBeforeRouteLeave,
|
|
||||||
onBeforeRouteUpdate,
|
|
||||||
} from "vue-router";
|
|
||||||
import { useI18n } from "vue-i18n";
|
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 { useFileStore } from "@/stores/file";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { useAddonsStore } from "@/stores/addons";
|
import { useAddonsStore } from "@/stores/addons";
|
||||||
@@ -98,17 +87,18 @@ import { baseURL } from "@/utils/constants";
|
|||||||
import { fetchURL, StatusError } from "@/api/utils";
|
import { fetchURL, StatusError } from "@/api/utils";
|
||||||
import { craftMessage, safeCraftName } from "@/utils/craft";
|
import { craftMessage, safeCraftName } from "@/utils/craft";
|
||||||
const route = useRoute(),
|
const route = useRoute(),
|
||||||
router = useRouter(),
|
|
||||||
store = useAddonsStore(),
|
store = useAddonsStore(),
|
||||||
files = useFileStore(),
|
files = useFileStore(),
|
||||||
auth = useAuthStore(),
|
auth = useAuthStore(),
|
||||||
{ t } = useI18n();
|
{ t } = useI18n();
|
||||||
// Bind the editor to the file opened at mount; later store navigation must not redirect a save.
|
// Bind the editor to the file opened at mount; later store navigation must not redirect a save.
|
||||||
const file = files.req,
|
const file = files.req,
|
||||||
id = String(route.query.craft || ""),
|
id = String(route.params.addon || route.query.craft || ""),
|
||||||
sourcePath = file?.path || "";
|
sourcePath = route.params.addon
|
||||||
|
? String(route.query.path || "")
|
||||||
|
: file?.path || "";
|
||||||
const currentPath = ref(sourcePath),
|
const currentPath = ref(sourcePath),
|
||||||
currentName = ref(file?.name || "");
|
currentName = ref(sourcePath.split("/").pop() || "");
|
||||||
const title = computed(
|
const title = computed(
|
||||||
() => store.items.find((item) => item.id === id)?.name || id
|
() => store.items.find((item) => item.id === id)?.name || id
|
||||||
);
|
);
|
||||||
@@ -193,11 +183,6 @@ onBeforeRouteUpdate(mayLeave);
|
|||||||
function beforeUnload(event: BeforeUnloadEvent) {
|
function beforeUnload(event: BeforeUnloadEvent) {
|
||||||
if (unsaved.value) event.preventDefault();
|
if (unsaved.value) event.preventDefault();
|
||||||
}
|
}
|
||||||
function close() {
|
|
||||||
router.push({
|
|
||||||
path: file?.url.slice(0, file.url.lastIndexOf("/") + 1) || "/files/",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
async function persist() {
|
async function persist() {
|
||||||
const payload = pending.value;
|
const payload = pending.value;
|
||||||
if (!payload || saving.value) return;
|
if (!payload || saving.value) return;
|
||||||
@@ -292,7 +277,7 @@ function receive(event: MessageEvent) {
|
|||||||
opened = true;
|
opened = true;
|
||||||
clearTimeout(startup);
|
clearTimeout(startup);
|
||||||
frame.value!.contentWindow!.postMessage(
|
frame.value!.contentWindow!.postMessage(
|
||||||
{ type: id + ":open", name: file!.name, bytes: original },
|
{ type: id + ":open", name: currentName.value, bytes: original },
|
||||||
window.location.origin,
|
window.location.origin,
|
||||||
[original]
|
[original]
|
||||||
);
|
);
|
||||||
@@ -340,6 +325,7 @@ onMounted(async () => {
|
|||||||
window.addEventListener("message", receive);
|
window.addEventListener("message", receive);
|
||||||
window.addEventListener("beforeunload", beforeUnload);
|
window.addEventListener("beforeunload", beforeUnload);
|
||||||
try {
|
try {
|
||||||
|
document.title = currentName.value;
|
||||||
await store.refresh();
|
await store.refresh();
|
||||||
const addon = store.items.find(
|
const addon = store.items.find(
|
||||||
(item) => item.id === id && item.enabled && item.build
|
(item) => item.id === id && item.enabled && item.build
|
||||||
|
|||||||
@@ -271,6 +271,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useAddonsStore } from "@/stores/addons";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { useClipboardStore } from "@/stores/clipboard";
|
import { useClipboardStore } from "@/stores/clipboard";
|
||||||
import { useFileStore } from "@/stores/file";
|
import { useFileStore } from "@/stores/file";
|
||||||
@@ -318,6 +319,7 @@ const $showError = inject<IToastError>("$showError")!;
|
|||||||
|
|
||||||
const clipboardStore = useClipboardStore();
|
const clipboardStore = useClipboardStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
const addons = useAddonsStore();
|
||||||
const fileStore = useFileStore();
|
const fileStore = useFileStore();
|
||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
|
|
||||||
@@ -442,6 +444,7 @@ watch(req, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
if (authStore.isLoggedIn) addons.refresh().catch(() => {});
|
||||||
// Check the columns size for the first time.
|
// Check the columns size for the first time.
|
||||||
columnsResize();
|
columnsResize();
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ const harness = vi.hoisted(() => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("@/stores/addons", () => ({
|
||||||
|
useAddonsStore: () => ({
|
||||||
|
items: [],
|
||||||
|
refresh: vi.fn().mockResolvedValue(undefined),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
vi.mock("@/stores/auth", () => ({
|
vi.mock("@/stores/auth", () => ({
|
||||||
useAuthStore: () => ({ user: null }),
|
useAuthStore: () => ({ user: null }),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
param([string]$Version = '3.0.0-sso.20')
|
param([string]$Version = '3.0.0-sso.21')
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||||
Push-Location $repo
|
Push-Location $repo
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
VERSION="${VERSION:-3.0.0-sso.20}"
|
VERSION="${VERSION:-3.0.0-sso.21}"
|
||||||
COMMIT=$(git rev-parse --short HEAD)
|
COMMIT=$(git rev-parse --short HEAD)
|
||||||
(cd frontend && pnpm install --frozen-lockfile && pnpm run build)
|
(cd frontend && pnpm install --frozen-lockfile && pnpm run build)
|
||||||
mkdir -p build/release/linux-amd64
|
mkdir -p build/release/linux-amd64
|
||||||
|
|||||||
Reference in new issue
Block a user