wp/wp-includes/js/dist/shortcode.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /******/ (function() { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	var __webpack_modules__ = ({
     2 /******/ 	"use strict";
     3 
     3 /******/ 	// The require scope
     4 /***/ 9756:
     4 /******/ 	var __webpack_require__ = {};
     5 /***/ (function(module) {
     5 /******/ 	
     6 
     6 /************************************************************************/
       
     7 /******/ 	/* webpack/runtime/define property getters */
       
     8 /******/ 	(() => {
       
     9 /******/ 		// define getter functions for harmony exports
       
    10 /******/ 		__webpack_require__.d = (exports, definition) => {
       
    11 /******/ 			for(var key in definition) {
       
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
       
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
       
    14 /******/ 				}
       
    15 /******/ 			}
       
    16 /******/ 		};
       
    17 /******/ 	})();
       
    18 /******/ 	
       
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
       
    20 /******/ 	(() => {
       
    21 /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
       
    22 /******/ 	})();
       
    23 /******/ 	
       
    24 /************************************************************************/
       
    25 var __webpack_exports__ = {};
       
    26 
       
    27 // EXPORTS
       
    28 __webpack_require__.d(__webpack_exports__, {
       
    29   "default": () => (/* binding */ build_module)
       
    30 });
       
    31 
       
    32 // UNUSED EXPORTS: attrs, fromMatch, next, regexp, replace, string
       
    33 
       
    34 ;// CONCATENATED MODULE: ./node_modules/memize/dist/index.js
     7 /**
    35 /**
     8  * Memize options object.
    36  * Memize options object.
     9  *
    37  *
    10  * @typedef MemizeOptions
    38  * @typedef MemizeOptions
    11  *
    39  *
    34 
    62 
    35 /**
    63 /**
    36  * Accepts a function to be memoized, and returns a new memoized function, with
    64  * Accepts a function to be memoized, and returns a new memoized function, with
    37  * optional options.
    65  * optional options.
    38  *
    66  *
    39  * @template {Function} F
    67  * @template {(...args: any[]) => any} F
    40  *
    68  *
    41  * @param {F}             fn        Function to memoize.
    69  * @param {F}             fn        Function to memoize.
    42  * @param {MemizeOptions} [options] Options object.
    70  * @param {MemizeOptions} [options] Options object.
    43  *
    71  *
    44  * @return {F & MemizeMemoizedFunction} Memoized function.
    72  * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function.
    45  */
    73  */
    46 function memize( fn, options ) {
    74 function memize(fn, options) {
    47 	var size = 0;
    75 	var size = 0;
    48 
    76 
    49 	/** @type {?MemizeCacheNode|undefined} */
    77 	/** @type {?MemizeCacheNode|undefined} */
    50 	var head;
    78 	var head;
    51 
    79 
    52 	/** @type {?MemizeCacheNode|undefined} */
    80 	/** @type {?MemizeCacheNode|undefined} */
    53 	var tail;
    81 	var tail;
    54 
    82 
    55 	options = options || {};
    83 	options = options || {};
    56 
    84 
    57 	function memoized( /* ...args */ ) {
    85 	function memoized(/* ...args */) {
    58 		var node = head,
    86 		var node = head,
    59 			len = arguments.length,
    87 			len = arguments.length,
    60 			args, i;
    88 			args,
    61 
    89 			i;
    62 		searchCache: while ( node ) {
    90 
       
    91 		searchCache: while (node) {
    63 			// Perform a shallow equality test to confirm that whether the node
    92 			// Perform a shallow equality test to confirm that whether the node
    64 			// under test is a candidate for the arguments passed. Two arrays
    93 			// under test is a candidate for the arguments passed. Two arrays
    65 			// are shallowly equal if their length matches and each entry is
    94 			// are shallowly equal if their length matches and each entry is
    66 			// strictly equal between the two sets. Avoid abstracting to a
    95 			// strictly equal between the two sets. Avoid abstracting to a
    67 			// function which could incur an arguments leaking deoptimization.
    96 			// function which could incur an arguments leaking deoptimization.
    68 
    97 
    69 			// Check whether node arguments match arguments length
    98 			// Check whether node arguments match arguments length
    70 			if ( node.args.length !== arguments.length ) {
    99 			if (node.args.length !== arguments.length) {
    71 				node = node.next;
   100 				node = node.next;
    72 				continue;
   101 				continue;
    73 			}
   102 			}
    74 
   103 
    75 			// Check whether node arguments match arguments values
   104 			// Check whether node arguments match arguments values
    76 			for ( i = 0; i < len; i++ ) {
   105 			for (i = 0; i < len; i++) {
    77 				if ( node.args[ i ] !== arguments[ i ] ) {
   106 				if (node.args[i] !== arguments[i]) {
    78 					node = node.next;
   107 					node = node.next;
    79 					continue searchCache;
   108 					continue searchCache;
    80 				}
   109 				}
    81 			}
   110 			}
    82 
   111 
    83 			// At this point we can assume we've found a match
   112 			// At this point we can assume we've found a match
    84 
   113 
    85 			// Surface matched node to head if not already
   114 			// Surface matched node to head if not already
    86 			if ( node !== head ) {
   115 			if (node !== head) {
    87 				// As tail, shift to previous. Must only shift if not also
   116 				// As tail, shift to previous. Must only shift if not also
    88 				// head, since if both head and tail, there is no previous.
   117 				// head, since if both head and tail, there is no previous.
    89 				if ( node === tail ) {
   118 				if (node === tail) {
    90 					tail = node.prev;
   119 					tail = node.prev;
    91 				}
   120 				}
    92 
   121 
    93 				// Adjust siblings to point to each other. If node was tail,
   122 				// Adjust siblings to point to each other. If node was tail,
    94 				// this also handles new tail's empty `next` assignment.
   123 				// this also handles new tail's empty `next` assignment.
    95 				/** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
   124 				/** @type {MemizeCacheNode} */ (node.prev).next = node.next;
    96 				if ( node.next ) {
   125 				if (node.next) {
    97 					node.next.prev = node.prev;
   126 					node.next.prev = node.prev;
    98 				}
   127 				}
    99 
   128 
   100 				node.next = head;
   129 				node.next = head;
   101 				node.prev = null;
   130 				node.prev = null;
   102 				/** @type {MemizeCacheNode} */ ( head ).prev = node;
   131 				/** @type {MemizeCacheNode} */ (head).prev = node;
   103 				head = node;
   132 				head = node;
   104 			}
   133 			}
   105 
   134 
   106 			// Return immediately
   135 			// Return immediately
   107 			return node.val;
   136 			return node.val;
   108 		}
   137 		}
   109 
   138 
   110 		// No cached value found. Continue to insertion phase:
   139 		// No cached value found. Continue to insertion phase:
   111 
   140 
   112 		// Create a copy of arguments (avoid leaking deoptimization)
   141 		// Create a copy of arguments (avoid leaking deoptimization)
   113 		args = new Array( len );
   142 		args = new Array(len);
   114 		for ( i = 0; i < len; i++ ) {
   143 		for (i = 0; i < len; i++) {
   115 			args[ i ] = arguments[ i ];
   144 			args[i] = arguments[i];
   116 		}
   145 		}
   117 
   146 
   118 		node = {
   147 		node = {
   119 			args: args,
   148 			args: args,
   120 
   149 
   121 			// Generate the result from original function
   150 			// Generate the result from original function
   122 			val: fn.apply( null, args ),
   151 			val: fn.apply(null, args),
   123 		};
   152 		};
   124 
   153 
   125 		// Don't need to check whether node is already head, since it would
   154 		// Don't need to check whether node is already head, since it would
   126 		// have been returned above already if it was
   155 		// have been returned above already if it was
   127 
   156 
   128 		// Shift existing head down list
   157 		// Shift existing head down list
   129 		if ( head ) {
   158 		if (head) {
   130 			head.prev = node;
   159 			head.prev = node;
   131 			node.next = head;
   160 			node.next = head;
   132 		} else {
   161 		} else {
   133 			// If no head, follows that there's no tail (at initial or reset)
   162 			// If no head, follows that there's no tail (at initial or reset)
   134 			tail = node;
   163 			tail = node;
   135 		}
   164 		}
   136 
   165 
   137 		// Trim tail if we're reached max size and are pending cache insertion
   166 		// Trim tail if we're reached max size and are pending cache insertion
   138 		if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
   167 		if (size === /** @type {MemizeOptions} */ (options).maxSize) {
   139 			tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
   168 			tail = /** @type {MemizeCacheNode} */ (tail).prev;
   140 			/** @type {MemizeCacheNode} */ ( tail ).next = null;
   169 			/** @type {MemizeCacheNode} */ (tail).next = null;
   141 		} else {
   170 		} else {
   142 			size++;
   171 			size++;
   143 		}
   172 		}
   144 
   173 
   145 		head = node;
   174 		head = node;
   146 
   175 
   147 		return node.val;
   176 		return node.val;
   148 	}
   177 	}
   149 
   178 
   150 	memoized.clear = function() {
   179 	memoized.clear = function () {
   151 		head = null;
   180 		head = null;
   152 		tail = null;
   181 		tail = null;
   153 		size = 0;
   182 		size = 0;
   154 	};
   183 	};
   155 
   184 
   156 	if ( false ) {}
       
   157 
       
   158 	// Ignore reason: There's not a clear solution to create an intersection of
   185 	// Ignore reason: There's not a clear solution to create an intersection of
   159 	// the function with additional properties, where the goal is to retain the
   186 	// the function with additional properties, where the goal is to retain the
   160 	// function signature of the incoming argument and add control properties
   187 	// function signature of the incoming argument and add control properties
   161 	// on the return value.
   188 	// on the return value.
   162 
   189 
   163 	// @ts-ignore
   190 	// @ts-ignore
   164 	return memoized;
   191 	return memoized;
   165 }
   192 }
   166 
   193 
   167 module.exports = memize;
   194 
   168 
   195 
   169 
       
   170 /***/ })
       
   171 
       
   172 /******/ 	});
       
   173 /************************************************************************/
       
   174 /******/ 	// The module cache
       
   175 /******/ 	var __webpack_module_cache__ = {};
       
   176 /******/ 	
       
   177 /******/ 	// The require function
       
   178 /******/ 	function __webpack_require__(moduleId) {
       
   179 /******/ 		// Check if module is in cache
       
   180 /******/ 		var cachedModule = __webpack_module_cache__[moduleId];
       
   181 /******/ 		if (cachedModule !== undefined) {
       
   182 /******/ 			return cachedModule.exports;
       
   183 /******/ 		}
       
   184 /******/ 		// Create a new module (and put it into the cache)
       
   185 /******/ 		var module = __webpack_module_cache__[moduleId] = {
       
   186 /******/ 			// no module.id needed
       
   187 /******/ 			// no module.loaded needed
       
   188 /******/ 			exports: {}
       
   189 /******/ 		};
       
   190 /******/ 	
       
   191 /******/ 		// Execute the module function
       
   192 /******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
       
   193 /******/ 	
       
   194 /******/ 		// Return the exports of the module
       
   195 /******/ 		return module.exports;
       
   196 /******/ 	}
       
   197 /******/ 	
       
   198 /************************************************************************/
       
   199 /******/ 	/* webpack/runtime/compat get default export */
       
   200 /******/ 	!function() {
       
   201 /******/ 		// getDefaultExport function for compatibility with non-harmony modules
       
   202 /******/ 		__webpack_require__.n = function(module) {
       
   203 /******/ 			var getter = module && module.__esModule ?
       
   204 /******/ 				function() { return module['default']; } :
       
   205 /******/ 				function() { return module; };
       
   206 /******/ 			__webpack_require__.d(getter, { a: getter });
       
   207 /******/ 			return getter;
       
   208 /******/ 		};
       
   209 /******/ 	}();
       
   210 /******/ 	
       
   211 /******/ 	/* webpack/runtime/define property getters */
       
   212 /******/ 	!function() {
       
   213 /******/ 		// define getter functions for harmony exports
       
   214 /******/ 		__webpack_require__.d = function(exports, definition) {
       
   215 /******/ 			for(var key in definition) {
       
   216 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
       
   217 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
       
   218 /******/ 				}
       
   219 /******/ 			}
       
   220 /******/ 		};
       
   221 /******/ 	}();
       
   222 /******/ 	
       
   223 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
       
   224 /******/ 	!function() {
       
   225 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
       
   226 /******/ 	}();
       
   227 /******/ 	
       
   228 /************************************************************************/
       
   229 var __webpack_exports__ = {};
       
   230 // This entry need to be wrapped in an IIFE because it need to be in strict mode.
       
   231 !function() {
       
   232 "use strict";
       
   233 
       
   234 // EXPORTS
       
   235 __webpack_require__.d(__webpack_exports__, {
       
   236   "default": function() { return /* binding */ build_module; }
       
   237 });
       
   238 
       
   239 // UNUSED EXPORTS: attrs, fromMatch, next, regexp, replace, string
       
   240 
       
   241 ;// CONCATENATED MODULE: external "lodash"
       
   242 var external_lodash_namespaceObject = window["lodash"];
       
   243 // EXTERNAL MODULE: ./node_modules/memize/index.js
       
   244 var memize = __webpack_require__(9756);
       
   245 var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
       
   246 ;// CONCATENATED MODULE: ./node_modules/@wordpress/shortcode/build-module/index.js
   196 ;// CONCATENATED MODULE: ./node_modules/@wordpress/shortcode/build-module/index.js
   247 /**
   197 /**
   248  * External dependencies
   198  * External dependencies
   249  */
   199  */
   250 
   200 
   283  *
   233  *
   284  * @param {string} tag   Shortcode tag.
   234  * @param {string} tag   Shortcode tag.
   285  * @param {string} text  Text to search.
   235  * @param {string} text  Text to search.
   286  * @param {number} index Index to start search from.
   236  * @param {number} index Index to start search from.
   287  *
   237  *
   288  * @return {?WPShortcodeMatch} Matched information.
   238  * @return {WPShortcodeMatch | undefined} Matched information.
   289  */
   239  */
   290 
   240 function next(tag, text, index = 0) {
   291 function next(tag, text) {
       
   292   let index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
       
   293   const re = regexp(tag);
   241   const re = regexp(tag);
   294   re.lastIndex = index;
   242   re.lastIndex = index;
   295   const match = re.exec(text);
   243   const match = re.exec(text);
   296 
       
   297   if (!match) {
   244   if (!match) {
   298     return;
   245     return;
   299   } // If we matched an escaped shortcode, try again.
   246   }
   300 
   247 
   301 
   248   // If we matched an escaped shortcode, try again.
   302   if ('[' === match[1] && ']' === match[7]) {
   249   if ('[' === match[1] && ']' === match[7]) {
   303     return next(tag, text, re.lastIndex);
   250     return next(tag, text, re.lastIndex);
   304   }
   251   }
   305 
       
   306   const result = {
   252   const result = {
   307     index: match.index,
   253     index: match.index,
   308     content: match[0],
   254     content: match[0],
   309     shortcode: fromMatch(match)
   255     shortcode: fromMatch(match)
   310   }; // If we matched a leading `[`, strip it from the match and increment the
   256   };
       
   257 
       
   258   // If we matched a leading `[`, strip it from the match and increment the
   311   // index accordingly.
   259   // index accordingly.
   312 
       
   313   if (match[1]) {
   260   if (match[1]) {
   314     result.content = result.content.slice(1);
   261     result.content = result.content.slice(1);
   315     result.index++;
   262     result.index++;
   316   } // If we matched a trailing `]`, strip it from the match.
   263   }
   317 
   264 
   318 
   265   // If we matched a trailing `]`, strip it from the match.
   319   if (match[7]) {
   266   if (match[7]) {
   320     result.content = result.content.slice(0, -1);
   267     result.content = result.content.slice(0, -1);
   321   }
   268   }
   322 
       
   323   return result;
   269   return result;
   324 }
   270 }
       
   271 
   325 /**
   272 /**
   326  * Replace matching shortcodes in a block of text.
   273  * Replace matching shortcodes in a block of text.
   327  *
   274  *
   328  * @param {string}   tag      Shortcode tag.
   275  * @param {string}   tag      Shortcode tag.
   329  * @param {string}   text     Text to search.
   276  * @param {string}   text     Text to search.
   330  * @param {Function} callback Function to process the match and return
   277  * @param {Function} callback Function to process the match and return
   331  *                            replacement string.
   278  *                            replacement string.
   332  *
   279  *
   333  * @return {string} Text with shortcodes replaced.
   280  * @return {string} Text with shortcodes replaced.
   334  */
   281  */
   335 
       
   336 function replace(tag, text, callback) {
   282 function replace(tag, text, callback) {
   337   return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
   283   return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
   338     // If both extra brackets exist, the shortcode has been properly
   284     // If both extra brackets exist, the shortcode has been properly
   339     // escaped.
   285     // escaped.
   340     if (left === '[' && right === ']') {
   286     if (left === '[' && right === ']') {
   341       return match;
   287       return match;
   342     } // Create the match object and pass it through the callback.
   288     }
   343 
   289 
   344 
   290     // Create the match object and pass it through the callback.
   345     const result = callback(fromMatch(arguments)); // Make sure to return any of the extra brackets if they weren't used to
   291     const result = callback(fromMatch(arguments));
       
   292 
       
   293     // Make sure to return any of the extra brackets if they weren't used to
   346     // escape the shortcode.
   294     // escape the shortcode.
   347 
       
   348     return result || result === '' ? left + result + right : match;
   295     return result || result === '' ? left + result + right : match;
   349   });
   296   });
   350 }
   297 }
       
   298 
   351 /**
   299 /**
   352  * Generate a string from shortcode parameters.
   300  * Generate a string from shortcode parameters.
   353  *
   301  *
   354  * Creates a shortcode instance and returns a string.
   302  * Creates a shortcode instance and returns a string.
   355  *
   303  *
   359  *
   307  *
   360  * @param {Object} options
   308  * @param {Object} options
   361  *
   309  *
   362  * @return {string} String representation of the shortcode.
   310  * @return {string} String representation of the shortcode.
   363  */
   311  */
   364 
       
   365 function string(options) {
   312 function string(options) {
   366   return new shortcode(options).string();
   313   return new shortcode(options).string();
   367 }
   314 }
       
   315 
   368 /**
   316 /**
   369  * Generate a RegExp to identify a shortcode.
   317  * Generate a RegExp to identify a shortcode.
   370  *
   318  *
   371  * The base regex is functionally equivalent to the one found in
   319  * The base regex is functionally equivalent to the one found in
   372  * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
   320  * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
   383  *
   331  *
   384  * @param {string} tag Shortcode tag.
   332  * @param {string} tag Shortcode tag.
   385  *
   333  *
   386  * @return {RegExp} Shortcode RegExp.
   334  * @return {RegExp} Shortcode RegExp.
   387  */
   335  */
   388 
       
   389 function regexp(tag) {
   336 function regexp(tag) {
   390   return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
   337   return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
   391 }
   338 }
       
   339 
   392 /**
   340 /**
   393  * Parse shortcode attributes.
   341  * Parse shortcode attributes.
   394  *
   342  *
   395  * Shortcodes accept many types of attributes. These can chiefly be divided into
   343  * Shortcodes accept many types of attributes. These can chiefly be divided into
   396  * named and numeric attributes:
   344  * named and numeric attributes:
   404  *
   352  *
   405  * @param {string} text Serialised shortcode attributes.
   353  * @param {string} text Serialised shortcode attributes.
   406  *
   354  *
   407  * @return {WPShortcodeAttrs} Parsed shortcode attributes.
   355  * @return {WPShortcodeAttrs} Parsed shortcode attributes.
   408  */
   356  */
   409 
   357 const attrs = memize(text => {
   410 const attrs = memize_default()(text => {
       
   411   const named = {};
   358   const named = {};
   412   const numeric = []; // This regular expression is reused from `shortcode_parse_atts()` in
   359   const numeric = [];
       
   360 
       
   361   // This regular expression is reused from `shortcode_parse_atts()` in
   413   // `wp-includes/shortcodes.php`.
   362   // `wp-includes/shortcodes.php`.
   414   //
   363   //
   415   // Capture groups:
   364   // Capture groups:
   416   //
   365   //
   417   // 1. An attribute name, that corresponds to...
   366   // 1. An attribute name, that corresponds to...
   421   // 5. An attribute name, that corresponds to...
   370   // 5. An attribute name, that corresponds to...
   422   // 6. an unquoted value.
   371   // 6. an unquoted value.
   423   // 7. A numeric attribute in double quotes.
   372   // 7. A numeric attribute in double quotes.
   424   // 8. A numeric attribute in single quotes.
   373   // 8. A numeric attribute in single quotes.
   425   // 9. An unquoted numeric attribute.
   374   // 9. An unquoted numeric attribute.
   426 
   375   const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
   427   const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; // Map zero-width spaces to actual spaces.
   376 
   428 
   377   // Map zero-width spaces to actual spaces.
   429   text = text.replace(/[\u00a0\u200b]/g, ' ');
   378   text = text.replace(/[\u00a0\u200b]/g, ' ');
   430   let match; // Match and normalize attributes.
   379   let match;
   431 
   380 
       
   381   // Match and normalize attributes.
   432   while (match = pattern.exec(text)) {
   382   while (match = pattern.exec(text)) {
   433     if (match[1]) {
   383     if (match[1]) {
   434       named[match[1].toLowerCase()] = match[2];
   384       named[match[1].toLowerCase()] = match[2];
   435     } else if (match[3]) {
   385     } else if (match[3]) {
   436       named[match[3].toLowerCase()] = match[4];
   386       named[match[3].toLowerCase()] = match[4];
   442       numeric.push(match[8]);
   392       numeric.push(match[8]);
   443     } else if (match[9]) {
   393     } else if (match[9]) {
   444       numeric.push(match[9]);
   394       numeric.push(match[9]);
   445     }
   395     }
   446   }
   396   }
   447 
       
   448   return {
   397   return {
   449     named,
   398     named,
   450     numeric
   399     numeric
   451   };
   400   };
   452 });
   401 });
       
   402 
   453 /**
   403 /**
   454  * Generate a Shortcode Object from a RegExp match.
   404  * Generate a Shortcode Object from a RegExp match.
   455  *
   405  *
   456  * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
   406  * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
   457  * by `regexp()`. `match` can also be set to the `arguments` from a callback
   407  * by `regexp()`. `match` can also be set to the `arguments` from a callback
   459  *
   409  *
   460  * @param {Array} match Match array.
   410  * @param {Array} match Match array.
   461  *
   411  *
   462  * @return {WPShortcode} Shortcode instance.
   412  * @return {WPShortcode} Shortcode instance.
   463  */
   413  */
   464 
       
   465 function fromMatch(match) {
   414 function fromMatch(match) {
   466   let type;
   415   let type;
   467 
       
   468   if (match[4]) {
   416   if (match[4]) {
   469     type = 'self-closing';
   417     type = 'self-closing';
   470   } else if (match[6]) {
   418   } else if (match[6]) {
   471     type = 'closed';
   419     type = 'closed';
   472   } else {
   420   } else {
   473     type = 'single';
   421     type = 'single';
   474   }
   422   }
   475 
       
   476   return new shortcode({
   423   return new shortcode({
   477     tag: match[2],
   424     tag: match[2],
   478     attrs: match[3],
   425     attrs: match[3],
   479     type,
   426     type,
   480     content: match[5]
   427     content: match[5]
   481   });
   428   });
   482 }
   429 }
       
   430 
   483 /**
   431 /**
   484  * Creates a shortcode instance.
   432  * Creates a shortcode instance.
   485  *
   433  *
   486  * To access a raw representation of a shortcode, pass an `options` object,
   434  * To access a raw representation of a shortcode, pass an `options` object,
   487  * containing a `tag` string, a string or object of `attrs`, a string indicating
   435  * containing a `tag` string, a string or object of `attrs`, a string indicating
   490  *
   438  *
   491  * @param {Object} options Options as described.
   439  * @param {Object} options Options as described.
   492  *
   440  *
   493  * @return {WPShortcode} Shortcode instance.
   441  * @return {WPShortcode} Shortcode instance.
   494  */
   442  */
   495 
   443 const shortcode = Object.assign(function (options) {
   496 const shortcode = (0,external_lodash_namespaceObject.extend)(function (options) {
   444   const {
   497   (0,external_lodash_namespaceObject.extend)(this, (0,external_lodash_namespaceObject.pick)(options || {}, 'tag', 'attrs', 'type', 'content'));
   445     tag,
   498   const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
   446     attrs: attributes,
   499 
   447     type,
       
   448     content
       
   449   } = options || {};
       
   450   Object.assign(this, {
       
   451     tag,
       
   452     type,
       
   453     content
       
   454   });
       
   455 
       
   456   // Ensure we have a correctly formatted `attrs` object.
   500   this.attrs = {
   457   this.attrs = {
   501     named: {},
   458     named: {},
   502     numeric: []
   459     numeric: []
   503   };
   460   };
   504 
       
   505   if (!attributes) {
   461   if (!attributes) {
   506     return;
   462     return;
   507   } // Parse a string of attributes.
   463   }
   508 
   464   const attributeTypes = ['named', 'numeric'];
   509 
   465 
   510   if ((0,external_lodash_namespaceObject.isString)(attributes)) {
   466   // Parse a string of attributes.
   511     this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
   467   if (typeof attributes === 'string') {
   512   } else if ((0,external_lodash_namespaceObject.isEqual)(Object.keys(attributes), ['named', 'numeric'])) {
   468     this.attrs = attrs(attributes);
   513     this.attrs = attributes; // Handle a flat object of attributes.
   469     // Identify a correctly formatted `attrs` object.
       
   470   } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
       
   471     this.attrs = attributes;
       
   472     // Handle a flat object of attributes.
   514   } else {
   473   } else {
   515     (0,external_lodash_namespaceObject.forEach)(attributes, (value, key) => {
   474     Object.entries(attributes).forEach(([key, value]) => {
   516       this.set(key, value);
   475       this.set(key, value);
   517     });
   476     });
   518   }
   477   }
   519 }, {
   478 }, {
   520   next,
   479   next,
   522   string,
   481   string,
   523   regexp,
   482   regexp,
   524   attrs,
   483   attrs,
   525   fromMatch
   484   fromMatch
   526 });
   485 });
   527 (0,external_lodash_namespaceObject.extend)(shortcode.prototype, {
   486 Object.assign(shortcode.prototype, {
   528   /**
   487   /**
   529    * Get a shortcode attribute.
   488    * Get a shortcode attribute.
   530    *
   489    *
   531    * Automatically detects whether `attr` is named or numeric and routes it
   490    * Automatically detects whether `attr` is named or numeric and routes it
   532    * accordingly.
   491    * accordingly.
   534    * @param {(number|string)} attr Attribute key.
   493    * @param {(number|string)} attr Attribute key.
   535    *
   494    *
   536    * @return {string} Attribute value.
   495    * @return {string} Attribute value.
   537    */
   496    */
   538   get(attr) {
   497   get(attr) {
   539     return this.attrs[(0,external_lodash_namespaceObject.isNumber)(attr) ? 'numeric' : 'named'][attr];
   498     return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
   540   },
   499   },
   541 
       
   542   /**
   500   /**
   543    * Set a shortcode attribute.
   501    * Set a shortcode attribute.
   544    *
   502    *
   545    * Automatically detects whether `attr` is named or numeric and routes it
   503    * Automatically detects whether `attr` is named or numeric and routes it
   546    * accordingly.
   504    * accordingly.
   549    * @param {string}          value Attribute value.
   507    * @param {string}          value Attribute value.
   550    *
   508    *
   551    * @return {WPShortcode} Shortcode instance.
   509    * @return {WPShortcode} Shortcode instance.
   552    */
   510    */
   553   set(attr, value) {
   511   set(attr, value) {
   554     this.attrs[(0,external_lodash_namespaceObject.isNumber)(attr) ? 'numeric' : 'named'][attr] = value;
   512     this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
   555     return this;
   513     return this;
   556   },
   514   },
   557 
       
   558   /**
   515   /**
   559    * Transform the shortcode into a string.
   516    * Transform the shortcode into a string.
   560    *
   517    *
   561    * @return {string} String representation of the shortcode.
   518    * @return {string} String representation of the shortcode.
   562    */
   519    */
   563   string() {
   520   string() {
   564     let text = '[' + this.tag;
   521     let text = '[' + this.tag;
   565     (0,external_lodash_namespaceObject.forEach)(this.attrs.numeric, value => {
   522     this.attrs.numeric.forEach(value => {
   566       if (/\s/.test(value)) {
   523       if (/\s/.test(value)) {
   567         text += ' "' + value + '"';
   524         text += ' "' + value + '"';
   568       } else {
   525       } else {
   569         text += ' ' + value;
   526         text += ' ' + value;
   570       }
   527       }
   571     });
   528     });
   572     (0,external_lodash_namespaceObject.forEach)(this.attrs.named, (value, name) => {
   529     Object.entries(this.attrs.named).forEach(([name, value]) => {
   573       text += ' ' + name + '="' + value + '"';
   530       text += ' ' + name + '="' + value + '"';
   574     }); // If the tag is marked as `single` or `self-closing`, close the tag and
   531     });
       
   532 
       
   533     // If the tag is marked as `single` or `self-closing`, close the tag and
   575     // ignore any additional content.
   534     // ignore any additional content.
   576 
       
   577     if ('single' === this.type) {
   535     if ('single' === this.type) {
   578       return text + ']';
   536       return text + ']';
   579     } else if ('self-closing' === this.type) {
   537     } else if ('self-closing' === this.type) {
   580       return text + ' /]';
   538       return text + ' /]';
   581     } // Complete the opening tag.
   539     }
   582 
   540 
   583 
   541     // Complete the opening tag.
   584     text += ']';
   542     text += ']';
   585 
       
   586     if (this.content) {
   543     if (this.content) {
   587       text += this.content;
   544       text += this.content;
   588     } // Add the closing tag.
   545     }
   589 
   546 
   590 
   547     // Add the closing tag.
   591     return text + '[/' + this.tag + ']';
   548     return text + '[/' + this.tag + ']';
   592   }
   549   }
   593 
       
   594 });
   550 });
   595 /* harmony default export */ var build_module = (shortcode);
   551 /* harmony default export */ const build_module = (shortcode);
   596 
   552 
   597 }();
       
   598 (window.wp = window.wp || {}).shortcode = __webpack_exports__["default"];
   553 (window.wp = window.wp || {}).shortcode = __webpack_exports__["default"];
   599 /******/ })()
   554 /******/ })()
   600 ;
   555 ;