Skip to:
Content

BuddyPress.org

Changeset 13463


Ignore:
Timestamp:
04/25/2023 09:15:07 PM (20 months ago)
Author:
imath
Message:

Use @wordpress/scripts to build BP Blocks and other Modern JS files

  • Reorganize the src/js directory so that all blocks are moved inside a

src/js/blocks/bp-{component-name} directory and all WP Admin scripts
moved inside a src/js/admin/bp-{component-name} directory

  • Create a specific webpack.config.js file for each component’s blocks

and for all scripts used inside the WP Administration.

  • Do not migrate BP Widget blocks transforms functions as Legacy widgets

will be moved from BuddyPress 12.0 to the BP Classic plugin.

  • Update all BP Blocks to use the WP Block API v2.
  • Add a new BP Block collection.
  • Built JavaScript files for blocks are now located inside a blocks

subdirectory of corresponding component's src directories

  • Built JavaScript files for WP Admin scripts are located at the same

place than before.

See #8457

Location:
trunk/src
Files:
256 added
34 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/admin/js/dismissible-admin-notices.js

    r13164 r13463  
    1 // modules are defined as an array
    2 // [ module function, map of requires ]
    3 //
    4 // map of requires is short require name -> numeric require
    5 //
    6 // anything defined in a previous bundle is accessed via the
    7 // orig method which is the require for previous bundles
    8 parcelRequire = (function (modules, cache, entry, globalName) {
    9   // Save the require from previous bundle to this closure if any
    10   var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
    11   var nodeRequire = typeof require === 'function' && require;
    12 
    13   function newRequire(name, jumped) {
    14     if (!cache[name]) {
    15       if (!modules[name]) {
    16         // if we cannot find the module within our internal map or
    17         // cache jump to the current global require ie. the last bundle
    18         // that was added to the page.
    19         var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
    20         if (!jumped && currentRequire) {
    21           return currentRequire(name, true);
    22         }
    23 
    24         // If there are other bundles on this page the require from the
    25         // previous one is saved to 'previousRequire'. Repeat this as
    26         // many times as there are bundles until the module is found or
    27         // we exhaust the require chain.
    28         if (previousRequire) {
    29           return previousRequire(name, true);
    30         }
    31 
    32         // Try the node require function if it exists.
    33         if (nodeRequire && typeof name === 'string') {
    34           return nodeRequire(name);
    35         }
    36 
    37         var err = new Error('Cannot find module \'' + name + '\'');
    38         err.code = 'MODULE_NOT_FOUND';
    39         throw err;
    40       }
    41 
    42       localRequire.resolve = resolve;
    43       localRequire.cache = {};
    44 
    45       var module = cache[name] = new newRequire.Module(name);
    46 
    47       modules[name][0].call(module.exports, localRequire, module, module.exports, this);
    48     }
    49 
    50     return cache[name].exports;
    51 
    52     function localRequire(x){
    53       return newRequire(localRequire.resolve(x));
    54     }
    55 
    56     function resolve(x){
    57       return modules[name][1][x] || x;
    58     }
    59   }
    60 
    61   function Module(moduleName) {
    62     this.id = moduleName;
    63     this.bundle = newRequire;
    64     this.exports = {};
    65   }
    66 
    67   newRequire.isParcelRequire = true;
    68   newRequire.Module = Module;
    69   newRequire.modules = modules;
    70   newRequire.cache = cache;
    71   newRequire.parent = previousRequire;
    72   newRequire.register = function (id, exports) {
    73     modules[id] = [function (require, module) {
    74       module.exports = exports;
    75     }, {}];
    76   };
    77 
    78   var error;
    79   for (var i = 0; i < entry.length; i++) {
    80     try {
    81       newRequire(entry[i]);
    82     } catch (e) {
    83       // Save first error but execute all entries
    84       if (!error) {
    85         error = e;
    86       }
    87     }
    88   }
    89 
    90   if (entry.length) {
    91     // Expose entry point to Node, AMD or browser globals
    92     // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
    93     var mainExports = newRequire(entry[entry.length - 1]);
    94 
    95     // CommonJS
    96     if (typeof exports === "object" && typeof module !== "undefined") {
    97       module.exports = mainExports;
    98 
    99     // RequireJS
    100     } else if (typeof define === "function" && define.amd) {
    101      define(function () {
    102        return mainExports;
    103      });
    104 
    105     // <script>
    106     } else if (globalName) {
    107       this[globalName] = mainExports;
    108     }
    109   }
    110 
    111   // Override the current require with this new one
    112   parcelRequire = newRequire;
    113 
    114   if (error) {
    115     // throw error from earlier, _after updating parcelRequire_
    116     throw error;
    117   }
    118 
    119   return newRequire;
    120 })({"XBG5":[function(require,module,exports) {
    121 // Use the bp global.
    122 window.bp = window.bp || {};
    123 /**
    124  * Use an XHR request to dismiss admin notices.
    125  *
    126  * @since 10.0.0
    127  */
    128 
    129 bp.DismissibleAdminNotices = class {
    130   constructor(settings) {
    131     this.settings = settings || {};
    132   }
    133 
    134   start() {
    135     const {
    136       url,
    137       nonce
    138     } = this.settings;
    139 
    140     if (!url || !nonce) {
    141       return;
    142     }
    143 
    144     document.querySelectorAll('.bp-is-dismissible').forEach(notice => {
    145       notice.addEventListener('click', event => {
    146         event.preventDefault();
    147         const noticeLink = event.target;
    148 
    149         if (noticeLink.classList.contains('loading')) {
    150           return;
    151         } // Prevent multiple clicks.
    152 
    153 
    154         noticeLink.classList.add('loading'); // Set the notice ID & notice container.
    155 
    156         const {
    157           notice_id
    158         } = noticeLink.dataset;
    159         const noticeContainer = noticeLink.closest('.bp-notice-container'); // Set notice headers.
    160 
    161         const noticeHeaders = new Headers({
    162           'X-BP-Nonce': nonce
    163         }); // Set notice data.
    164 
    165         const noticeData = new FormData();
    166         noticeData.append('action', 'bp_dismiss_notice');
    167         noticeData.append('notice_id', notice_id);
    168         fetch(url, {
    169           method: 'POST',
    170           headers: noticeHeaders,
    171           body: noticeData
    172         }).then(response => {
    173           return response.json();
    174         }).then(data => {
    175           const {
    176             success
    177           } = data;
    178 
    179           if (success) {
    180             noticeContainer.remove();
    181           } else {
    182             noticeLink.classList.remove('loading');
    183           }
    184         });
    185       });
    186     });
    187   }
    188 
    189 };
    190 const settings = window.bpDismissibleAdminNoticesSettings || {};
    191 const bpDismissibleAdminNotices = new bp.DismissibleAdminNotices(settings);
    192 
    193 if ('loading' === document.readyState) {
    194   document.addEventListener('DOMContentLoaded', bpDismissibleAdminNotices.start());
    195 } else {
    196   bpDismissibleAdminNotices.start();
    197 }
    198 },{}]},{},["XBG5"], null)
     1!function(){window.bp=window.bp||{},bp.DismissibleAdminNotices=class{constructor(t){this.settings=t||{}}start(){const{url:t,nonce:e}=this.settings;t&&e&&document.querySelectorAll(".bp-is-dismissible").forEach((s=>{s.addEventListener("click",(s=>{s.preventDefault();const n=s.target;if(n.classList.contains("loading"))return;n.classList.add("loading");const{notice_id:i}=n.dataset,o=n.closest(".bp-notice-container"),c=new Headers({"X-BP-Nonce":e}),d=new FormData;d.append("action","bp_dismiss_notice"),d.append("notice_id",i),fetch(t,{method:"POST",headers:c,body:d}).then((t=>t.json())).then((t=>{const{success:e}=t;e?o.remove():n.classList.remove("loading")}))}))}))}};const t=window.bpDismissibleAdminNoticesSettings||{},e=new bp.DismissibleAdminNotices(t);"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e.start()):e.start()}();
  • trunk/src/bp-members/admin/js/admin.js

    r13164 r13463  
    1 // modules are defined as an array
    2 // [ module function, map of requires ]
    3 //
    4 // map of requires is short require name -> numeric require
    5 //
    6 // anything defined in a previous bundle is accessed via the
    7 // orig method which is the require for previous bundles
    8 parcelRequire = (function (modules, cache, entry, globalName) {
    9   // Save the require from previous bundle to this closure if any
    10   var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
    11   var nodeRequire = typeof require === 'function' && require;
    12 
    13   function newRequire(name, jumped) {
    14     if (!cache[name]) {
    15       if (!modules[name]) {
    16         // if we cannot find the module within our internal map or
    17         // cache jump to the current global require ie. the last bundle
    18         // that was added to the page.
    19         var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
    20         if (!jumped && currentRequire) {
    21           return currentRequire(name, true);
    22         }
    23 
    24         // If there are other bundles on this page the require from the
    25         // previous one is saved to 'previousRequire'. Repeat this as
    26         // many times as there are bundles until the module is found or
    27         // we exhaust the require chain.
    28         if (previousRequire) {
    29           return previousRequire(name, true);
    30         }
    31 
    32         // Try the node require function if it exists.
    33         if (nodeRequire && typeof name === 'string') {
    34           return nodeRequire(name);
    35         }
    36 
    37         var err = new Error('Cannot find module \'' + name + '\'');
    38         err.code = 'MODULE_NOT_FOUND';
    39         throw err;
    40       }
    41 
    42       localRequire.resolve = resolve;
    43       localRequire.cache = {};
    44 
    45       var module = cache[name] = new newRequire.Module(name);
    46 
    47       modules[name][0].call(module.exports, localRequire, module, module.exports, this);
    48     }
    49 
    50     return cache[name].exports;
    51 
    52     function localRequire(x){
    53       return newRequire(localRequire.resolve(x));
    54     }
    55 
    56     function resolve(x){
    57       return modules[name][1][x] || x;
    58     }
    59   }
    60 
    61   function Module(moduleName) {
    62     this.id = moduleName;
    63     this.bundle = newRequire;
    64     this.exports = {};
    65   }
    66 
    67   newRequire.isParcelRequire = true;
    68   newRequire.Module = Module;
    69   newRequire.modules = modules;
    70   newRequire.cache = cache;
    71   newRequire.parent = previousRequire;
    72   newRequire.register = function (id, exports) {
    73     modules[id] = [function (require, module) {
    74       module.exports = exports;
    75     }, {}];
    76   };
    77 
    78   var error;
    79   for (var i = 0; i < entry.length; i++) {
    80     try {
    81       newRequire(entry[i]);
    82     } catch (e) {
    83       // Save first error but execute all entries
    84       if (!error) {
    85         error = e;
    86       }
    87     }
    88   }
    89 
    90   if (entry.length) {
    91     // Expose entry point to Node, AMD or browser globals
    92     // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
    93     var mainExports = newRequire(entry[entry.length - 1]);
    94 
    95     // CommonJS
    96     if (typeof exports === "object" && typeof module !== "undefined") {
    97       module.exports = mainExports;
    98 
    99     // RequireJS
    100     } else if (typeof define === "function" && define.amd) {
    101      define(function () {
    102        return mainExports;
    103      });
    104 
    105     // <script>
    106     } else if (globalName) {
    107       this[globalName] = mainExports;
    108     }
    109   }
    110 
    111   // Override the current require with this new one
    112   parcelRequire = newRequire;
    113 
    114   if (error) {
    115     // throw error from earlier, _after updating parcelRequire_
    116     throw error;
    117   }
    118 
    119   return newRequire;
    120 })({"wb1e":[function(require,module,exports) {
    121 // Use the bp global.
    122 window.bp = window.bp || {};
    123 /**
    124  * Clears the checked/selected options of a radio button or a multiple select.
    125  *
    126  * @since 10.0.0
    127  * @param {HTMLElement} container The HTMLElement containing the options to clear.
    128  * @returns {void}
    129  */
    130 
    131 bp.clear = container => {
    132   const optionsContainer = document.getElementById(container);
    133 
    134   if (!optionsContainer) {
    135     return;
    136   }
    137 
    138   const checkedRadio = optionsContainer.querySelector('input:checked');
    139   const allOptions = optionsContainer.querySelectorAll('option');
    140 
    141   if (checkedRadio) {
    142     checkedRadio.checked = '';
    143   }
    144 
    145   if (allOptions) {
    146     allOptions.forEach(option => {
    147       option.selected = false;
    148     });
    149   }
    150 };
    151 
    152 document.querySelectorAll('.visibility-toggle-link').forEach(button => {
    153   button.addEventListener('click', event => {
    154     event.preventDefault();
    155     const changeButton = event.target;
    156     const changeButtonContainer = changeButton.closest('.field-visibility-settings-toggle');
    157     const settingsContainer = changeButtonContainer.nextElementSibling; // Hides the "Change" button.
    158 
    159     changeButton.setAttribute('aria-expanded', true);
    160     changeButtonContainer.style.display = 'none'; // Displays the settings visibility container.
    161 
    162     settingsContainer.style.display = 'block';
    163   });
    164 });
    165 document.querySelectorAll('.field-visibility-settings-close').forEach(button => {
    166   button.addEventListener('click', event => {
    167     event.preventDefault();
    168     const closeButton = event.target;
    169     const settingsContainer = closeButton.closest('.field-visibility-settings');
    170     const changeButtonContainer = settingsContainer.previousElementSibling;
    171     const currentVisibility = settingsContainer.querySelector('input:checked').nextElementSibling.innerHTML; // Closes the visibility settings options.
    172 
    173     settingsContainer.style.display = 'none'; // Displays the current visibility.
    174 
    175     changeButtonContainer.querySelector('.visibility-toggle-link').setAttribute('aria-expanded', false);
    176     changeButtonContainer.querySelector('.current-visibility-level').innerHTML = currentVisibility;
    177     changeButtonContainer.style.display = 'block';
    178   });
    179 });
    180 },{}]},{},["wb1e"], null)
     1window.bp=window.bp||{},bp.clear=e=>{const t=document.getElementById(e);if(!t)return;const i=t.querySelector("input:checked"),l=t.querySelectorAll("option");i&&(i.checked=""),l&&l.forEach((e=>{e.selected=!1}))},document.querySelectorAll(".visibility-toggle-link").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.target,i=t.closest(".field-visibility-settings-toggle"),l=i.nextElementSibling;t.setAttribute("aria-expanded",!0),i.style.display="none",l.style.display="block"}))})),document.querySelectorAll(".field-visibility-settings-close").forEach((e=>{e.addEventListener("click",(e=>{e.preventDefault();const t=e.target.closest(".field-visibility-settings"),i=t.previousElementSibling,l=t.querySelector("input:checked").nextElementSibling.innerHTML;t.style.display="none",i.querySelector(".visibility-toggle-link").setAttribute("aria-expanded",!1),i.querySelector(".current-visibility-level").innerHTML=l,i.style.display="block"}))}));
Note: See TracChangeset for help on using the changeset viewer.