enhancing brochures formt system

This commit is contained in:
Antoine M 2024-01-16 15:00:19 +01:00
parent 5731177580
commit b06e0632be
5 changed files with 47 additions and 44 deletions

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '617b3841d9e762364fd5'); <?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '251b40e555a82eb6d434');

View File

@ -119,12 +119,13 @@ const BrochureLinkFormatButton = props => {
} }
}); });
function setFormat(postDatas) { function setFormat(postDatas) {
console.log("postdata", postDatas);
setIsPopoverOpen(!isPopoverOpen); setIsPopoverOpen(!isPopoverOpen);
setPendingBrochure(true); setPendingBrochure(true);
onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, { onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, {
type: formatName, type: formatName,
attributes: { attributes: {
href: "", href: postDatas.url,
brochurePostID: postDatas.id.toString(), brochurePostID: postDatas.id.toString(),
target: "_blank", target: "_blank",
style: "text-decoration: underline;" style: "text-decoration: underline;"
@ -137,28 +138,30 @@ const BrochureLinkFormatButton = props => {
type: formatName type: formatName
})); }));
} }
console.log(brochurePost);
console.log(brochureAttachedMedia); // if (brochurePost && brochureAttachedMedia && pendingBrochure) {
if (brochurePost && brochureAttachedMedia && pendingBrochure) { // onChange(
onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, { // applyFormat(value, {
type: formatName, // type: formatName,
attributes: { // attributes: {
target: "_blank", // target: "_blank",
brochurePostID: brochurePost.id.toString(), // brochurePostID: brochurePost.id.toString(),
brochureID: brochureAttachedMedia.id.toString(), // brochureID: brochureAttachedMedia.id.toString(),
href: brochureAttachedMedia.source_url, // href: brochurePost.link,
style: "text-decoration: underline;" // style: "text-decoration: underline;",
} // },
})); // })
setPendingBrochure(false); // );
} // setPendingBrochure(false);
// }
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.BlockControls, null, isPopoverOpen && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.Popover, { return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.BlockControls, null, isPopoverOpen && (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.Popover, {
onClose: () => setIsPopoverOpen(false), onClose: () => setIsPopoverOpen(false),
className: "popover_tooltip_field" className: "popover_tooltip_field"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.__experimentalLinkControl, { }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.__experimentalLinkControl, {
suggestionsQuery: { suggestionsQuery: {
type: "post", type: "post",
subtype: "brochures" subtype: ["brochures", "fiches-infos"]
// subtype: "application/pdf", // Not working // subtype: "application/pdf", // Not working
// mime_type: "application/pdf", // Not working // mime_type: "application/pdf", // Not working
}, },
@ -170,12 +173,12 @@ const BrochureLinkFormatButton = props => {
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarButton, { }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarButton, {
isActive: isActive, isActive: isActive,
icon: !isActive ? "book" : _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__["default"], icon: !isActive ? "book" : _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__["default"],
label: !isActive ? "Ajouter un lien brochure" : "Supprimer le lien brochure", label: !isActive ? "Ajouter un lien Brochure / Fiche-info" : "Supprimer le lien Brochure / Fiche-info",
onClick: () => !isActive ? setIsPopoverOpen(!isPopoverOpen) : removeFormat() onClick: () => !isActive ? setIsPopoverOpen(!isPopoverOpen) : removeFormat()
})))); }))));
}; };
(0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.registerFormatType)("homegrade-format/brochure-format", { (0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.registerFormatType)("homegrade-format/brochure-format", {
title: "Lien Brochure", title: "Lien Brochure/Fiche-info",
tagName: "a", tagName: "a",
attributes: { attributes: {
brochureID: "brochure-id", brochureID: "brochure-id",

File diff suppressed because one or more lines are too long

View File

@ -43,5 +43,5 @@ async function hydrateBrochuresLinks() {
window.addEventListener("DOMContentLoaded", (event) => { window.addEventListener("DOMContentLoaded", (event) => {
buildDownloadIcons(); buildDownloadIcons();
hydrateBrochuresLinks(); // hydrateBrochuresLinks(); // Plus besoin depuis le que single-post-type Brochure redirige automatiquement vers le PDF correspondant
}); });

View File

@ -36,13 +36,14 @@ const BrochureLinkFormatButton = (props) => {
}); });
function setFormat(postDatas) { function setFormat(postDatas) {
console.log("postdata", postDatas);
setIsPopoverOpen(!isPopoverOpen); setIsPopoverOpen(!isPopoverOpen);
setPendingBrochure(true); setPendingBrochure(true);
onChange( onChange(
applyFormat(value, { applyFormat(value, {
type: formatName, type: formatName,
attributes: { attributes: {
href: "", href: postDatas.url,
brochurePostID: postDatas.id.toString(), brochurePostID: postDatas.id.toString(),
target: "_blank", target: "_blank",
style: "text-decoration: underline;", style: "text-decoration: underline;",
@ -59,23 +60,22 @@ const BrochureLinkFormatButton = (props) => {
}) })
); );
} }
console.log(brochurePost);
console.log(brochureAttachedMedia); // if (brochurePost && brochureAttachedMedia && pendingBrochure) {
if (brochurePost && brochureAttachedMedia && pendingBrochure) { // onChange(
onChange( // applyFormat(value, {
applyFormat(value, { // type: formatName,
type: formatName, // attributes: {
attributes: { // target: "_blank",
target: "_blank", // brochurePostID: brochurePost.id.toString(),
brochurePostID: brochurePost.id.toString(), // brochureID: brochureAttachedMedia.id.toString(),
brochureID: brochureAttachedMedia.id.toString(), // href: brochurePost.link,
href: brochureAttachedMedia.source_url, // style: "text-decoration: underline;",
style: "text-decoration: underline;", // },
}, // })
}) // );
); // setPendingBrochure(false);
setPendingBrochure(false); // }
}
return ( return (
<> <>
@ -87,7 +87,7 @@ const BrochureLinkFormatButton = (props) => {
<LinkControl <LinkControl
suggestionsQuery={{ suggestionsQuery={{
type: "post", type: "post",
subtype: "brochures", subtype: ["brochures", "fiches-infos"],
// subtype: "application/pdf", // Not working // subtype: "application/pdf", // Not working
// mime_type: "application/pdf", // Not working // mime_type: "application/pdf", // Not working
}} }}
@ -103,8 +103,8 @@ const BrochureLinkFormatButton = (props) => {
icon={!isActive ? "book" : trash} icon={!isActive ? "book" : trash}
label={ label={
!isActive !isActive
? "Ajouter un lien brochure" ? "Ajouter un lien Brochure / Fiche-info"
: "Supprimer le lien brochure" : "Supprimer le lien Brochure / Fiche-info"
} }
onClick={() => onClick={() =>
!isActive ? setIsPopoverOpen(!isPopoverOpen) : removeFormat() !isActive ? setIsPopoverOpen(!isPopoverOpen) : removeFormat()
@ -117,7 +117,7 @@ const BrochureLinkFormatButton = (props) => {
}; };
registerFormatType("homegrade-format/brochure-format", { registerFormatType("homegrade-format/brochure-format", {
title: "Lien Brochure", title: "Lien Brochure/Fiche-info",
tagName: "a", tagName: "a",
attributes: { attributes: {
brochureID: "brochure-id", brochureID: "brochure-id",