[ 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  })({"gr8I":[function(require,module,exports) {
 121  "use strict";
 122  
 123  Object.defineProperty(exports, "__esModule", {
 124    value: true
 125  });
 126  exports.EXTRA_DATA = exports.AVATAR_SIZES = void 0;
 127  
 128  /**
 129   * WordPress dependencies.
 130   */
 131  const {
 132    i18n: {
 133      __
 134    }
 135  } = wp;
 136  /**
 137   * Avatar sizes.
 138   *
 139   * @type {Array}
 140   */
 141  
 142  const AVATAR_SIZES = [{
 143    label: __('None', 'buddypress'),
 144    value: 'none'
 145  }, {
 146    label: __('Thumb', 'buddypress'),
 147    value: 'thumb'
 148  }, {
 149    label: __('Full', 'buddypress'),
 150    value: 'full'
 151  }];
 152  /**
 153   * BuddyPress Extra data.
 154   *
 155   * @type {Array}
 156   */
 157  
 158  exports.AVATAR_SIZES = AVATAR_SIZES;
 159  const EXTRA_DATA = [{
 160    label: __('None', 'buddypress'),
 161    value: 'none'
 162  }, {
 163    label: __('Last time the user was active', 'buddypress'),
 164    value: 'last_activity'
 165  }, {
 166    label: __('Latest activity the user posted', 'buddypress'),
 167    value: 'latest_update'
 168  }];
 169  exports.EXTRA_DATA = EXTRA_DATA;
 170  },{}],"PZSE":[function(require,module,exports) {
 171  "use strict";
 172  
 173  Object.defineProperty(exports, "__esModule", {
 174    value: true
 175  });
 176  exports.default = void 0;
 177  
 178  var _constants = require("./constants");
 179  
 180  /**
 181   * WordPress dependencies.
 182   */
 183  const {
 184    blockEditor: {
 185      InspectorControls,
 186      BlockControls
 187    },
 188    components: {
 189      Placeholder,
 190      PanelBody,
 191      SelectControl,
 192      ToggleControl,
 193      Button,
 194      Dashicon,
 195      Tooltip,
 196      ToolbarGroup,
 197      RangeControl
 198    },
 199    element: {
 200      createElement,
 201      Fragment,
 202      useState
 203    },
 204    i18n: {
 205      __,
 206      sprintf
 207    },
 208    apiFetch,
 209    url: {
 210      addQueryArgs
 211    }
 212  } = wp;
 213  /**
 214   * BuddyPress dependencies.
 215   */
 216  
 217  const {
 218    blockComponents: {
 219      AutoCompleter
 220    },
 221    blockData: {
 222      isActive
 223    }
 224  } = bp;
 225  /**
 226   * Internal dependencies.
 227   */
 228  
 229  /**
 230   * External dependencies.
 231   */
 232  const {
 233    reject,
 234    remove,
 235    sortBy
 236  } = lodash;
 237  
 238  const getSlugValue = item => {
 239    if (item && item.mention_name) {
 240      return item.mention_name;
 241    }
 242  
 243    return null;
 244  };
 245  
 246  const editMembersBlock = ({
 247    attributes,
 248    setAttributes,
 249    isSelected
 250  }) => {
 251    const isAvatarEnabled = isActive('members', 'avatar');
 252    const isMentionEnabled = isActive('activity', 'mentions');
 253    const {
 254      itemIDs,
 255      avatarSize,
 256      displayMentionSlug,
 257      displayUserName,
 258      extraData,
 259      layoutPreference,
 260      columns
 261    } = attributes;
 262    const hasMembers = 0 !== itemIDs.length;
 263    const [members, setMembers] = useState([]);
 264    const layoutControls = [{
 265      icon: 'text',
 266      title: __('List view', 'buddypress'),
 267      onClick: () => setAttributes({
 268        layoutPreference: 'list'
 269      }),
 270      isActive: layoutPreference === 'list'
 271    }, {
 272      icon: 'screenoptions',
 273      title: __('Grid view', 'buddypress'),
 274      onClick: () => setAttributes({
 275        layoutPreference: 'grid'
 276      }),
 277      isActive: layoutPreference === 'grid'
 278    }];
 279    let membersList;
 280    let containerClasses = 'bp-block-members avatar-' + avatarSize;
 281    let extraDataOptions = _constants.EXTRA_DATA;
 282  
 283    if (layoutPreference === 'grid') {
 284      containerClasses += ' is-grid columns-' + columns;
 285      extraDataOptions = _constants.EXTRA_DATA.filter(extra => {
 286        return 'latest_update' !== extra.value;
 287      });
 288    }
 289  
 290    const onSelectedMember = ({
 291      itemID
 292    }) => {
 293      if (itemID && -1 === itemIDs.indexOf(itemID)) {
 294        setAttributes({
 295          itemIDs: [...itemIDs, parseInt(itemID, 10)]
 296        });
 297      }
 298    };
 299  
 300    const onRemoveMember = itemID => {
 301      if (itemID && -1 !== itemIDs.indexOf(itemID)) {
 302        setMembers(reject(members, ['id', itemID]));
 303        setAttributes({
 304          itemIDs: remove(itemIDs, value => {
 305            return value !== itemID;
 306          })
 307        });
 308      }
 309    };
 310  
 311    if (hasMembers && itemIDs.length !== members.length) {
 312      apiFetch({
 313        path: addQueryArgs(`/buddypress/v1/members`, {
 314          populate_extras: true,
 315          include: itemIDs
 316        })
 317      }).then(items => {
 318        setMembers(sortBy(items, [item => {
 319          return itemIDs.indexOf(item.id);
 320        }]));
 321      });
 322    }
 323  
 324    if (members.length) {
 325      membersList = members.map(member => {
 326        let hasActivity = false;
 327        let memberItemClasses = 'member-content';
 328  
 329        if (layoutPreference === 'list' && 'latest_update' === extraData && member.latest_update && member.latest_update.rendered) {
 330          hasActivity = true;
 331          memberItemClasses = 'member-content has-activity';
 332        }
 333  
 334        return createElement("div", {
 335          key: 'bp-member-' + member.id,
 336          className: memberItemClasses
 337        }, isSelected && createElement(Tooltip, {
 338          text: __('Remove member', 'buddypress')
 339        }, createElement(Button, {
 340          className: "is-right",
 341          onClick: () => onRemoveMember(member.id),
 342          label: __('Remove member', 'buddypress')
 343        }, createElement(Dashicon, {
 344          icon: "no"
 345        }))), isAvatarEnabled && 'none' !== avatarSize && createElement("div", {
 346          className: "item-header-avatar"
 347        }, createElement("a", {
 348          href: member.link,
 349          target: "_blank"
 350        }, createElement("img", {
 351          key: 'avatar-' + member.id,
 352          className: "avatar",
 353          alt: sprintf(__('Profile photo of %s', 'buddypress'), member.name),
 354          src: member.avatar_urls[avatarSize]
 355        }))), createElement("div", {
 356          className: "member-description"
 357        }, hasActivity && createElement("blockquote", {
 358          className: "wp-block-quote"
 359        }, createElement("div", {
 360          dangerouslySetInnerHTML: {
 361            __html: member.latest_update.rendered
 362          }
 363        }), createElement("cite", null, displayUserName && createElement("span", null, member.name), "\xA0", isMentionEnabled && displayMentionSlug && createElement("a", {
 364          href: member.link,
 365          target: "_blank"
 366        }, "(@", member.mention_name, ")"))), !hasActivity && displayUserName && createElement("strong", null, createElement("a", {
 367          href: member.link,
 368          target: "_blank"
 369        }, member.name)), !hasActivity && isMentionEnabled && displayMentionSlug && createElement("span", {
 370          className: "user-nicename"
 371        }, "@", member.mention_name), 'last_activity' === extraData && member.last_activity && member.last_activity.date && createElement("time", {
 372          dateTime: member.last_activity.date
 373        }, sprintf(__('Active %s', 'buddypress'), member.last_activity.timediff))));
 374      });
 375    }
 376  
 377    return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
 378      title: __('Settings', 'buddypress'),
 379      initialOpen: true
 380    }, createElement(ToggleControl, {
 381      label: __('Display the user name', 'buddypress'),
 382      checked: !!displayUserName,
 383      onChange: () => {
 384        setAttributes({
 385          displayUserName: !displayUserName
 386        });
 387      },
 388      help: displayUserName ? __('Include the user\'s display name.', 'buddypress') : __('Toggle to include user\'s display name.', 'buddypress')
 389    }), isMentionEnabled && createElement(ToggleControl, {
 390      label: __('Display Mention slug', 'buddypress'),
 391      checked: !!displayMentionSlug,
 392      onChange: () => {
 393        setAttributes({
 394          displayMentionSlug: !displayMentionSlug
 395        });
 396      },
 397      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')
 398    }), isAvatarEnabled && createElement(SelectControl, {
 399      label: __('Avatar size', 'buddypress'),
 400      value: avatarSize,
 401      options: _constants.AVATAR_SIZES,
 402      help: __('Select "None" to disable the avatar.', 'buddypress'),
 403      onChange: option => {
 404        setAttributes({
 405          avatarSize: option
 406        });
 407      }
 408    }), createElement(SelectControl, {
 409      label: __('BuddyPress extra information', 'buddypress'),
 410      value: extraData,
 411      options: extraDataOptions,
 412      help: __('Select "None" to show no extra information.', 'buddypress'),
 413      onChange: option => {
 414        setAttributes({
 415          extraData: option
 416        });
 417      }
 418    }), layoutPreference === 'grid' && createElement(RangeControl, {
 419      label: __('Columns', 'buddypress'),
 420      value: columns,
 421      onChange: value => setAttributes({
 422        columns: value
 423      }),
 424      min: 2,
 425      max: 4,
 426      required: true
 427    }))), createElement(BlockControls, null, createElement(ToolbarGroup, {
 428      controls: layoutControls
 429    })), hasMembers && createElement("div", {
 430      className: containerClasses
 431    }, membersList), (isSelected || 0 === itemIDs.length) && createElement(Placeholder, {
 432      icon: hasMembers ? '' : 'groups',
 433      label: hasMembers ? '' : __('BuddyPress Members', 'buddypress'),
 434      instructions: __('Start typing the name of the member you want to add to the members list.', 'buddypress'),
 435      className: 0 !== itemIDs.length ? 'is-appender' : 'is-large'
 436    }, createElement(AutoCompleter, {
 437      component: "members",
 438      objectQueryArgs: {
 439        exclude: itemIDs
 440      },
 441      slugValue: getSlugValue,
 442      ariaLabel: __('Member\'s username', 'buddypress'),
 443      placeholder: __('Enter Member\'s username hereā€¦', 'buddypress'),
 444      onSelectItem: onSelectedMember,
 445      useAvatar: isAvatarEnabled
 446    })));
 447  };
 448  
 449  var _default = editMembersBlock;
 450  exports.default = _default;
 451  },{"./constants":"gr8I"}],"XEHU":[function(require,module,exports) {
 452  "use strict";
 453  
 454  var _edit = _interopRequireDefault(require("./members/edit"));
 455  
 456  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 457  
 458  /**
 459   * WordPress dependencies.
 460   */
 461  const {
 462    blocks: {
 463      registerBlockType
 464    },
 465    i18n: {
 466      __
 467    }
 468  } = wp;
 469  /**
 470   * Internal dependencies.
 471   */
 472  
 473  registerBlockType('bp/members', {
 474    title: __('Members', 'buddypress'),
 475    description: __('BuddyPress Members.', 'buddypress'),
 476    icon: {
 477      background: '#fff',
 478      foreground: '#d84800',
 479      src: 'groups'
 480    },
 481    category: 'buddypress',
 482    attributes: {
 483      itemIDs: {
 484        type: 'array',
 485        items: {
 486          type: 'integer'
 487        },
 488        default: []
 489      },
 490      avatarSize: {
 491        type: 'string',
 492        default: 'full'
 493      },
 494      displayMentionSlug: {
 495        type: 'boolean',
 496        default: true
 497      },
 498      displayUserName: {
 499        type: 'boolean',
 500        default: true
 501      },
 502      extraData: {
 503        type: 'string',
 504        default: 'none'
 505      },
 506      layoutPreference: {
 507        type: 'string',
 508        default: 'list'
 509      },
 510      columns: {
 511        type: 'number',
 512        default: 2
 513      }
 514    },
 515    edit: _edit.default
 516  });
 517  },{"./members/edit":"PZSE"}]},{},["XEHU"], null)


Generated: Mon Jun 27 01:00:52 2022 Cross-referenced by PHPXref 0.7.1