handling deprecation

This commit is contained in:
Antoine M 2024-04-02 11:39:03 +02:00
parent 105ad0a612
commit aa56bc7bc0
12 changed files with 293 additions and 111 deletions

View File

@ -14,12 +14,6 @@
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"attributes": {
"sectionTitle": {
"type": "string"
},
"sectionSubtitle": {
"type": "string"
},
"textAlign": {
"type": "string",
"default": "left"

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'a530ef6e4b300fa39187');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '532929bbc982cc64e979');

View File

@ -1,6 +1,6 @@
/*!****************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/editor.scss ***!
\****************************************************************************************************************************************************************************************************************************************/
/*!***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/.pnpm/css-loader@6.10.0_webpack@5.90.3/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.35_webpack@5.90.3/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/.pnpm/sass-loader@12.6.0_sass@1.71.1_webpack@5.90.3/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/editor.scss ***!
\***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
.homegrade-blocks-staff-list .homegrade-blocks-staff-list__staff-list {
display: unset;
}

View File

@ -2,6 +2,105 @@
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/deprecated.js":
/*!***************************!*\
!*** ./src/deprecated.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 react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
/* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__);
const v2 = {
attributes: {
sectionTitle: {
type: "string"
},
sectionSubtitle: {
type: "string"
},
textAlign: {
type: "string",
default: "left"
}
},
save({
attributes
}) {
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps.save({
className: `section_titling section_titling--${attributes.textAlign}`
})
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: attributes.sectionTitle,
tagName: "h3",
className: "section_titling__title"
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: attributes.sectionSubtitle,
tagName: "p",
className: "section_titling__subtitle"
}));
},
migrate(attributes, innerBlocks) {
const textAlign = attributes.textAlign;
return [{
textAlign: textAlign
}, [(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__.createBlock)("core/heading", {
content: attributes.sectionTitle,
level: 3,
className: "section_titling__title"
}), (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_2__.createBlock)("core/paragraph", {
content: attributes.sectionSubtitle,
className: "section_titling__subtitle"
})]];
}
};
const v1 = {
attributes: {
sectionTitle: {
type: "string"
},
sectionSubtitle: {
type: "string"
},
textAlign: {
type: "string",
default: "left"
}
},
save({
attributes
}) {
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps.save({
className: `section_titling section_titling--${textAlign}`
})
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: sectionTitle,
tagName: "h3",
className: "section_titling__title"
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: sectionSubtitle,
tagName: "p",
className: "section_titling__subtitle"
}));
}
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ([v2, v1]);
/***/ }),
/***/ "./src/edit.js":
/*!*********************!*\
!*** ./src/edit.js ***!
@ -12,8 +111,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ Edit)
/* 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 react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _editor_scss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./editor.scss */ "./src/editor.scss");
@ -37,28 +136,17 @@ function Edit({
clientId
}) {
let {
sectionTitle,
sectionSubtitle,
textAlign
} = attributes;
function onChangeSectionTitle(sectionTitle) {
setAttributes({
sectionTitle
});
}
function onChangeSectionSubtitle(sectionSubtitle) {
setAttributes({
sectionSubtitle
});
}
console.log("attributes", attributes);
function onChangeTextAlignment(textAlign) {
setAttributes({
textAlign
});
}
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, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.Toolbar, {
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.BlockControls, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.Toolbar, {
label: "Options"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarDropdownMenu, {
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToolbarDropdownMenu, {
icon: textAlign === "left" ? _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__["default"] : textAlign === "center" ? _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__["default"] : _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__["default"],
label: "Alignement du titrage",
controls: [{
@ -74,22 +162,20 @@ function Edit({
icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__["default"],
onClick: () => onChangeTextAlignment("right")
}]
}))), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
}))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
...(0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.useBlockProps)({
className: `section_titling section_titling--${textAlign}`
})
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.RichText, {
value: sectionTitle,
tagName: "h3",
className: "section_titling__title",
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ajouter ici le Titre de Section", "homegrade-blocks__texte-backoffice"),
onChange: onChangeSectionTitle
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.RichText, {
value: sectionSubtitle,
tagName: "p",
className: "section_titling__subtitle",
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Ajouter ici le Sous-titre", "homegrade"),
onChange: onChangeSectionSubtitle
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InnerBlocks, {
allowedBlocks: ["core/paragraph", "core/list", "core/heading"],
templateLock: "contentOnly",
template: [["core/heading", {
placeholder: "Titre de section",
level: 3,
className: "section_titling__title"
}], ["core/paragraph", {
className: "section_titling__subtitle"
}]]
})));
}
@ -107,21 +193,24 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _style_scss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./style.scss */ "./src/style.scss");
/* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./edit */ "./src/edit.js");
/* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./save */ "./src/save.js");
/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./block.json */ "./src/block.json");
/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/icons */ "../../node_modules/@wordpress/icons/build-module/library/header.js");
/* harmony import */ var _deprecated__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./deprecated */ "./src/deprecated.js");
/* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./block.json */ "./src/block.json");
/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/icons */ "../../node_modules/@wordpress/icons/build-module/library/header.js");
(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_4__.name, {
(0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_5__.name, {
icon: {
src: _wordpress_icons__WEBPACK_IMPORTED_MODULE_5__["default"],
src: _wordpress_icons__WEBPACK_IMPORTED_MODULE_6__["default"],
foreground: "#DF1E1E"
},
edit: _edit__WEBPACK_IMPORTED_MODULE_2__["default"],
save: _save__WEBPACK_IMPORTED_MODULE_3__["default"]
save: _save__WEBPACK_IMPORTED_MODULE_3__["default"],
deprecated: _deprecated__WEBPACK_IMPORTED_MODULE_4__["default"]
});
/***/ }),
@ -136,8 +225,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ save)
/* 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 react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__);
@ -145,24 +234,16 @@ __webpack_require__.r(__webpack_exports__);
function save({
attributes
}) {
let {
const {
sectionTitle,
sectionSubtitle,
textAlign
} = attributes;
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
..._wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.useBlockProps.save({
className: `section_titling section_titling--${textAlign}`
})
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: sectionTitle,
tagName: "h3",
className: "section_titling__title"
}), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.RichText.Content, {
value: sectionSubtitle,
tagName: "p",
className: "section_titling__subtitle"
}));
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_1__.InnerBlocks.Content, null));
}
/***/ }),
@ -315,6 +396,16 @@ const positionRight = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createE
/***/ }),
/***/ "react":
/*!************************!*\
!*** external "React" ***!
\************************/
/***/ ((module) => {
module.exports = window["React"];
/***/ }),
/***/ "@wordpress/block-editor":
/*!*************************************!*\
!*** external ["wp","blockEditor"] ***!
@ -381,7 +472,7 @@ module.exports = window["wp"]["primitives"];
\************************/
/***/ ((module) => {
module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/section-titling","version":"0.1.0","title":"Titre de section","category":"homegrade-blocks","description":"Pour insérer un bloc de titrage (dans une grey-box ou une white-box) ","supports":{"html":false},"textdomain":"homegrade-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","attributes":{"sectionTitle":{"type":"string"},"sectionSubtitle":{"type":"string"},"textAlign":{"type":"string","default":"left"}}}');
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/section-titling","version":"0.1.0","title":"Titre de section","category":"homegrade-blocks","description":"Pour insérer un bloc de titrage (dans une grey-box ou une white-box) ","supports":{"html":false},"textdomain":"homegrade-blocks","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","attributes":{"textAlign":{"type":"string","default":"left"}}}');
/***/ })
@ -427,9 +518,7 @@ module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json
/******/ }
/******/ var notFulfilled = Infinity;
/******/ for (var i = 0; i < deferred.length; i++) {
/******/ var chunkIds = deferred[i][0];
/******/ var fn = deferred[i][1];
/******/ var priority = deferred[i][2];
/******/ var [chunkIds, fn, priority] = deferred[i];
/******/ var fulfilled = true;
/******/ for (var j = 0; j < chunkIds.length; j++) {
/******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
@ -515,9 +604,7 @@ module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json
/******/
/******/ // install a JSONP callback for chunk loading
/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
/******/ var chunkIds = data[0];
/******/ var moreModules = data[1];
/******/ var runtime = data[2];
/******/ var [chunkIds, moreModules, runtime] = data;
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0;
@ -540,7 +627,7 @@ module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json
/******/ return __webpack_require__.O(result);
/******/ }
/******/
/******/ var chunkLoadingGlobal = self["webpackChunkmultiblocks"] = self["webpackChunkmultiblocks"] || [];
/******/ var chunkLoadingGlobal = globalThis["webpackChunkmultiblocks"] = globalThis["webpackChunkmultiblocks"] || [];
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
/******/ })();

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*!***************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/style.scss ***!
\***************************************************************************************************************************************************************************************************************************************/
/*!**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/.pnpm/css-loader@6.10.0_webpack@5.90.3/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[4].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.35_webpack@5.90.3/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[4].use[2]!./node_modules/.pnpm/sass-loader@12.6.0_sass@1.71.1_webpack@5.90.3/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[4].use[3]!./src/style.scss ***!
\**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/

View File

@ -0,0 +1,24 @@
import { useBlockProps, RichText } from "@wordpress/block-editor";
export default function save({ attributes }) {
let { sectionTitle, sectionSubtitle, textAlign } = attributes;
return (
<div
{...useBlockProps.save({
className: `section_titling section_titling--${textAlign}`,
})}
>
<RichText.Content
value={sectionTitle}
tagName="h3"
className="section_titling__title"
/>
<RichText.Content
value={sectionSubtitle}
tagName="p"
className="section_titling__subtitle"
/>
</div>
);
}

View File

@ -14,12 +14,6 @@
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"attributes": {
"sectionTitle": {
"type": "string"
},
"sectionSubtitle": {
"type": "string"
},
"textAlign": {
"type": "string",
"default": "left"

View File

@ -0,0 +1,97 @@
import { useBlockProps } from "@wordpress/block-editor";
import { RichText } from "@wordpress/block-editor";
import { createBlock } from "@wordpress/blocks";
const v2 = {
attributes: {
sectionTitle: {
type: "string",
},
sectionSubtitle: {
type: "string",
},
textAlign: {
type: "string",
default: "left",
},
},
save({ attributes }) {
return (
<div
{...useBlockProps.save({
className: `section_titling section_titling--${attributes.textAlign}`,
})}
>
<RichText.Content
value={attributes.sectionTitle}
tagName="h3"
className="section_titling__title"
/>
<RichText.Content
value={attributes.sectionSubtitle}
tagName="p"
className="section_titling__subtitle"
/>
</div>
);
},
migrate(attributes, innerBlocks) {
const textAlign = attributes.textAlign;
return [
{
textAlign: textAlign,
},
[
createBlock("core/heading", {
content: attributes.sectionTitle,
level: 3,
className: "section_titling__title",
}),
createBlock("core/paragraph", {
content: attributes.sectionSubtitle,
className: "section_titling__subtitle",
}),
],
];
},
};
const v1 = {
attributes: {
sectionTitle: {
type: "string",
},
sectionSubtitle: {
type: "string",
},
textAlign: {
type: "string",
default: "left",
},
},
save({ attributes }) {
return (
<div
{...useBlockProps.save({
className: `section_titling section_titling--${textAlign}`,
})}
>
<RichText.Content
value={sectionTitle}
tagName="h3"
className="section_titling__title"
/>
<RichText.Content
value={sectionSubtitle}
tagName="p"
className="section_titling__subtitle"
/>
</div>
);
},
};
export default [v2, v1];

View File

@ -1,19 +1,14 @@
import { __ } from "@wordpress/i18n";
import "./editor.scss";
import { BlockControls } from "@wordpress/block-editor";
import { useBlockProps, RichText } from "@wordpress/block-editor";
import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor";
import { Toolbar, ToolbarDropdownMenu } from "@wordpress/components";
import { positionLeft, positionCenter, positionRight } from "@wordpress/icons";
export default function Edit({ attributes, setAttributes, clientId }) {
let { sectionTitle, sectionSubtitle, textAlign } = attributes;
let { textAlign } = attributes;
function onChangeSectionTitle(sectionTitle) {
setAttributes({ sectionTitle });
}
function onChangeSectionSubtitle(sectionSubtitle) {
setAttributes({ sectionSubtitle });
}
console.log("attributes", attributes);
function onChangeTextAlignment(textAlign) {
setAttributes({ textAlign });
@ -57,22 +52,20 @@ export default function Edit({ attributes, setAttributes, clientId }) {
className: `section_titling section_titling--${textAlign}`,
})}
>
<RichText
value={sectionTitle}
tagName="h3"
className="section_titling__title"
placeholder={__(
"Ajouter ici le Titre de Section",
"homegrade-blocks"
)}
onChange={onChangeSectionTitle}
/>
<RichText
value={sectionSubtitle}
tagName="p"
className="section_titling__subtitle"
placeholder={__("Ajouter ici le Sous-titre", "homegrade-blocks")}
onChange={onChangeSectionSubtitle}
<InnerBlocks
allowedBlocks={["core/paragraph", "core/list", "core/heading"]}
templateLock="contentOnly"
template={[
[
"core/heading",
{
placeholder: "Titre de section",
level: 3,
className: "section_titling__title",
},
],
["core/paragraph", { className: "section_titling__subtitle" }],
]}
/>
</div>
</>

View File

@ -3,6 +3,7 @@ import "./style.scss";
import Edit from "./edit";
import save from "./save";
import deprecated from "./deprecated";
import metadata from "./block.json";
import { header } from "@wordpress/icons";
@ -14,4 +15,5 @@ registerBlockType(metadata.name, {
},
edit: Edit,
save,
deprecated,
});

View File

@ -1,7 +1,7 @@
import { useBlockProps, RichText } from "@wordpress/block-editor";
import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor";
export default function save({ attributes }) {
let { sectionTitle, sectionSubtitle, textAlign } = attributes;
const { sectionTitle, sectionSubtitle, textAlign } = attributes;
return (
<div
@ -9,16 +9,7 @@ export default function save({ attributes }) {
className: `section_titling section_titling--${textAlign}`,
})}
>
<RichText.Content
value={sectionTitle}
tagName="h3"
className="section_titling__title"
/>
<RichText.Content
value={sectionSubtitle}
tagName="p"
className="section_titling__subtitle"
/>
<InnerBlocks.Content />
</div>
);
}