gcg-website/static/admin/shortcodes/audio.js
Denys Konovalov 13dde42eb0 Static CMS v2.0 (#226)
- [x] Update auf Static CMS v2.0
- [x] aktualisierte Shortcodes (schließt #225)
- [x] aktualisierte Previews (schließt #181)
- Ordnerunterstützung
- [x] vervollständigte Seiten
- [x] Aufräumarbeiten

Reviewed-on: #226
2023-04-19 22:44:06 +02:00

68 lines
1.3 KiB
JavaScript

import { Card, TextField } from "./components/index.js";
const AudioShortcode = {
label: "Audiodatei",
openTag: "{{< ",
closeTag: " >}}",
separator: " ",
toProps: (args) => {
if (args.length > 0) {
const src =
args
.find((arg) => arg.startsWith("src="))
?.split("=")[1]
.replaceAll('"', "") ?? "";
return { src: src };
}
return { src: "" };
},
toArgs: ({ src }) => {
return [`src=\"${src}\"`];
},
control: ({ src, onChange, controlProps }) => {
const { collection, field } = controlProps;
const handleChange = ({ path }) => {
onChange({ src: path });
};
const handleOpenMediaLibrary = useMediaInsert(
src,
{ collection, field },
handleChange
);
return Card([
TextField({
label: "Audiodatei",
value: src,
onChange: (event) => {
onChange({ src: event.target.value });
},
}),
h(
"span",
{ key: "audio-button", className: "flex gap-2 pt-2 px-2" },
h(
"button",
{
type: "button",
onClick: handleOpenMediaLibrary,
className: "btn btn-contained-primary",
},
"wählen"
)
),
]);
},
preview: ({ src }) => {
return h(
"div",
{ className: "card" },
h("audio", { src: src, controls: true })
);
},
};
export default AudioShortcode;