From 6f098e4881f3966f07cc9ce1edacb070a99c60be Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 28 May 2026 10:38:14 +0200 Subject: [PATCH] FEATURE Desactivating pannel for other publication thatn dynamiques papers --- .../build/index.asset.php | 2 +- .../build/index.js | 58 ++--- .../build/index.js.map | 2 +- .../src/modification-date.js | 233 +++++++++--------- 4 files changed, 151 insertions(+), 144 deletions(-) diff --git a/plugins/dynamiques-modification-date/build/index.asset.php b/plugins/dynamiques-modification-date/build/index.asset.php index 9dcebc5..93b5f38 100644 --- a/plugins/dynamiques-modification-date/build/index.asset.php +++ b/plugins/dynamiques-modification-date/build/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '2926f9bf61acc4d0cf7e'); + array('react-jsx-runtime', 'wp-components', 'wp-data', 'wp-date', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '3c86a0bf59d03b58250c'); diff --git a/plugins/dynamiques-modification-date/build/index.js b/plugins/dynamiques-modification-date/build/index.js index c8ba552..eaac82b 100644 --- a/plugins/dynamiques-modification-date/build/index.js +++ b/plugins/dynamiques-modification-date/build/index.js @@ -19,13 +19,10 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__); -/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/date */ "@wordpress/date"); -/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_date__WEBPACK_IMPORTED_MODULE_6__); -/* 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__); - +/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/date */ "@wordpress/date"); +/* harmony import */ var _wordpress_date__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_date__WEBPACK_IMPORTED_MODULE_5__); +/* 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__); @@ -35,19 +32,26 @@ __webpack_require__.r(__webpack_exports__); const ModificationDatePanel = () => { const { - modificationDate + modificationDate, + postType } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => { const meta = select("core/editor").getEditedPostAttribute("meta"); + const postType = select("core/editor").getCurrentPostType(); return { - modificationDate: meta?.article_modification_date || "" + modificationDate: meta?.article_modification_date || "", + postType: postType }; }); + const allowedPostTypes = ["article", "revue"]; // adapte avec tes vrais slugs + if (!allowedPostTypes.includes(postType)) { + return null; + } const { editPost } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useDispatch)("core/editor"); - const settings = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.getSettings)(); + const settings = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.getSettings)(); const updateModificationDate = newDate => { - const formattedDate = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.format)("Y-m-d H:i:s", newDate); + const formattedDate = (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.format)("Y-m-d H:i:s", newDate); editPost({ meta: { article_modification_date: formattedDate @@ -63,22 +67,22 @@ const ModificationDatePanel = () => { }; // Formater la date pour l'affichage - const displayDate = modificationDate ? (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_6__.dateI18n)(settings.formats.datetime, modificationDate) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Non définie", "dynamiques-modification-date"); - return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.PluginDocumentSettingPanel, { + const displayDate = modificationDate ? (0,_wordpress_date__WEBPACK_IMPORTED_MODULE_5__.dateI18n)(settings.formats.datetime, modificationDate) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Non définie", "dynamiques-modification-date"); + return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.PluginDocumentSettingPanel, { name: "modification-date-panel", title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Dernière mise à jour du papier", "dynamiques-modification-date"), - children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { + children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", { style: { marginBottom: "12px", fontSize: "12px", color: "#757575" }, children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)("Choisissez ici la dernière date de révision de cet article", "dynamiques-modification-date") - }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { + }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", { style: { marginBottom: "16px" }, - children: modificationDate ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Dropdown, { + children: modificationDate ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Dropdown, { popoverProps: { placement: "bottom-start" }, @@ -86,7 +90,7 @@ const ModificationDatePanel = () => { renderToggle: ({ isOpen, onToggle - }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { + }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { variant: "secondary", onClick: onToggle, "aria-expanded": isOpen, @@ -100,24 +104,24 @@ const ModificationDatePanel = () => { }), renderContent: ({ onClose - }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsxs)("div", { + }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxs)("div", { style: { padding: "16px" }, - children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.DateTimePicker, { + children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.DateTimePicker, { currentDate: modificationDate, onChange: newDate => { updateModificationDate(newDate); onClose(); }, is12Hour: settings.formats.time.includes("a") - }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)("div", { + }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)("div", { style: { marginTop: "16px", display: "flex", gap: "8px" }, - children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { + children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { variant: "secondary", onClick: () => { clearModificationDate(); @@ -127,7 +131,7 @@ const ModificationDatePanel = () => { }) })] }) - }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_7__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { + }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_6__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_1__.Button, { variant: "secondary", onClick: () => updateModificationDate(new Date()), style: { @@ -187,16 +191,6 @@ module.exports = window["wp"]["editor"]; /***/ }), -/***/ "@wordpress/element": -/*!*********************************!*\ - !*** external ["wp","element"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["element"]; - -/***/ }), - /***/ "@wordpress/i18n": /*!******************************!*\ !*** external ["wp","i18n"] ***! diff --git a/plugins/dynamiques-modification-date/build/index.js.map b/plugins/dynamiques-modification-date/build/index.js.map index 71c349d..17e17cc 100644 --- a/plugins/dynamiques-modification-date/build/index.js.map +++ b/plugins/dynamiques-modification-date/build/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAoD;AACqB;AACV;AACN;AACpB;AACS;AACkB;AAAA;AAEhE,MAAMgB,qBAAqB,G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,EACT,8BACD;YAAC,CACM;UAAC,CACL,CAAC;QAAA,CACF;MACJ,CACF,CAAC,gBAEFM,sDAAA,CAACZ,yDAAM;QACN2C,OAAO,EAAC,WAAW;QACnBC,OAAO,EAAEA,CAAA,KAAMrB,sBAAsB,CAAC,IAAIoC,IAAI,CAAC,CAAC,CAAE;QAClD1B,KAAK,EAAE;UACNY,SAAS,EAAE,MAAM;UACjBC,KAAK,EAAE,MAAM;UACbC,cAAc,EAAE,YAAY;UAC5BX,KAAK,EAAE;QACR,CAAE;QAAAJ,QAAA,EACDL;MAAW,CACL;IACR,CACG,CAAC;EAAA,CACqB,CAAC;AAE/B,CAAC;AAED5B,kEAAc,CAAC,yBAAyB,EAAE;EACzC6D,MAAM,EAAE7C;AACT,CAAC,CAAC,C;;;;;;;;;;AC/HF,4C;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,wC;;;;;;;;;;ACAA,yC;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,yC;;;;;;;;;;ACAA,2C;;;;;;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,E;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E","sources":["webpack://dynamiques-modification-date/./src/modification-date.js","webpack://dynamiques-modification-date/external window [\"wp\",\"components\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"data\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"date\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"editor\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"element\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"i18n\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"plugins\"]","webpack://dynamiques-modification-date/external window \"ReactJSXRuntime\"","webpack://dynamiques-modification-date/webpack/bootstrap","webpack://dynamiques-modification-date/webpack/runtime/compat get default export","webpack://dynamiques-modification-date/webpack/runtime/define property getters","webpack://dynamiques-modification-date/webpack/runtime/hasOwnProperty shorthand","webpack://dynamiques-modification-date/webpack/runtime/make namespace object"],"sourcesContent":["import { registerPlugin } from \"@wordpress/plugins\";\r\nimport { Button, DateTimePicker, Dropdown } from \"@wordpress/components\";\r\nimport { PluginDocumentSettingPanel } from \"@wordpress/editor\";\r\nimport { useSelect, useDispatch } from \"@wordpress/data\";\r\nimport { __ } from \"@wordpress/i18n\";\r\nimport { useState } from \"@wordpress/element\";\r\nimport { dateI18n, format, getSettings } from \"@wordpress/date\";\r\n\r\nconst ModificationDatePanel = () => {\r\n\tconst { modificationDate } = useSelect((select) => {\r\n\t\tconst meta = select(\"core/editor\").getEditedPostAttribute(\"meta\");\r\n\t\treturn {\r\n\t\t\tmodificationDate: meta?.article_modification_date || \"\",\r\n\t\t};\r\n\t});\r\n\r\n\tconst { editPost } = useDispatch(\"core/editor\");\r\n\tconst settings = getSettings();\r\n\r\n\tconst updateModificationDate = (newDate) => {\r\n\t\tconst formattedDate = format(\"Y-m-d H:i:s\", newDate);\r\n\t\teditPost({\r\n\t\t\tmeta: {\r\n\t\t\t\tarticle_modification_date: formattedDate,\r\n\t\t\t},\r\n\t\t});\r\n\t};\r\n\r\n\tconst clearModificationDate = () => {\r\n\t\teditPost({\r\n\t\t\tmeta: {\r\n\t\t\t\tarticle_modification_date: \"\",\r\n\t\t\t},\r\n\t\t});\r\n\t};\r\n\r\n\t// Formater la date pour l'affichage\r\n\tconst displayDate = modificationDate\r\n\t\t? dateI18n(settings.formats.datetime, modificationDate)\r\n\t\t: __(\"Non définie\", \"dynamiques-modification-date\");\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\t\t\"Choisissez ici la dernière date de révision de cet article\",\r\n\t\t\t\t\t\"dynamiques-modification-date\"\r\n\t\t\t\t)}\r\n\t\t\t\r\n\r\n\t\t\t
\r\n\t\t\t\t{modificationDate ? (\r\n\t\t\t\t\t (\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t{displayDate}\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t)}\r\n\t\t\t\t\t\trenderContent={({ onClose }) => (\r\n\t\t\t\t\t\t\t
\r\n\t\t\t\t\t\t\t\t {\r\n\t\t\t\t\t\t\t\t\t\tupdateModificationDate(newDate);\r\n\t\t\t\t\t\t\t\t\t\tonClose();\r\n\t\t\t\t\t\t\t\t\t}}\r\n\t\t\t\t\t\t\t\t\tis12Hour={settings.formats.time.includes(\"a\")}\r\n\t\t\t\t\t\t\t\t/>\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t {\r\n\t\t\t\t\t\t\t\t\t\t\tclearModificationDate();\r\n\t\t\t\t\t\t\t\t\t\t\tonClose();\r\n\t\t\t\t\t\t\t\t\t\t}}>\r\n\t\t\t\t\t\t\t\t\t\t{__(\r\n\t\t\t\t\t\t\t\t\t\t\t\"Effacer\",\r\n\t\t\t\t\t\t\t\t\t\t\t\"dynamiques-modification-date\"\r\n\t\t\t\t\t\t\t\t\t\t)}\r\n\t\t\t\t\t\t\t\t\t\r\n\t\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\t\t\t\t\t updateModificationDate(new Date())}\r\n\t\t\t\t\t\tstyle={{\r\n\t\t\t\t\t\t\ttextAlign: \"left\",\r\n\t\t\t\t\t\t\twidth: \"100%\",\r\n\t\t\t\t\t\t\tjustifyContent: \"flex-start\",\r\n\t\t\t\t\t\t\tcolor: \"#757575\",\r\n\t\t\t\t\t\t}}>\r\n\t\t\t\t\t\t{displayDate}\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\nregisterPlugin(\"modification-date-panel\", {\r\n\trender: ModificationDatePanel,\r\n});\r\n","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"date\"];","module.exports = window[\"wp\"][\"editor\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"plugins\"];","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};"],"names":["registerPlugin","Button","DateTimePicker","Dropdown","PluginDocumentSettingPanel","useSelect","useDispatch","__","useState","dateI18n","format","getSettings","jsx","_jsx","jsxs","_jsxs","ModificationDatePanel","modificationDate","select","meta","getEditedPostAttribute","article_modification_date","editPost","settings","updateModificationDate","newDate","formattedDate","clearModificationDate","displayDate","formats","datetime","name","title","children","style","marginBottom","fontSize","color","popoverProps","placement","contentClassName","renderToggle","isOpen","onToggle","variant","onClick","textAlign","width","justifyContent","renderContent","onClose","padding","currentDate","onChange","is12Hour","time","includes","marginTop","display","gap","Date","render"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAoD;AACqB;AACV;AACN;AACpB;AAC2B;AAAA;AAEhE,MAAMe,qBAAqB,GAAGA,CAAA,KAAM;EAClC,MAAM;IAAEC,gBAAgB;IAAEC;EAAS,CAAC,GAAGZ,0DAAS,CAAEa,MAAM,IAAK;IAC3D,MAAMC,IAAI,GAAGD,MAAM,CAAC,aAAa,CAAC,CAACE,sBAAsB,CAAC,MAAM,CAAC;IACjE,MAAMH,QAAQ,GAAGC,MAAM,CAAC,aAAa,CAAC,CAACG,kBAAkB,CAAC,CAAC;IAE3D,OAAO;MACLL,gBAAgB,EAAEG,IAAI,EAAEG,yBAAyB,IAAI,EAAE;MACvDL,QAAQ,EAAEA;IACZ,CAAC;EACH,CAAC,CAAC;EAEF,MAAMM,gBAAgB,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;EAC/C,IAAI,CAACA,gBAAgB,CAACC,QAAQ,CAACP,QAAQ,CAAC,EAAE;IACxC,OAAO,IAAI;EACb;EAEA,MAAM;IAAEQ;EAAS,CAAC,GAAGnB,4DAAW,CAAC,aAAa,CAAC;EAC/C,MAAMoB,QAAQ,GAAGhB,4DAAW,CAAC,CAAC;EAE9B,MAAMiB,sBAAsB,GAAIC,OAAO,IAAK;IAC1C,MAAMC,aAAa,GA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E;EACxC+D,MAAM,EAAEhD;AACV,CAAC,CAAC,C;;;;;;;;;;AC5IF,4C;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,wC;;;;;;;;;;ACAA,sC;;;;;;;;;;ACAA,yC;;;;;;;;;;ACAA,2C;;;;;;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,E;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E","sources":["webpack://dynamiques-modification-date/./src/modification-date.js","webpack://dynamiques-modification-date/external window [\"wp\",\"components\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"data\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"date\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"editor\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"i18n\"]","webpack://dynamiques-modification-date/external window [\"wp\",\"plugins\"]","webpack://dynamiques-modification-date/external window \"ReactJSXRuntime\"","webpack://dynamiques-modification-date/webpack/bootstrap","webpack://dynamiques-modification-date/webpack/runtime/compat get default export","webpack://dynamiques-modification-date/webpack/runtime/define property getters","webpack://dynamiques-modification-date/webpack/runtime/hasOwnProperty shorthand","webpack://dynamiques-modification-date/webpack/runtime/make namespace object"],"sourcesContent":["import { registerPlugin } from \"@wordpress/plugins\";\r\nimport { Button, DateTimePicker, Dropdown } from \"@wordpress/components\";\r\nimport { PluginDocumentSettingPanel } from \"@wordpress/editor\";\r\nimport { useSelect, useDispatch } from \"@wordpress/data\";\r\nimport { __ } from \"@wordpress/i18n\";\r\nimport { dateI18n, format, getSettings } from \"@wordpress/date\";\r\n\r\nconst ModificationDatePanel = () => {\r\n const { modificationDate, postType } = useSelect((select) => {\r\n const meta = select(\"core/editor\").getEditedPostAttribute(\"meta\");\r\n const postType = select(\"core/editor\").getCurrentPostType();\r\n\r\n return {\r\n modificationDate: meta?.article_modification_date || \"\",\r\n postType: postType,\r\n };\r\n });\r\n\r\n const allowedPostTypes = [\"article\", \"revue\"]; // adapte avec tes vrais slugs\r\n if (!allowedPostTypes.includes(postType)) {\r\n return null;\r\n }\r\n\r\n const { editPost } = useDispatch(\"core/editor\");\r\n const settings = getSettings();\r\n\r\n const updateModificationDate = (newDate) => {\r\n const formattedDate = format(\"Y-m-d H:i:s\", newDate);\r\n editPost({\r\n meta: {\r\n article_modification_date: formattedDate,\r\n },\r\n });\r\n };\r\n\r\n const clearModificationDate = () => {\r\n editPost({\r\n meta: {\r\n article_modification_date: \"\",\r\n },\r\n });\r\n };\r\n\r\n // Formater la date pour l'affichage\r\n const displayDate = modificationDate\r\n ? dateI18n(settings.formats.datetime, modificationDate)\r\n : __(\"Non définie\", \"dynamiques-modification-date\");\r\n\r\n return (\r\n \r\n \r\n {__(\r\n \"Choisissez ici la dernière date de révision de cet article\",\r\n \"dynamiques-modification-date\",\r\n )}\r\n \r\n\r\n
\r\n {modificationDate ? (\r\n (\r\n \r\n {displayDate}\r\n \r\n )}\r\n renderContent={({ onClose }) => (\r\n
\r\n {\r\n updateModificationDate(newDate);\r\n onClose();\r\n }}\r\n is12Hour={settings.formats.time.includes(\"a\")}\r\n />\r\n \r\n {\r\n clearModificationDate();\r\n onClose();\r\n }}\r\n >\r\n {__(\"Effacer\", \"dynamiques-modification-date\")}\r\n \r\n
\r\n
\r\n )}\r\n />\r\n ) : (\r\n updateModificationDate(new Date())}\r\n style={{\r\n textAlign: \"left\",\r\n width: \"100%\",\r\n justifyContent: \"flex-start\",\r\n color: \"#757575\",\r\n }}\r\n >\r\n {displayDate}\r\n \r\n )}\r\n \r\n \r\n );\r\n};\r\n\r\nregisterPlugin(\"modification-date-panel\", {\r\n render: ModificationDatePanel,\r\n});\r\n","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"date\"];","module.exports = window[\"wp\"][\"editor\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"plugins\"];","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};"],"names":["registerPlugin","Button","DateTimePicker","Dropdown","PluginDocumentSettingPanel","useSelect","useDispatch","__","dateI18n","format","getSettings","jsx","_jsx","jsxs","_jsxs","ModificationDatePanel","modificationDate","postType","select","meta","getEditedPostAttribute","getCurrentPostType","article_modification_date","allowedPostTypes","includes","editPost","settings","updateModificationDate","newDate","formattedDate","clearModificationDate","displayDate","formats","datetime","name","title","children","style","marginBottom","fontSize","color","popoverProps","placement","contentClassName","renderToggle","isOpen","onToggle","variant","onClick","textAlign","width","justifyContent","renderContent","onClose","padding","currentDate","onChange","is12Hour","time","marginTop","display","gap","Date","render"],"sourceRoot":""} \ No newline at end of file diff --git a/plugins/dynamiques-modification-date/src/modification-date.js b/plugins/dynamiques-modification-date/src/modification-date.js index 66f0300..d8b6e1d 100644 --- a/plugins/dynamiques-modification-date/src/modification-date.js +++ b/plugins/dynamiques-modification-date/src/modification-date.js @@ -3,126 +3,139 @@ import { Button, DateTimePicker, Dropdown } from "@wordpress/components"; import { PluginDocumentSettingPanel } from "@wordpress/editor"; import { useSelect, useDispatch } from "@wordpress/data"; import { __ } from "@wordpress/i18n"; -import { useState } from "@wordpress/element"; import { dateI18n, format, getSettings } from "@wordpress/date"; const ModificationDatePanel = () => { - const { modificationDate } = useSelect((select) => { - const meta = select("core/editor").getEditedPostAttribute("meta"); - return { - modificationDate: meta?.article_modification_date || "", - }; - }); + const { modificationDate, postType } = useSelect((select) => { + const meta = select("core/editor").getEditedPostAttribute("meta"); + const postType = select("core/editor").getCurrentPostType(); - const { editPost } = useDispatch("core/editor"); - const settings = getSettings(); + return { + modificationDate: meta?.article_modification_date || "", + postType: postType, + }; + }); - const updateModificationDate = (newDate) => { - const formattedDate = format("Y-m-d H:i:s", newDate); - editPost({ - meta: { - article_modification_date: formattedDate, - }, - }); - }; + const allowedPostTypes = ["article", "revue"]; // adapte avec tes vrais slugs + if (!allowedPostTypes.includes(postType)) { + return null; + } - const clearModificationDate = () => { - editPost({ - meta: { - article_modification_date: "", - }, - }); - }; + const { editPost } = useDispatch("core/editor"); + const settings = getSettings(); - // Formater la date pour l'affichage - const displayDate = modificationDate - ? dateI18n(settings.formats.datetime, modificationDate) - : __("Non définie", "dynamiques-modification-date"); + const updateModificationDate = (newDate) => { + const formattedDate = format("Y-m-d H:i:s", newDate); + editPost({ + meta: { + article_modification_date: formattedDate, + }, + }); + }; - return ( - -
- {__( - "Choisissez ici la dernière date de révision de cet article", - "dynamiques-modification-date" - )} -
+ const clearModificationDate = () => { + editPost({ + meta: { + article_modification_date: "", + }, + }); + }; -
- {modificationDate ? ( - ( - - )} - renderContent={({ onClose }) => ( -
- { - updateModificationDate(newDate); - onClose(); - }} - is12Hour={settings.formats.time.includes("a")} - /> -
- -
-
- )} - /> - ) : ( - - )} -
-
- ); + // Formater la date pour l'affichage + const displayDate = modificationDate + ? dateI18n(settings.formats.datetime, modificationDate) + : __("Non définie", "dynamiques-modification-date"); + + return ( + +
+ {__( + "Choisissez ici la dernière date de révision de cet article", + "dynamiques-modification-date", + )} +
+ +
+ {modificationDate ? ( + ( + + )} + renderContent={({ onClose }) => ( +
+ { + updateModificationDate(newDate); + onClose(); + }} + is12Hour={settings.formats.time.includes("a")} + /> +
+ +
+
+ )} + /> + ) : ( + + )} +
+
+ ); }; registerPlugin("modification-date-panel", { - render: ModificationDatePanel, + render: ModificationDatePanel, });