[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/js/blocks/ -> members.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"}],"gr8I":[function(require,module,exports) {
 235  "use strict";
 236  
 237  Object.defineProperty(exports, "__esModule", {
 238    value: true
 239  });
 240  exports.EXTRA_DATA = 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   * BuddyPress Extra data.
 265   *
 266   * @type {Array}
 267   */
 268  
 269  exports.AVATAR_SIZES = AVATAR_SIZES;
 270  var EXTRA_DATA = [{
 271    label: __('None', 'buddypress'),
 272    value: 'none'
 273  }, {
 274    label: __('Last time the user was active', 'buddypress'),
 275    value: 'last_activity'
 276  }, {
 277    label: __('Latest activity the user posted', 'buddypress'),
 278    value: 'latest_update'
 279  }];
 280  exports.EXTRA_DATA = EXTRA_DATA;
 281  },{}],"PZSE":[function(require,module,exports) {
 282  "use strict";
 283  
 284  Object.defineProperty(exports, "__esModule", {
 285    value: true
 286  });
 287  exports.default = void 0;
 288  
 289  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
 290  
 291  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
 292  
 293  var _constants = require("./constants");
 294  
 295  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 296  
 297  /**
 298   * WordPress dependencies.
 299   */
 300  var _wp = wp,
 301      _wp$blockEditor = _wp.blockEditor,
 302      InspectorControls = _wp$blockEditor.InspectorControls,
 303      BlockControls = _wp$blockEditor.BlockControls,
 304      _wp$components = _wp.components,
 305      Placeholder = _wp$components.Placeholder,
 306      PanelBody = _wp$components.PanelBody,
 307      SelectControl = _wp$components.SelectControl,
 308      ToggleControl = _wp$components.ToggleControl,
 309      Button = _wp$components.Button,
 310      Dashicon = _wp$components.Dashicon,
 311      Tooltip = _wp$components.Tooltip,
 312      ToolbarGroup = _wp$components.ToolbarGroup,
 313      RangeControl = _wp$components.RangeControl,
 314      _wp$element = _wp.element,
 315      createElement = _wp$element.createElement,
 316      Fragment = _wp$element.Fragment,
 317      useState = _wp$element.useState,
 318      _wp$i18n = _wp.i18n,
 319      __ = _wp$i18n.__,
 320      sprintf = _wp$i18n.sprintf,
 321      apiFetch = _wp.apiFetch,
 322      addQueryArgs = _wp.url.addQueryArgs;
 323  /**
 324   * BuddyPress dependencies.
 325   */
 326  
 327  var _bp = bp,
 328      AutoCompleter = _bp.blockComponents.AutoCompleter,
 329      isActive = _bp.blockData.isActive;
 330  /**
 331   * Internal dependencies.
 332   */
 333  
 334  /**
 335   * External dependencies.
 336   */
 337  var _lodash = lodash,
 338      reject = _lodash.reject,
 339      remove = _lodash.remove,
 340      sortBy = _lodash.sortBy;
 341  
 342  var getSlugValue = function getSlugValue(item) {
 343    if (item && item.mention_name) {
 344      return item.mention_name;
 345    }
 346  
 347    return null;
 348  };
 349  
 350  var editMembersBlock = function editMembersBlock(_ref) {
 351    var attributes = _ref.attributes,
 352        setAttributes = _ref.setAttributes,
 353        isSelected = _ref.isSelected;
 354    var isAvatarEnabled = isActive('members', 'avatar');
 355    var isMentionEnabled = isActive('activity', 'mentions');
 356    var itemIDs = attributes.itemIDs,
 357        avatarSize = attributes.avatarSize,
 358        displayMentionSlug = attributes.displayMentionSlug,
 359        displayUserName = attributes.displayUserName,
 360        extraData = attributes.extraData,
 361        layoutPreference = attributes.layoutPreference,
 362        columns = attributes.columns;
 363    var hasMembers = 0 !== itemIDs.length;
 364  
 365    var _useState = useState([]),
 366        _useState2 = (0, _slicedToArray2.default)(_useState, 2),
 367        members = _useState2[0],
 368        setMembers = _useState2[1];
 369  
 370    var layoutControls = [{
 371      icon: 'text',
 372      title: __('List view', 'buddypress'),
 373      onClick: function onClick() {
 374        return setAttributes({
 375          layoutPreference: 'list'
 376        });
 377      },
 378      isActive: layoutPreference === 'list'
 379    }, {
 380      icon: 'screenoptions',
 381      title: __('Grid view', 'buddypress'),
 382      onClick: function onClick() {
 383        return setAttributes({
 384          layoutPreference: 'grid'
 385        });
 386      },
 387      isActive: layoutPreference === 'grid'
 388    }];
 389    var membersList;
 390    var containerClasses = 'bp-block-members avatar-' + avatarSize;
 391    var extraDataOptions = _constants.EXTRA_DATA;
 392  
 393    if (layoutPreference === 'grid') {
 394      containerClasses += ' is-grid columns-' + columns;
 395      extraDataOptions = _constants.EXTRA_DATA.filter(function (extra) {
 396        return 'latest_update' !== extra.value;
 397      });
 398    }
 399  
 400    var onSelectedMember = function onSelectedMember(_ref2) {
 401      var itemID = _ref2.itemID;
 402  
 403      if (itemID && -1 === itemIDs.indexOf(itemID)) {
 404        setAttributes({
 405          itemIDs: [].concat((0, _toConsumableArray2.default)(itemIDs), [parseInt(itemID, 10)])
 406        });
 407      }
 408    };
 409  
 410    var onRemoveMember = function onRemoveMember(itemID) {
 411      if (itemID && -1 !== itemIDs.indexOf(itemID)) {
 412        setMembers(reject(members, ['id', itemID]));
 413        setAttributes({
 414          itemIDs: remove(itemIDs, function (value) {
 415            return value !== itemID;
 416          })
 417        });
 418      }
 419    };
 420  
 421    if (hasMembers && itemIDs.length !== members.length) {
 422      apiFetch({
 423        path: addQueryArgs("/buddypress/v1/members", {
 424          populate_extras: true,
 425          include: itemIDs
 426        })
 427      }).then(function (items) {
 428        setMembers(sortBy(items, [function (item) {
 429          return itemIDs.indexOf(item.id);
 430        }]));
 431      });
 432    }
 433  
 434    if (members.length) {
 435      membersList = members.map(function (member) {
 436        var hasActivity = false;
 437        var memberItemClasses = 'member-content';
 438  
 439        if (layoutPreference === 'list' && 'latest_update' === extraData && member.latest_update && member.latest_update.rendered) {
 440          hasActivity = true;
 441          memberItemClasses = 'member-content has-activity';
 442        }
 443  
 444        return createElement("div", {
 445          key: 'bp-member-' + member.id,
 446          className: memberItemClasses
 447        }, isSelected && createElement(Tooltip, {
 448          text: __('Remove member', 'buddypress')
 449        }, createElement(Button, {
 450          className: "is-right",
 451          onClick: function onClick() {
 452            return onRemoveMember(member.id);
 453          },
 454          label: __('Remove member', 'buddypress')
 455        }, createElement(Dashicon, {
 456          icon: "no"
 457        }))), isAvatarEnabled && 'none' !== avatarSize && createElement("div", {
 458          className: "item-header-avatar"
 459        }, createElement("a", {
 460          href: member.link,
 461          target: "_blank"
 462        }, createElement("img", {
 463          key: 'avatar-' + member.id,
 464          className: "avatar",
 465          alt: sprintf(__('Profile photo of %s', 'buddypress'), member.name),
 466          src: member.avatar_urls[avatarSize]
 467        }))), createElement("div", {
 468          className: "member-description"
 469        }, hasActivity && createElement("blockquote", {
 470          className: "wp-block-quote"
 471        }, createElement("div", {
 472          dangerouslySetInnerHTML: {
 473            __html: member.latest_update.rendered
 474          }
 475        }), createElement("cite", null, displayUserName && createElement("span", null, member.name), "\xA0", isMentionEnabled && displayMentionSlug && createElement("a", {
 476          href: member.link,
 477          target: "_blank"
 478        }, "(@", member.mention_name, ")"))), !hasActivity && displayUserName && createElement("strong", null, createElement("a", {
 479          href: member.link,
 480          target: "_blank"
 481        }, member.name)), !hasActivity && isMentionEnabled && displayMentionSlug && createElement("span", {
 482          className: "user-nicename"
 483        }, "@", member.mention_name), 'last_activity' === extraData && member.last_activity && member.last_activity.date && createElement("time", {
 484          dateTime: member.last_activity.date
 485        }, sprintf(__('Active %s', 'buddypress'), member.last_activity.timediff))));
 486      });
 487    }
 488  
 489    return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
 490      title: __('Settings', 'buddypress'),
 491      initialOpen: true
 492    }, createElement(ToggleControl, {
 493      label: __('Display the user name', 'buddypress'),
 494      checked: !!displayUserName,
 495      onChange: function onChange() {
 496        setAttributes({
 497          displayUserName: !displayUserName
 498        });
 499      },
 500      help: displayUserName ? __('Include the user\'s display name.', 'buddypress') : __('Toggle to include user\'s display name.', 'buddypress')
 501    }), isMentionEnabled && createElement(ToggleControl, {
 502      label: __('Display Mention slug', 'buddypress'),
 503      checked: !!displayMentionSlug,
 504      onChange: function onChange() {
 505        setAttributes({
 506          displayMentionSlug: !displayMentionSlug
 507        });
 508      },
 509      help: displayMentionSlug ? __('Include the user\'s mention name under their display name.', 'buddypress') : __('Toggle to display the user\'s mention name under their display name.', 'buddypress')
 510    }), isAvatarEnabled && createElement(SelectControl, {
 511      label: __('Avatar size', 'buddypress'),
 512      value: avatarSize,
 513      options: _constants.AVATAR_SIZES,
 514      help: __('Select "None" to disable the avatar.', 'buddypress'),
 515      onChange: function onChange(option) {
 516        setAttributes({
 517          avatarSize: option
 518        });
 519      }
 520    }), createElement(SelectControl, {
 521      label: __('BuddyPress extra information', 'buddypress'),
 522      value: extraData,
 523      options: extraDataOptions,
 524      help: __('Select "None" to show no extra information.', 'buddypress'),
 525      onChange: function onChange(option) {
 526        setAttributes({
 527          extraData: option
 528        });
 529      }
 530    }), layoutPreference === 'grid' && createElement(RangeControl, {
 531      label: __('Columns', 'buddypress'),
 532      value: columns,
 533      onChange: function onChange(value) {
 534        return setAttributes({
 535          columns: value
 536        });
 537      },
 538      min: 2,
 539      max: 4,
 540      required: true
 541    }))), createElement(BlockControls, null, createElement(ToolbarGroup, {
 542      controls: layoutControls
 543    })), hasMembers && createElement("div", {
 544      className: containerClasses
 545    }, membersList), (isSelected || 0 === itemIDs.length) && createElement(Placeholder, {
 546      icon: hasMembers ? '' : 'groups',
 547      label: hasMembers ? '' : __('BuddyPress Members', 'buddypress'),
 548      instructions: __('Start typing the name of the member you want to add to the members list.', 'buddypress'),
 549      className: 0 !== itemIDs.length ? 'is-appender' : 'is-large'
 550    }, createElement(AutoCompleter, {
 551      component: "members",
 552      objectQueryArgs: {
 553        exclude: itemIDs
 554      },
 555      slugValue: getSlugValue,
 556      ariaLabel: __('Member\'s username', 'buddypress'),
 557      placeholder: __('Enter Member\'s username hereā€¦', 'buddypress'),
 558      onSelectItem: onSelectedMember,
 559      useAvatar: isAvatarEnabled
 560    })));
 561  };
 562  
 563  var _default = editMembersBlock;
 564  exports.default = _default;
 565  },{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"DERy","./constants":"gr8I"}],"XEHU":[function(require,module,exports) {
 566  "use strict";
 567  
 568  var _edit = _interopRequireDefault(require("./members/edit"));
 569  
 570  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 571  
 572  /**
 573   * WordPress dependencies.
 574   */
 575  var _wp = wp,
 576      registerBlockType = _wp.blocks.registerBlockType,
 577      __ = _wp.i18n.__;
 578  /**
 579   * Internal dependencies.
 580   */
 581  
 582  registerBlockType('bp/members', {
 583    title: __('Members', 'buddypress'),
 584    description: __('BuddyPress Members.', 'buddypress'),
 585    icon: {
 586      background: '#fff',
 587      foreground: '#d84800',
 588      src: 'groups'
 589    },
 590    category: 'buddypress',
 591    attributes: {
 592      itemIDs: {
 593        type: 'array',
 594        items: {
 595          type: 'integer'
 596        },
 597        default: []
 598      },
 599      avatarSize: {
 600        type: 'string',
 601        default: 'full'
 602      },
 603      displayMentionSlug: {
 604        type: 'boolean',
 605        default: true
 606      },
 607      displayUserName: {
 608        type: 'boolean',
 609        default: true
 610      },
 611      extraData: {
 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  },{"./members/edit":"PZSE"}]},{},["XEHU"], null)


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