handling brochure format type rehydratation

This commit is contained in:
Antoine M 2024-01-15 15:36:16 +01:00
parent b1778a6e7b
commit c14881fa98
3 changed files with 46 additions and 52 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' => 'fbce063ab27a220c98f0'); <?php return array('dependencies' => array('wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '617b3841d9e762364fd5');

View File

@ -2,37 +2,6 @@
/******/ "use strict"; /******/ "use strict";
/******/ var __webpack_modules__ = ({ /******/ var __webpack_modules__ = ({
/***/ "./node_modules/@wordpress/icons/build-module/library/check.js":
/*!*********************************************************************!*\
!*** ./node_modules/@wordpress/icons/build-module/library/check.js ***!
\*********************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives");
/* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__);
/**
* WordPress dependencies
*/
const check = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.SVG, {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_1__.Path, {
d: "M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"
}));
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (check);
//# sourceMappingURL=check.js.map
/***/ }),
/***/ "./node_modules/@wordpress/icons/build-module/library/trash.js": /***/ "./node_modules/@wordpress/icons/build-module/library/trash.js":
/*!*********************************************************************!*\ /*!*********************************************************************!*\
!*** ./node_modules/@wordpress/icons/build-module/library/trash.js ***! !*** ./node_modules/@wordpress/icons/build-module/library/trash.js ***!
@ -115,8 +84,9 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/check.js");
/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/trash.js"); /* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/trash.js");
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_5__);
@ -125,6 +95,8 @@ __webpack_require__.r(__webpack_exports__);
// pour les querry
const formatName = "homegrade-format/brochure-format"; const formatName = "homegrade-format/brochure-format";
const BrochureLinkFormatButton = props => { const BrochureLinkFormatButton = props => {
const { const {
@ -133,49 +105,67 @@ const BrochureLinkFormatButton = props => {
onChange onChange
} = props; } = props;
const [isPopoverOpen, setIsPopoverOpen] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(false); const [isPopoverOpen, setIsPopoverOpen] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
const [linkValue, setLinkValue] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(""); const [relatedPost, setRelatedPost] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)("");
const [pendingBrochure, setPendingBrochure] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
const activeFormat = (0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.getActiveFormats)(value).filter(format => format.type === formatName)[0]; const activeFormat = (0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.getActiveFormats)(value).filter(format => format.type === formatName)[0];
function setFormat() { const brochurePost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => {
if (activeFormat && activeFormat.attributes.brochurePostID) {
return select("core").getEntityRecord("postType", "brochures", activeFormat.attributes.brochurePostID);
}
});
const brochureAttachedMedia = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => {
if (brochurePost && brochurePost.acf && brochurePost.acf.brochure_pdf) {
return select("core").getEntityRecord("postType", "attachment", brochurePost.acf.brochure_pdf);
}
});
function setFormat(postDatas) {
setIsPopoverOpen(!isPopoverOpen); setIsPopoverOpen(!isPopoverOpen);
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: linkValue.url, href: "",
brochurePostID: postDatas.id.toString(),
target: "_blank", target: "_blank",
dataId: linkValue.id.toString(),
style: "text-decoration: underline;" style: "text-decoration: underline;"
} }
})); }));
} }
function removeFormat() { function removeFormat() {
setIsPopoverOpen(false); setIsPopoverOpen(false);
setLinkValue("");
onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.toggleFormat)(value, { onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.toggleFormat)(value, {
type: formatName type: formatName
})); }));
} }
console.log(brochurePost);
console.log(brochureAttachedMedia);
if (brochurePost && brochureAttachedMedia && pendingBrochure) {
onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, {
type: formatName,
attributes: {
target: "_blank",
brochurePostID: brochurePost.id.toString(),
brochureID: brochureAttachedMedia.id.toString(),
href: brochureAttachedMedia.source_url,
style: "text-decoration: underline;"
}
}));
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: "attachment" type: "post",
subtype: "brochures"
// subtype: "application/pdf", // Not working // subtype: "application/pdf", // Not working
// mime_type: "application/pdf", // Not working // mime_type: "application/pdf", // Not working
}, },
value: linkValue, value: relatedPost,
onChange: value => { onChange: setFormat
setLinkValue(value); })), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarGroup, {
}
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.Button, {
icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__["default"],
variant: "primary",
onClick: () => {
setIsPopoverOpen(!isPopoverOpen);
setFormat();
}
}, "Valider")), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarGroup, {
className: "test" className: "test"
}, (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,
@ -187,6 +177,10 @@ const BrochureLinkFormatButton = props => {
(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",
tagName: "a", tagName: "a",
attributes: {
brochureID: "brochure-id",
brochurePostID: "brochure-post-id"
},
className: "brochure-link-format", className: "brochure-link-format",
edit: BrochureLinkFormatButton edit: BrochureLinkFormatButton
}); });

File diff suppressed because one or more lines are too long