From bbeb97fe2b8a61ead62991e9d1e50cbe798459fb Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 2 Oct 2025 14:24:27 +0200 Subject: [PATCH] FEATURE Refactoring format type and introducing new uppercase format --- .../carhop-format-types/build/index-rtl.css | 13 +- .../carhop-format-types/build/index.asset.php | 2 +- plugins/carhop-format-types/build/index.css | 13 +- .../carhop-format-types/build/index.css.map | 2 +- plugins/carhop-format-types/build/index.js | 346 +++++++++++++----- .../carhop-format-types/build/index.js.map | 2 +- .../carhop-format-types.php | 3 +- .../src/formats/footnote.js | 107 ++++++ .../src/formats/uppercased-small-title.css | 3 + .../src/formats/uppercased-small-title.js | 58 +++ plugins/carhop-format-types/src/index.js | 103 +----- 11 files changed, 453 insertions(+), 199 deletions(-) create mode 100644 plugins/carhop-format-types/src/formats/footnote.js create mode 100644 plugins/carhop-format-types/src/formats/uppercased-small-title.css create mode 100644 plugins/carhop-format-types/src/formats/uppercased-small-title.js diff --git a/plugins/carhop-format-types/build/index-rtl.css b/plugins/carhop-format-types/build/index-rtl.css index c857f33..2946455 100644 --- a/plugins/carhop-format-types/build/index-rtl.css +++ b/plugins/carhop-format-types/build/index-rtl.css @@ -1,6 +1,6 @@ -/*!**********************************************************************************************************************************************************************!*\ - !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/footnote.css ***! - \**********************************************************************************************************************************************************************/ +/*!******************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/formats/footnote.css ***! + \******************************************************************************************************************************************************************************/ body { counter-reset: footnote-index; } @@ -60,3 +60,10 @@ body { } } +/*!********************************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/formats/uppercased-small-title.css ***! + \********************************************************************************************************************************************************************************************/ +.uppercased-small-title { + text-transform: uppercase; +} + diff --git a/plugins/carhop-format-types/build/index.asset.php b/plugins/carhop-format-types/build/index.asset.php index 1861dc7..708dd47 100644 --- a/plugins/carhop-format-types/build/index.asset.php +++ b/plugins/carhop-format-types/build/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '8e32672f1170d7729a15'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => 'abb02131aeec09fd0594'); diff --git a/plugins/carhop-format-types/build/index.css b/plugins/carhop-format-types/build/index.css index 006ee45..f5d6ac8 100644 --- a/plugins/carhop-format-types/build/index.css +++ b/plugins/carhop-format-types/build/index.css @@ -1,6 +1,6 @@ -/*!**********************************************************************************************************************************************************************!*\ - !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/footnote.css ***! - \**********************************************************************************************************************************************************************/ +/*!******************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/formats/footnote.css ***! + \******************************************************************************************************************************************************************************/ body { counter-reset: footnote-index; } @@ -60,5 +60,12 @@ body { } } +/*!********************************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/formats/uppercased-small-title.css ***! + \********************************************************************************************************************************************************************************************/ +.uppercased-small-title { + text-transform: uppercase; +} + /*# sourceMappingURL=index.css.map*/ \ No newline at end of file diff --git a/plugins/carhop-format-types/build/index.css.map b/plugins/carhop-format-types/build/index.css.map index 2fdd341..f4f33b3 100644 --- a/plugins/carhop-format-types/build/index.css.map +++ b/plugins/carhop-format-types/build/index.css.map @@ -1 +1 @@ -{"version":3,"file":"index.css","mappings":";;;AAAA;CACC,6BAA6B;AAC9B;AACA;CACC,iCAAiC;CACjC,kBAAkB;CAClB,YAAY;;CAEZ;EACC,mDAAmD;EACnD,WAAW;EACX,WAAW;EACX,YAAY;EACZ,kBAAkB;EAClB,gCAAgC;EAChC,oBAAoB;EACpB,uBAAuB;EACvB,mBAAmB;EACnB,0BAA0B;EAC1B,gBAAgB;EAChB,gBAAgB;EAChB,iBAAiB;CAClB;AACD;;AAEA;;CAEC;EACC,0BAA0B;EAC1B,6BAA6B;EAC7B,wDAAwD;EACxD,8BAA8B;EAC9B,0BAA0B;CAC3B;AACD;;AAEA;CACC;EACC,wBAAwB;EACxB,gBAAgB;CACjB;CACA;EACC,aAAa;EACb,yBAAyB;EACzB,SAAS;EACT,gBAAgB;;EAEhB;GACC,oCAAoC;GACpC,sBAAsB;EACvB;;EAEA;GACC,8DAA8D;GAC9D,sBAAsB;EACvB;CACD;AACD","sources":["webpack:///./src/footnote.css"],"sourcesContent":["body {\r\n\tcounter-reset: footnote-index;\r\n}\r\n.footnote-reference {\r\n\tcounter-increment: footnote-index;\r\n\tposition: relative;\r\n\tcolor: unset;\r\n\r\n\t&::after {\r\n\t\tbackground-color: var(--wp--preset--color--primary);\r\n\t\tcolor: #fff;\r\n\t\twidth: 22px;\r\n\t\theight: 22px;\r\n\t\tborder-radius: 50%;\r\n\t\tcontent: counter(footnote-index);\r\n\t\tdisplay: inline-flex;\r\n\t\tjustify-content: center;\r\n\t\talign-items: center;\r\n\t\tfont-size: 11px !important;\r\n\t\tfont-weight: 600;\r\n\t\tmargin-left: 3px;\r\n\t\tmargin-right: 3px;\r\n\t}\r\n}\r\n\r\n// Editor\r\n.footnote-reference {\r\n\t.wp-block-post-content & {\r\n\t\ttext-decoration: underline;\r\n\t\ttext-decoration-style: dotted;\r\n\t\ttext-decoration-color: var(--wp--preset--color--primary);\r\n\t\ttext-decoration-thickness: 2px;\r\n\t\ttext-underline-offset: 2px;\r\n\t}\r\n}\r\n\r\n.popover_footnote_field {\r\n\t.components-popover__content {\r\n\t\tpadding: 10px !important;\r\n\t\tmin-width: 500px;\r\n\t}\r\n\t.popover_footnote_field_buttons {\r\n\t\tdisplay: flex;\r\n\t\tjustify-content: flex-end;\r\n\t\tgap: 10px;\r\n\t\tmargin-top: 10px;\r\n\r\n\t\tbutton.is-destructive {\r\n\t\t\tbackground-color: #cc1818 !important;\r\n\t\t\tcolor: #fff !important;\r\n\t\t}\r\n\r\n\t\tbutton.is-primary {\r\n\t\t\tbackground-color: var(--wp--preset--color--primary) !important;\r\n\t\t\tcolor: #fff !important;\r\n\t\t}\r\n\t}\r\n}\r\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.css","mappings":";;;AAAA;CACC,6BAA6B;AAC9B;AACA;CACC,iCAAiC;CACjC,kBAAkB;CAClB,YAAY;;CAEZ;EACC,mDAAmD;EACnD,WAAW;EACX,WAAW;EACX,YAAY;EACZ,kBAAkB;EAClB,gCAAgC;EAChC,oBAAoB;EACpB,uBAAuB;EACvB,mBAAmB;EACnB,0BAA0B;EAC1B,gBAAgB;EAChB,gBAAgB;EAChB,iBAAiB;CAClB;AACD;;AAEA;;CAEC;EACC,0BAA0B;EAC1B,6BAA6B;EAC7B,wDAAwD;EACxD,8BAA8B;EAC9B,0BAA0B;CAC3B;AACD;;AAEA;CACC;EACC,wBAAwB;EACxB,gBAAgB;CACjB;CACA;EACC,aAAa;EACb,yBAAyB;EACzB,SAAS;EACT,gBAAgB;;EAEhB;GACC,oCAAoC;GACpC,sBAAsB;EACvB;;EAEA;GACC,8DAA8D;GAC9D,sBAAsB;EACvB;CACD;AACD;;;;;ACzDA;CACC,yBAAyB;AAC1B","sources":["webpack:///./src/formats/footnote.css","webpack:///./src/formats/uppercased-small-title.css"],"sourcesContent":["body {\r\n\tcounter-reset: footnote-index;\r\n}\r\n.footnote-reference {\r\n\tcounter-increment: footnote-index;\r\n\tposition: relative;\r\n\tcolor: unset;\r\n\r\n\t&::after {\r\n\t\tbackground-color: var(--wp--preset--color--primary);\r\n\t\tcolor: #fff;\r\n\t\twidth: 22px;\r\n\t\theight: 22px;\r\n\t\tborder-radius: 50%;\r\n\t\tcontent: counter(footnote-index);\r\n\t\tdisplay: inline-flex;\r\n\t\tjustify-content: center;\r\n\t\talign-items: center;\r\n\t\tfont-size: 11px !important;\r\n\t\tfont-weight: 600;\r\n\t\tmargin-left: 3px;\r\n\t\tmargin-right: 3px;\r\n\t}\r\n}\r\n\r\n// Editor\r\n.footnote-reference {\r\n\t.wp-block-post-content & {\r\n\t\ttext-decoration: underline;\r\n\t\ttext-decoration-style: dotted;\r\n\t\ttext-decoration-color: var(--wp--preset--color--primary);\r\n\t\ttext-decoration-thickness: 2px;\r\n\t\ttext-underline-offset: 2px;\r\n\t}\r\n}\r\n\r\n.popover_footnote_field {\r\n\t.components-popover__content {\r\n\t\tpadding: 10px !important;\r\n\t\tmin-width: 500px;\r\n\t}\r\n\t.popover_footnote_field_buttons {\r\n\t\tdisplay: flex;\r\n\t\tjustify-content: flex-end;\r\n\t\tgap: 10px;\r\n\t\tmargin-top: 10px;\r\n\r\n\t\tbutton.is-destructive {\r\n\t\t\tbackground-color: #cc1818 !important;\r\n\t\t\tcolor: #fff !important;\r\n\t\t}\r\n\r\n\t\tbutton.is-primary {\r\n\t\t\tbackground-color: var(--wp--preset--color--primary) !important;\r\n\t\t\tcolor: #fff !important;\r\n\t\t}\r\n\t}\r\n}\r\n",".uppercased-small-title {\r\n\ttext-transform: uppercase;\r\n}\r\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/plugins/carhop-format-types/build/index.js b/plugins/carhop-format-types/build/index.js index 453caf8..286419f 100644 --- a/plugins/carhop-format-types/build/index.js +++ b/plugins/carhop-format-types/build/index.js @@ -33,16 +33,245 @@ const customPostType = /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODUL /***/ }), -/***/ "./src/footnote.css": -/*!**************************!*\ - !*** ./src/footnote.css ***! - \**************************/ +/***/ "./node_modules/@wordpress/icons/build-module/library/text-color.js": +/*!**************************************************************************!*\ + !*** ./node_modules/@wordpress/icons/build-module/library/text-color.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_primitives__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/primitives */ "@wordpress/primitives"); +/* harmony import */ var _wordpress_primitives__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__); +/** + * WordPress dependencies + */ + + +const textColor = /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_0__.SVG, { + xmlns: "http://www.w3.org/2000/svg", + viewBox: "0 0 24 24", + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_1__.jsx)(_wordpress_primitives__WEBPACK_IMPORTED_MODULE_0__.Path, { + d: "M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z" + }) +}); +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (textColor); +//# sourceMappingURL=text-color.js.map + +/***/ }), + +/***/ "./src/formats/footnote.css": +/*!**********************************!*\ + !*** ./src/formats/footnote.css ***! + \**********************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); // extracted by mini-css-extract-plugin +/***/ }), + +/***/ "./src/formats/footnote.js": +/*!*********************************!*\ + !*** ./src/formats/footnote.js ***! + \*********************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/rich-text */ "@wordpress/rich-text"); +/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/custom-post-type.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_4__); +/* 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__); +/* harmony import */ var _footnote_css__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./footnote.css */ "./src/formats/footnote.css"); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__); + + + + + + + + + +const formatName = "carhop-format/footnote"; +const FootnoteFormatButton = props => { + const { + isActive, + value, + onChange + } = props; + const [isPopoverOpen, setIsPopoverOpen] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_4__.useState)(false); + + // Vérifier si on est dans un article (post type 'post') + const postType = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => { + return select("core/editor")?.getCurrentPostType(); + }, []); + + // Ne pas afficher le bouton si ce n'est pas un article + if (postType !== "articles") { + return null; + } + const activeFormat = (0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.getActiveFormats)(value).filter(format => format.type === formatName)[0]; + function handleFootnoteContentChange(value) { + setFormat(value); + } + function removeFormat() { + setIsPopoverOpen(false); + onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.toggleFormat)(value, { + type: formatName + })); + } + function setFormat(footnoteContent) { + onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, { + type: formatName, + attributes: { + dataFootnoteContent: footnoteContent + } + })); + } + return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.Fragment, { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.BlockControls, { + children: [isPopoverOpen && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Popover, { + onClose: () => setIsPopoverOpen(false), + className: "popover_footnote_field", + children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.TextareaControl, { + __nextHasNoMarginBottom: true, + __next40pxDefaultSize: true, + label: "Note de bas de page", + value: activeFormat?.attributes?.dataFootnoteContent || "", + onChange: handleFootnoteContentChange + }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)("div", { + className: "popover_footnote_field_buttons", + children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, { + variant: "primary", + onClick: () => setIsPopoverOpen(false), + children: "Ok" + }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, { + isDestructive: true, + onClick: () => removeFormat(), + children: "Supprimer" + })] + })] + }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarGroup, { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarButton, { + isActive: isActive, + icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__["default"], + isPressed: isActive, + label: !isActive ? "Ajouter une note de bas de page" : "Éditer la note de bas de page", + onClick: () => setIsPopoverOpen(true) + }) + })] + }) + }); +}; +(0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.registerFormatType)(formatName, { + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Notes de bas de page", "carhop-format-types"), + tagName: "a", + attributes: { + dataFootnoteContent: "data-footnote-content" + }, + className: "footnote-reference", + edit: FootnoteFormatButton +}); + +/***/ }), + +/***/ "./src/formats/uppercased-small-title.css": +/*!************************************************!*\ + !*** ./src/formats/uppercased-small-title.css ***! + \************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "./src/formats/uppercased-small-title.js": +/*!***********************************************!*\ + !*** ./src/formats/uppercased-small-title.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/rich-text */ "@wordpress/rich-text"); +/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/text-color.js"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_4__); +/* harmony import */ var _uppercased_small_title_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./uppercased-small-title.css */ "./src/formats/uppercased-small-title.css"); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); +/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__); + + + + + + + + +const formatName = "carhop-format/uppercased-small-title"; +const UppercasedSmallTitleFormatButton = props => { + const { + isActive, + value, + onChange + } = props; + function toggleUppercasedSmallTitle() { + onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.toggleFormat)(value, { + type: formatName + })); + } + + // Vérifier si on est dans un article (post type 'post') + const postType = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_4__.useSelect)(select => { + return select("core/editor")?.getCurrentPostType(); + }, []); + + // Ne pas afficher le bouton si ce n'est pas un article + if (postType !== "page") { + return null; + } + return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.BlockControls, { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarGroup, { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarButton, { + isActive: isActive, + icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__["default"], + title: !isActive ? "Petit titre en majuscules" : "Retirer Petit titre en majuscules", + onClick: toggleUppercasedSmallTitle + }) + }) + }); +}; +(0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.registerFormatType)(formatName, { + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Petit titre en majuscules", "carhop-format-types"), + tagName: "span", + className: "uppercased-small-title", + edit: UppercasedSmallTitleFormatButton +}); + /***/ }), /***/ "@wordpress/block-editor": @@ -65,6 +294,16 @@ module.exports = window["wp"]["components"]; /***/ }), +/***/ "@wordpress/data": +/*!******************************!*\ + !*** external ["wp","data"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["data"]; + +/***/ }), + /***/ "@wordpress/element": /*!*********************************!*\ !*** external ["wp","element"] ***! @@ -190,98 +429,17 @@ var __webpack_exports__ = {}; !*** ./src/index.js ***! \**********************/ __webpack_require__.r(__webpack_exports__); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/rich-text */ "@wordpress/rich-text"); -/* harmony import */ var _wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/icons */ "./node_modules/@wordpress/icons/build-module/library/custom-post-type.js"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_4__); -/* harmony import */ var _footnote_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./footnote.css */ "./src/footnote.css"); -/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); -/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__); +/* harmony import */ var _formats_footnote_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./formats/footnote.js */ "./src/formats/footnote.js"); +/* harmony import */ var _formats_uppercased_small_title_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./formats/uppercased-small-title.js */ "./src/formats/uppercased-small-title.js"); +/** + * Carhop Format Types + * + * Point d'entrée principal qui importe tous les format types personnalisés + */ + +// Import all format types - - - - - - -const formatName = "carhop-format/footnote"; -const FootnoteFormatButton = props => { - const { - isActive, - value, - onChange - } = props; - const [isPopoverOpen, setIsPopoverOpen] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_4__.useState)(false); - const activeFormat = (0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.getActiveFormats)(value).filter(format => format.type === formatName)[0]; - function handleFootnoteContentChange(value) { - setFormat(value); - } - function removeFormat() { - setIsPopoverOpen(false); - onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.toggleFormat)(value, { - type: formatName - })); - } - function setFormat(footnoteContent) { - onChange((0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.applyFormat)(value, { - type: formatName, - attributes: { - dataFootnoteContent: footnoteContent - } - })); - } - return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.Fragment, { - children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.BlockControls, { - children: [isPopoverOpen && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Popover, { - onClose: () => setIsPopoverOpen(false), - className: "popover_footnote_field", - children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.TextareaControl, { - __nextHasNoMarginBottom: true, - __next40pxDefaultSize: true, - label: "Note de bas de page", - value: activeFormat?.attributes?.dataFootnoteContent || "", - onChange: handleFootnoteContentChange - }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("div", { - className: "popover_footnote_field_buttons", - children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, { - variant: "primary", - onClick: () => setIsPopoverOpen(false), - children: "Ok" - }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.Button, { - isDestructive: true, - onClick: () => removeFormat(), - children: "Supprimer" - })] - })] - }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarGroup, { - children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToolbarButton, { - isActive: isActive, - icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_7__["default"], - isPressed: isActive, - label: !isActive ? "Ajouter une note de bas de page" : "Éditer la note de bas de page", - onClick: () => setIsPopoverOpen(true) - }) - })] - }) - }); -}; -(0,_wordpress_rich_text__WEBPACK_IMPORTED_MODULE_1__.registerFormatType)(formatName, { - title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Notes de bas de page", "carhop-format-types"), - tagName: "a", - attributes: { - dataFootnoteContent: "data-footnote-content" - }, - className: "footnote-reference", - edit: FootnoteFormatButton -}); })(); /******/ })() diff --git a/plugins/carhop-format-types/build/index.js.map b/plugins/carhop-format-types/build/index.js.map index 610b966..89cc17b 100644 --- a/plugins/carhop-format-types/build/index.js.map +++ b/plugins/carhop-format-types/build/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACkD;AACF;AAChD,oCAAoC,sDAAI,CAAC,sDAAG;AAC5C;AACA;AACA,yBAAyB,sDAAI,CAAC,uDAAI;AAClC;AACA,GAAG;AACH,CAAC;AACD,iEAAe,cAAc,EAAC;AAC9B;;;;;;;;;;;ACbA;;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;;;;;;;;;;ACNqC;AACkE;AAEL;AACiB;AAE1D;AACX;AAEtB;AAAA;AAExB,MAAMuB,UAAU,GAAG,wBAAwB;AAE3C,MAAMC,oBAAoB,GAAIC,KAAK,IAAK;EACvC,MAAM;IAAEC,QAAQ;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAGH,KAAK;EAC3C,MAAM,CAACI,aAAa,EAAEC,gBAAgB,CAAC,GAAGd,4DAAQ,CAAC,KAAK,CAAC;EAEzD,MAAMe,YAAY,GAAG3B,sEAAgB,CAACuB,KAAK,CAAC,CAACK,MAA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Y,CAAC,CAAE;YAAAI,QAAA,EAAC;UAErD,CAAQ,CAAC;QAAA,CACL,CAAC;MAAA,CACE,CACT,eAEDvB,sDAAA,CAACT,+DAAY;QAAAgC,QAAA,eACZvB,sDAAA,CAACR,gEAAa;UACbgB,QAAQ,EAAEA,QAAS;UACnBwB,IAAI,EAAEnC,wDAAe;UACrBoC,SAAS,EAAEzB,QAAS;UACpBoB,KAAK,EACJ,CAACpB,QAAQ,GACN,iCAAiC,GACjC,+BACH;UACDsB,OAAO,EAAEA,CAAA,KAAMlB,gBAAgB,CAAC,IAAI;QAAE,CACtC;MAAC,CACW,CAAC;IAAA,CACD;EAAC,CACf,CAAC;AAEL,CAAC;AAED7B,wEAAkB,CAACsB,UAAU,EAAE;EAC9B6B,KAAK,EAAEpD,mDAAE,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;EACxDqD,OAAO,EAAE,GAAG;EACZd,UAAU,EAAE;IACXC,mBAAmB,EAAE;EACtB,CAAC;EACDG,SAAS,EAAE,oBAAoB;EAC/BW,IAAI,EAAE9B;AACP,CAAC,CAAC,C","sources":["webpack:///./node_modules/@wordpress/icons/build-module/library/custom-post-type.js","webpack:///./src/footnote.css?0d32","webpack:///external window [\"wp\",\"blockEditor\"]","webpack:///external window [\"wp\",\"components\"]","webpack:///external window [\"wp\",\"element\"]","webpack:///external window [\"wp\",\"i18n\"]","webpack:///external window [\"wp\",\"primitives\"]","webpack:///external window [\"wp\",\"richText\"]","webpack:///external window \"ReactJSXRuntime\"","webpack:///webpack/bootstrap","webpack:///webpack/runtime/compat get default export","webpack:///webpack/runtime/define property getters","webpack:///webpack/runtime/hasOwnProperty shorthand","webpack:///webpack/runtime/make namespace object","webpack:///./src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/primitives';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst customPostType = /*#__PURE__*/_jsx(SVG, {\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 24 24\",\n children: /*#__PURE__*/_jsx(Path, {\n d: \"M4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4zm.8-4l.7.7 2-2V12h1V9.2l2 2 .7-.7-2-2H12v-1H9.2l2-2-.7-.7-2 2V4h-1v2.8l-2-2-.7.7 2 2H4v1h2.8l-2 2z\"\n })\n});\nexport default customPostType;\n//# sourceMappingURL=custom-post-type.js.map","// extracted by mini-css-extract-plugin\nexport {};","module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"primitives\"];","module.exports = window[\"wp\"][\"richText\"];","module.exports = window[\"ReactJSXRuntime\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { __ } from \"@wordpress/i18n\";\r\nimport { registerFormatType, toggleFormat, applyFormat, getActiveFormats } from \"@wordpress/rich-text\";\r\n\r\nimport { BlockControls, __experimentalLinkControl as LinkControl } from \"@wordpress/block-editor\";\r\nimport { Popover, ToolbarGroup, ToolbarButton, TextControl, TextareaControl, Button } from \"@wordpress/components\";\r\n\r\nimport { trash, customPostType } from \"@wordpress/icons\";\r\nimport { useState } from \"@wordpress/element\";\r\n\r\nimport \"./footnote.css\";\r\n\r\nconst formatName = \"carhop-format/footnote\";\r\n\r\nconst FootnoteFormatButton = (props) => {\r\n\tconst { isActive, value, onChange } = props;\r\n\tconst [isPopoverOpen, setIsPopoverOpen] = useState(false);\r\n\r\n\tconst activeFormat = getActiveFormats(value).filter((format) => format.type === formatName)[0];\r\n\r\n\tfunction handleFootnoteContentChange(value) {\r\n\t\tsetFormat(value);\r\n\t}\r\n\r\n\tfunction removeFormat() {\r\n\t\tsetIsPopoverOpen(false);\r\n\t\tonChange(\r\n\t\t\ttoggleFormat(value, {\r\n\t\t\t\ttype: formatName,\r\n\t\t\t})\r\n\t\t);\r\n\t}\r\n\tfunction setFormat(footnoteContent) {\r\n\t\tonChange(\r\n\t\t\tapplyFormat(value, {\r\n\t\t\t\ttype: formatName,\r\n\t\t\t\tattributes: {\r\n\t\t\t\t\tdataFootnoteContent: footnoteContent,\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t);\r\n\t}\r\n\r\n\treturn (\r\n\t\t<>\r\n\t\t\t\r\n\t\t\t\t{isPopoverOpen && (\r\n\t\t\t\t\t setIsPopoverOpen(false)}\r\n\t\t\t\t\t\tclassName='popover_footnote_field'>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t
\r\n\t\t\t\t\t\t\t setIsPopoverOpen(false)}>\r\n\t\t\t\t\t\t\t\tOk\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t
\r\n\t\t\t\t\t\r\n\t\t\t\t)}\r\n\r\n\t\t\t\t\r\n\t\t\t\t\t setIsPopoverOpen(true)}\r\n\t\t\t\t\t/>\r\n\t\t\t\t\r\n\t\t\t
\r\n\t\t\r\n\t);\r\n};\r\n\r\nregisterFormatType(formatName, {\r\n\ttitle: __(\"Notes de bas de page\", \"carhop-format-types\"),\r\n\ttagName: \"a\",\r\n\tattributes: {\r\n\t\tdataFootnoteContent: \"data-footnote-content\",\r\n\t},\r\n\tclassName: \"footnote-reference\",\r\n\tedit: FootnoteFormatButton,\r\n});\r\n"],"names":["__","registerFormatType","toggleFormat","applyFormat","getActiveFormats","BlockControls","__experimentalLinkControl","LinkControl","Popover","ToolbarGroup","ToolbarButton","TextControl","TextareaControl","Button","trash","customPostType","useState","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","formatName","FootnoteFormatButton","props","isActive","value","onChange","isPopoverOpen","setIsPopoverOpen","activeFormat","filter","format","type","handleFootnoteContentChange","setFormat","removeFormat","footnoteContent","attributes","dataFootnoteContent","children","onClose","className","__nextHasNoMarginBottom","__next40pxDefaultSize","label","variant","onClick","isDestructive","icon","isPressed","title","tagName","edit"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACkD;AACF;AAChD,oCAAoC,sDAAI,CAAC,sDAAG;AAC5C;AACA;AACA,yBAAyB,sDAAI,CAAC,uDAAI;AAClC;AACA,GAAG;AACH,CAAC;AACD,iEAAe,cAAc,EAAC;AAC9B;;;;;;;;;;;;;;;;;;ACbA;AACA;AACA;AACkD;AACF;AAChD,+BAA+B,sDAAI,CAAC,sDAAG;AACvC;AACA;AACA,yBAAyB,sDAAI,CAAC,uDAAI;AAClC;AACA,GAAG;AACH,CAAC;AACD,iEAAe,SAAS,EAAC;A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ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;ACNA;AACA;AACA;AACA;AACA;;AAEA;AAC+B","sources":["webpack:///./node_modules/@wordpress/icons/build-module/library/custom-post-type.js","webpack:///./node_modules/@wordpress/icons/build-module/library/text-color.js","webpack:///./src/formats/footnote.css?cafd","webpack:///./src/formats/footnote.js","webpack:///./src/formats/uppercased-small-title.css?7a1c","webpack:///./src/formats/uppercased-small-title.js","webpack:///external window [\"wp\",\"blockEditor\"]","webpack:///external window [\"wp\",\"components\"]","webpack:///external window [\"wp\",\"data\"]","webpack:///external window [\"wp\",\"element\"]","webpack:///external window [\"wp\",\"i18n\"]","webpack:///external window [\"wp\",\"primitives\"]","webpack:///external window [\"wp\",\"richText\"]","webpack:///external window \"ReactJSXRuntime\"","webpack:///webpack/bootstrap","webpack:///webpack/runtime/compat get default export","webpack:///webpack/runtime/define property getters","webpack:///webpack/runtime/hasOwnProperty shorthand","webpack:///webpack/runtime/make namespace object","webpack:///./src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/primitives';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst customPostType = /*#__PURE__*/_jsx(SVG, {\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 24 24\",\n children: /*#__PURE__*/_jsx(Path, {\n d: \"M4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4zm.8-4l.7.7 2-2V12h1V9.2l2 2 .7-.7-2-2H12v-1H9.2l2-2-.7-.7-2 2V4h-1v2.8l-2-2-.7.7 2 2H4v1h2.8l-2 2z\"\n })\n});\nexport default customPostType;\n//# sourceMappingURL=custom-post-type.js.map","/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/primitives';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst textColor = /*#__PURE__*/_jsx(SVG, {\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 24 24\",\n children: /*#__PURE__*/_jsx(Path, {\n d: \"M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z\"\n })\n});\nexport default textColor;\n//# sourceMappingURL=text-color.js.map","// extracted by mini-css-extract-plugin\nexport {};","import { __ } from \"@wordpress/i18n\";\r\nimport { registerFormatType, toggleFormat, applyFormat, getActiveFormats } from \"@wordpress/rich-text\";\r\n\r\nimport { BlockControls, __experimentalLinkControl as LinkControl } from \"@wordpress/block-editor\";\r\nimport { Popover, ToolbarGroup, ToolbarButton, TextControl, TextareaControl, Button } from \"@wordpress/components\";\r\n\r\nimport { trash, customPostType } from \"@wordpress/icons\";\r\nimport { useState } from \"@wordpress/element\";\r\nimport { useSelect } from \"@wordpress/data\";\r\n\r\nimport \"./footnote.css\";\r\n\r\nconst formatName = \"carhop-format/footnote\";\r\n\r\nconst FootnoteFormatButton = (props) => {\r\n\tconst { isActive, value, onChange } = props;\r\n\tconst [isPopoverOpen, setIsPopoverOpen] = useState(false);\r\n\r\n\t// Vérifier si on est dans un article (post type 'post')\r\n\tconst postType = useSelect((select) => {\r\n\t\treturn select(\"core/editor\")?.getCurrentPostType();\r\n\t}, []);\r\n\r\n\t// Ne pas afficher le bouton si ce n'est pas un article\r\n\tif (postType !== \"articles\") {\r\n\t\treturn null;\r\n\t}\r\n\r\n\tconst activeFormat = getActiveFormats(value).filter((format) => format.type === formatName)[0];\r\n\r\n\tfunction handleFootnoteContentChange(value) {\r\n\t\tsetFormat(value);\r\n\t}\r\n\r\n\tfunction removeFormat() {\r\n\t\tsetIsPopoverOpen(false);\r\n\t\tonChange(\r\n\t\t\ttoggleFormat(value, {\r\n\t\t\t\ttype: formatName,\r\n\t\t\t})\r\n\t\t);\r\n\t}\r\n\tfunction setFormat(footnoteContent) {\r\n\t\tonChange(\r\n\t\t\tapplyFormat(value, {\r\n\t\t\t\ttype: formatName,\r\n\t\t\t\tattributes: {\r\n\t\t\t\t\tdataFootnoteContent: footnoteContent,\r\n\t\t\t\t},\r\n\t\t\t})\r\n\t\t);\r\n\t}\r\n\r\n\treturn (\r\n\t\t<>\r\n\t\t\t\r\n\t\t\t\t{isPopoverOpen && (\r\n\t\t\t\t\t setIsPopoverOpen(false)}\r\n\t\t\t\t\t\tclassName='popover_footnote_field'>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t
\r\n\t\t\t\t\t\t\t setIsPopoverOpen(false)}>\r\n\t\t\t\t\t\t\t\tOk\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t
\r\n\t\t\t\t\t\r\n\t\t\t\t)}\r\n\r\n\t\t\t\t\r\n\t\t\t\t\t setIsPopoverOpen(true)}\r\n\t\t\t\t\t/>\r\n\t\t\t\t\r\n\t\t\t
\r\n\t\t\r\n\t);\r\n};\r\n\r\nregisterFormatType(formatName, {\r\n\ttitle: __(\"Notes de bas de page\", \"carhop-format-types\"),\r\n\ttagName: \"a\",\r\n\tattributes: {\r\n\t\tdataFootnoteContent: \"data-footnote-content\",\r\n\t},\r\n\tclassName: \"footnote-reference\",\r\n\tedit: FootnoteFormatButton,\r\n});\r\n","// extracted by mini-css-extract-plugin\nexport {};","import { __ } from \"@wordpress/i18n\";\r\nimport { registerFormatType, toggleFormat } from \"@wordpress/rich-text\";\r\n\r\nimport { RichTextToolbarButton, BlockControls } from \"@wordpress/block-editor\";\r\nimport { ToolbarGroup, ToolbarButton } from \"@wordpress/components\";\r\n\r\nimport { textColor } from \"@wordpress/icons\";\r\nimport { useSelect } from \"@wordpress/data\";\r\n\r\nimport \"./uppercased-small-title.css\";\r\n\r\nconst formatName = \"carhop-format/uppercased-small-title\";\r\n\r\nconst UppercasedSmallTitleFormatButton = (props) => {\r\n\tconst { isActive, value, onChange } = props;\r\n\r\n\tfunction toggleUppercasedSmallTitle() {\r\n\t\tonChange(\r\n\t\t\ttoggleFormat(value, {\r\n\t\t\t\ttype: formatName,\r\n\t\t\t})\r\n\t\t);\r\n\t}\r\n\r\n\t// Vérifier si on est dans un article (post type 'post')\r\n\tconst postType = useSelect((select) => {\r\n\t\treturn select(\"core/editor\")?.getCurrentPostType();\r\n\t}, []);\r\n\r\n\t// Ne pas afficher le bouton si ce n'est pas un article\r\n\tif (postType !== \"page\") {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn (\r\n\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\r\n\t);\r\n};\r\n\r\nregisterFormatType(formatName, {\r\n\ttitle: __(\"Petit titre en majuscules\", \"carhop-format-types\"),\r\n\ttagName: \"span\",\r\n\tclassName: \"uppercased-small-title\",\r\n\tedit: UppercasedSmallTitleFormatButton,\r\n});\r\n","module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"primitives\"];","module.exports = window[\"wp\"][\"richText\"];","module.exports = window[\"ReactJSXRuntime\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\r\n * Carhop Format Types\r\n *\r\n * Point d'entrée principal qui importe tous les format types personnalisés\r\n */\r\n\r\n// Import all format types\r\nimport \"./formats/footnote.js\";\r\nimport \"./formats/uppercased-small-title.js\";\r\n"],"names":["__","registerFormatType","toggleFormat","applyFormat","getActiveFormats","BlockControls","__experimentalLinkControl","LinkControl","Popover","ToolbarGroup","ToolbarButton","TextControl","TextareaControl","Button","trash","customPostType","useState","useSelect","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","formatName","FootnoteFormatButton","props","isActive","value","onChange","isPopoverOpen","setIsPopoverOpen","postType","select","getCurrentPostType","activeFormat","filter","format","type","handleFootnoteContentChange","setFormat","removeFormat","footnoteContent","attributes","dataFootnoteContent","children","onClose","className","__nextHasNoMarginBottom","__next40pxDefaultSize","label","variant","onClick","isDestructive","icon","isPressed","title","tagName","edit","RichTextToolbarButton","textColor","UppercasedSmallTitleFormatButton","toggleUppercasedSmallTitle"],"sourceRoot":""} \ No newline at end of file diff --git a/plugins/carhop-format-types/carhop-format-types.php b/plugins/carhop-format-types/carhop-format-types.php index 18df0da..88c3c5e 100644 --- a/plugins/carhop-format-types/carhop-format-types.php +++ b/plugins/carhop-format-types/carhop-format-types.php @@ -25,6 +25,7 @@ add_action('enqueue_block_editor_assets', 'carhop_format_types_enqueue_assets'); function carhop_format_types_enqueue_front_assets() { - wp_enqueue_style('carhop-format-types-style', plugins_url('src/footnote.css', __FILE__)); + wp_enqueue_style('carhop-format-types-footnote-style', plugins_url('src/formats/footnote.css', __FILE__)); + wp_enqueue_style('carhop-format-types-uppercased-small-title-style', plugins_url('src/formats/uppercased-small-title.css', __FILE__)); } add_action('wp_enqueue_scripts', 'carhop_format_types_enqueue_front_assets'); diff --git a/plugins/carhop-format-types/src/formats/footnote.js b/plugins/carhop-format-types/src/formats/footnote.js new file mode 100644 index 0000000..8a6931a --- /dev/null +++ b/plugins/carhop-format-types/src/formats/footnote.js @@ -0,0 +1,107 @@ +import { __ } from "@wordpress/i18n"; +import { registerFormatType, toggleFormat, applyFormat, getActiveFormats } from "@wordpress/rich-text"; + +import { BlockControls, __experimentalLinkControl as LinkControl } from "@wordpress/block-editor"; +import { Popover, ToolbarGroup, ToolbarButton, TextControl, TextareaControl, Button } from "@wordpress/components"; + +import { trash, customPostType } from "@wordpress/icons"; +import { useState } from "@wordpress/element"; +import { useSelect } from "@wordpress/data"; + +import "./footnote.css"; + +const formatName = "carhop-format/footnote"; + +const FootnoteFormatButton = (props) => { + const { isActive, value, onChange } = props; + const [isPopoverOpen, setIsPopoverOpen] = useState(false); + + // Vérifier si on est dans un article (post type 'post') + const postType = useSelect((select) => { + return select("core/editor")?.getCurrentPostType(); + }, []); + + // Ne pas afficher le bouton si ce n'est pas un article + if (postType !== "articles") { + return null; + } + + const activeFormat = getActiveFormats(value).filter((format) => format.type === formatName)[0]; + + function handleFootnoteContentChange(value) { + setFormat(value); + } + + function removeFormat() { + setIsPopoverOpen(false); + onChange( + toggleFormat(value, { + type: formatName, + }) + ); + } + function setFormat(footnoteContent) { + onChange( + applyFormat(value, { + type: formatName, + attributes: { + dataFootnoteContent: footnoteContent, + }, + }) + ); + } + + return ( + <> + + {isPopoverOpen && ( + setIsPopoverOpen(false)} + className='popover_footnote_field'> + +
+ + +
+
+ )} + + + setIsPopoverOpen(true)} + /> + +
+ + ); +}; + +registerFormatType(formatName, { + title: __("Notes de bas de page", "carhop-format-types"), + tagName: "a", + attributes: { + dataFootnoteContent: "data-footnote-content", + }, + className: "footnote-reference", + edit: FootnoteFormatButton, +}); diff --git a/plugins/carhop-format-types/src/formats/uppercased-small-title.css b/plugins/carhop-format-types/src/formats/uppercased-small-title.css new file mode 100644 index 0000000..7afa7f9 --- /dev/null +++ b/plugins/carhop-format-types/src/formats/uppercased-small-title.css @@ -0,0 +1,3 @@ +.uppercased-small-title { + text-transform: uppercase; +} diff --git a/plugins/carhop-format-types/src/formats/uppercased-small-title.js b/plugins/carhop-format-types/src/formats/uppercased-small-title.js new file mode 100644 index 0000000..b94de0f --- /dev/null +++ b/plugins/carhop-format-types/src/formats/uppercased-small-title.js @@ -0,0 +1,58 @@ +import { __ } from "@wordpress/i18n"; +import { registerFormatType, toggleFormat } from "@wordpress/rich-text"; + +import { RichTextToolbarButton, BlockControls } from "@wordpress/block-editor"; +import { ToolbarGroup, ToolbarButton } from "@wordpress/components"; + +import { textColor } from "@wordpress/icons"; +import { useSelect } from "@wordpress/data"; + +import "./uppercased-small-title.css"; + +const formatName = "carhop-format/uppercased-small-title"; + +const UppercasedSmallTitleFormatButton = (props) => { + const { isActive, value, onChange } = props; + + function toggleUppercasedSmallTitle() { + onChange( + toggleFormat(value, { + type: formatName, + }) + ); + } + + // Vérifier si on est dans un article (post type 'post') + const postType = useSelect((select) => { + return select("core/editor")?.getCurrentPostType(); + }, []); + + // Ne pas afficher le bouton si ce n'est pas un article + if (postType !== "page") { + return null; + } + + return ( + + + + + + ); +}; + +registerFormatType(formatName, { + title: __("Petit titre en majuscules", "carhop-format-types"), + tagName: "span", + className: "uppercased-small-title", + edit: UppercasedSmallTitleFormatButton, +}); diff --git a/plugins/carhop-format-types/src/index.js b/plugins/carhop-format-types/src/index.js index e548d1c..d4713bc 100644 --- a/plugins/carhop-format-types/src/index.js +++ b/plugins/carhop-format-types/src/index.js @@ -1,96 +1,9 @@ -import { __ } from "@wordpress/i18n"; -import { registerFormatType, toggleFormat, applyFormat, getActiveFormats } from "@wordpress/rich-text"; +/** + * Carhop Format Types + * + * Point d'entrée principal qui importe tous les format types personnalisés + */ -import { BlockControls, __experimentalLinkControl as LinkControl } from "@wordpress/block-editor"; -import { Popover, ToolbarGroup, ToolbarButton, TextControl, TextareaControl, Button } from "@wordpress/components"; - -import { trash, customPostType } from "@wordpress/icons"; -import { useState } from "@wordpress/element"; - -import "./footnote.css"; - -const formatName = "carhop-format/footnote"; - -const FootnoteFormatButton = (props) => { - const { isActive, value, onChange } = props; - const [isPopoverOpen, setIsPopoverOpen] = useState(false); - - const activeFormat = getActiveFormats(value).filter((format) => format.type === formatName)[0]; - - function handleFootnoteContentChange(value) { - setFormat(value); - } - - function removeFormat() { - setIsPopoverOpen(false); - onChange( - toggleFormat(value, { - type: formatName, - }) - ); - } - function setFormat(footnoteContent) { - onChange( - applyFormat(value, { - type: formatName, - attributes: { - dataFootnoteContent: footnoteContent, - }, - }) - ); - } - - return ( - <> - - {isPopoverOpen && ( - setIsPopoverOpen(false)} - className='popover_footnote_field'> - -
- - -
-
- )} - - - setIsPopoverOpen(true)} - /> - -
- - ); -}; - -registerFormatType(formatName, { - title: __("Notes de bas de page", "carhop-format-types"), - tagName: "a", - attributes: { - dataFootnoteContent: "data-footnote-content", - }, - className: "footnote-reference", - edit: FootnoteFormatButton, -}); +// Import all format types +import "./formats/footnote.js"; +import "./formats/uppercased-small-title.js";