[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/js/blocks/ -> embed-activity.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  })({"DCTP":[function(require,module,exports) {
 121  function _arrayWithHoles(arr) {
 122    if (Array.isArray(arr)) return arr;
 123  }
 124  
 125  module.exports = _arrayWithHoles;
 126  },{}],"LoeL":[function(require,module,exports) {
 127  function _iterableToArrayLimit(arr, i) {
 128    if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
 129    var _arr = [];
 130    var _n = true;
 131    var _d = false;
 132    var _e = undefined;
 133  
 134    try {
 135      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
 136        _arr.push(_s.value);
 137  
 138        if (i && _arr.length === i) break;
 139      }
 140    } catch (err) {
 141      _d = true;
 142      _e = err;
 143    } finally {
 144      try {
 145        if (!_n && _i["return"] != null) _i["return"]();
 146      } finally {
 147        if (_d) throw _e;
 148      }
 149    }
 150  
 151    return _arr;
 152  }
 153  
 154  module.exports = _iterableToArrayLimit;
 155  },{}],"jEQo":[function(require,module,exports) {
 156  function _arrayLikeToArray(arr, len) {
 157    if (len == null || len > arr.length) len = arr.length;
 158  
 159    for (var i = 0, arr2 = new Array(len); i < len; i++) {
 160      arr2[i] = arr[i];
 161    }
 162  
 163    return arr2;
 164  }
 165  
 166  module.exports = _arrayLikeToArray;
 167  },{}],"Dbv9":[function(require,module,exports) {
 168  var arrayLikeToArray = require("./arrayLikeToArray");
 169  
 170  function _unsupportedIterableToArray(o, minLen) {
 171    if (!o) return;
 172    if (typeof o === "string") return arrayLikeToArray(o, minLen);
 173    var n = Object.prototype.toString.call(o).slice(8, -1);
 174    if (n === "Object" && o.constructor) n = o.constructor.name;
 175    if (n === "Map" || n === "Set") return Array.from(n);
 176    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
 177  }
 178  
 179  module.exports = _unsupportedIterableToArray;
 180  },{"./arrayLikeToArray":"jEQo"}],"MWEO":[function(require,module,exports) {
 181  function _nonIterableRest() {
 182    throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
 183  }
 184  
 185  module.exports = _nonIterableRest;
 186  },{}],"DERy":[function(require,module,exports) {
 187  var arrayWithHoles = require("./arrayWithHoles");
 188  
 189  var iterableToArrayLimit = require("./iterableToArrayLimit");
 190  
 191  var unsupportedIterableToArray = require("./unsupportedIterableToArray");
 192  
 193  var nonIterableRest = require("./nonIterableRest");
 194  
 195  function _slicedToArray(arr, i) {
 196    return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
 197  }
 198  
 199  module.exports = _slicedToArray;
 200  },{"./arrayWithHoles":"DCTP","./iterableToArrayLimit":"LoeL","./unsupportedIterableToArray":"Dbv9","./nonIterableRest":"MWEO"}],"Sjre":[function(require,module,exports) {
 201  "use strict";
 202  
 203  Object.defineProperty(exports, "__esModule", {
 204    value: true
 205  });
 206  exports.default = void 0;
 207  
 208  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
 209  
 210  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 211  
 212  /**
 213   * WordPress dependencies.
 214   */
 215  var _wp = wp,
 216      _wp$element = _wp.element,
 217      createElement = _wp$element.createElement,
 218      Fragment = _wp$element.Fragment,
 219      useState = _wp$element.useState,
 220      __ = _wp.i18n.__,
 221      _wp$components = _wp.components,
 222      Placeholder = _wp$components.Placeholder,
 223      Disabled = _wp$components.Disabled,
 224      SandBox = _wp$components.SandBox,
 225      Button = _wp$components.Button,
 226      ExternalLink = _wp$components.ExternalLink,
 227      Spinner = _wp$components.Spinner,
 228      ToolbarGroup = _wp$components.ToolbarGroup,
 229      ToolbarButton = _wp$components.ToolbarButton,
 230      compose = _wp.compose.compose,
 231      withSelect = _wp.data.withSelect,
 232      _wp$blockEditor = _wp.blockEditor,
 233      RichText = _wp$blockEditor.RichText,
 234      BlockControls = _wp$blockEditor.BlockControls;
 235  /**
 236   * BuddyPress dependencies.
 237   */
 238  
 239  var _bp = bp,
 240      embedScriptURL = _bp.blockData.embedScriptURL;
 241  
 242  var EditEmbedActivity = function EditEmbedActivity(_ref) {
 243    var attributes = _ref.attributes,
 244        setAttributes = _ref.setAttributes,
 245        isSelected = _ref.isSelected,
 246        preview = _ref.preview,
 247        fetching = _ref.fetching;
 248    var url = attributes.url,
 249        caption = attributes.caption;
 250  
 251    var label = __('BuddyPress Activity URL', 'buddypress');
 252  
 253    var _useState = useState(url),
 254        _useState2 = (0, _slicedToArray2.default)(_useState, 2),
 255        value = _useState2[0],
 256        setURL = _useState2[1];
 257  
 258    var _useState3 = useState(!url),
 259        _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
 260        isEditingURL = _useState4[0],
 261        setIsEditingURL = _useState4[1];
 262  
 263    var onSubmit = function onSubmit(event) {
 264      if (event) {
 265        event.preventDefault();
 266      }
 267  
 268      setIsEditingURL(false);
 269      setAttributes({
 270        url: value
 271      });
 272    };
 273  
 274    var switchBackToURLInput = function switchBackToURLInput(event) {
 275      if (event) {
 276        event.preventDefault();
 277      }
 278  
 279      setIsEditingURL(true);
 280    };
 281  
 282    var editToolbar = createElement(BlockControls, null, createElement(ToolbarGroup, null, createElement(ToolbarButton, {
 283      icon: "edit",
 284      title: __('Edit URL', 'buddypress'),
 285      onClick: switchBackToURLInput
 286    })));
 287  
 288    if (isEditingURL) {
 289      return createElement(Placeholder, {
 290        icon: "buddicons-activity",
 291        label: label,
 292        className: "wp-block-embed",
 293        instructions: __('Paste the link to the activity content you want to display on your site.', 'buddypress')
 294      }, createElement("form", {
 295        onSubmit: onSubmit
 296      }, createElement("input", {
 297        type: "url",
 298        value: value || '',
 299        className: "components-placeholder__input",
 300        "aria-label": label,
 301        placeholder: __('Enter URL to embed here…', 'buddypress'),
 302        onChange: function onChange(event) {
 303          return setURL(event.target.value);
 304        }
 305      }), createElement(Button, {
 306        isPrimary: true,
 307        type: "submit"
 308      }, __('Embed', 'buddypress'))), createElement("div", {
 309        className: "components-placeholder__learn-more"
 310      }, createElement(ExternalLink, {
 311        href: __('https://codex.buddypress.org/activity-embeds/')
 312      }, __('Learn more about activity embeds', 'buddypress'))));
 313    }
 314  
 315    if (fetching) {
 316      return createElement("div", {
 317        className: "wp-block-embed is-loading"
 318      }, createElement(Spinner, null), createElement("p", null, __('Embedding…', 'buddypress')));
 319    }
 320  
 321    if (!preview || !preview['x_buddypress'] || 'activity' !== preview['x_buddypress']) {
 322      return createElement(Fragment, null, editToolbar, createElement(Placeholder, {
 323        icon: "buddicons-activity",
 324        label: label
 325      }, createElement("p", {
 326        className: "components-placeholder__error"
 327      }, __('The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.', 'buddypress'))));
 328    }
 329  
 330    return createElement(Fragment, null, !isEditingURL && editToolbar, createElement("figure", {
 331      className: "wp-block-embed is-type-bp-activity"
 332    }, createElement("div", {
 333      className: "wp-block-embed__wrapper"
 334    }, createElement(Disabled, null, createElement(SandBox, {
 335      html: preview && preview.html ? preview.html : '',
 336      scripts: [embedScriptURL]
 337    }))), (!RichText.isEmpty(caption) || isSelected) && createElement(RichText, {
 338      tagName: "figcaption",
 339      placeholder: __('Write caption…', 'buddypress'),
 340      value: caption,
 341      onChange: function onChange(value) {
 342        return setAttributes({
 343          caption: value
 344        });
 345      },
 346      inlineToolbar: true
 347    })));
 348  };
 349  
 350  var editEmbedActivityBlock = compose([withSelect(function (select, ownProps) {
 351    var url = ownProps.attributes.url;
 352  
 353    var _select = select('core'),
 354        getEmbedPreview = _select.getEmbedPreview,
 355        isRequestingEmbedPreview = _select.isRequestingEmbedPreview;
 356  
 357    var preview = !!url && getEmbedPreview(url);
 358    var fetching = !!url && isRequestingEmbedPreview(url);
 359    return {
 360      preview: preview,
 361      fetching: fetching
 362    };
 363  })])(EditEmbedActivity);
 364  var _default = editEmbedActivityBlock;
 365  exports.default = _default;
 366  },{"@babel/runtime/helpers/slicedToArray":"DERy"}],"zmBI":[function(require,module,exports) {
 367  "use strict";
 368  
 369  Object.defineProperty(exports, "__esModule", {
 370    value: true
 371  });
 372  exports.default = void 0;
 373  
 374  /**
 375   * WordPress dependencies.
 376   */
 377  var _wp = wp,
 378      RichText = _wp.blockEditor.RichText,
 379      createElement = _wp.element.createElement;
 380  
 381  var saveEmbedActivityBlock = function saveEmbedActivityBlock(_ref) {
 382    var attributes = _ref.attributes;
 383    var url = attributes.url,
 384        caption = attributes.caption;
 385  
 386    if (!url) {
 387      return null;
 388    }
 389  
 390    return createElement("figure", {
 391      className: "wp-block-embed is-type-bp-activity"
 392    }, createElement("div", {
 393      className: "wp-block-embed__wrapper"
 394    }, "\n".concat(url, "\n")
 395    /* URL needs to be on its own line. */
 396    ), !RichText.isEmpty(caption) && createElement(RichText.Content, {
 397      tagName: "figcaption",
 398      value: caption
 399    }));
 400  };
 401  
 402  var _default = saveEmbedActivityBlock;
 403  exports.default = _default;
 404  },{}],"hBDw":[function(require,module,exports) {
 405  "use strict";
 406  
 407  var _edit = _interopRequireDefault(require("./embed-activity/edit"));
 408  
 409  var _save = _interopRequireDefault(require("./embed-activity/save"));
 410  
 411  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 412  
 413  /**
 414   * WordPress dependencies.
 415   */
 416  var _wp = wp,
 417      __ = _wp.i18n.__,
 418      registerBlockType = _wp.blocks.registerBlockType;
 419  /**
 420   * Internal dependencies.
 421   */
 422  
 423  registerBlockType('bp/embed-activity', {
 424    title: __('Embed an activity', 'buddypress'),
 425    description: __('Add a block that displays the activity content pulled from this or other community sites.', 'buddypress'),
 426    icon: {
 427      background: '#fff',
 428      foreground: '#d84800',
 429      src: 'buddicons-activity'
 430    },
 431    category: 'buddypress',
 432    attributes: {
 433      url: {
 434        type: 'string'
 435      },
 436      caption: {
 437        type: 'string',
 438        source: 'html',
 439        selector: 'figcaption'
 440      }
 441    },
 442    supports: {
 443      align: true
 444    },
 445    edit: _edit.default,
 446    save: _save.default
 447  });
 448  },{"./embed-activity/edit":"Sjre","./embed-activity/save":"zmBI"}]},{},["hBDw"], null)


Generated: Thu Oct 28 01:00:59 2021 Cross-referenced by PHPXref 0.7.1