Files
lucent-laravel/front/js/svelte/records/elements/Markdown.svelte
T

59 lines
1.5 KiB
Svelte
Raw Normal View History

2023-10-23 18:05:06 +03:00
<script>
2026-05-14 22:49:47 +03:00
import { getContext } from "svelte";
import { htmlurl, presetUrl } from "../../files/imageserver";
2023-10-23 18:05:06 +03:00
import Codemirror from "../../libs/CodemirrorMarkdown.svelte";
import { getErrorMessage } from "./errorMessage";
2024-09-07 15:31:56 +03:00
import RichEditorFiles from "./RichEditorFiles.svelte";
2026-05-14 22:49:47 +03:00
const channel = getContext("channel");
2023-10-23 18:05:06 +03:00
export let value;
export let field;
2026-05-14 22:49:47 +03:00
2024-09-07 15:31:56 +03:00
export let record;
2023-10-23 18:05:06 +03:00
export let isCreateMode;
// export let id;
export let validationErrors;
$: errorMessage = getErrorMessage(validationErrors, field.name);
2024-09-07 15:31:56 +03:00
let editor;
2026-05-14 19:24:25 +03:00
function insertMedia(e) {
editor.insertMedia(e.detail);
2024-09-07 15:31:56 +03:00
}
2026-05-14 22:49:47 +03:00
function onFilesInserted(e) {
console.log(e.detail);
const presetPath = e.detail.preset.path;
e.detail.files.map((aFile) => {
let html = htmlurl(channel, record, presetPath);
editor.insertMedia({
html: html,
url: presetUrl(channel, aFile, presetPath),
originalUrl: channel.filesUrl + "/" + aFile.path,
file: aFile,
});
});
}
2023-10-23 18:05:06 +03:00
</script>
<div class="mb-3">
2026-05-14 19:24:25 +03:00
<RichEditorFiles
{record}
{field}
{validationErrors}
2026-05-14 22:49:47 +03:00
{onFilesInserted}
2026-05-14 19:24:25 +03:00
on:editor-insert={insertMedia}
></RichEditorFiles>
2026-05-14 22:49:47 +03:00
<Codemirror
bind:this={editor}
bind:value
editable={!field.readonly || isCreateMode}
/>
2023-10-23 18:05:06 +03:00
{#if errorMessage}
<div class="invalid-feedback d-block">
{errorMessage}
</div>
{/if}
</div>