Plugin Directory

Changeset 3033669


Ignore:
Timestamp:
02/09/2024 02:24:34 PM (2 years ago)
Author:
EdwardBock
Message:

release 2.2.0

Location:
headless
Files:
6 added
3 deleted
10 edited
61 copied

Legend:

Unmodified
Added
Removed
  • headless/tags/2.2.0/README.txt

    r3032167 r3033669  
    66Tested up to: 6.4.3
    77Requires PHP: 8.0
    8 Stable tag: 2.1.2
     8Stable tag: 2.2.0
    99License: GPLv3
    1010License URI: http://www.gnu.org/licenses/gpl
     
    2727
    2828== Changelog ==
     29
     30= 2.2.0 =
     31* Feature: Revalidate pending posts via dashboard button
     32* Fix: date format on dashboard
    2933
    3034= 2.1.2 =
  • headless/tags/2.2.0/classes/Ajax.php

    r2868064 r3033669  
    88
    99    const GET_ACTION = "headless_revalidate";
     10    const GET_ACTION_PENDING = "headless_revalidate_pending";
    1011    const GET_FRONTEND_INDEX = "frontend";
    1112    const GET_PATH = "path";
     
    1516        parent::onCreate();
    1617        add_action('wp_ajax_'.self::GET_ACTION, [$this, 'revalidate']);
     18        add_action('wp_ajax_'.self::GET_ACTION_PENDING, [$this, 'revalidate_pending']);
    1719    }
    1820
     
    7173
    7274
     75    function revalidate_pending() {
     76        if(!current_user_can('edit_posts')){
     77            wp_send_json_error();
     78            exit;
     79        }
     80        $this->plugin->schedule->revalidate();
     81        wp_send_json_success([
     82            "success" => true,
     83        ]);
     84        exit;
     85    }
    7386}
  • headless/tags/2.2.0/classes/Dashboard.php

    r2868064 r3033669  
    2424
    2525        $lastRevalidationRun = $this->plugin->schedule->getLastRevalidationRun();
    26         $lastRevalidationRunDate = strtotime($lastRevalidationRun);
    2726        $nextRevalidationRun = $this->plugin->schedule->getNextSchedule();
    2827
     
    3029        $ajaxUrl = admin_url('admin-ajax.php');
    3130        ?>
    32             <p>Last automatic revalidation run: <?= date_i18n($dateFormat,$lastRevalidationRunDate)." ".date_i18n($timeFormat, $lastRevalidationRunDate); ?></p>
    33             <p>Next automatic revalidation run: <?= ($nextRevalidationRun === false) ? "🚨 Broken" : date_i18n($dateFormat, $nextRevalidationRun)." ".date_i18n($timeFormat, $nextRevalidationRun); ?></p>
     31            <p><strong>Automatic revalidation</strong></p>
     32            <p>Last revalidation run: <span data-headless-timestamp="<?= $lastRevalidationRun; ?>">
     33                    <?= date_i18n($dateFormat,$lastRevalidationRun)." ".date_i18n($timeFormat, $lastRevalidationRun); ?>
     34                </span></p>
     35
     36            <p>Next revalidation run:  <span data-headless-timestamp="<?= $nextRevalidationRun; ?>">
     37                <?= ($nextRevalidationRun === false) ? "🚨 Broken" : date_i18n($dateFormat, $nextRevalidationRun)." ".date_i18n($timeFormat, $nextRevalidationRun); ?>
     38                </span></p>
     39
    3440            <p>Pending posts to be revalidated: <?= $this->plugin->dbRevalidation->countPendingPosts(); ?></p>
    35             <p>Available frontends:</p>
    36             <ol>
     41
     42            <button class="button button-secondary" id="headless-revalidate-pending">Revalidate pending</button>
     43            <span id="headless-revalidate-pending-spinner" class="spinner"></span>
     44
     45            <script>
     46                document.querySelectorAll("[data-headless-timestamp]").forEach((el) => {
     47                    const timestamp = el.getAttribute("data-headless-timestamp");
     48                    console.debug("headless timestamp", timestamp, el);
     49                    console.debug(Intl.DateTimeFormat().format(parseInt(timestamp) * 1000));
     50                });
     51                const button = document.getElementById("headless-revalidate-pending");
     52                const spinner = document.getElementById("headless-revalidate-pending-spinner");
     53
     54                button.addEventListener("click", (e)=> {
     55                    e.preventDefault();
     56                    console.debug(button);
     57                    button.disabled = true;
     58                    spinner.classList.add("is-active");
     59                    fetch("<?= $ajaxUrl ?>?action=headless_revalidate_pending")
     60                        .then(res => res.json())
     61                        .then(console.debug)
     62                        .finally(()=>{
     63                            spinner.classList.remove("is-active");
     64                            button.disabled = false;
     65                        });
     66                })
     67            </script>
     68
     69            <hr />
     70
     71            <p><strong>Manual revalidation</strong></p>
     72            <ul>
    3773                <?php
    3874                foreach ($frontends as $index => $frontend){
     
    4682                }
    4783                ?>
    48             </ol>
     84            </ul>
    4985            <form method="post" id="headless-revalidate-form">
    5086                <input type="text" name="headless_invalidate_path" placeholder="path/to/invalidate" />
  • headless/tags/2.2.0/dist/admin.asset.php

    r2901812 r3033669  
    1 <?php return array('dependencies' => array(), 'version' => 'ecdaf49b7e3ddff3eb2a');
     1<?php return array('dependencies' => array(), 'version' => '4395236daaca37a54365');
  • headless/tags/2.2.0/dist/admin.js

    r2901812 r3033669  
    1 !function(){"use strict";window.addEventListener("DOMContentLoaded",(async()=>{await Promise.all(window.HeadlessAdmin.frontends.map((e=>e+window.HeadlessAdmin.preview_path)).map((e=>fetch(e,{credentials:"include"}).then((e=>e.json())))))}))}();
     1/******/ (function() { // webpackBootstrap
     2/******/    "use strict";
     3/******/    var __webpack_modules__ = ({
     4
     5/***/ "./src/store/admin-window.ts":
     6/*!***********************************!*\
     7  !*** ./src/store/admin-window.ts ***!
     8  \***********************************/
     9/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     10
     11__webpack_require__.r(__webpack_exports__);
     12/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     13/* harmony export */   getPreviewPath: function() { return /* binding */ getPreviewPath; },
     14/* harmony export */   getPreviewUrls: function() { return /* binding */ getPreviewUrls; }
     15/* harmony export */ });
     16const getPreviewPath = () => window.HeadlessAdmin.preview_path;
     17const getPreviewUrls = () => {
     18  return window.HeadlessAdmin.frontends.map(frontend => {
     19    return frontend + getPreviewPath();
     20  });
     21};
     22
     23/***/ })
     24
     25/******/    });
     26/************************************************************************/
     27/******/    // The module cache
     28/******/    var __webpack_module_cache__ = {};
     29/******/   
     30/******/    // The require function
     31/******/    function __webpack_require__(moduleId) {
     32/******/        // Check if module is in cache
     33/******/        var cachedModule = __webpack_module_cache__[moduleId];
     34/******/        if (cachedModule !== undefined) {
     35/******/            return cachedModule.exports;
     36/******/        }
     37/******/        // Create a new module (and put it into the cache)
     38/******/        var module = __webpack_module_cache__[moduleId] = {
     39/******/            // no module.id needed
     40/******/            // no module.loaded needed
     41/******/            exports: {}
     42/******/        };
     43/******/   
     44/******/        // Execute the module function
     45/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
     46/******/   
     47/******/        // Return the exports of the module
     48/******/        return module.exports;
     49/******/    }
     50/******/   
     51/************************************************************************/
     52/******/    /* webpack/runtime/define property getters */
     53/******/    !function() {
     54/******/        // define getter functions for harmony exports
     55/******/        __webpack_require__.d = function(exports, definition) {
     56/******/            for(var key in definition) {
     57/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
     58/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
     59/******/                }
     60/******/            }
     61/******/        };
     62/******/    }();
     63/******/   
     64/******/    /* webpack/runtime/hasOwnProperty shorthand */
     65/******/    !function() {
     66/******/        __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
     67/******/    }();
     68/******/   
     69/******/    /* webpack/runtime/make namespace object */
     70/******/    !function() {
     71/******/        // define __esModule on exports
     72/******/        __webpack_require__.r = function(exports) {
     73/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
     74/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
     75/******/            }
     76/******/            Object.defineProperty(exports, '__esModule', { value: true });
     77/******/        };
     78/******/    }();
     79/******/   
     80/************************************************************************/
     81var __webpack_exports__ = {};
     82// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
     83!function() {
     84/*!**********************!*\
     85  !*** ./src/admin.ts ***!
     86  \**********************/
     87__webpack_require__.r(__webpack_exports__);
     88/* harmony import */ var _store_admin_window__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./store/admin-window */ "./src/store/admin-window.ts");
     89
     90window.addEventListener("DOMContentLoaded", async () => {
     91  const results = await Promise.all((0,_store_admin_window__WEBPACK_IMPORTED_MODULE_0__.getPreviewUrls)().map(url => fetch(url, {
     92    credentials: "include"
     93  }).then(res => res.json())));
     94});
     95}();
     96/******/ })()
     97;
     98//# sourceMappingURL=admin.js.map
  • headless/tags/2.2.0/dist/gutenberg.asset.php

    r3020918 r3033669  
    1 <?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins'), 'version' => '5b547f4c4cc23f7700c1');
     1<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins'), 'version' => 'd6a44e1effbbfab625f6');
  • headless/tags/2.2.0/dist/gutenberg.css

    r2901812 r3033669  
    1 .block-editor-post-preview__dropdown-content .components-menu-group .edit-post-header-preview__grouping-external{display:none}#headless-preview-link{display:flex;justify-content:space-between}#headless-preview-link.is-disabled{border-color:#d3d3d3;color:grey;outline-color:#d3d3d3}
     1/*!*********************************************************************************************************************************************************************************************************************************************************************************************!*\
     2  !*** css ./node_modules/.pnpm/css-loader@6.8.1_webpack@5.88.2/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.31_webpack@5.88.2/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles.css ***!
     3  \*********************************************************************************************************************************************************************************************************************************************************************************************/
     4.block-editor-post-preview__dropdown-content .components-menu-group .edit-post-header-preview__grouping-external {
     5    display: none;
     6}
     7#headless-preview-link {
     8    display: flex;
     9    justify-content: space-between;
     10}
     11
     12#headless-preview-link.is-disabled {
     13    color: grey;
     14    border-color: lightgrey;
     15    outline-color: lightgrey;
     16}
     17
     18
     19
     20/*# sourceMappingURL=gutenberg.css.map*/
  • headless/tags/2.2.0/dist/gutenberg.js

    r3020918 r3033669  
    1 !function(){"use strict";var t=window.wp.plugins,e=window.React,n=window.wp.editPost,s=window.wp.components;var a=window.wp.data,i=window.wp.element;const r=()=>(0,a.useSelect)((t=>t("core/editor").getCurrentPost()),[]),o=({index:t,baseUrl:n,controller:s,onStateChanged:a})=>{const{state:o,reload:l}=(t=>{const[e,n]=(0,i.useState)("idle"),s=r(),a=(0,i.useMemo)((()=>s?.link?new URL(s?.link).pathname:""),[s.link]);return{state:e,reload:()=>{n("loading"),(async()=>{try{const e=await fetch(((t,e)=>window.Headless.ajax+`?action=${window.Headless.actions.revalidate}&frontend=${t}&path=${e}`)(t,a)),s=await e.json();s.success?n("success"):(console.error(s),n("error"))}catch(t){n("error")}})()}}})(t),c=r(),d=(0,i.useMemo)((()=>{const t=c.link,e=new URL(t);return n.replace(/^\/|\/$/g,"")+e.pathname}),[c.link]);return(0,i.useEffect)((()=>{s.add(t,l)}),[t]),(0,i.useEffect)((()=>{a(t,o)}),[o]),(0,e.createElement)("div",{title:d},(0,e.createElement)("a",{href:d,target:"_blank"},"Frontend ",t),"loading"==o&&(0,e.createElement)(e.Fragment,null," 🧹"),"success"==o&&(0,e.createElement)(e.Fragment,null," ✅"),"error"==o&&(0,e.createElement)(e.Fragment,null," 🚨"))};(0,t.registerPlugin)("headless-plugin",{icon:()=>null,render:function(){const t=window.Headless.frontends,a=(0,i.useMemo)((()=>(()=>{const t=new Map;return{add:(e,n)=>{t.set(e,n)},run:()=>{t.forEach((t=>{t()}))}}})()),[]),[l,c]=(0,i.useState)({}),d="publish"==r().status,p=Object.values(l).find((t=>1==t));return(0,e.createElement)(n.PluginDocumentSettingPanel,{title:"Headless"},d?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("ol",null,t.map(((t,n)=>(0,e.createElement)("li",{key:n},(0,e.createElement)(o,{baseUrl:t,index:n,controller:a,onStateChanged:(t,e)=>{c((n=>{const s={...n};return s[t]="loading"==e,s}))}}))))),(0,e.createElement)(s.Button,{variant:"secondary",disabled:p||!d,onClick:()=>{a.run()}},"Revalidate cache")):(0,e.createElement)("p",{className:"description"},"Only published contents can be revalidated."))}}),document.addEventListener("DOMContentLoaded",(function(){const t=(0,a.select)("core/editor"),e=t.getCurrentPostId,n=t.isSavingPost,s=(0,a.dispatch)("core/editor"),i=s.autosave,r=s.savePost,o=document.createElement("a");o.className="components-button",o.addEventListener("click",(e=>{if(e.preventDefault(),n())return;const s=window.open("about:blank",o.target);!function(t){let e="";e+='\n\t\t<style>\n\t\t\tbody {\n\t\t\t\tmargin: 0;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message {\n\t\t\t\tdisplay: flex;\n\t\t\t\tflex-direction: column;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\twidth: 100vw;\n\t\t\t}\n\t\t\t@-webkit-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-moz-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-o-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg {\n\t\t\t\twidth: 192px;\n\t\t\t\theight: 192px;\n\t\t\t\tstroke: #555d66;\n\t\t\t\tstroke-width: 0.75;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg .outer,\n\t\t\t.editor-post-preview-button__interstitial-message svg .inner {\n\t\t\t\tstroke-dasharray: 280;\n\t\t\t\tstroke-dashoffset: 280;\n\t\t\t\t-webkit-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-moz-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-o-animation: paint 1.5s ease infinite alternate;\n\t\t\t\tanimation: paint 1.5s ease infinite alternate;\n\t\t\t}\n\t\t\tp {\n\t\t\t\ttext-align: center;\n\t\t\t\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;\n\t\t\t}\n\t\t</style>\n\t',e+='\n        <div class="editor-post-preview-button__interstitial-message">\n            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">\n                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />\n                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />\n            </svg>\n            <p>Generating preview…</p>\n        </div>\n    ',t.write('\n\t\t<style>\n\t\t\tbody {\n\t\t\t\tmargin: 0;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message {\n\t\t\t\tdisplay: flex;\n\t\t\t\tflex-direction: column;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\twidth: 100vw;\n\t\t\t}\n\t\t\t@-webkit-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-moz-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-o-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg {\n\t\t\t\twidth: 192px;\n\t\t\t\theight: 192px;\n\t\t\t\tstroke: #555d66;\n\t\t\t\tstroke-width: 0.75;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg .outer,\n\t\t\t.editor-post-preview-button__interstitial-message svg .inner {\n\t\t\t\tstroke-dasharray: 280;\n\t\t\t\tstroke-dashoffset: 280;\n\t\t\t\t-webkit-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-moz-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-o-animation: paint 1.5s ease infinite alternate;\n\t\t\t\tanimation: paint 1.5s ease infinite alternate;\n\t\t\t}\n\t\t\tp {\n\t\t\t\ttext-align: center;\n\t\t\t\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;\n\t\t\t}\n\t\t</style>\n\t\n        <div class="editor-post-preview-button__interstitial-message">\n            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">\n                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />\n                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />\n            </svg>\n            <p>Generating preview…</p>\n        </div>\n    '),t.close()}(s.document),((()=>{const e=t.getCurrentPost().status;return"draft"==e||"auto-draft"==e})()?r:i)().then((()=>{s.location=o.href}))})),(0,a.subscribe)((()=>{n()?o.classList.add("is-disabled"):o.classList.remove("is-disabled")})),setInterval((function(){const t=e(),n=(t=>window.Headless.preview_url.replace(window.Headless.post_id_placeholder,`${t}`))(t),s=document.querySelectorAll("[target^=wp-preview-]");s&&s.length&&s.forEach((t=>{t.setAttribute("href",n)})),document.querySelectorAll(".components-snackbar-list .components-snackbar__content a.components-button").forEach((e=>{(e.href.includes("?post="+t)||e.href.includes("?page_id="+t)||e.href.includes("?p="+t))&&(e.href=n,e.target="wp-preview-"+t)}));const a=document.querySelectorAll(".edit-post-post-preview-dropdown .components-menu-group");let i=null;if(a.forEach((t=>{t.querySelector(".edit-post-header-preview__grouping-external")&&(i=t)})),!i)return;const r="headless-preview-link";if(i.querySelector("#"+r))return;const l=i.querySelector(".edit-post-header-preview__grouping-external a"),c=l.getAttribute("target");o.text=l.textContent;const d=document.createElement("span");d.className="dashicons dashicons-external",o.append(d),o.target=c,o.href=n,o.id=r,i.querySelector('[role="group"]').append(o)}),300)}))}();
     1/******/ (function() { // webpackBootstrap
     2/******/    "use strict";
     3/******/    var __webpack_modules__ = ({
     4
     5/***/ "./src/components/ReloadPanel.tsx":
     6/*!****************************************!*\
     7  !*** ./src/components/ReloadPanel.tsx ***!
     8  \****************************************/
     9/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     10
     11__webpack_require__.r(__webpack_exports__);
     12/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     13/* harmony export */   "default": function() { return /* binding */ ReloadPanel; }
     14/* harmony export */ });
     15/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
     16/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
     17/* harmony import */ var _wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/edit-post */ "@wordpress/edit-post");
     18/* harmony import */ var _wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__);
     19/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
     20/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__);
     21/* harmony import */ var _hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../hooks/use-reload */ "./src/hooks/use-reload.ts");
     22/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../store/window */ "./src/store/window.ts");
     23/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
     24/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__);
     25
     26
     27
     28
     29
     30
     31const buildController = () => {
     32  const fns = new Map();
     33  return {
     34    add: (frontend, fn) => {
     35      fns.set(frontend, fn);
     36    },
     37    run: () => {
     38      fns.forEach(fn => {
     39        fn();
     40      });
     41    }
     42  };
     43};
     44const FrontendItem = ({
     45  index,
     46  baseUrl,
     47  controller,
     48  onStateChanged
     49}) => {
     50  const {
     51    state,
     52    reload
     53  } = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.useReload)(index);
     54  const post = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.usePost)();
     55  const url = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => {
     56    const link = post.link;
     57    const url = new URL(link);
     58    ;
     59    return baseUrl.replace(/^\/|\/$/g, '') + url.pathname;
     60  }, [post.link]);
     61  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => {
     62    controller.add(index, reload);
     63  }, [index]);
     64  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => {
     65    onStateChanged(index, state);
     66  }, [state]);
     67  return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     68    title: url
     69  }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
     70    href: url,
     71    target: "_blank"
     72  }, "Frontend ", index), state == "loading" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \uD83E\uDDF9"), state == "success" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \u2705"), state == "error" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \uD83D\uDEA8"));
     73};
     74function ReloadPanel() {
     75  const frontends = (0,_store_window__WEBPACK_IMPORTED_MODULE_4__.getFrontends)();
     76  const controller = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => buildController(), []);
     77  const [loadingState, setLoadingState] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useState)({});
     78  const canRevalidate = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.useCanRevalidate)();
     79  const handleClick = () => {
     80    controller.run();
     81  };
     82  const isLoading = Object.values(loadingState).find(value => value == true);
     83  return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__.PluginDocumentSettingPanel, {
     84    title: "Headless"
     85  }, canRevalidate ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("ol", null, frontends.map((frontend, index) => {
     86    return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", {
     87      key: index
     88    }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(FrontendItem, {
     89      baseUrl: frontend,
     90      index: index,
     91      controller: controller,
     92      onStateChanged: (index, state) => {
     93        setLoadingState(prev => {
     94          const copy = {
     95            ...prev
     96          };
     97          copy[index] = state == "loading";
     98          return copy;
     99        });
     100      }
     101    }));
     102  })), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.Button, {
     103    variant: "secondary",
     104    disabled: isLoading || !canRevalidate,
     105    onClick: handleClick
     106  }, "Revalidate cache")) : (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", {
     107    className: "description"
     108  }, "Only published contents can be revalidated."));
     109}
     110
     111/***/ }),
     112
     113/***/ "./src/hooks/use-reload.ts":
     114/*!*********************************!*\
     115  !*** ./src/hooks/use-reload.ts ***!
     116  \*********************************/
     117/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     118
     119__webpack_require__.r(__webpack_exports__);
     120/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     121/* harmony export */   useCanRevalidate: function() { return /* binding */ useCanRevalidate; },
     122/* harmony export */   usePost: function() { return /* binding */ usePost; },
     123/* harmony export */   useReload: function() { return /* binding */ useReload; }
     124/* harmony export */ });
     125/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/window */ "./src/store/window.ts");
     126/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
     127/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
     128/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
     129/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__);
     130
     131
     132
     133const usePost = () => {
     134  return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => select("core/editor").getCurrentPost(), []);
     135};
     136const useCanRevalidate = () => {
     137  return usePost().status == "publish";
     138};
     139const useReload = frontend => {
     140  const [state, setState] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useState)("idle");
     141  const post = usePost();
     142  const path = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => {
     143    if (post?.link) {
     144      const url = new URL(post?.link);
     145      return url.pathname;
     146    } else {
     147      return "";
     148    }
     149  }, [post.link]);
     150  return {
     151    state,
     152    reload: () => {
     153      setState("loading");
     154      (async () => {
     155        try {
     156          const response = await fetch((0,_store_window__WEBPACK_IMPORTED_MODULE_0__.getReloadAjaxUrl)(frontend, path));
     157          const json = await response.json();
     158          if (json.success) {
     159            setState("success");
     160          } else {
     161            console.error(json);
     162            setState("error");
     163          }
     164        } catch (e) {
     165          setState("error");
     166        }
     167      })();
     168    }
     169  };
     170};
     171
     172/***/ }),
     173
     174/***/ "./src/preview.ts":
     175/*!************************!*\
     176  !*** ./src/preview.ts ***!
     177  \************************/
     178/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     179
     180__webpack_require__.r(__webpack_exports__);
     181/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     182/* harmony export */   writeInterstitialMessage: function() { return /* binding */ writeInterstitialMessage; }
     183/* harmony export */ });
     184function writeInterstitialMessage(targetDocument) {
     185  let markup = '';
     186  markup += `
     187        <style>
     188            body {
     189                margin: 0;
     190            }
     191            .editor-post-preview-button__interstitial-message {
     192                display: flex;
     193                flex-direction: column;
     194                align-items: center;
     195                justify-content: center;
     196                height: 100vh;
     197                width: 100vw;
     198            }
     199            @-webkit-keyframes paint {
     200                0% {
     201                    stroke-dashoffset: 0;
     202                }
     203            }
     204            @-moz-keyframes paint {
     205                0% {
     206                    stroke-dashoffset: 0;
     207                }
     208            }
     209            @-o-keyframes paint {
     210                0% {
     211                    stroke-dashoffset: 0;
     212                }
     213            }
     214            @keyframes paint {
     215                0% {
     216                    stroke-dashoffset: 0;
     217                }
     218            }
     219            .editor-post-preview-button__interstitial-message svg {
     220                width: 192px;
     221                height: 192px;
     222                stroke: #555d66;
     223                stroke-width: 0.75;
     224            }
     225            .editor-post-preview-button__interstitial-message svg .outer,
     226            .editor-post-preview-button__interstitial-message svg .inner {
     227                stroke-dasharray: 280;
     228                stroke-dashoffset: 280;
     229                -webkit-animation: paint 1.5s ease infinite alternate;
     230                -moz-animation: paint 1.5s ease infinite alternate;
     231                -o-animation: paint 1.5s ease infinite alternate;
     232                animation: paint 1.5s ease infinite alternate;
     233            }
     234            p {
     235                text-align: center;
     236                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
     237            }
     238        </style>
     239    `;
     240  markup += `
     241        <div class="editor-post-preview-button__interstitial-message">
     242            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">
     243                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />
     244                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />
     245            </svg>
     246            <p>Generating preview…</p>
     247        </div>
     248    `;
     249  targetDocument.write(markup);
     250  targetDocument.close();
     251}
     252
     253/***/ }),
     254
     255/***/ "./src/store/window.ts":
     256/*!*****************************!*\
     257  !*** ./src/store/window.ts ***!
     258  \*****************************/
     259/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     260
     261__webpack_require__.r(__webpack_exports__);
     262/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     263/* harmony export */   getAjaxUrl: function() { return /* binding */ getAjaxUrl; },
     264/* harmony export */   getFrontends: function() { return /* binding */ getFrontends; },
     265/* harmony export */   getPreviewUrl: function() { return /* binding */ getPreviewUrl; },
     266/* harmony export */   getReloadAjaxUrl: function() { return /* binding */ getReloadAjaxUrl; }
     267/* harmony export */ });
     268const getAjaxUrl = () => window.Headless.ajax;
     269const getReloadAjaxUrl = (frontend, path) => getAjaxUrl() + `?action=${window.Headless.actions.revalidate}&frontend=${frontend}&path=${path}`;
     270const getPreviewUrl = postId => {
     271  return window.Headless.preview_url.replace(window.Headless.post_id_placeholder, `${postId}`);
     272};
     273const getFrontends = () => window.Headless.frontends;
     274
     275/***/ }),
     276
     277/***/ "./src/styles.css":
     278/*!************************!*\
     279  !*** ./src/styles.css ***!
     280  \************************/
     281/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     282
     283__webpack_require__.r(__webpack_exports__);
     284// extracted by mini-css-extract-plugin
     285
     286
     287/***/ }),
     288
     289/***/ "react":
     290/*!************************!*\
     291  !*** external "React" ***!
     292  \************************/
     293/***/ (function(module) {
     294
     295module.exports = window["React"];
     296
     297/***/ }),
     298
     299/***/ "@wordpress/components":
     300/*!************************************!*\
     301  !*** external ["wp","components"] ***!
     302  \************************************/
     303/***/ (function(module) {
     304
     305module.exports = window["wp"]["components"];
     306
     307/***/ }),
     308
     309/***/ "@wordpress/data":
     310/*!******************************!*\
     311  !*** external ["wp","data"] ***!
     312  \******************************/
     313/***/ (function(module) {
     314
     315module.exports = window["wp"]["data"];
     316
     317/***/ }),
     318
     319/***/ "@wordpress/edit-post":
     320/*!**********************************!*\
     321  !*** external ["wp","editPost"] ***!
     322  \**********************************/
     323/***/ (function(module) {
     324
     325module.exports = window["wp"]["editPost"];
     326
     327/***/ }),
     328
     329/***/ "@wordpress/element":
     330/*!*********************************!*\
     331  !*** external ["wp","element"] ***!
     332  \*********************************/
     333/***/ (function(module) {
     334
     335module.exports = window["wp"]["element"];
     336
     337/***/ }),
     338
     339/***/ "@wordpress/plugins":
     340/*!*********************************!*\
     341  !*** external ["wp","plugins"] ***!
     342  \*********************************/
     343/***/ (function(module) {
     344
     345module.exports = window["wp"]["plugins"];
     346
     347/***/ })
     348
     349/******/    });
     350/************************************************************************/
     351/******/    // The module cache
     352/******/    var __webpack_module_cache__ = {};
     353/******/   
     354/******/    // The require function
     355/******/    function __webpack_require__(moduleId) {
     356/******/        // Check if module is in cache
     357/******/        var cachedModule = __webpack_module_cache__[moduleId];
     358/******/        if (cachedModule !== undefined) {
     359/******/            return cachedModule.exports;
     360/******/        }
     361/******/        // Create a new module (and put it into the cache)
     362/******/        var module = __webpack_module_cache__[moduleId] = {
     363/******/            // no module.id needed
     364/******/            // no module.loaded needed
     365/******/            exports: {}
     366/******/        };
     367/******/   
     368/******/        // Execute the module function
     369/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
     370/******/   
     371/******/        // Return the exports of the module
     372/******/        return module.exports;
     373/******/    }
     374/******/   
     375/************************************************************************/
     376/******/    /* webpack/runtime/compat get default export */
     377/******/    !function() {
     378/******/        // getDefaultExport function for compatibility with non-harmony modules
     379/******/        __webpack_require__.n = function(module) {
     380/******/            var getter = module && module.__esModule ?
     381/******/                function() { return module['default']; } :
     382/******/                function() { return module; };
     383/******/            __webpack_require__.d(getter, { a: getter });
     384/******/            return getter;
     385/******/        };
     386/******/    }();
     387/******/   
     388/******/    /* webpack/runtime/define property getters */
     389/******/    !function() {
     390/******/        // define getter functions for harmony exports
     391/******/        __webpack_require__.d = function(exports, definition) {
     392/******/            for(var key in definition) {
     393/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
     394/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
     395/******/                }
     396/******/            }
     397/******/        };
     398/******/    }();
     399/******/   
     400/******/    /* webpack/runtime/hasOwnProperty shorthand */
     401/******/    !function() {
     402/******/        __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
     403/******/    }();
     404/******/   
     405/******/    /* webpack/runtime/make namespace object */
     406/******/    !function() {
     407/******/        // define __esModule on exports
     408/******/        __webpack_require__.r = function(exports) {
     409/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
     410/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
     411/******/            }
     412/******/            Object.defineProperty(exports, '__esModule', { value: true });
     413/******/        };
     414/******/    }();
     415/******/   
     416/************************************************************************/
     417var __webpack_exports__ = {};
     418// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
     419!function() {
     420/*!**************************!*\
     421  !*** ./src/gutenberg.ts ***!
     422  \**************************/
     423__webpack_require__.r(__webpack_exports__);
     424/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins");
     425/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__);
     426/* harmony import */ var _components_ReloadPanel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/ReloadPanel */ "./src/components/ReloadPanel.tsx");
     427/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store/window */ "./src/store/window.ts");
     428/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
     429/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
     430/* harmony import */ var _preview__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./preview */ "./src/preview.ts");
     431/* harmony import */ var _styles_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./styles.css */ "./src/styles.css");
     432
     433
     434
     435
     436
     437
     438(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('headless-plugin', {
     439  icon: () => null,
     440  render: _components_ReloadPanel__WEBPACK_IMPORTED_MODULE_1__["default"]
     441});
     442document.addEventListener("DOMContentLoaded", function () {
     443  const coreEditorSelect = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.select)("core/editor");
     444  const getCurrentPostId = coreEditorSelect.getCurrentPostId;
     445  const isSavingPost = coreEditorSelect.isSavingPost;
     446  const isDraft = () => {
     447    const status = coreEditorSelect.getCurrentPost().status;
     448    return status == "draft" || status == "auto-draft";
     449  };
     450  const coreEditorDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.dispatch)("core/editor");
     451  const autosave = coreEditorDispatch.autosave;
     452  const savePost = coreEditorDispatch.savePost;
     453
     454  // --------------------------------------------------------
     455  // create replacement for preview link
     456  // --------------------------------------------------------
     457  const a = document.createElement("a");
     458  a.className = "components-button";
     459  a.addEventListener('click', e => {
     460    e.preventDefault();
     461    if (isSavingPost()) {
     462      return;
     463    }
     464    const ref = window.open('about:blank', a.target);
     465    (0,_preview__WEBPACK_IMPORTED_MODULE_4__.writeInterstitialMessage)(ref.document);
     466    const saveFn = isDraft() ? savePost : autosave;
     467    saveFn().then(() => {
     468      ref.location = a.href;
     469    });
     470  });
     471  (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.subscribe)(() => {
     472    if (isSavingPost()) {
     473      a.classList.add("is-disabled");
     474    } else {
     475      a.classList.remove("is-disabled");
     476    }
     477  });
     478
     479  // --------------------------------------------------------
     480  // hack it with interval updates
     481  // --------------------------------------------------------
     482  // workaround script until there's an official solution for https://github.com/WordPress/gutenberg/issues/13998
     483  setInterval(checkPreview, 300);
     484  function checkPreview() {
     485    const postId = getCurrentPostId();
     486    const previewUrl = (0,_store_window__WEBPACK_IMPORTED_MODULE_2__.getPreviewUrl)(postId);
     487
     488    // replace all preview links
     489    const editorPreviewLink = document.querySelectorAll("[target^=wp-preview-]");
     490    if (editorPreviewLink && editorPreviewLink.length) {
     491      editorPreviewLink.forEach(link => {
     492        link.setAttribute("href", previewUrl);
     493      });
     494    }
     495
     496    // replace notice link
     497    const notices = document.querySelectorAll(".components-snackbar-list .components-snackbar__content a.components-button");
     498    notices.forEach(notice => {
     499      if (notice.href.includes("?post=" + postId) // custom post types
     500      || notice.href.includes("?page_id=" + postId) // pages
     501      || notice.href.includes("?p=" + postId) // posts
     502      ) {
     503        notice.href = previewUrl;
     504        notice.target = "wp-preview-" + postId;
     505      }
     506    });
     507
     508    // replace this special preview link
     509    const previewGroups = document.querySelectorAll(".edit-post-post-preview-dropdown .components-menu-group");
     510    let externalPreviewGroup = null;
     511    previewGroups.forEach(group => {
     512      if (group.querySelector(".edit-post-header-preview__grouping-external")) {
     513        externalPreviewGroup = group;
     514      }
     515    });
     516    if (!externalPreviewGroup) {
     517      return;
     518    }
     519    const id = "headless-preview-link";
     520    if (externalPreviewGroup.querySelector("#" + id)) {
     521      return;
     522    }
     523
     524    // is hidden via styles.css
     525    const gutenbergLink = externalPreviewGroup.querySelector(".edit-post-header-preview__grouping-external a");
     526    const target = gutenbergLink.getAttribute("target");
     527    a.text = gutenbergLink.textContent;
     528    const icon = document.createElement("span");
     529    icon.className = "dashicons dashicons-external";
     530    a.append(icon);
     531    a.target = target;
     532    a.href = previewUrl;
     533    a.id = id;
     534    externalPreviewGroup.querySelector('[role="group"]').append(a);
     535  }
     536});
     537}();
     538/******/ })()
     539;
     540//# sourceMappingURL=gutenberg.js.map
  • headless/tags/2.2.0/headless.php

    r3032167 r3033669  
    55 * Plugin URI: https://github.com/palasthotel/headless
    66 * Description: Adds features to use WordPress as headless CMS
    7  * Version: 2.1.2
     7 * Version: 2.2.0
    88 * Author: Palasthotel (Edward Bock) <edward.bock@palasthotel.de>
    99 * Author URI: http://www.palasthotel.de
  • headless/tags/2.2.0/vendor/composer/installed.php

    r3032167 r3033669  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '333db9baf1136108d25cdaad5b62cea1aa72c601',
     6        'reference' => 'dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '333db9baf1136108d25cdaad5b62cea1aa72c601',
     16            'reference' => 'dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • headless/trunk/README.txt

    r3032167 r3033669  
    66Tested up to: 6.4.3
    77Requires PHP: 8.0
    8 Stable tag: 2.1.2
     8Stable tag: 2.2.0
    99License: GPLv3
    1010License URI: http://www.gnu.org/licenses/gpl
     
    2727
    2828== Changelog ==
     29
     30= 2.2.0 =
     31* Feature: Revalidate pending posts via dashboard button
     32* Fix: date format on dashboard
    2933
    3034= 2.1.2 =
  • headless/trunk/classes/Ajax.php

    r2868064 r3033669  
    88
    99    const GET_ACTION = "headless_revalidate";
     10    const GET_ACTION_PENDING = "headless_revalidate_pending";
    1011    const GET_FRONTEND_INDEX = "frontend";
    1112    const GET_PATH = "path";
     
    1516        parent::onCreate();
    1617        add_action('wp_ajax_'.self::GET_ACTION, [$this, 'revalidate']);
     18        add_action('wp_ajax_'.self::GET_ACTION_PENDING, [$this, 'revalidate_pending']);
    1719    }
    1820
     
    7173
    7274
     75    function revalidate_pending() {
     76        if(!current_user_can('edit_posts')){
     77            wp_send_json_error();
     78            exit;
     79        }
     80        $this->plugin->schedule->revalidate();
     81        wp_send_json_success([
     82            "success" => true,
     83        ]);
     84        exit;
     85    }
    7386}
  • headless/trunk/classes/Dashboard.php

    r2868064 r3033669  
    2424
    2525        $lastRevalidationRun = $this->plugin->schedule->getLastRevalidationRun();
    26         $lastRevalidationRunDate = strtotime($lastRevalidationRun);
    2726        $nextRevalidationRun = $this->plugin->schedule->getNextSchedule();
    2827
     
    3029        $ajaxUrl = admin_url('admin-ajax.php');
    3130        ?>
    32             <p>Last automatic revalidation run: <?= date_i18n($dateFormat,$lastRevalidationRunDate)." ".date_i18n($timeFormat, $lastRevalidationRunDate); ?></p>
    33             <p>Next automatic revalidation run: <?= ($nextRevalidationRun === false) ? "🚨 Broken" : date_i18n($dateFormat, $nextRevalidationRun)." ".date_i18n($timeFormat, $nextRevalidationRun); ?></p>
     31            <p><strong>Automatic revalidation</strong></p>
     32            <p>Last revalidation run: <span data-headless-timestamp="<?= $lastRevalidationRun; ?>">
     33                    <?= date_i18n($dateFormat,$lastRevalidationRun)." ".date_i18n($timeFormat, $lastRevalidationRun); ?>
     34                </span></p>
     35
     36            <p>Next revalidation run:  <span data-headless-timestamp="<?= $nextRevalidationRun; ?>">
     37                <?= ($nextRevalidationRun === false) ? "🚨 Broken" : date_i18n($dateFormat, $nextRevalidationRun)." ".date_i18n($timeFormat, $nextRevalidationRun); ?>
     38                </span></p>
     39
    3440            <p>Pending posts to be revalidated: <?= $this->plugin->dbRevalidation->countPendingPosts(); ?></p>
    35             <p>Available frontends:</p>
    36             <ol>
     41
     42            <button class="button button-secondary" id="headless-revalidate-pending">Revalidate pending</button>
     43            <span id="headless-revalidate-pending-spinner" class="spinner"></span>
     44
     45            <script>
     46                document.querySelectorAll("[data-headless-timestamp]").forEach((el) => {
     47                    const timestamp = el.getAttribute("data-headless-timestamp");
     48                    console.debug("headless timestamp", timestamp, el);
     49                    console.debug(Intl.DateTimeFormat().format(parseInt(timestamp) * 1000));
     50                });
     51                const button = document.getElementById("headless-revalidate-pending");
     52                const spinner = document.getElementById("headless-revalidate-pending-spinner");
     53
     54                button.addEventListener("click", (e)=> {
     55                    e.preventDefault();
     56                    console.debug(button);
     57                    button.disabled = true;
     58                    spinner.classList.add("is-active");
     59                    fetch("<?= $ajaxUrl ?>?action=headless_revalidate_pending")
     60                        .then(res => res.json())
     61                        .then(console.debug)
     62                        .finally(()=>{
     63                            spinner.classList.remove("is-active");
     64                            button.disabled = false;
     65                        });
     66                })
     67            </script>
     68
     69            <hr />
     70
     71            <p><strong>Manual revalidation</strong></p>
     72            <ul>
    3773                <?php
    3874                foreach ($frontends as $index => $frontend){
     
    4682                }
    4783                ?>
    48             </ol>
     84            </ul>
    4985            <form method="post" id="headless-revalidate-form">
    5086                <input type="text" name="headless_invalidate_path" placeholder="path/to/invalidate" />
  • headless/trunk/dist/admin.asset.php

    r2901812 r3033669  
    1 <?php return array('dependencies' => array(), 'version' => 'ecdaf49b7e3ddff3eb2a');
     1<?php return array('dependencies' => array(), 'version' => '4395236daaca37a54365');
  • headless/trunk/dist/admin.js

    r2901812 r3033669  
    1 !function(){"use strict";window.addEventListener("DOMContentLoaded",(async()=>{await Promise.all(window.HeadlessAdmin.frontends.map((e=>e+window.HeadlessAdmin.preview_path)).map((e=>fetch(e,{credentials:"include"}).then((e=>e.json())))))}))}();
     1/******/ (function() { // webpackBootstrap
     2/******/    "use strict";
     3/******/    var __webpack_modules__ = ({
     4
     5/***/ "./src/store/admin-window.ts":
     6/*!***********************************!*\
     7  !*** ./src/store/admin-window.ts ***!
     8  \***********************************/
     9/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     10
     11__webpack_require__.r(__webpack_exports__);
     12/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     13/* harmony export */   getPreviewPath: function() { return /* binding */ getPreviewPath; },
     14/* harmony export */   getPreviewUrls: function() { return /* binding */ getPreviewUrls; }
     15/* harmony export */ });
     16const getPreviewPath = () => window.HeadlessAdmin.preview_path;
     17const getPreviewUrls = () => {
     18  return window.HeadlessAdmin.frontends.map(frontend => {
     19    return frontend + getPreviewPath();
     20  });
     21};
     22
     23/***/ })
     24
     25/******/    });
     26/************************************************************************/
     27/******/    // The module cache
     28/******/    var __webpack_module_cache__ = {};
     29/******/   
     30/******/    // The require function
     31/******/    function __webpack_require__(moduleId) {
     32/******/        // Check if module is in cache
     33/******/        var cachedModule = __webpack_module_cache__[moduleId];
     34/******/        if (cachedModule !== undefined) {
     35/******/            return cachedModule.exports;
     36/******/        }
     37/******/        // Create a new module (and put it into the cache)
     38/******/        var module = __webpack_module_cache__[moduleId] = {
     39/******/            // no module.id needed
     40/******/            // no module.loaded needed
     41/******/            exports: {}
     42/******/        };
     43/******/   
     44/******/        // Execute the module function
     45/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
     46/******/   
     47/******/        // Return the exports of the module
     48/******/        return module.exports;
     49/******/    }
     50/******/   
     51/************************************************************************/
     52/******/    /* webpack/runtime/define property getters */
     53/******/    !function() {
     54/******/        // define getter functions for harmony exports
     55/******/        __webpack_require__.d = function(exports, definition) {
     56/******/            for(var key in definition) {
     57/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
     58/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
     59/******/                }
     60/******/            }
     61/******/        };
     62/******/    }();
     63/******/   
     64/******/    /* webpack/runtime/hasOwnProperty shorthand */
     65/******/    !function() {
     66/******/        __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
     67/******/    }();
     68/******/   
     69/******/    /* webpack/runtime/make namespace object */
     70/******/    !function() {
     71/******/        // define __esModule on exports
     72/******/        __webpack_require__.r = function(exports) {
     73/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
     74/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
     75/******/            }
     76/******/            Object.defineProperty(exports, '__esModule', { value: true });
     77/******/        };
     78/******/    }();
     79/******/   
     80/************************************************************************/
     81var __webpack_exports__ = {};
     82// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
     83!function() {
     84/*!**********************!*\
     85  !*** ./src/admin.ts ***!
     86  \**********************/
     87__webpack_require__.r(__webpack_exports__);
     88/* harmony import */ var _store_admin_window__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./store/admin-window */ "./src/store/admin-window.ts");
     89
     90window.addEventListener("DOMContentLoaded", async () => {
     91  const results = await Promise.all((0,_store_admin_window__WEBPACK_IMPORTED_MODULE_0__.getPreviewUrls)().map(url => fetch(url, {
     92    credentials: "include"
     93  }).then(res => res.json())));
     94});
     95}();
     96/******/ })()
     97;
     98//# sourceMappingURL=admin.js.map
  • headless/trunk/dist/gutenberg.asset.php

    r3020918 r3033669  
    1 <?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins'), 'version' => '5b547f4c4cc23f7700c1');
     1<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-plugins'), 'version' => 'd6a44e1effbbfab625f6');
  • headless/trunk/dist/gutenberg.css

    r2901812 r3033669  
    1 .block-editor-post-preview__dropdown-content .components-menu-group .edit-post-header-preview__grouping-external{display:none}#headless-preview-link{display:flex;justify-content:space-between}#headless-preview-link.is-disabled{border-color:#d3d3d3;color:grey;outline-color:#d3d3d3}
     1/*!*********************************************************************************************************************************************************************************************************************************************************************************************!*\
     2  !*** css ./node_modules/.pnpm/css-loader@6.8.1_webpack@5.88.2/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/.pnpm/postcss-loader@6.2.1_postcss@8.4.31_webpack@5.88.2/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles.css ***!
     3  \*********************************************************************************************************************************************************************************************************************************************************************************************/
     4.block-editor-post-preview__dropdown-content .components-menu-group .edit-post-header-preview__grouping-external {
     5    display: none;
     6}
     7#headless-preview-link {
     8    display: flex;
     9    justify-content: space-between;
     10}
     11
     12#headless-preview-link.is-disabled {
     13    color: grey;
     14    border-color: lightgrey;
     15    outline-color: lightgrey;
     16}
     17
     18
     19
     20/*# sourceMappingURL=gutenberg.css.map*/
  • headless/trunk/dist/gutenberg.js

    r3020918 r3033669  
    1 !function(){"use strict";var t=window.wp.plugins,e=window.React,n=window.wp.editPost,s=window.wp.components;var a=window.wp.data,i=window.wp.element;const r=()=>(0,a.useSelect)((t=>t("core/editor").getCurrentPost()),[]),o=({index:t,baseUrl:n,controller:s,onStateChanged:a})=>{const{state:o,reload:l}=(t=>{const[e,n]=(0,i.useState)("idle"),s=r(),a=(0,i.useMemo)((()=>s?.link?new URL(s?.link).pathname:""),[s.link]);return{state:e,reload:()=>{n("loading"),(async()=>{try{const e=await fetch(((t,e)=>window.Headless.ajax+`?action=${window.Headless.actions.revalidate}&frontend=${t}&path=${e}`)(t,a)),s=await e.json();s.success?n("success"):(console.error(s),n("error"))}catch(t){n("error")}})()}}})(t),c=r(),d=(0,i.useMemo)((()=>{const t=c.link,e=new URL(t);return n.replace(/^\/|\/$/g,"")+e.pathname}),[c.link]);return(0,i.useEffect)((()=>{s.add(t,l)}),[t]),(0,i.useEffect)((()=>{a(t,o)}),[o]),(0,e.createElement)("div",{title:d},(0,e.createElement)("a",{href:d,target:"_blank"},"Frontend ",t),"loading"==o&&(0,e.createElement)(e.Fragment,null," 🧹"),"success"==o&&(0,e.createElement)(e.Fragment,null," ✅"),"error"==o&&(0,e.createElement)(e.Fragment,null," 🚨"))};(0,t.registerPlugin)("headless-plugin",{icon:()=>null,render:function(){const t=window.Headless.frontends,a=(0,i.useMemo)((()=>(()=>{const t=new Map;return{add:(e,n)=>{t.set(e,n)},run:()=>{t.forEach((t=>{t()}))}}})()),[]),[l,c]=(0,i.useState)({}),d="publish"==r().status,p=Object.values(l).find((t=>1==t));return(0,e.createElement)(n.PluginDocumentSettingPanel,{title:"Headless"},d?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("ol",null,t.map(((t,n)=>(0,e.createElement)("li",{key:n},(0,e.createElement)(o,{baseUrl:t,index:n,controller:a,onStateChanged:(t,e)=>{c((n=>{const s={...n};return s[t]="loading"==e,s}))}}))))),(0,e.createElement)(s.Button,{variant:"secondary",disabled:p||!d,onClick:()=>{a.run()}},"Revalidate cache")):(0,e.createElement)("p",{className:"description"},"Only published contents can be revalidated."))}}),document.addEventListener("DOMContentLoaded",(function(){const t=(0,a.select)("core/editor"),e=t.getCurrentPostId,n=t.isSavingPost,s=(0,a.dispatch)("core/editor"),i=s.autosave,r=s.savePost,o=document.createElement("a");o.className="components-button",o.addEventListener("click",(e=>{if(e.preventDefault(),n())return;const s=window.open("about:blank",o.target);!function(t){let e="";e+='\n\t\t<style>\n\t\t\tbody {\n\t\t\t\tmargin: 0;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message {\n\t\t\t\tdisplay: flex;\n\t\t\t\tflex-direction: column;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\twidth: 100vw;\n\t\t\t}\n\t\t\t@-webkit-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-moz-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-o-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg {\n\t\t\t\twidth: 192px;\n\t\t\t\theight: 192px;\n\t\t\t\tstroke: #555d66;\n\t\t\t\tstroke-width: 0.75;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg .outer,\n\t\t\t.editor-post-preview-button__interstitial-message svg .inner {\n\t\t\t\tstroke-dasharray: 280;\n\t\t\t\tstroke-dashoffset: 280;\n\t\t\t\t-webkit-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-moz-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-o-animation: paint 1.5s ease infinite alternate;\n\t\t\t\tanimation: paint 1.5s ease infinite alternate;\n\t\t\t}\n\t\t\tp {\n\t\t\t\ttext-align: center;\n\t\t\t\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;\n\t\t\t}\n\t\t</style>\n\t',e+='\n        <div class="editor-post-preview-button__interstitial-message">\n            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">\n                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />\n                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />\n            </svg>\n            <p>Generating preview…</p>\n        </div>\n    ',t.write('\n\t\t<style>\n\t\t\tbody {\n\t\t\t\tmargin: 0;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message {\n\t\t\t\tdisplay: flex;\n\t\t\t\tflex-direction: column;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\twidth: 100vw;\n\t\t\t}\n\t\t\t@-webkit-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-moz-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@-o-keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t@keyframes paint {\n\t\t\t\t0% {\n\t\t\t\t\tstroke-dashoffset: 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg {\n\t\t\t\twidth: 192px;\n\t\t\t\theight: 192px;\n\t\t\t\tstroke: #555d66;\n\t\t\t\tstroke-width: 0.75;\n\t\t\t}\n\t\t\t.editor-post-preview-button__interstitial-message svg .outer,\n\t\t\t.editor-post-preview-button__interstitial-message svg .inner {\n\t\t\t\tstroke-dasharray: 280;\n\t\t\t\tstroke-dashoffset: 280;\n\t\t\t\t-webkit-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-moz-animation: paint 1.5s ease infinite alternate;\n\t\t\t\t-o-animation: paint 1.5s ease infinite alternate;\n\t\t\t\tanimation: paint 1.5s ease infinite alternate;\n\t\t\t}\n\t\t\tp {\n\t\t\t\ttext-align: center;\n\t\t\t\tfont-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;\n\t\t\t}\n\t\t</style>\n\t\n        <div class="editor-post-preview-button__interstitial-message">\n            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">\n                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />\n                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />\n            </svg>\n            <p>Generating preview…</p>\n        </div>\n    '),t.close()}(s.document),((()=>{const e=t.getCurrentPost().status;return"draft"==e||"auto-draft"==e})()?r:i)().then((()=>{s.location=o.href}))})),(0,a.subscribe)((()=>{n()?o.classList.add("is-disabled"):o.classList.remove("is-disabled")})),setInterval((function(){const t=e(),n=(t=>window.Headless.preview_url.replace(window.Headless.post_id_placeholder,`${t}`))(t),s=document.querySelectorAll("[target^=wp-preview-]");s&&s.length&&s.forEach((t=>{t.setAttribute("href",n)})),document.querySelectorAll(".components-snackbar-list .components-snackbar__content a.components-button").forEach((e=>{(e.href.includes("?post="+t)||e.href.includes("?page_id="+t)||e.href.includes("?p="+t))&&(e.href=n,e.target="wp-preview-"+t)}));const a=document.querySelectorAll(".edit-post-post-preview-dropdown .components-menu-group");let i=null;if(a.forEach((t=>{t.querySelector(".edit-post-header-preview__grouping-external")&&(i=t)})),!i)return;const r="headless-preview-link";if(i.querySelector("#"+r))return;const l=i.querySelector(".edit-post-header-preview__grouping-external a"),c=l.getAttribute("target");o.text=l.textContent;const d=document.createElement("span");d.className="dashicons dashicons-external",o.append(d),o.target=c,o.href=n,o.id=r,i.querySelector('[role="group"]').append(o)}),300)}))}();
     1/******/ (function() { // webpackBootstrap
     2/******/    "use strict";
     3/******/    var __webpack_modules__ = ({
     4
     5/***/ "./src/components/ReloadPanel.tsx":
     6/*!****************************************!*\
     7  !*** ./src/components/ReloadPanel.tsx ***!
     8  \****************************************/
     9/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     10
     11__webpack_require__.r(__webpack_exports__);
     12/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     13/* harmony export */   "default": function() { return /* binding */ ReloadPanel; }
     14/* harmony export */ });
     15/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
     16/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
     17/* harmony import */ var _wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/edit-post */ "@wordpress/edit-post");
     18/* harmony import */ var _wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__);
     19/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
     20/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__);
     21/* harmony import */ var _hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../hooks/use-reload */ "./src/hooks/use-reload.ts");
     22/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../store/window */ "./src/store/window.ts");
     23/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
     24/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__);
     25
     26
     27
     28
     29
     30
     31const buildController = () => {
     32  const fns = new Map();
     33  return {
     34    add: (frontend, fn) => {
     35      fns.set(frontend, fn);
     36    },
     37    run: () => {
     38      fns.forEach(fn => {
     39        fn();
     40      });
     41    }
     42  };
     43};
     44const FrontendItem = ({
     45  index,
     46  baseUrl,
     47  controller,
     48  onStateChanged
     49}) => {
     50  const {
     51    state,
     52    reload
     53  } = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.useReload)(index);
     54  const post = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.usePost)();
     55  const url = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => {
     56    const link = post.link;
     57    const url = new URL(link);
     58    ;
     59    return baseUrl.replace(/^\/|\/$/g, '') + url.pathname;
     60  }, [post.link]);
     61  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => {
     62    controller.add(index, reload);
     63  }, [index]);
     64  (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => {
     65    onStateChanged(index, state);
     66  }, [state]);
     67  return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
     68    title: url
     69  }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", {
     70    href: url,
     71    target: "_blank"
     72  }, "Frontend ", index), state == "loading" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \uD83E\uDDF9"), state == "success" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \u2705"), state == "error" && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, " \uD83D\uDEA8"));
     73};
     74function ReloadPanel() {
     75  const frontends = (0,_store_window__WEBPACK_IMPORTED_MODULE_4__.getFrontends)();
     76  const controller = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => buildController(), []);
     77  const [loadingState, setLoadingState] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useState)({});
     78  const canRevalidate = (0,_hooks_use_reload__WEBPACK_IMPORTED_MODULE_3__.useCanRevalidate)();
     79  const handleClick = () => {
     80    controller.run();
     81  };
     82  const isLoading = Object.values(loadingState).find(value => value == true);
     83  return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_post__WEBPACK_IMPORTED_MODULE_1__.PluginDocumentSettingPanel, {
     84    title: "Headless"
     85  }, canRevalidate ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("ol", null, frontends.map((frontend, index) => {
     86    return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", {
     87      key: index
     88    }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(FrontendItem, {
     89      baseUrl: frontend,
     90      index: index,
     91      controller: controller,
     92      onStateChanged: (index, state) => {
     93        setLoadingState(prev => {
     94          const copy = {
     95            ...prev
     96          };
     97          copy[index] = state == "loading";
     98          return copy;
     99        });
     100      }
     101    }));
     102  })), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_2__.Button, {
     103    variant: "secondary",
     104    disabled: isLoading || !canRevalidate,
     105    onClick: handleClick
     106  }, "Revalidate cache")) : (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", {
     107    className: "description"
     108  }, "Only published contents can be revalidated."));
     109}
     110
     111/***/ }),
     112
     113/***/ "./src/hooks/use-reload.ts":
     114/*!*********************************!*\
     115  !*** ./src/hooks/use-reload.ts ***!
     116  \*********************************/
     117/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     118
     119__webpack_require__.r(__webpack_exports__);
     120/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     121/* harmony export */   useCanRevalidate: function() { return /* binding */ useCanRevalidate; },
     122/* harmony export */   usePost: function() { return /* binding */ usePost; },
     123/* harmony export */   useReload: function() { return /* binding */ useReload; }
     124/* harmony export */ });
     125/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../store/window */ "./src/store/window.ts");
     126/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
     127/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
     128/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
     129/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__);
     130
     131
     132
     133const usePost = () => {
     134  return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => select("core/editor").getCurrentPost(), []);
     135};
     136const useCanRevalidate = () => {
     137  return usePost().status == "publish";
     138};
     139const useReload = frontend => {
     140  const [state, setState] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useState)("idle");
     141  const post = usePost();
     142  const path = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useMemo)(() => {
     143    if (post?.link) {
     144      const url = new URL(post?.link);
     145      return url.pathname;
     146    } else {
     147      return "";
     148    }
     149  }, [post.link]);
     150  return {
     151    state,
     152    reload: () => {
     153      setState("loading");
     154      (async () => {
     155        try {
     156          const response = await fetch((0,_store_window__WEBPACK_IMPORTED_MODULE_0__.getReloadAjaxUrl)(frontend, path));
     157          const json = await response.json();
     158          if (json.success) {
     159            setState("success");
     160          } else {
     161            console.error(json);
     162            setState("error");
     163          }
     164        } catch (e) {
     165          setState("error");
     166        }
     167      })();
     168    }
     169  };
     170};
     171
     172/***/ }),
     173
     174/***/ "./src/preview.ts":
     175/*!************************!*\
     176  !*** ./src/preview.ts ***!
     177  \************************/
     178/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     179
     180__webpack_require__.r(__webpack_exports__);
     181/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     182/* harmony export */   writeInterstitialMessage: function() { return /* binding */ writeInterstitialMessage; }
     183/* harmony export */ });
     184function writeInterstitialMessage(targetDocument) {
     185  let markup = '';
     186  markup += `
     187        <style>
     188            body {
     189                margin: 0;
     190            }
     191            .editor-post-preview-button__interstitial-message {
     192                display: flex;
     193                flex-direction: column;
     194                align-items: center;
     195                justify-content: center;
     196                height: 100vh;
     197                width: 100vw;
     198            }
     199            @-webkit-keyframes paint {
     200                0% {
     201                    stroke-dashoffset: 0;
     202                }
     203            }
     204            @-moz-keyframes paint {
     205                0% {
     206                    stroke-dashoffset: 0;
     207                }
     208            }
     209            @-o-keyframes paint {
     210                0% {
     211                    stroke-dashoffset: 0;
     212                }
     213            }
     214            @keyframes paint {
     215                0% {
     216                    stroke-dashoffset: 0;
     217                }
     218            }
     219            .editor-post-preview-button__interstitial-message svg {
     220                width: 192px;
     221                height: 192px;
     222                stroke: #555d66;
     223                stroke-width: 0.75;
     224            }
     225            .editor-post-preview-button__interstitial-message svg .outer,
     226            .editor-post-preview-button__interstitial-message svg .inner {
     227                stroke-dasharray: 280;
     228                stroke-dashoffset: 280;
     229                -webkit-animation: paint 1.5s ease infinite alternate;
     230                -moz-animation: paint 1.5s ease infinite alternate;
     231                -o-animation: paint 1.5s ease infinite alternate;
     232                animation: paint 1.5s ease infinite alternate;
     233            }
     234            p {
     235                text-align: center;
     236                font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
     237            }
     238        </style>
     239    `;
     240  markup += `
     241        <div class="editor-post-preview-button__interstitial-message">
     242            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96">
     243                <path class="outer" d="M48 12c19.9 0 36 16.1 36 36S67.9 84 48 84 12 67.9 12 48s16.1-36 36-36" fill="none" />
     244                <path class="inner" d="M69.5 46.4c0-3.9-1.4-6.7-2.6-8.8-1.6-2.6-3.1-4.9-3.1-7.5 0-2.9 2.2-5.7 5.4-5.7h.4C63.9 19.2 56.4 16 48 16c-11.2 0-21 5.7-26.7 14.4h2.1c3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3L40 67.5l7-20.9L42 33c-1.7-.1-3.3-.3-3.3-.3-1.7-.1-1.5-2.7.2-2.6 0 0 5.3.4 8.4.4 3.3 0 8.5-.4 8.5-.4 1.7-.1 1.9 2.4.2 2.6 0 0-1.7.2-3.7.3l11.5 34.3 3.3-10.4c1.6-4.5 2.4-7.8 2.4-10.5zM16.1 48c0 12.6 7.3 23.5 18 28.7L18.8 35c-1.7 4-2.7 8.4-2.7 13zm32.5 2.8L39 78.6c2.9.8 5.9 1.3 9 1.3 3.7 0 7.3-.6 10.6-1.8-.1-.1-.2-.3-.2-.4l-9.8-26.9zM76.2 36c0 3.2-.6 6.9-2.4 11.4L64 75.6c9.5-5.5 15.9-15.8 15.9-27.6 0-5.5-1.4-10.8-3.9-15.3.1 1 .2 2.1.2 3.3z" fill="none" />
     245            </svg>
     246            <p>Generating preview…</p>
     247        </div>
     248    `;
     249  targetDocument.write(markup);
     250  targetDocument.close();
     251}
     252
     253/***/ }),
     254
     255/***/ "./src/store/window.ts":
     256/*!*****************************!*\
     257  !*** ./src/store/window.ts ***!
     258  \*****************************/
     259/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     260
     261__webpack_require__.r(__webpack_exports__);
     262/* harmony export */ __webpack_require__.d(__webpack_exports__, {
     263/* harmony export */   getAjaxUrl: function() { return /* binding */ getAjaxUrl; },
     264/* harmony export */   getFrontends: function() { return /* binding */ getFrontends; },
     265/* harmony export */   getPreviewUrl: function() { return /* binding */ getPreviewUrl; },
     266/* harmony export */   getReloadAjaxUrl: function() { return /* binding */ getReloadAjaxUrl; }
     267/* harmony export */ });
     268const getAjaxUrl = () => window.Headless.ajax;
     269const getReloadAjaxUrl = (frontend, path) => getAjaxUrl() + `?action=${window.Headless.actions.revalidate}&frontend=${frontend}&path=${path}`;
     270const getPreviewUrl = postId => {
     271  return window.Headless.preview_url.replace(window.Headless.post_id_placeholder, `${postId}`);
     272};
     273const getFrontends = () => window.Headless.frontends;
     274
     275/***/ }),
     276
     277/***/ "./src/styles.css":
     278/*!************************!*\
     279  !*** ./src/styles.css ***!
     280  \************************/
     281/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
     282
     283__webpack_require__.r(__webpack_exports__);
     284// extracted by mini-css-extract-plugin
     285
     286
     287/***/ }),
     288
     289/***/ "react":
     290/*!************************!*\
     291  !*** external "React" ***!
     292  \************************/
     293/***/ (function(module) {
     294
     295module.exports = window["React"];
     296
     297/***/ }),
     298
     299/***/ "@wordpress/components":
     300/*!************************************!*\
     301  !*** external ["wp","components"] ***!
     302  \************************************/
     303/***/ (function(module) {
     304
     305module.exports = window["wp"]["components"];
     306
     307/***/ }),
     308
     309/***/ "@wordpress/data":
     310/*!******************************!*\
     311  !*** external ["wp","data"] ***!
     312  \******************************/
     313/***/ (function(module) {
     314
     315module.exports = window["wp"]["data"];
     316
     317/***/ }),
     318
     319/***/ "@wordpress/edit-post":
     320/*!**********************************!*\
     321  !*** external ["wp","editPost"] ***!
     322  \**********************************/
     323/***/ (function(module) {
     324
     325module.exports = window["wp"]["editPost"];
     326
     327/***/ }),
     328
     329/***/ "@wordpress/element":
     330/*!*********************************!*\
     331  !*** external ["wp","element"] ***!
     332  \*********************************/
     333/***/ (function(module) {
     334
     335module.exports = window["wp"]["element"];
     336
     337/***/ }),
     338
     339/***/ "@wordpress/plugins":
     340/*!*********************************!*\
     341  !*** external ["wp","plugins"] ***!
     342  \*********************************/
     343/***/ (function(module) {
     344
     345module.exports = window["wp"]["plugins"];
     346
     347/***/ })
     348
     349/******/    });
     350/************************************************************************/
     351/******/    // The module cache
     352/******/    var __webpack_module_cache__ = {};
     353/******/   
     354/******/    // The require function
     355/******/    function __webpack_require__(moduleId) {
     356/******/        // Check if module is in cache
     357/******/        var cachedModule = __webpack_module_cache__[moduleId];
     358/******/        if (cachedModule !== undefined) {
     359/******/            return cachedModule.exports;
     360/******/        }
     361/******/        // Create a new module (and put it into the cache)
     362/******/        var module = __webpack_module_cache__[moduleId] = {
     363/******/            // no module.id needed
     364/******/            // no module.loaded needed
     365/******/            exports: {}
     366/******/        };
     367/******/   
     368/******/        // Execute the module function
     369/******/        __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
     370/******/   
     371/******/        // Return the exports of the module
     372/******/        return module.exports;
     373/******/    }
     374/******/   
     375/************************************************************************/
     376/******/    /* webpack/runtime/compat get default export */
     377/******/    !function() {
     378/******/        // getDefaultExport function for compatibility with non-harmony modules
     379/******/        __webpack_require__.n = function(module) {
     380/******/            var getter = module && module.__esModule ?
     381/******/                function() { return module['default']; } :
     382/******/                function() { return module; };
     383/******/            __webpack_require__.d(getter, { a: getter });
     384/******/            return getter;
     385/******/        };
     386/******/    }();
     387/******/   
     388/******/    /* webpack/runtime/define property getters */
     389/******/    !function() {
     390/******/        // define getter functions for harmony exports
     391/******/        __webpack_require__.d = function(exports, definition) {
     392/******/            for(var key in definition) {
     393/******/                if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
     394/******/                    Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
     395/******/                }
     396/******/            }
     397/******/        };
     398/******/    }();
     399/******/   
     400/******/    /* webpack/runtime/hasOwnProperty shorthand */
     401/******/    !function() {
     402/******/        __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
     403/******/    }();
     404/******/   
     405/******/    /* webpack/runtime/make namespace object */
     406/******/    !function() {
     407/******/        // define __esModule on exports
     408/******/        __webpack_require__.r = function(exports) {
     409/******/            if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
     410/******/                Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
     411/******/            }
     412/******/            Object.defineProperty(exports, '__esModule', { value: true });
     413/******/        };
     414/******/    }();
     415/******/   
     416/************************************************************************/
     417var __webpack_exports__ = {};
     418// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
     419!function() {
     420/*!**************************!*\
     421  !*** ./src/gutenberg.ts ***!
     422  \**************************/
     423__webpack_require__.r(__webpack_exports__);
     424/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins");
     425/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__);
     426/* harmony import */ var _components_ReloadPanel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/ReloadPanel */ "./src/components/ReloadPanel.tsx");
     427/* harmony import */ var _store_window__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store/window */ "./src/store/window.ts");
     428/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
     429/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__);
     430/* harmony import */ var _preview__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./preview */ "./src/preview.ts");
     431/* harmony import */ var _styles_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./styles.css */ "./src/styles.css");
     432
     433
     434
     435
     436
     437
     438(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('headless-plugin', {
     439  icon: () => null,
     440  render: _components_ReloadPanel__WEBPACK_IMPORTED_MODULE_1__["default"]
     441});
     442document.addEventListener("DOMContentLoaded", function () {
     443  const coreEditorSelect = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.select)("core/editor");
     444  const getCurrentPostId = coreEditorSelect.getCurrentPostId;
     445  const isSavingPost = coreEditorSelect.isSavingPost;
     446  const isDraft = () => {
     447    const status = coreEditorSelect.getCurrentPost().status;
     448    return status == "draft" || status == "auto-draft";
     449  };
     450  const coreEditorDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.dispatch)("core/editor");
     451  const autosave = coreEditorDispatch.autosave;
     452  const savePost = coreEditorDispatch.savePost;
     453
     454  // --------------------------------------------------------
     455  // create replacement for preview link
     456  // --------------------------------------------------------
     457  const a = document.createElement("a");
     458  a.className = "components-button";
     459  a.addEventListener('click', e => {
     460    e.preventDefault();
     461    if (isSavingPost()) {
     462      return;
     463    }
     464    const ref = window.open('about:blank', a.target);
     465    (0,_preview__WEBPACK_IMPORTED_MODULE_4__.writeInterstitialMessage)(ref.document);
     466    const saveFn = isDraft() ? savePost : autosave;
     467    saveFn().then(() => {
     468      ref.location = a.href;
     469    });
     470  });
     471  (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.subscribe)(() => {
     472    if (isSavingPost()) {
     473      a.classList.add("is-disabled");
     474    } else {
     475      a.classList.remove("is-disabled");
     476    }
     477  });
     478
     479  // --------------------------------------------------------
     480  // hack it with interval updates
     481  // --------------------------------------------------------
     482  // workaround script until there's an official solution for https://github.com/WordPress/gutenberg/issues/13998
     483  setInterval(checkPreview, 300);
     484  function checkPreview() {
     485    const postId = getCurrentPostId();
     486    const previewUrl = (0,_store_window__WEBPACK_IMPORTED_MODULE_2__.getPreviewUrl)(postId);
     487
     488    // replace all preview links
     489    const editorPreviewLink = document.querySelectorAll("[target^=wp-preview-]");
     490    if (editorPreviewLink && editorPreviewLink.length) {
     491      editorPreviewLink.forEach(link => {
     492        link.setAttribute("href", previewUrl);
     493      });
     494    }
     495
     496    // replace notice link
     497    const notices = document.querySelectorAll(".components-snackbar-list .components-snackbar__content a.components-button");
     498    notices.forEach(notice => {
     499      if (notice.href.includes("?post=" + postId) // custom post types
     500      || notice.href.includes("?page_id=" + postId) // pages
     501      || notice.href.includes("?p=" + postId) // posts
     502      ) {
     503        notice.href = previewUrl;
     504        notice.target = "wp-preview-" + postId;
     505      }
     506    });
     507
     508    // replace this special preview link
     509    const previewGroups = document.querySelectorAll(".edit-post-post-preview-dropdown .components-menu-group");
     510    let externalPreviewGroup = null;
     511    previewGroups.forEach(group => {
     512      if (group.querySelector(".edit-post-header-preview__grouping-external")) {
     513        externalPreviewGroup = group;
     514      }
     515    });
     516    if (!externalPreviewGroup) {
     517      return;
     518    }
     519    const id = "headless-preview-link";
     520    if (externalPreviewGroup.querySelector("#" + id)) {
     521      return;
     522    }
     523
     524    // is hidden via styles.css
     525    const gutenbergLink = externalPreviewGroup.querySelector(".edit-post-header-preview__grouping-external a");
     526    const target = gutenbergLink.getAttribute("target");
     527    a.text = gutenbergLink.textContent;
     528    const icon = document.createElement("span");
     529    icon.className = "dashicons dashicons-external";
     530    a.append(icon);
     531    a.target = target;
     532    a.href = previewUrl;
     533    a.id = id;
     534    externalPreviewGroup.querySelector('[role="group"]').append(a);
     535  }
     536});
     537}();
     538/******/ })()
     539;
     540//# sourceMappingURL=gutenberg.js.map
  • headless/trunk/headless.php

    r3032167 r3033669  
    55 * Plugin URI: https://github.com/palasthotel/headless
    66 * Description: Adds features to use WordPress as headless CMS
    7  * Version: 2.1.2
     7 * Version: 2.2.0
    88 * Author: Palasthotel (Edward Bock) <edward.bock@palasthotel.de>
    99 * Author URI: http://www.palasthotel.de
  • headless/trunk/vendor/composer/installed.php

    r3032167 r3033669  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '333db9baf1136108d25cdaad5b62cea1aa72c601',
     6        'reference' => 'dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '333db9baf1136108d25cdaad5b62cea1aa72c601',
     16            'reference' => 'dbd1b93a4b371dbbe1368ba0301bf88e86cb9723',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.