[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/js/dist/ -> block-serialization-default-parser.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["blockSerializationDefaultParser"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = "./node_modules/@wordpress/block-serialization-default-parser/build-module/index.js");
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ "./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js":
  91  /*!*******************************************************************!*\
  92    !*** ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js ***!
  93    \*******************************************************************/
  94  /*! exports provided: default */
  95  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  96  
  97  "use strict";
  98  __webpack_require__.r(__webpack_exports__);
  99  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _arrayWithHoles; });
 100  function _arrayWithHoles(arr) {
 101    if (Array.isArray(arr)) return arr;
 102  }
 103  
 104  /***/ }),
 105  
 106  /***/ "./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js":
 107  /*!*************************************************************************!*\
 108    !*** ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js ***!
 109    \*************************************************************************/
 110  /*! exports provided: default */
 111  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 112  
 113  "use strict";
 114  __webpack_require__.r(__webpack_exports__);
 115  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _iterableToArrayLimit; });
 116  function _iterableToArrayLimit(arr, i) {
 117    var _arr = [];
 118    var _n = true;
 119    var _d = false;
 120    var _e = undefined;
 121  
 122    try {
 123      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
 124        _arr.push(_s.value);
 125  
 126        if (i && _arr.length === i) break;
 127      }
 128    } catch (err) {
 129      _d = true;
 130      _e = err;
 131    } finally {
 132      try {
 133        if (!_n && _i["return"] != null) _i["return"]();
 134      } finally {
 135        if (_d) throw _e;
 136      }
 137    }
 138  
 139    return _arr;
 140  }
 141  
 142  /***/ }),
 143  
 144  /***/ "./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js":
 145  /*!********************************************************************!*\
 146    !*** ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js ***!
 147    \********************************************************************/
 148  /*! exports provided: default */
 149  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 150  
 151  "use strict";
 152  __webpack_require__.r(__webpack_exports__);
 153  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _nonIterableRest; });
 154  function _nonIterableRest() {
 155    throw new TypeError("Invalid attempt to destructure non-iterable instance");
 156  }
 157  
 158  /***/ }),
 159  
 160  /***/ "./node_modules/@babel/runtime/helpers/esm/slicedToArray.js":
 161  /*!******************************************************************!*\
 162    !*** ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js ***!
 163    \******************************************************************/
 164  /*! exports provided: default */
 165  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 166  
 167  "use strict";
 168  __webpack_require__.r(__webpack_exports__);
 169  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _slicedToArray; });
 170  /* harmony import */ var _arrayWithHoles__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./arrayWithHoles */ "./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js");
 171  /* harmony import */ var _iterableToArrayLimit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./iterableToArrayLimit */ "./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js");
 172  /* harmony import */ var _nonIterableRest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./nonIterableRest */ "./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js");
 173  
 174  
 175  
 176  function _slicedToArray(arr, i) {
 177    return Object(_arrayWithHoles__WEBPACK_IMPORTED_MODULE_0__["default"])(arr) || Object(_iterableToArrayLimit__WEBPACK_IMPORTED_MODULE_1__["default"])(arr, i) || Object(_nonIterableRest__WEBPACK_IMPORTED_MODULE_2__["default"])();
 178  }
 179  
 180  /***/ }),
 181  
 182  /***/ "./node_modules/@wordpress/block-serialization-default-parser/build-module/index.js":
 183  /*!******************************************************************************************!*\
 184    !*** ./node_modules/@wordpress/block-serialization-default-parser/build-module/index.js ***!
 185    \******************************************************************************************/
 186  /*! exports provided: parse */
 187  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 188  
 189  "use strict";
 190  __webpack_require__.r(__webpack_exports__);
 191  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parse", function() { return parse; });
 192  /* harmony import */ var _babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/slicedToArray */ "./node_modules/@babel/runtime/helpers/esm/slicedToArray.js");
 193  
 194  var document;
 195  var offset;
 196  var output;
 197  var stack;
 198  var tokenizer = /<!--\s+(\/)?wp:([a-z][a-z0-9_-]*\/)?([a-z][a-z0-9_-]*)\s+({(?:(?!}\s+-->)[^])+?}\s+)?(\/)?-->/g;
 199  
 200  function Block(blockName, attrs, innerBlocks, innerHTML) {
 201    return {
 202      blockName: blockName,
 203      attrs: attrs,
 204      innerBlocks: innerBlocks,
 205      innerHTML: innerHTML
 206    };
 207  }
 208  
 209  function Freeform(innerHTML) {
 210    return Block(null, {}, [], innerHTML);
 211  }
 212  
 213  function Frame(block, tokenStart, tokenLength, prevOffset, leadingHtmlStart) {
 214    return {
 215      block: block,
 216      tokenStart: tokenStart,
 217      tokenLength: tokenLength,
 218      prevOffset: prevOffset || tokenStart + tokenLength,
 219      leadingHtmlStart: leadingHtmlStart
 220    };
 221  }
 222  
 223  var parse = function parse(doc) {
 224    document = doc;
 225    offset = 0;
 226    output = [];
 227    stack = [];
 228    tokenizer.lastIndex = 0;
 229  
 230    do {// twiddle our thumbs
 231    } while (proceed());
 232  
 233    return output;
 234  };
 235  
 236  function proceed() {
 237    var next = nextToken();
 238  
 239    var _next = Object(_babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__["default"])(next, 5),
 240        tokenType = _next[0],
 241        blockName = _next[1],
 242        attrs = _next[2],
 243        startOffset = _next[3],
 244        tokenLength = _next[4];
 245  
 246    var stackDepth = stack.length; // we may have some HTML soup before the next block
 247  
 248    var leadingHtmlStart = startOffset > offset ? offset : null;
 249  
 250    switch (tokenType) {
 251      case 'no-more-tokens':
 252        // if not in a block then flush output
 253        if (0 === stackDepth) {
 254          addFreeform();
 255          return false;
 256        } // Otherwise we have a problem
 257        // This is an error
 258        // we have options
 259        //  - treat it all as freeform text
 260        //  - assume an implicit closer (easiest when not nesting)
 261        // for the easy case we'll assume an implicit closer
 262  
 263  
 264        if (1 === stackDepth) {
 265          addBlockFromStack();
 266          return false;
 267        } // for the nested case where it's more difficult we'll
 268        // have to assume that multiple closers are missing
 269        // and so we'll collapse the whole stack piecewise
 270  
 271  
 272        while (0 < stack.length) {
 273          addBlockFromStack();
 274        }
 275  
 276        return false;
 277  
 278      case 'void-block':
 279        // easy case is if we stumbled upon a void block
 280        // in the top-level of the document
 281        if (0 === stackDepth) {
 282          if (null !== leadingHtmlStart) {
 283            output.push(Freeform(document.substr(leadingHtmlStart, startOffset - leadingHtmlStart)));
 284          }
 285  
 286          output.push(Block(blockName, attrs, [], ''));
 287          offset = startOffset + tokenLength;
 288          return true;
 289        } // otherwise we found an inner block
 290  
 291  
 292        addInnerBlock(Block(blockName, attrs, [], ''), startOffset, tokenLength);
 293        offset = startOffset + tokenLength;
 294        return true;
 295  
 296      case 'block-opener':
 297        // track all newly-opened blocks on the stack
 298        stack.push(Frame(Block(blockName, attrs, [], ''), startOffset, tokenLength, startOffset + tokenLength, leadingHtmlStart));
 299        offset = startOffset + tokenLength;
 300        return true;
 301  
 302      case 'block-closer':
 303        // if we're missing an opener we're in trouble
 304        // This is an error
 305        if (0 === stackDepth) {
 306          // we have options
 307          //  - assume an implicit opener
 308          //  - assume _this_ is the opener
 309          //  - give up and close out the document
 310          addFreeform();
 311          return false;
 312        } // if we're not nesting then this is easy - close the block
 313  
 314  
 315        if (1 === stackDepth) {
 316          addBlockFromStack(startOffset);
 317          offset = startOffset + tokenLength;
 318          return true;
 319        } // otherwise we're nested and we have to close out the current
 320        // block and add it as a innerBlock to the parent
 321  
 322  
 323        var stackTop = stack.pop();
 324        stackTop.block.innerHTML += document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset);
 325        stackTop.prevOffset = startOffset + tokenLength;
 326        addInnerBlock(stackTop.block, stackTop.tokenStart, stackTop.tokenLength, startOffset + tokenLength);
 327        offset = startOffset + tokenLength;
 328        return true;
 329  
 330      default:
 331        // This is an error
 332        addFreeform();
 333        return false;
 334    }
 335  }
 336  /**
 337   * Parse JSON if valid, otherwise return null
 338   *
 339   * Note that JSON coming from the block comment
 340   * delimiters is constrained to be an object
 341   * and cannot be things like `true` or `null`
 342   *
 343   * @param {string} input JSON input string to parse
 344   * @return {Object|null} parsed JSON if valid
 345   */
 346  
 347  
 348  function parseJSON(input) {
 349    try {
 350      return JSON.parse(input);
 351    } catch (e) {
 352      return null;
 353    }
 354  }
 355  
 356  function nextToken() {
 357    // aye the magic
 358    // we're using a single RegExp to tokenize the block comment delimiters
 359    // we're also using a trick here because the only difference between a
 360    // block opener and a block closer is the leading `/` before `wp:` (and
 361    // a closer has no attributes). we can trap them both and process the
 362    // match back in Javascript to see which one it was.
 363    var matches = tokenizer.exec(document); // we have no more tokens
 364  
 365    if (null === matches) {
 366      return ['no-more-tokens'];
 367    }
 368  
 369    var startedAt = matches.index;
 370  
 371    var _matches = Object(_babel_runtime_helpers_esm_slicedToArray__WEBPACK_IMPORTED_MODULE_0__["default"])(matches, 6),
 372        match = _matches[0],
 373        closerMatch = _matches[1],
 374        namespaceMatch = _matches[2],
 375        nameMatch = _matches[3],
 376        attrsMatch = _matches[4],
 377        voidMatch = _matches[5];
 378  
 379    var length = match.length;
 380    var isCloser = !!closerMatch;
 381    var isVoid = !!voidMatch;
 382    var namespace = namespaceMatch || 'core/';
 383    var name = namespace + nameMatch;
 384    var hasAttrs = !!attrsMatch;
 385    var attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed
 386    // This is an error
 387  
 388    if (isCloser && (isVoid || hasAttrs)) {// we can ignore them since they don't hurt anything
 389      // we may warn against this at some point or reject it
 390    }
 391  
 392    if (isVoid) {
 393      return ['void-block', name, attrs, startedAt, length];
 394    }
 395  
 396    if (isCloser) {
 397      return ['block-closer', name, null, startedAt, length];
 398    }
 399  
 400    return ['block-opener', name, attrs, startedAt, length];
 401  }
 402  
 403  function addFreeform(rawLength) {
 404    var length = rawLength ? rawLength : document.length - offset;
 405  
 406    if (0 === length) {
 407      return;
 408    }
 409  
 410    output.push(Freeform(document.substr(offset, length)));
 411  }
 412  
 413  function addInnerBlock(block, tokenStart, tokenLength, lastOffset) {
 414    var parent = stack[stack.length - 1];
 415    parent.block.innerBlocks.push(block);
 416    parent.block.innerHTML += document.substr(parent.prevOffset, tokenStart - parent.prevOffset);
 417    parent.prevOffset = lastOffset ? lastOffset : tokenStart + tokenLength;
 418  }
 419  
 420  function addBlockFromStack(endOffset) {
 421    var _stack$pop = stack.pop(),
 422        block = _stack$pop.block,
 423        leadingHtmlStart = _stack$pop.leadingHtmlStart,
 424        prevOffset = _stack$pop.prevOffset,
 425        tokenStart = _stack$pop.tokenStart;
 426  
 427    if (endOffset) {
 428      block.innerHTML += document.substr(prevOffset, endOffset - prevOffset);
 429    } else {
 430      block.innerHTML += document.substr(prevOffset);
 431    }
 432  
 433    if (null !== leadingHtmlStart) {
 434      output.push(Freeform(document.substr(leadingHtmlStart, tokenStart - leadingHtmlStart)));
 435    }
 436  
 437    output.push(block);
 438  }
 439  
 440  
 441  /***/ })
 442  
 443  /******/ });
 444  //# sourceMappingURL=block-serialization-default-parser.js.map


Generated: Mon Jan 7 01:00:05 2019 Cross-referenced by PHPXref 0.7.1