wp/wp-includes/js/dist/block-serialization-default-parser.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 this["wp"] = this["wp"] || {}; this["wp"]["blockSerializationDefaultParser"] =
     1 /******/ (function() { // webpackBootstrap
     2 /******/ (function(modules) { // webpackBootstrap
     2 /******/ 	"use strict";
     3 /******/ 	// The module cache
     3 /******/ 	// The require scope
     4 /******/ 	var installedModules = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/
     5 /******/ 	
     6 /******/ 	// The require function
     6 /************************************************************************/
     7 /******/ 	function __webpack_require__(moduleId) {
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/
     8 /******/ 	!function() {
     9 /******/ 		// Check if module is in cache
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		if(installedModules[moduleId]) {
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    11 /******/ 			return installedModules[moduleId].exports;
    11 /******/ 			for(var key in definition) {
    12 /******/ 		}
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 		// Create a new module (and put it into the cache)
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 		var module = installedModules[moduleId] = {
    14 /******/ 				}
    15 /******/ 			i: moduleId,
    15 /******/ 			}
    16 /******/ 			l: false,
       
    17 /******/ 			exports: {}
       
    18 /******/ 		};
    16 /******/ 		};
    19 /******/
    17 /******/ 	}();
    20 /******/ 		// Execute the module function
    18 /******/ 	
    21 /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    22 /******/
    20 /******/ 	!function() {
    23 /******/ 		// Flag the module as loaded
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    24 /******/ 		module.l = true;
    22 /******/ 	}();
    25 /******/
    23 /******/ 	
    26 /******/ 		// Return the exports of the module
    24 /******/ 	/* webpack/runtime/make namespace object */
    27 /******/ 		return module.exports;
    25 /******/ 	!function() {
    28 /******/ 	}
    26 /******/ 		// define __esModule on exports
    29 /******/
    27 /******/ 		__webpack_require__.r = function(exports) {
    30 /******/
    28 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    31 /******/ 	// expose the modules object (__webpack_modules__)
    29 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    32 /******/ 	__webpack_require__.m = modules;
    30 /******/ 			}
    33 /******/
    31 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    34 /******/ 	// expose the module cache
    32 /******/ 		};
    35 /******/ 	__webpack_require__.c = installedModules;
    33 /******/ 	}();
    36 /******/
    34 /******/ 	
    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 = "SiJt");
       
    86 /******/ })
       
    87 /************************************************************************/
    35 /************************************************************************/
    88 /******/ ({
    36 var __webpack_exports__ = {};
    89 
       
    90 /***/ "SiJt":
       
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
    92 
       
    93 "use strict";
       
    94 __webpack_require__.r(__webpack_exports__);
    37 __webpack_require__.r(__webpack_exports__);
    95 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parse", function() { return parse; });
    38 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
       
    39 /* harmony export */   "parse": function() { return /* binding */ parse; }
       
    40 /* harmony export */ });
    96 let document;
    41 let document;
    97 let offset;
    42 let offset;
    98 let output;
    43 let output;
    99 let stack;
    44 let stack;
   100 /**
    45 /**
   257 };
   202 };
   258 
   203 
   259 function proceed() {
   204 function proceed() {
   260   const next = nextToken();
   205   const next = nextToken();
   261   const [tokenType, blockName, attrs, startOffset, tokenLength] = next;
   206   const [tokenType, blockName, attrs, startOffset, tokenLength] = next;
   262   const stackDepth = stack.length; // we may have some HTML soup before the next block
   207   const stackDepth = stack.length; // We may have some HTML soup before the next block.
   263 
   208 
   264   const leadingHtmlStart = startOffset > offset ? offset : null;
   209   const leadingHtmlStart = startOffset > offset ? offset : null;
   265 
   210 
   266   switch (tokenType) {
   211   switch (tokenType) {
   267     case 'no-more-tokens':
   212     case 'no-more-tokens':
   268       // if not in a block then flush output
   213       // If not in a block then flush output.
   269       if (0 === stackDepth) {
   214       if (0 === stackDepth) {
   270         addFreeform();
   215         addFreeform();
   271         return false;
   216         return false;
   272       } // Otherwise we have a problem
   217       } // Otherwise we have a problem
   273       // This is an error
   218       // This is an error
   274       // we have options
   219       // we have options
   275       //  - treat it all as freeform text
   220       //  - treat it all as freeform text
   276       //  - assume an implicit closer (easiest when not nesting)
   221       //  - assume an implicit closer (easiest when not nesting)
   277       // for the easy case we'll assume an implicit closer
   222       // For the easy case we'll assume an implicit closer.
   278 
   223 
   279 
   224 
   280       if (1 === stackDepth) {
   225       if (1 === stackDepth) {
   281         addBlockFromStack();
   226         addBlockFromStack();
   282         return false;
   227         return false;
   283       } // for the nested case where it's more difficult we'll
   228       } // For the nested case where it's more difficult we'll
   284       // have to assume that multiple closers are missing
   229       // have to assume that multiple closers are missing
   285       // and so we'll collapse the whole stack piecewise
   230       // and so we'll collapse the whole stack piecewise.
   286 
   231 
   287 
   232 
   288       while (0 < stack.length) {
   233       while (0 < stack.length) {
   289         addBlockFromStack();
   234         addBlockFromStack();
   290       }
   235       }
   291 
   236 
   292       return false;
   237       return false;
   293 
   238 
   294     case 'void-block':
   239     case 'void-block':
   295       // easy case is if we stumbled upon a void block
   240       // easy case is if we stumbled upon a void block
   296       // in the top-level of the document
   241       // in the top-level of the document.
   297       if (0 === stackDepth) {
   242       if (0 === stackDepth) {
   298         if (null !== leadingHtmlStart) {
   243         if (null !== leadingHtmlStart) {
   299           output.push(Freeform(document.substr(leadingHtmlStart, startOffset - leadingHtmlStart)));
   244           output.push(Freeform(document.substr(leadingHtmlStart, startOffset - leadingHtmlStart)));
   300         }
   245         }
   301 
   246 
   302         output.push(Block(blockName, attrs, [], '', []));
   247         output.push(Block(blockName, attrs, [], '', []));
   303         offset = startOffset + tokenLength;
   248         offset = startOffset + tokenLength;
   304         return true;
   249         return true;
   305       } // otherwise we found an inner block
   250       } // Otherwise we found an inner block.
   306 
   251 
   307 
   252 
   308       addInnerBlock(Block(blockName, attrs, [], '', []), startOffset, tokenLength);
   253       addInnerBlock(Block(blockName, attrs, [], '', []), startOffset, tokenLength);
   309       offset = startOffset + tokenLength;
   254       offset = startOffset + tokenLength;
   310       return true;
   255       return true;
   311 
   256 
   312     case 'block-opener':
   257     case 'block-opener':
   313       // track all newly-opened blocks on the stack
   258       // Track all newly-opened blocks on the stack.
   314       stack.push(Frame(Block(blockName, attrs, [], '', []), startOffset, tokenLength, startOffset + tokenLength, leadingHtmlStart));
   259       stack.push(Frame(Block(blockName, attrs, [], '', []), startOffset, tokenLength, startOffset + tokenLength, leadingHtmlStart));
   315       offset = startOffset + tokenLength;
   260       offset = startOffset + tokenLength;
   316       return true;
   261       return true;
   317 
   262 
   318     case 'block-closer':
   263     case 'block-closer':
   319       // if we're missing an opener we're in trouble
   264       // If we're missing an opener we're in trouble
   320       // This is an error
   265       // This is an error.
   321       if (0 === stackDepth) {
   266       if (0 === stackDepth) {
   322         // we have options
   267         // We have options
   323         //  - assume an implicit opener
   268         //  - assume an implicit opener
   324         //  - assume _this_ is the opener
   269         //  - assume _this_ is the opener
   325         //  - give up and close out the document
   270         // - give up and close out the document.
   326         addFreeform();
   271         addFreeform();
   327         return false;
   272         return false;
   328       } // if we're not nesting then this is easy - close the block
   273       } // If we're not nesting then this is easy - close the block.
   329 
   274 
   330 
   275 
   331       if (1 === stackDepth) {
   276       if (1 === stackDepth) {
   332         addBlockFromStack(startOffset);
   277         addBlockFromStack(startOffset);
   333         offset = startOffset + tokenLength;
   278         offset = startOffset + tokenLength;
   334         return true;
   279         return true;
   335       } // otherwise we're nested and we have to close out the current
   280       } // Otherwise we're nested and we have to close out the current
   336       // block and add it as a innerBlock to the parent
   281       // block and add it as a innerBlock to the parent.
   337 
   282 
   338 
   283 
   339       const stackTop = stack.pop();
   284       const stackTop = stack.pop();
   340       const html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset);
   285       const html = document.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset);
   341       stackTop.block.innerHTML += html;
   286       stackTop.block.innerHTML += html;
   344       addInnerBlock(stackTop.block, stackTop.tokenStart, stackTop.tokenLength, startOffset + tokenLength);
   289       addInnerBlock(stackTop.block, stackTop.tokenStart, stackTop.tokenLength, startOffset + tokenLength);
   345       offset = startOffset + tokenLength;
   290       offset = startOffset + tokenLength;
   346       return true;
   291       return true;
   347 
   292 
   348     default:
   293     default:
   349       // This is an error
   294       // This is an error.
   350       addFreeform();
   295       addFreeform();
   351       return false;
   296       return false;
   352   }
   297   }
   353 }
   298 }
   354 /**
   299 /**
   370     return null;
   315     return null;
   371   }
   316   }
   372 }
   317 }
   373 
   318 
   374 function nextToken() {
   319 function nextToken() {
   375   // aye the magic
   320   // Aye the magic
   376   // we're using a single RegExp to tokenize the block comment delimiters
   321   // we're using a single RegExp to tokenize the block comment delimiters
   377   // we're also using a trick here because the only difference between a
   322   // we're also using a trick here because the only difference between a
   378   // block opener and a block closer is the leading `/` before `wp:` (and
   323   // block opener and a block closer is the leading `/` before `wp:` (and
   379   // a closer has no attributes). we can trap them both and process the
   324   // a closer has no attributes). we can trap them both and process the
   380   // match back in JavaScript to see which one it was.
   325   // match back in JavaScript to see which one it was.
   381   const matches = tokenizer.exec(document); // we have no more tokens
   326   const matches = tokenizer.exec(document); // We have no more tokens.
   382 
   327 
   383   if (null === matches) {
   328   if (null === matches) {
   384     return ['no-more-tokens'];
   329     return ['no-more-tokens'];
   385   }
   330   }
   386 
   331 
   387   const startedAt = matches.index;
   332   const startedAt = matches.index;
   388   const [match, closerMatch, namespaceMatch, nameMatch, attrsMatch
   333   const [match, closerMatch, namespaceMatch, nameMatch, attrsMatch
   389   /* internal/unused */
   334   /* Internal/unused. */
   390   ,, voidMatch] = matches;
   335   ,, voidMatch] = matches;
   391   const length = match.length;
   336   const length = match.length;
   392   const isCloser = !!closerMatch;
   337   const isCloser = !!closerMatch;
   393   const isVoid = !!voidMatch;
   338   const isVoid = !!voidMatch;
   394   const namespace = namespaceMatch || 'core/';
   339   const namespace = namespaceMatch || 'core/';
   395   const name = namespace + nameMatch;
   340   const name = namespace + nameMatch;
   396   const hasAttrs = !!attrsMatch;
   341   const hasAttrs = !!attrsMatch;
   397   const attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed
   342   const attrs = hasAttrs ? parseJSON(attrsMatch) : {}; // This state isn't allowed
   398   // This is an error
   343   // This is an error.
   399 
   344 
   400   if (isCloser && (isVoid || hasAttrs)) {// we can ignore them since they don't hurt anything
   345   if (isCloser && (isVoid || hasAttrs)) {// We can ignore them since they don't hurt anything
   401     // we may warn against this at some point or reject it
   346     // we may warn against this at some point or reject it.
   402   }
   347   }
   403 
   348 
   404   if (isVoid) {
   349   if (isVoid) {
   405     return ['void-block', name, attrs, startedAt, length];
   350     return ['void-block', name, attrs, startedAt, length];
   406   }
   351   }
   455   }
   400   }
   456 
   401 
   457   output.push(block);
   402   output.push(block);
   458 }
   403 }
   459 
   404 
   460 
   405 (window.wp = window.wp || {}).blockSerializationDefaultParser = __webpack_exports__;
   461 /***/ })
   406 /******/ })()
   462 
   407 ;
   463 /******/ });