2023-04-19 22:44:06 +02:00
|
|
|
import { Card, TextField } from "./components/index.js";
|
|
|
|
|
|
|
|
const GalleryShortcode = {
|
2023-05-29 16:22:34 +02:00
|
|
|
label: "Bildergallerie",
|
|
|
|
openTag: "{{< ",
|
|
|
|
closeTag: " >}}",
|
|
|
|
separator: " ",
|
|
|
|
toProps: (args) => {
|
|
|
|
if (args.length > 0) {
|
|
|
|
return {
|
|
|
|
dir:
|
|
|
|
args
|
|
|
|
.find((arg) => arg.startsWith("dir="))
|
|
|
|
?.split("=")[1]
|
|
|
|
.replaceAll('"', "") ?? "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return { dir: "" };
|
|
|
|
},
|
|
|
|
toArgs: ({ dir }) => {
|
|
|
|
return [`dir=\"${dir}\"`];
|
|
|
|
},
|
|
|
|
control: ({ dir, onChange, controlProps }) => {
|
|
|
|
const { collection, field } = controlProps;
|
2023-04-19 22:44:06 +02:00
|
|
|
|
2023-05-29 16:22:34 +02:00
|
|
|
const handleChange = ({ path }) => {
|
|
|
|
onChange({ dir: path });
|
|
|
|
};
|
2023-04-19 22:44:06 +02:00
|
|
|
|
2023-05-29 16:22:34 +02:00
|
|
|
const handleOpenMediaLibrary = useMediaInsert(
|
|
|
|
dir,
|
|
|
|
{ collection, field, forFolder: true },
|
|
|
|
handleChange
|
|
|
|
);
|
2023-04-19 22:44:06 +02:00
|
|
|
|
2023-05-29 16:22:34 +02:00
|
|
|
return Card([
|
|
|
|
TextField({
|
|
|
|
label: "Gallerie-Ordner",
|
|
|
|
value: dir,
|
|
|
|
onChange: (event) => {
|
|
|
|
onChange({ dir: event.target.value });
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
h(
|
|
|
|
"span",
|
2023-09-30 21:15:23 +02:00
|
|
|
{
|
|
|
|
key: "gallery-button",
|
|
|
|
className: "CMS_WidgetDateTime_NowButton_root",
|
|
|
|
},
|
2023-05-29 16:22:34 +02:00
|
|
|
h(
|
|
|
|
"button",
|
|
|
|
{
|
|
|
|
type: "button",
|
|
|
|
onClick: handleOpenMediaLibrary,
|
2023-09-30 21:15:23 +02:00
|
|
|
className: "CMS_Button_root CMS_Button_outlined-primary",
|
2023-05-29 16:22:34 +02:00
|
|
|
},
|
|
|
|
"wählen"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
preview: ({ dir }) => {
|
|
|
|
return h(
|
|
|
|
"div",
|
|
|
|
{ className: "card mb-4" },
|
|
|
|
h(
|
|
|
|
"div",
|
|
|
|
{ className: "card-body mb-0" },
|
|
|
|
h("div", { className: "card-title h4" }, "Gallerie-Ordner"),
|
|
|
|
h("div", { className: "card-text" }, dir)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-04-19 22:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default GalleryShortcode;
|