[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/js/ -> block-components.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  })({"W80x":[function(require,module,exports) {
 121  "use strict";
 122  
 123  Object.defineProperty(exports, "__esModule", {
 124    value: true
 125  });
 126  exports.default = void 0;
 127  
 128  /**
 129   * WordPress dependencies.
 130   */
 131  const {
 132    apiFetch,
 133    components: {
 134      Popover
 135    },
 136    element: {
 137      Component,
 138      Fragment,
 139      createElement
 140    },
 141    i18n: {
 142      __
 143    },
 144    url: {
 145      addQueryArgs
 146    }
 147  } = wp;
 148  
 149  class AutoCompleter extends Component {
 150    constructor() {
 151      super(...arguments);
 152      this.state = {
 153        search: '',
 154        items: [],
 155        error: ''
 156      };
 157      this.searchItemName = this.searchItemName.bind(this);
 158      this.selectItemName = this.selectItemName.bind(this);
 159    }
 160  
 161    searchItemName(value) {
 162      const {
 163        search
 164      } = this.state;
 165      const {
 166        component,
 167        objectQueryArgs
 168      } = this.props;
 169      this.setState({
 170        search: value
 171      });
 172  
 173      if (value.length < search.length) {
 174        this.setState({
 175          items: []
 176        });
 177      }
 178  
 179      let path = '/buddypress/v1/' + component;
 180      let queryArgs = {};
 181  
 182      if (value) {
 183        queryArgs.search = encodeURIComponent(value);
 184      }
 185  
 186      if (objectQueryArgs) {
 187        queryArgs = Object.assign(queryArgs, objectQueryArgs);
 188      }
 189  
 190      apiFetch({
 191        path: addQueryArgs(path, queryArgs)
 192      }).then(items => {
 193        this.setState({
 194          items: items
 195        });
 196      }, error => {
 197        this.setState({
 198          error: error.message
 199        });
 200      });
 201    }
 202  
 203    selectItemName(event, itemID) {
 204      const {
 205        onSelectItem
 206      } = this.props;
 207      event.preventDefault();
 208      this.setState({
 209        search: '',
 210        items: [],
 211        error: ''
 212      });
 213      return onSelectItem({
 214        itemID: itemID
 215      });
 216    }
 217  
 218    render() {
 219      const {
 220        search,
 221        items
 222      } = this.state;
 223      let {
 224        ariaLabel,
 225        placeholder,
 226        useAvatar,
 227        slugValue
 228      } = this.props;
 229      let itemsList;
 230  
 231      if (!ariaLabel) {
 232        ariaLabel = __('Item\'s name', 'buddypress');
 233      }
 234  
 235      if (!placeholder) {
 236        placeholder = __('Enter Item\'s name hereā€¦', 'buddypress');
 237      }
 238  
 239      if (items.length) {
 240        itemsList = items.map(item => {
 241          return createElement("button", {
 242            type: "button",
 243            key: 'editor-autocompleters__item-item-' + item.id,
 244            role: "option",
 245            "aria-selected": "true",
 246            className: "components-button components-autocomplete__result editor-autocompleters__user",
 247            onClick: event => this.selectItemName(event, item.id)
 248          }, useAvatar && createElement("img", {
 249            key: "avatar",
 250            className: "editor-autocompleters__user-avatar",
 251            alt: "",
 252            src: item.avatar_urls.thumb.replaceAll('&#038;', '&')
 253          }), createElement("span", {
 254            key: "name",
 255            className: "editor-autocompleters__user-name"
 256          }, item.name), slugValue && null !== slugValue(item) && createElement("span", {
 257            key: "slug",
 258            className: "editor-autocompleters__user-slug"
 259          }, slugValue(item)));
 260        });
 261      }
 262  
 263      return createElement(Fragment, null, createElement("input", {
 264        type: "text",
 265        value: search,
 266        className: "components-placeholder__input",
 267        "aria-label": ariaLabel,
 268        placeholder: placeholder,
 269        onChange: event => this.searchItemName(event.target.value)
 270      }), 0 !== items.length && createElement(Popover, {
 271        className: "components-autocomplete__popover",
 272        focusOnMount: false,
 273        position: "bottom left"
 274      }, createElement("div", {
 275        className: "components-autocomplete__results"
 276      }, itemsList)));
 277    }
 278  
 279  }
 280  
 281  var _default = AutoCompleter;
 282  exports.default = _default;
 283  },{}],"iA92":[function(require,module,exports) {
 284  "use strict";
 285  
 286  Object.defineProperty(exports, "__esModule", {
 287    value: true
 288  });
 289  exports.default = void 0;
 290  
 291  var _autocompleter = _interopRequireDefault(require("./autocompleter"));
 292  
 293  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 294  
 295  /**
 296   * BuddyPress components.
 297   */
 298  var _default = {
 299    AutoCompleter: _autocompleter.default
 300  };
 301  exports.default = _default;
 302  },{"./autocompleter":"W80x"}],"Ee8M":[function(require,module,exports) {
 303  "use strict";
 304  
 305  Object.defineProperty(exports, "__esModule", {
 306    value: true
 307  });
 308  Object.defineProperty(exports, "blockComponents", {
 309    enumerable: true,
 310    get: function () {
 311      return _components.default;
 312    }
 313  });
 314  
 315  var _components = _interopRequireDefault(require("./components"));
 316  
 317  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 318  },{"./components":"iA92"}]},{},["Ee8M"], "bpBlock")


Generated: Wed Jan 19 01:01:00 2022 Cross-referenced by PHPXref 0.7.1