[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/js/blocks/ -> groups.js (source)

   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  })({"jEQo":[function(require,module,exports) {
 121  function _arrayLikeToArray(arr, len) {
 122    if (len == null || len > arr.length) len = arr.length;
 123  
 124    for (var i = 0, arr2 = new Array(len); i < len; i++) {
 125      arr2[i] = arr[i];
 126    }
 127  
 128    return arr2;
 129  }
 130  
 131  module.exports = _arrayLikeToArray;
 132  },{}],"o3SL":[function(require,module,exports) {
 133  var arrayLikeToArray = require("./arrayLikeToArray");
 134  
 135  function _arrayWithoutHoles(arr) {
 136    if (Array.isArray(arr)) return arrayLikeToArray(arr);
 137  }
 138  
 139  module.exports = _arrayWithoutHoles;
 140  },{"./arrayLikeToArray":"jEQo"}],"lZpU":[function(require,module,exports) {
 141  function _iterableToArray(iter) {
 142    if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
 143  }
 144  
 145  module.exports = _iterableToArray;
 146  },{}],"Dbv9":[function(require,module,exports) {
 147  var arrayLikeToArray = require("./arrayLikeToArray");
 148  
 149  function _unsupportedIterableToArray(o, minLen) {
 150    if (!o) return;
 151    if (typeof o === "string") return arrayLikeToArray(o, minLen);
 152    var n = Object.prototype.toString.call(o).slice(8, -1);
 153    if (n === "Object" && o.constructor) n = o.constructor.name;
 154    if (n === "Map" || n === "Set") return Array.from(n);
 155    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
 156  }
 157  
 158  module.exports = _unsupportedIterableToArray;
 159  },{"./arrayLikeToArray":"jEQo"}],"NCaH":[function(require,module,exports) {
 160  function _nonIterableSpread() {
 161    throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
 162  }
 163  
 164  module.exports = _nonIterableSpread;
 165  },{}],"I9dH":[function(require,module,exports) {
 166  var arrayWithoutHoles = require("./arrayWithoutHoles");
 167  
 168  var iterableToArray = require("./iterableToArray");
 169  
 170  var unsupportedIterableToArray = require("./unsupportedIterableToArray");
 171  
 172  var nonIterableSpread = require("./nonIterableSpread");
 173  
 174  function _toConsumableArray(arr) {
 175    return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
 176  }
 177  
 178  module.exports = _toConsumableArray;
 179  },{"./arrayWithoutHoles":"o3SL","./iterableToArray":"lZpU","./unsupportedIterableToArray":"Dbv9","./nonIterableSpread":"NCaH"}],"DCTP":[function(require,module,exports) {
 180  function _arrayWithHoles(arr) {
 181    if (Array.isArray(arr)) return arr;
 182  }
 183  
 184  module.exports = _arrayWithHoles;
 185  },{}],"LoeL":[function(require,module,exports) {
 186  function _iterableToArrayLimit(arr, i) {
 187    if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
 188    var _arr = [];
 189    var _n = true;
 190    var _d = false;
 191    var _e = undefined;
 192  
 193    try {
 194      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
 195        _arr.push(_s.value);
 196  
 197        if (i && _arr.length === i) break;
 198      }
 199    } catch (err) {
 200      _d = true;
 201      _e = err;
 202    } finally {
 203      try {
 204        if (!_n && _i["return"] != null) _i["return"]();
 205      } finally {
 206        if (_d) throw _e;
 207      }
 208    }
 209  
 210    return _arr;
 211  }
 212  
 213  module.exports = _iterableToArrayLimit;
 214  },{}],"MWEO":[function(require,module,exports) {
 215  function _nonIterableRest() {
 216    throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
 217  }
 218  
 219  module.exports = _nonIterableRest;
 220  },{}],"DERy":[function(require,module,exports) {
 221  var arrayWithHoles = require("./arrayWithHoles");
 222  
 223  var iterableToArrayLimit = require("./iterableToArrayLimit");
 224  
 225  var unsupportedIterableToArray = require("./unsupportedIterableToArray");
 226  
 227  var nonIterableRest = require("./nonIterableRest");
 228  
 229  function _slicedToArray(arr, i) {
 230    return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
 231  }
 232  
 233  module.exports = _slicedToArray;
 234  },{"./arrayWithHoles":"DCTP","./iterableToArrayLimit":"LoeL","./unsupportedIterableToArray":"Dbv9","./nonIterableRest":"MWEO"}],"jS06":[function(require,module,exports) {
 235  "use strict";
 236  
 237  Object.defineProperty(exports, "__esModule", {
 238    value: true
 239  });
 240  exports.EXTRA_INFO = exports.GROUP_STATI = exports.AVATAR_SIZES = void 0;
 241  
 242  /**
 243   * WordPress dependencies.
 244   */
 245  var _wp = wp,
 246      __ = _wp.i18n.__;
 247  /**
 248   * Avatar sizes.
 249   *
 250   * @type {Array}
 251   */
 252  
 253  var AVATAR_SIZES = [{
 254    label: __('None', 'buddypress'),
 255    value: 'none'
 256  }, {
 257    label: __('Thumb', 'buddypress'),
 258    value: 'thumb'
 259  }, {
 260    label: __('Full', 'buddypress'),
 261    value: 'full'
 262  }];
 263  /**
 264   * Group stati.
 265   *
 266   * @type {Object}
 267   */
 268  
 269  exports.AVATAR_SIZES = AVATAR_SIZES;
 270  var GROUP_STATI = {
 271    public: __('Public', 'buddypress'),
 272    private: __('Private', 'buddypress'),
 273    hidden: __('Hidden', 'buddypress')
 274  };
 275  /**
 276   * Group Extra data.
 277   *
 278   * @type {Array}
 279   */
 280  
 281  exports.GROUP_STATI = GROUP_STATI;
 282  var EXTRA_INFO = [{
 283    label: __('None', 'buddypress'),
 284    value: 'none'
 285  }, {
 286    label: __('Group\'s description', 'buddypress'),
 287    value: 'description'
 288  }, {
 289    label: __('Last time the group was active', 'buddypress'),
 290    value: 'active'
 291  }, {
 292    label: __('Amount of group members', 'buddypress'),
 293    value: 'popular'
 294  }];
 295  exports.EXTRA_INFO = EXTRA_INFO;
 296  },{}],"Ccmh":[function(require,module,exports) {
 297  "use strict";
 298  
 299  Object.defineProperty(exports, "__esModule", {
 300    value: true
 301  });
 302  exports.default = void 0;
 303  
 304  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
 305  
 306  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
 307  
 308  var _constants = require("./constants");
 309  
 310  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 311  
 312  /**
 313   * WordPress dependencies.
 314   */
 315  var _wp = wp,
 316      _wp$blockEditor = _wp.blockEditor,
 317      InspectorControls = _wp$blockEditor.InspectorControls,
 318      BlockControls = _wp$blockEditor.BlockControls,
 319      _wp$components = _wp.components,
 320      Placeholder = _wp$components.Placeholder,
 321      PanelBody = _wp$components.PanelBody,
 322      SelectControl = _wp$components.SelectControl,
 323      ToggleControl = _wp$components.ToggleControl,
 324      Button = _wp$components.Button,
 325      Dashicon = _wp$components.Dashicon,
 326      Tooltip = _wp$components.Tooltip,
 327      ToolbarGroup = _wp$components.ToolbarGroup,
 328      RangeControl = _wp$components.RangeControl,
 329      _wp$element = _wp.element,
 330      createElement = _wp$element.createElement,
 331      Fragment = _wp$element.Fragment,
 332      useState = _wp$element.useState,
 333      _wp$i18n = _wp.i18n,
 334      __ = _wp$i18n.__,
 335      sprintf = _wp$i18n.sprintf,
 336      _n = _wp$i18n._n,
 337      apiFetch = _wp.apiFetch,
 338      addQueryArgs = _wp.url.addQueryArgs;
 339  /**
 340   * BuddyPress dependencies.
 341   */
 342  
 343  var _bp = bp,
 344      AutoCompleter = _bp.blockComponents.AutoCompleter,
 345      isActive = _bp.blockData.isActive;
 346  /**
 347   * Internal dependencies.
 348   */
 349  
 350  /**
 351   * External dependencies.
 352   */
 353  var _lodash = lodash,
 354      reject = _lodash.reject,
 355      remove = _lodash.remove,
 356      sortBy = _lodash.sortBy;
 357  
 358  var getSlugValue = function getSlugValue(item) {
 359    if (item && item.status && _constants.GROUP_STATI[item.status]) {
 360      return _constants.GROUP_STATI[item.status];
 361    }
 362  
 363    return null;
 364  };
 365  
 366  var editGroupsBlock = function editGroupsBlock(_ref) {
 367    var attributes = _ref.attributes,
 368        setAttributes = _ref.setAttributes,
 369        isSelected = _ref.isSelected;
 370    var isAvatarEnabled = isActive('groups', 'avatar');
 371    var itemIDs = attributes.itemIDs,
 372        avatarSize = attributes.avatarSize,
 373        displayGroupName = attributes.displayGroupName,
 374        extraInfo = attributes.extraInfo,
 375        layoutPreference = attributes.layoutPreference,
 376        columns = attributes.columns;
 377    var hasGroups = 0 !== itemIDs.length;
 378  
 379    var _useState = useState([]),
 380        _useState2 = (0, _slicedToArray2.default)(_useState, 2),
 381        groups = _useState2[0],
 382        setGroups = _useState2[1];
 383  
 384    var layoutControls = [{
 385      icon: 'text',
 386      title: __('List view', 'buddypress'),
 387      onClick: function onClick() {
 388        return setAttributes({
 389          layoutPreference: 'list'
 390        });
 391      },
 392      isActive: layoutPreference === 'list'
 393    }, {
 394      icon: 'screenoptions',
 395      title: __('Grid view', 'buddypress'),
 396      onClick: function onClick() {
 397        return setAttributes({
 398          layoutPreference: 'grid'
 399        });
 400      },
 401      isActive: layoutPreference === 'grid'
 402    }];
 403    var groupsList;
 404    var containerClasses = 'bp-block-groups avatar-' + avatarSize;
 405    var extraInfoOptions = _constants.EXTRA_INFO;
 406  
 407    if (layoutPreference === 'grid') {
 408      containerClasses += ' is-grid columns-' + columns;
 409      extraInfoOptions = _constants.EXTRA_INFO.filter(function (extra) {
 410        return 'description' !== extra.value;
 411      });
 412    }
 413  
 414    var onSelectedGroup = function onSelectedGroup(_ref2) {
 415      var itemID = _ref2.itemID;
 416  
 417      if (itemID && -1 === itemIDs.indexOf(itemID)) {
 418        setAttributes({
 419          itemIDs: [].concat((0, _toConsumableArray2.default)(itemIDs), [parseInt(itemID, 10)])
 420        });
 421      }
 422    };
 423  
 424    var onRemoveGroup = function onRemoveGroup(itemID) {
 425      if (itemID && -1 !== itemIDs.indexOf(itemID)) {
 426        setGroups(reject(groups, ['id', itemID]));
 427        setAttributes({
 428          itemIDs: remove(itemIDs, function (value) {
 429            return value !== itemID;
 430          })
 431        });
 432      }
 433    };
 434  
 435    if (hasGroups && itemIDs.length !== groups.length) {
 436      apiFetch({
 437        path: addQueryArgs("/buddypress/v1/groups", {
 438          populate_extras: true,
 439          include: itemIDs
 440        })
 441      }).then(function (items) {
 442        setGroups(sortBy(items, [function (item) {
 443          return itemIDs.indexOf(item.id);
 444        }]));
 445      });
 446    }
 447  
 448    if (groups.length) {
 449      groupsList = groups.map(function (group) {
 450        var hasDescription = false;
 451        var groupItemClasses = 'group-content';
 452  
 453        if (layoutPreference === 'list' && 'description' === extraInfo && group.description && group.description.rendered) {
 454          hasDescription = true;
 455          groupItemClasses = 'group-content has-description';
 456        }
 457  
 458        return createElement("div", {
 459          key: 'bp-group-' + group.id,
 460          className: groupItemClasses
 461        }, isSelected && createElement(Tooltip, {
 462          text: __('Remove group', 'buddypress')
 463        }, createElement(Button, {
 464          className: "is-right",
 465          onClick: function onClick() {
 466            return onRemoveGroup(group.id);
 467          },
 468          label: __('Remove group', 'buddypress')
 469        }, createElement(Dashicon, {
 470          icon: "no"
 471        }))), isAvatarEnabled && 'none' !== avatarSize && createElement("div", {
 472          className: "item-header-avatar"
 473        }, createElement("a", {
 474          href: group.link,
 475          target: "_blank"
 476        }, createElement("img", {
 477          key: 'avatar-' + group.id,
 478          className: "avatar",
 479          alt: sprintf(__('Profile photo of %s', 'buddypress'), group.name),
 480          src: group.avatar_urls[avatarSize]
 481        }))), createElement("div", {
 482          className: "group-description"
 483        }, displayGroupName && createElement("strong", null, createElement("a", {
 484          href: group.link,
 485          target: "_blank"
 486        }, group.name)), hasDescription && createElement("div", {
 487          className: "group-description-content",
 488          dangerouslySetInnerHTML: {
 489            __html: group.description.rendered
 490          }
 491        }), 'active' === extraInfo && group.last_activity && group.last_activity_diff && createElement("time", {
 492          dateTime: group.last_activity
 493        }, sprintf(__('Active %s', 'buddypress'), group.last_activity_diff)), 'popular' === extraInfo && group.total_member_count && createElement("div", {
 494          className: "group-meta"
 495        }, sprintf(
 496        /* translators: 1: number of group memberss. */
 497        _n('%1$d member', '%1$d members', group.total_member_count, 'buddypress'), group.total_member_count))));
 498      });
 499    }
 500  
 501    return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
 502      title: __('Settings', 'buddypress'),
 503      initialOpen: true
 504    }, createElement(ToggleControl, {
 505      label: __('Display the group\'s name', 'buddypress'),
 506      checked: !!displayGroupName,
 507      onChange: function onChange() {
 508        setAttributes({
 509          displayGroupName: !displayGroupName
 510        });
 511      },
 512      help: displayGroupName ? __('Include the group\'s name.', 'buddypress') : __('Toggle to include group\'s name.', 'buddypress')
 513    }), isAvatarEnabled && createElement(SelectControl, {
 514      label: __('Avatar size', 'buddypress'),
 515      value: avatarSize,
 516      options: _constants.AVATAR_SIZES,
 517      help: __('Select "None" to disable the avatar.', 'buddypress'),
 518      onChange: function onChange(option) {
 519        setAttributes({
 520          avatarSize: option
 521        });
 522      }
 523    }), createElement(SelectControl, {
 524      label: __('Group extra information', 'buddypress'),
 525      value: extraInfo,
 526      options: extraInfoOptions,
 527      help: __('Select "None" to show no extra information.', 'buddypress'),
 528      onChange: function onChange(option) {
 529        setAttributes({
 530          extraInfo: option
 531        });
 532      }
 533    }), layoutPreference === 'grid' && createElement(RangeControl, {
 534      label: __('Columns', 'buddypress'),
 535      value: columns,
 536      onChange: function onChange(value) {
 537        return setAttributes({
 538          columns: value
 539        });
 540      },
 541      min: 2,
 542      max: 4,
 543      required: true
 544    }))), createElement(BlockControls, null, createElement(ToolbarGroup, {
 545      controls: layoutControls
 546    })), hasGroups && createElement("div", {
 547      className: containerClasses
 548    }, groupsList), (isSelected || 0 === itemIDs.length) && createElement(Placeholder, {
 549      icon: hasGroups ? '' : 'groups',
 550      label: hasGroups ? '' : __('BuddyPress Groups', 'buddypress'),
 551      instructions: __('Start typing the name of the group you want to add to the groups list.', 'buddypress'),
 552      className: 0 !== itemIDs.length ? 'is-appender' : 'is-large'
 553    }, createElement(AutoCompleter, {
 554      component: "groups",
 555      objectQueryArgs: {
 556        'show_hidden': false,
 557        exclude: itemIDs
 558      },
 559      slugValue: getSlugValue,
 560      ariaLabel: __('Group\'s name', 'buddypress'),
 561      placeholder: __('Enter Group\'s name hereā€¦', 'buddypress'),
 562      onSelectItem: onSelectedGroup,
 563      useAvatar: isAvatarEnabled
 564    })));
 565  };
 566  
 567  var _default = editGroupsBlock;
 568  exports.default = _default;
 569  },{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"DERy","./constants":"jS06"}],"jcTh":[function(require,module,exports) {
 570  "use strict";
 571  
 572  var _edit = _interopRequireDefault(require("./groups/edit"));
 573  
 574  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 575  
 576  /**
 577   * WordPress dependencies.
 578   */
 579  var _wp = wp,
 580      registerBlockType = _wp.blocks.registerBlockType,
 581      __ = _wp.i18n.__;
 582  /**
 583   * Internal dependencies.
 584   */
 585  
 586  registerBlockType('bp/groups', {
 587    title: __('Groups', 'buddypress'),
 588    description: __('BuddyPress Groups.', 'buddypress'),
 589    icon: {
 590      background: '#fff',
 591      foreground: '#d84800',
 592      src: 'buddicons-groups'
 593    },
 594    category: 'buddypress',
 595    attributes: {
 596      itemIDs: {
 597        type: 'array',
 598        items: {
 599          type: 'integer'
 600        },
 601        default: []
 602      },
 603      avatarSize: {
 604        type: 'string',
 605        default: 'full'
 606      },
 607      displayGroupName: {
 608        type: 'boolean',
 609        default: true
 610      },
 611      extraInfo: {
 612        type: 'string',
 613        default: 'none'
 614      },
 615      layoutPreference: {
 616        type: 'string',
 617        default: 'list'
 618      },
 619      columns: {
 620        type: 'number',
 621        default: 2
 622      }
 623    },
 624    edit: _edit.default
 625  });
 626  },{"./groups/edit":"Ccmh"}]},{},["jcTh"], null)


Generated: Sun Sep 19 01:01:40 2021 Cross-referenced by PHPXref 0.7.1