Files
lucent-laravel/front/js/svelte/records/previews/PreviewFile.svelte
T

96 lines
3.1 KiB
Svelte
Raw Normal View History

2024-08-15 22:11:26 +03:00
<script>
2026-01-08 23:23:48 +02:00
import Icon from "../../../common/Icon.svelte";
2024-08-15 22:11:26 +03:00
2026-01-08 23:23:48 +02:00
import { createEventDispatcher, getContext } from "svelte";
2024-08-15 22:11:26 +03:00
import Preview from "../../files/Preview.svelte";
2026-01-08 23:23:48 +02:00
import { previewTitle } from "./../Preview";
import { fileurl, htmlurl } from "../../files/imageserver.js";
2024-08-15 22:11:26 +03:00
import Status from "./../Status.svelte";
2024-08-18 17:23:18 +03:00
import Dropdown from "../../common/Dropdown.svelte";
2024-08-15 22:11:26 +03:00
const dispatch = createEventDispatcher();
const channel = getContext("channel");
export let record;
export let hasDelete = false;
2024-08-18 17:23:18 +03:00
export let hasInsert = false;
2024-08-15 22:11:26 +03:00
2026-01-08 23:23:48 +02:00
let schema = channel.schemas.find(
(aschema) => aschema.name === record.schema,
);
2024-08-15 22:11:26 +03:00
let cardTitle = previewTitle(channel.schemas, record);
2024-08-18 17:23:18 +03:00
let imagePresets = Object.keys(channel.imageFilters);
2024-08-15 22:11:26 +03:00
function remove(e) {
e.preventDefault();
dispatch("remove", record.id);
}
2024-08-18 17:23:18 +03:00
function insert(e, preset) {
e.preventDefault();
2026-01-08 23:23:48 +02:00
let html = htmlurl(channel, record, preset);
let url = !preset
? `/${record._file.path}`
: `/templates/${preset}/${record._file.path}`;
2024-08-25 14:23:20 +03:00
dispatch("editor-insert", {
html: html,
2026-01-08 23:23:48 +02:00
url: channel.filesUrl + url,
originalUrl: channel.filesUrl + "/" + record._file.path,
record: record,
2024-08-25 14:23:20 +03:00
});
2024-08-18 17:23:18 +03:00
}
2024-08-15 22:11:26 +03:00
</script>
<div class="preview-file">
2024-08-16 14:34:39 +03:00
<div style="display: flex;align-items: center;gap: 10px;">
<div class="image">
2026-01-08 23:23:48 +02:00
<Preview {record} size="small" />
2024-08-15 22:11:26 +03:00
</div>
2024-08-16 14:34:39 +03:00
<div class="title">
<div>
<a
2026-01-08 23:23:48 +02:00
class="record-title"
href="{channel.lucentUrl}/records/{record.id}"
2024-08-16 14:34:39 +03:00
>
{cardTitle}
</a>
<small class="d-block">
from {schema.label}
{#if record.status === "draft"}
2026-01-08 23:23:48 +02:00
<Status status={record.status} />
2024-08-16 14:34:39 +03:00
{/if}
</small>
</div>
</div>
2024-08-15 22:11:26 +03:00
</div>
2026-01-08 23:23:48 +02:00
<div
style="display: flex;gap:4px; align-items: center; margin-right: 10px;"
>
2024-08-18 17:23:18 +03:00
{#if hasInsert}
<div class="reference-action">
<Dropdown>
<div slot="button">
2026-01-08 23:23:48 +02:00
<Icon icon="photo-film" />
2024-08-18 17:23:18 +03:00
</div>
2026-01-08 23:23:48 +02:00
<button
class="dropdown-item button"
on:click={(e) => insert(e, null)}>original</button
>
2024-08-18 17:23:18 +03:00
{#each imagePresets as preset}
2026-01-08 23:23:48 +02:00
<button
class="dropdown-item button"
on:click={(e) => insert(e, preset)}>{preset}</button
>
2024-08-18 17:23:18 +03:00
{/each}
</Dropdown>
</div>
{/if}
{#if hasDelete}
<div class="reference-action">
2026-01-08 23:23:48 +02:00
<button class="button" on:click={remove}>
<Icon icon="trash-can" />
2024-08-18 17:23:18 +03:00
</button>
</div>
{/if}
</div>
2024-08-15 22:11:26 +03:00
</div>