[ 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  })({"Sjre":[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    element: {
 133      createElement,
 134      Fragment,
 135      useState
 136    },
 137    i18n: {
 138      __
 139    },
 140    components: {
 141      Placeholder,
 142      Disabled,
 143      SandBox,
 144      Button,
 145      ExternalLink,
 146      Spinner,
 147      ToolbarGroup,
 148      ToolbarButton
 149    },
 150    compose: {
 151      compose
 152    },
 153    data: {
 154      withSelect
 155    },
 156    blockEditor: {
 157      RichText,
 158      BlockControls
 159    }
 160  } = wp;
 161  /**
 162   * BuddyPress dependencies.
 163   */
 164  
 165  const {
 166    blockData: {
 167      embedScriptURL
 168    }
 169  } = bp;
 170  
 171  const EditEmbedActivity = ({
 172    attributes,
 173    setAttributes,
 174    isSelected,
 175    preview,
 176    fetching
 177  }) => {
 178    const {
 179      url,
 180      caption
 181    } = attributes;
 182  
 183    const label = __('BuddyPress Activity URL', 'buddypress');
 184  
 185    const [value, setURL] = useState(url);
 186    const [isEditingURL, setIsEditingURL] = useState(!url);
 187  
 188    const onSubmit = event => {
 189      if (event) {
 190        event.preventDefault();
 191      }
 192  
 193      setIsEditingURL(false);
 194      setAttributes({
 195        url: value
 196      });
 197    };
 198  
 199    const switchBackToURLInput = event => {
 200      if (event) {
 201        event.preventDefault();
 202      }
 203  
 204      setIsEditingURL(true);
 205    };
 206  
 207    const editToolbar = createElement(BlockControls, null, createElement(ToolbarGroup, null, createElement(ToolbarButton, {
 208      icon: "edit",
 209      title: __('Edit URL', 'buddypress'),
 210      onClick: switchBackToURLInput
 211    })));
 212  
 213    if (isEditingURL) {
 214      return createElement(Placeholder, {
 215        icon: "buddicons-activity",
 216        label: label,
 217        className: "wp-block-embed",
 218        instructions: __('Paste the link to the activity content you want to display on your site.', 'buddypress')
 219      }, createElement("form", {
 220        onSubmit: onSubmit
 221      }, createElement("input", {
 222        type: "url",
 223        value: value || '',
 224        className: "components-placeholder__input",
 225        "aria-label": label,
 226        placeholder: __('Enter URL to embed here…', 'buddypress'),
 227        onChange: event => setURL(event.target.value)
 228      }), createElement(Button, {
 229        isPrimary: true,
 230        type: "submit"
 231      }, __('Embed', 'buddypress'))), createElement("div", {
 232        className: "components-placeholder__learn-more"
 233      }, createElement(ExternalLink, {
 234        href: __('https://codex.buddypress.org/activity-embeds/')
 235      }, __('Learn more about activity embeds', 'buddypress'))));
 236    }
 237  
 238    if (fetching) {
 239      return createElement("div", {
 240        className: "wp-block-embed is-loading"
 241      }, createElement(Spinner, null), createElement("p", null, __('Embedding…', 'buddypress')));
 242    }
 243  
 244    if (!preview || !preview['x_buddypress'] || 'activity' !== preview['x_buddypress']) {
 245      return createElement(Fragment, null, editToolbar, createElement(Placeholder, {
 246        icon: "buddicons-activity",
 247        label: label
 248      }, createElement("p", {
 249        className: "components-placeholder__error"
 250      }, __('The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.', 'buddypress'))));
 251    }
 252  
 253    return createElement(Fragment, null, !isEditingURL && editToolbar, createElement("figure", {
 254      className: "wp-block-embed is-type-bp-activity"
 255    }, createElement("div", {
 256      className: "wp-block-embed__wrapper"
 257    }, createElement(Disabled, null, createElement(SandBox, {
 258      html: preview && preview.html ? preview.html : '',
 259      scripts: [embedScriptURL]
 260    }))), (!RichText.isEmpty(caption) || isSelected) && createElement(RichText, {
 261      tagName: "figcaption",
 262      placeholder: __('Write caption…', 'buddypress'),
 263      value: caption,
 264      onChange: value => setAttributes({
 265        caption: value
 266      }),
 267      inlineToolbar: true
 268    })));
 269  };
 270  
 271  const editEmbedActivityBlock = compose([withSelect((select, ownProps) => {
 272    const {
 273      url
 274    } = ownProps.attributes;
 275    const {
 276      getEmbedPreview,
 277      isRequestingEmbedPreview
 278    } = select('core');
 279    const preview = !!url && getEmbedPreview(url);
 280    const fetching = !!url && isRequestingEmbedPreview(url);
 281    return {
 282      preview: preview,
 283      fetching: fetching
 284    };
 285  })])(EditEmbedActivity);
 286  var _default = editEmbedActivityBlock;
 287  exports.default = _default;
 288  },{}],"zmBI":[function(require,module,exports) {
 289  "use strict";
 290  
 291  Object.defineProperty(exports, "__esModule", {
 292    value: true
 293  });
 294  exports.default = void 0;
 295  
 296  /**
 297   * WordPress dependencies.
 298   */
 299  const {
 300    blockEditor: {
 301      RichText
 302    },
 303    element: {
 304      createElement
 305    }
 306  } = wp;
 307  
 308  const saveEmbedActivityBlock = ({
 309    attributes
 310  }) => {
 311    const {
 312      url,
 313      caption
 314    } = attributes;
 315  
 316    if (!url) {
 317      return null;
 318    }
 319  
 320    return createElement("figure", {
 321      className: "wp-block-embed is-type-bp-activity"
 322    }, createElement("div", {
 323      className: "wp-block-embed__wrapper"
 324    }, `\n$url}\n`
 325    /* URL needs to be on its own line. */
 326    ), !RichText.isEmpty(caption) && createElement(RichText.Content, {
 327      tagName: "figcaption",
 328      value: caption
 329    }));
 330  };
 331  
 332  var _default = saveEmbedActivityBlock;
 333  exports.default = _default;
 334  },{}],"hBDw":[function(require,module,exports) {
 335  "use strict";
 336  
 337  var _edit = _interopRequireDefault(require("./embed-activity/edit"));
 338  
 339  var _save = _interopRequireDefault(require("./embed-activity/save"));
 340  
 341  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 342  
 343  /**
 344   * WordPress dependencies.
 345   */
 346  const {
 347    i18n: {
 348      __
 349    },
 350    blocks: {
 351      registerBlockType
 352    }
 353  } = wp;
 354  /**
 355   * Internal dependencies.
 356   */
 357  
 358  registerBlockType('bp/embed-activity', {
 359    title: __('Embed an activity', 'buddypress'),
 360    description: __('Add a block that displays the activity content pulled from this or other community sites.', 'buddypress'),
 361    icon: {
 362      background: '#fff',
 363      foreground: '#d84800',
 364      src: 'buddicons-activity'
 365    },
 366    category: 'buddypress',
 367    attributes: {
 368      url: {
 369        type: 'string'
 370      },
 371      caption: {
 372        type: 'string',
 373        source: 'html',
 374        selector: 'figcaption'
 375      }
 376    },
 377    supports: {
 378      align: true
 379    },
 380    edit: _edit.default,
 381    save: _save.default
 382  });
 383  },{"./embed-activity/edit":"Sjre","./embed-activity/save":"zmBI"}]},{},["hBDw"], null)


Generated: Tue Apr 25 01:01:23 2023 Cross-referenced by PHPXref 0.7.1