fixing content heading problems due to extacring title from h3 tag

This commit is contained in:
Antoine M 2023-10-04 14:36:57 +02:00
parent 3a6b6092ab
commit 9ead7e7972
9 changed files with 28 additions and 86 deletions

View File

@ -16,9 +16,7 @@
"style": "file:./style-index.css",
"attributes": {
"title": {
"type": "string",
"source": "html",
"selector": "h3"
"type": "string"
},
"headingLevel": {
"type": "string",

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '915fe1008255560e528e');
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '81dbc9cde8701593054f');

View File

@ -0,0 +1,10 @@
/*!****************************************************************************************************************************************************************************************************************************************!*\
!*** 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 ***!
\****************************************************************************************************************************************************************************************************************************************/
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
*/
/*# sourceMappingURL=index.css.map*/

View File

@ -0,0 +1 @@
{"version":3,"file":"index.css","mappings":";;;AAAA;;;;EAAA,C","sources":["webpack://multiblocks/./src/editor.scss"],"sourcesContent":["/**\n * The following styles get applied inside the editor only.\n *\n * Replace them with your own styles or remove the file completely.\n */\n\n// .block-editor-image-size-control {\n// \tdisplay: none;\n// }\n\n"],"names":[],"sourceRoot":""}

View File

@ -57,6 +57,11 @@ function Edit({
} = select("core/block-editor");
return getBlockIndex(clientId);
});
function onChangeTitle(newTitle) {
setAttributes({
title: newTitle
});
}
function onChangeHeadingLevel(newHeadingLevel) {
setAttributes({
headingLevel: newHeadingLevel
@ -76,42 +81,6 @@ function Edit({
hasIcon: hasIconToggleValue
});
}
// function getIconPicture() {
// switch (iconName) {
// case "key":
// return keyIcon;
// case "chain":
// return chainIcon;
// case "house":
// return houseIcon;
// case "bulb":
// return bulbIcon;
// }
// }
// function getDashiconSymbol() {
// switch (iconName) {
// case "key":
// return "admin-network";
// case "chain":
// return "admin-links";
// case "house":
// return "admin-home";
// case "bulb":
// return "lightbulb";
// }
// }
// let iconPicture = getIconPicture();
// let iconDashiconSymbol = getDashiconSymbol();
console.log("hasIcon", hasIcon);
console.log("iconName", iconName);
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_4__.InspectorControls, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__.PanelBody, {
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Icone", "homegrade-blocks__texte-fonctionnel"),
initialOpen: true
@ -162,9 +131,7 @@ function Edit({
enter: e => insertParagraphOnEnter(e)
}
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.RichText, {
onChange: value => setAttributes({
title: value
}),
onChange: onChangeTitle,
value: title,
disableLineBreaks: true,
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)("Insérez votre titre ici", "homegrade-blocks__texte-fonctionnel"),
@ -451,7 +418,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/content-heading","version":"0.1.0","title":"Titre","category":"homegrade-blocks","icon":"smiley","description":"Bloc de titrage","supports":{"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","attributes":{"title":{"type":"string","source":"html","selector":"h3"},"headingLevel":{"type":"string","default":"h3"},"hasIcon":{"type":"boolean","default":false},"iconName":{"type":"string","default":"key"}}}');
module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/content-heading","version":"0.1.0","title":"Titre","category":"homegrade-blocks","icon":"smiley","description":"Bloc de titrage","supports":{"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","attributes":{"title":{"type":"string"},"headingLevel":{"type":"string","default":"h3"},"hasIcon":{"type":"boolean","default":false},"iconName":{"type":"string","default":"key"}}}');
/***/ })

File diff suppressed because one or more lines are too long

View File

@ -16,9 +16,7 @@
"style": "file:./style-index.css",
"attributes": {
"title": {
"type": "string",
"source": "html",
"selector": "h3"
"type": "string"
},
"headingLevel": {
"type": "string",

View File

@ -27,11 +27,16 @@ export default function Edit({
...blockProps
}) {
const { title, headingLevel, hasIcon, iconName } = attributes;
const blockIndex = useSelect((select) => {
const { getBlockIndex } = select("core/block-editor");
return getBlockIndex(clientId);
});
function onChangeTitle(newTitle) {
setAttributes({ title: newTitle });
}
function onChangeHeadingLevel(newHeadingLevel) {
setAttributes({ headingLevel: newHeadingLevel });
}
@ -48,42 +53,6 @@ export default function Edit({
hasIcon: hasIconToggleValue,
});
}
// function getIconPicture() {
// switch (iconName) {
// case "key":
// return keyIcon;
// case "chain":
// return chainIcon;
// case "house":
// return houseIcon;
// case "bulb":
// return bulbIcon;
// }
// }
// function getDashiconSymbol() {
// switch (iconName) {
// case "key":
// return "admin-network";
// case "chain":
// return "admin-links";
// case "house":
// return "admin-home";
// case "bulb":
// return "lightbulb";
// }
// }
// let iconPicture = getIconPicture();
// let iconDashiconSymbol = getDashiconSymbol();
console.log("hasIcon", hasIcon);
console.log("iconName", iconName);
return (
<>
@ -165,7 +134,7 @@ export default function Edit({
}}
>
<RichText
onChange={(value) => setAttributes({ title: value })}
onChange={onChangeTitle}
value={title}
disableLineBreaks
placeholder={__(

View File

@ -2,7 +2,6 @@ import { useBlockProps, RichText } from "@wordpress/block-editor";
export default function save({ attributes }) {
const { title, headingLevel, hasIcon, iconName } = attributes;
return (
<>
<RichText.Content