2023-04-19 22:44:06 +02:00
|
|
|
import { Card, TextField } from "./components/index.js";
|
|
|
|
|
|
|
|
const DownloadShortcode = {
|
2023-05-29 16:22:34 +02:00
|
|
|
label: "Download-Karte",
|
|
|
|
openTag: "{{< ",
|
|
|
|
closeTag: " >}}",
|
|
|
|
separator: " ",
|
|
|
|
toProps: (args) => {
|
|
|
|
if (args.length > 0) {
|
|
|
|
var title = "";
|
|
|
|
var link = "";
|
|
|
|
const linkIndex = args.findIndex((arg) => arg.startsWith('link="'));
|
|
|
|
const titleIndex = args.findIndex((arg) => arg.startsWith('title="'));
|
|
|
|
for (let arg of args.slice(titleIndex, linkIndex)) {
|
|
|
|
title += " " + arg.replaceAll("title=", "").replaceAll('"', "");
|
|
|
|
}
|
|
|
|
for (let arg of args.slice(linkIndex)) {
|
|
|
|
link += " " + arg.replaceAll("link=", "").replaceAll('"', "");
|
|
|
|
}
|
2023-09-30 21:15:23 +02:00
|
|
|
return { title: title.trimStart(), link: link.trim() };
|
2023-05-29 16:22:34 +02:00
|
|
|
}
|
2023-04-19 22:44:06 +02:00
|
|
|
|
2023-05-29 16:22:34 +02:00
|
|
|
return { title: "", link: "" };
|
|
|
|
},
|
|
|
|
toArgs: ({ title, link }) => {
|
|
|
|
return [`title=\"${title}\"`, `link=\"${link}\"`];
|
|
|
|
},
|
2023-09-30 21:15:23 +02:00
|
|
|
control: ({ title, link, onChange, controlProps }) => {
|
|
|
|
const { collection, field } = controlProps;
|
|
|
|
|
|
|
|
const handleChange = ({ path }) => {
|
|
|
|
onChange({ title: title, link: path });
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleOpenMediaLibrary = useMediaInsert(
|
|
|
|
link,
|
|
|
|
{ collection, field },
|
|
|
|
handleChange
|
|
|
|
);
|
|
|
|
|
2023-05-29 16:22:34 +02:00
|
|
|
return Card([
|
|
|
|
TextField({
|
|
|
|
label: "Titel",
|
|
|
|
value: title,
|
|
|
|
onChange: (event) => {
|
2023-09-30 21:15:23 +02:00
|
|
|
onChange({ title: event.target.value.trimStart(), link });
|
2023-05-29 16:22:34 +02:00
|
|
|
},
|
|
|
|
}),
|
2023-09-30 21:15:23 +02:00
|
|
|
h(
|
|
|
|
"span",
|
|
|
|
{
|
|
|
|
style: {
|
|
|
|
display: "flex",
|
|
|
|
"flex-direction": "row",
|
|
|
|
"align-items": "end",
|
|
|
|
},
|
2023-05-29 16:22:34 +02:00
|
|
|
},
|
2023-09-30 21:15:23 +02:00
|
|
|
TextField({
|
|
|
|
label: "Download-Link",
|
|
|
|
value: link,
|
|
|
|
onChange: (event) => {
|
|
|
|
onChange({ title, link: event.target.value });
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
h(
|
|
|
|
"button",
|
|
|
|
{
|
|
|
|
type: "button",
|
|
|
|
onClick: handleOpenMediaLibrary,
|
|
|
|
className: "CMS_Button_root CMS_Button_outlined-primary",
|
|
|
|
style: { "margin-left": "0.75rem", "margin-right": "0.75rem" },
|
|
|
|
},
|
|
|
|
"wählen"
|
|
|
|
)
|
|
|
|
),
|
2023-05-29 16:22:34 +02:00
|
|
|
]);
|
|
|
|
},
|
|
|
|
preview: ({ title, link }) => {
|
|
|
|
return h(
|
|
|
|
"div",
|
2023-07-31 20:54:52 +02:00
|
|
|
{ className: "card border-primary rounded-0 hover-shadow mb-2" },
|
2023-05-29 16:22:34 +02:00
|
|
|
h(
|
|
|
|
"div",
|
2023-07-31 20:54:52 +02:00
|
|
|
{ className: "card-body mb-0" },
|
2023-05-29 16:22:34 +02:00
|
|
|
h(
|
2023-07-31 20:54:52 +02:00
|
|
|
"h4",
|
|
|
|
{ className: "card-title" },
|
|
|
|
h("a", { className: "text-decoration-none", href: link }, title)
|
|
|
|
),
|
|
|
|
h(
|
|
|
|
"a",
|
|
|
|
{
|
|
|
|
className: "mb-0 btn btn-primary btn-sm text-decoration-none",
|
|
|
|
href: link,
|
|
|
|
},
|
|
|
|
h("i", { className: "mdi mdi-tray-arrow-down mb-0 me-2" }),
|
|
|
|
"Download"
|
2023-05-29 16:22:34 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-04-19 22:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DownloadShortcode;
|