PluginProbe
Gutenberg / 11.2.1
Gutenberg v11.2.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / shortcode / index.js

index.js in Gutenberg 11.2.1, at build/shortcode/index.js

632 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 window["wp"] = window["wp"] || {}; window["wp"]["shortcode"] =
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 = 492);
86 /******/ })
87 /************************************************************************/
88 /******/ ({
89
90 /***/ 2:
91 /***/ (function(module, exports) {
92
93 (function() { module.exports = window["lodash"]; }());
94
95 /***/ }),
96
97 /***/ 492:
98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
99
100 "use strict";
101 __webpack_require__.r(__webpack_exports__);
102 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "next", function() { return next; });
103 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replace", function() { return replace; });
104 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "string", function() { return string; });
105 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "regexp", function() { return regexp; });
106 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "attrs", function() { return attrs; });
107 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fromMatch", function() { return fromMatch; });
108 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
109 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
110 /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(60);
111 /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(memize__WEBPACK_IMPORTED_MODULE_1__);
112 /**
113 * External dependencies
114 */
115
116
117 /**
118 * Shortcode attributes object.
119 *
120 * @typedef {Object} WPShortcodeAttrs
121 *
122 * @property {Object} named Object with named attributes.
123 * @property {Array} numeric Array with numeric attributes.
124 */
125
126 /**
127 * Shortcode object.
128 *
129 * @typedef {Object} WPShortcode
130 *
131 * @property {string} tag Shortcode tag.
132 * @property {WPShortcodeAttrs} attrs Shortcode attributes.
133 * @property {string} content Shortcode content.
134 * @property {string} type Shortcode type: `self-closing`,
135 * `closed`, or `single`.
136 */
137
138 /**
139 * @typedef {Object} WPShortcodeMatch
140 *
141 * @property {number} index Index the shortcode is found at.
142 * @property {string} content Matched content.
143 * @property {WPShortcode} shortcode Shortcode instance of the match.
144 */
145
146 /**
147 * Find the next matching shortcode.
148 *
149 * @param {string} tag Shortcode tag.
150 * @param {string} text Text to search.
151 * @param {number} index Index to start search from.
152 *
153 * @return {?WPShortcodeMatch} Matched information.
154 */
155
156 function next(tag, text, index = 0) {
157 const re = regexp(tag);
158 re.lastIndex = index;
159 const match = re.exec(text);
160
161 if (!match) {
162 return;
163 } // If we matched an escaped shortcode, try again.
164
165
166 if ('[' === match[1] && ']' === match[7]) {
167 return next(tag, text, re.lastIndex);
168 }
169
170 const result = {
171 index: match.index,
172 content: match[0],
173 shortcode: fromMatch(match)
174 }; // If we matched a leading `[`, strip it from the match and increment the
175 // index accordingly.
176
177 if (match[1]) {
178 result.content = result.content.slice(1);
179 result.index++;
180 } // If we matched a trailing `]`, strip it from the match.
181
182
183 if (match[7]) {
184 result.content = result.content.slice(0, -1);
185 }
186
187 return result;
188 }
189 /**
190 * Replace matching shortcodes in a block of text.
191 *
192 * @param {string} tag Shortcode tag.
193 * @param {string} text Text to search.
194 * @param {Function} callback Function to process the match and return
195 * replacement string.
196 *
197 * @return {string} Text with shortcodes replaced.
198 */
199
200 function replace(tag, text, callback) {
201 return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) {
202 // If both extra brackets exist, the shortcode has been properly
203 // escaped.
204 if (left === '[' && right === ']') {
205 return match;
206 } // Create the match object and pass it through the callback.
207
208
209 const result = callback(fromMatch(arguments)); // Make sure to return any of the extra brackets if they weren't used to
210 // escape the shortcode.
211
212 return result || result === '' ? left + result + right : match;
213 });
214 }
215 /**
216 * Generate a string from shortcode parameters.
217 *
218 * Creates a shortcode instance and returns a string.
219 *
220 * Accepts the same `options` as the `shortcode()` constructor, containing a
221 * `tag` string, a string or object of `attrs`, a boolean indicating whether to
222 * format the shortcode using a `single` tag, and a `content` string.
223 *
224 * @param {Object} options
225 *
226 * @return {string} String representation of the shortcode.
227 */
228
229 function string(options) {
230 return new shortcode(options).string();
231 }
232 /**
233 * Generate a RegExp to identify a shortcode.
234 *
235 * The base regex is functionally equivalent to the one found in
236 * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
237 *
238 * Capture groups:
239 *
240 * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`
241 * 2. The shortcode name
242 * 3. The shortcode argument list
243 * 4. The self closing `/`
244 * 5. The content of a shortcode when it wraps some content.
245 * 6. The closing tag.
246 * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`
247 *
248 * @param {string} tag Shortcode tag.
249 *
250 * @return {RegExp} Shortcode RegExp.
251 */
252
253 function regexp(tag) {
254 return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g');
255 }
256 /**
257 * Parse shortcode attributes.
258 *
259 * Shortcodes accept many types of attributes. These can chiefly be divided into
260 * named and numeric attributes:
261 *
262 * Named attributes are assigned on a key/value basis, while numeric attributes
263 * are treated as an array.
264 *
265 * Named attributes can be formatted as either `name="value"`, `name='value'`,
266 * or `name=value`. Numeric attributes can be formatted as `"value"` or just
267 * `value`.
268 *
269 * @param {string} text Serialised shortcode attributes.
270 *
271 * @return {WPShortcodeAttrs} Parsed shortcode attributes.
272 */
273
274 const attrs = memize__WEBPACK_IMPORTED_MODULE_1___default()(text => {
275 const named = {};
276 const numeric = []; // This regular expression is reused from `shortcode_parse_atts()` in
277 // `wp-includes/shortcodes.php`.
278 //
279 // Capture groups:
280 //
281 // 1. An attribute name, that corresponds to...
282 // 2. a value in double quotes.
283 // 3. An attribute name, that corresponds to...
284 // 4. a value in single quotes.
285 // 5. An attribute name, that corresponds to...
286 // 6. an unquoted value.
287 // 7. A numeric attribute in double quotes.
288 // 8. A numeric attribute in single quotes.
289 // 9. An unquoted numeric attribute.
290
291 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.
292
293 text = text.replace(/[\u00a0\u200b]/g, ' ');
294 let match; // Match and normalize attributes.
295
296 while (match = pattern.exec(text)) {
297 if (match[1]) {
298 named[match[1].toLowerCase()] = match[2];
299 } else if (match[3]) {
300 named[match[3].toLowerCase()] = match[4];
301 } else if (match[5]) {
302 named[match[5].toLowerCase()] = match[6];
303 } else if (match[7]) {
304 numeric.push(match[7]);
305 } else if (match[8]) {
306 numeric.push(match[8]);
307 } else if (match[9]) {
308 numeric.push(match[9]);
309 }
310 }
311
312 return {
313 named,
314 numeric
315 };
316 });
317 /**
318 * Generate a Shortcode Object from a RegExp match.
319 *
320 * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated
321 * by `regexp()`. `match` can also be set to the `arguments` from a callback
322 * passed to `regexp.replace()`.
323 *
324 * @param {Array} match Match array.
325 *
326 * @return {WPShortcode} Shortcode instance.
327 */
328
329 function fromMatch(match) {
330 let type;
331
332 if (match[4]) {
333 type = 'self-closing';
334 } else if (match[6]) {
335 type = 'closed';
336 } else {
337 type = 'single';
338 }
339
340 return new shortcode({
341 tag: match[2],
342 attrs: match[3],
343 type,
344 content: match[5]
345 });
346 }
347 /**
348 * Creates a shortcode instance.
349 *
350 * To access a raw representation of a shortcode, pass an `options` object,
351 * containing a `tag` string, a string or object of `attrs`, a string indicating
352 * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a
353 * `content` string.
354 *
355 * @param {Object} options Options as described.
356 *
357 * @return {WPShortcode} Shortcode instance.
358 */
359
360 const shortcode = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(function (options) {
361 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(this, Object(lodash__WEBPACK_IMPORTED_MODULE_0__["pick"])(options || {}, 'tag', 'attrs', 'type', 'content'));
362 const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
363
364 this.attrs = {
365 named: {},
366 numeric: []
367 };
368
369 if (!attributes) {
370 return;
371 } // Parse a string of attributes.
372
373
374 if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isString"])(attributes)) {
375 this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
376 } else if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isEqual"])(Object.keys(attributes), ['named', 'numeric'])) {
377 this.attrs = attributes; // Handle a flat object of attributes.
378 } else {
379 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(attributes, (value, key) => {
380 this.set(key, value);
381 });
382 }
383 }, {
384 next,
385 replace,
386 string,
387 regexp,
388 attrs,
389 fromMatch
390 });
391 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(shortcode.prototype, {
392 /**
393 * Get a shortcode attribute.
394 *
395 * Automatically detects whether `attr` is named or numeric and routes it
396 * accordingly.
397 *
398 * @param {(number|string)} attr Attribute key.
399 *
400 * @return {string} Attribute value.
401 */
402 get(attr) {
403 return this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr];
404 },
405
406 /**
407 * Set a shortcode attribute.
408 *
409 * Automatically detects whether `attr` is named or numeric and routes it
410 * accordingly.
411 *
412 * @param {(number|string)} attr Attribute key.
413 * @param {string} value Attribute value.
414 *
415 * @return {WPShortcode} Shortcode instance.
416 */
417 set(attr, value) {
418 this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr] = value;
419 return this;
420 },
421
422 /**
423 * Transform the shortcode into a string.
424 *
425 * @return {string} String representation of the shortcode.
426 */
427 string() {
428 let text = '[' + this.tag;
429 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.numeric, value => {
430 if (/\s/.test(value)) {
431 text += ' "' + value + '"';
432 } else {
433 text += ' ' + value;
434 }
435 });
436 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.named, (value, name) => {
437 text += ' ' + name + '="' + value + '"';
438 }); // If the tag is marked as `single` or `self-closing`, close the tag and
439 // ignore any additional content.
440
441 if ('single' === this.type) {
442 return text + ']';
443 } else if ('self-closing' === this.type) {
444 return text + ' /]';
445 } // Complete the opening tag.
446
447
448 text += ']';
449
450 if (this.content) {
451 text += this.content;
452 } // Add the closing tag.
453
454
455 return text + '[/' + this.tag + ']';
456 }
457
458 });
459 /* harmony default export */ __webpack_exports__["default"] = (shortcode);
460 //# sourceMappingURL=index.js.map
461
462 /***/ }),
463
464 /***/ 60:
465 /***/ (function(module, exports, __webpack_require__) {
466
467 /**
468 * Memize options object.
469 *
470 * @typedef MemizeOptions
471 *
472 * @property {number} [maxSize] Maximum size of the cache.
473 */
474
475 /**
476 * Internal cache entry.
477 *
478 * @typedef MemizeCacheNode
479 *
480 * @property {?MemizeCacheNode|undefined} [prev] Previous node.
481 * @property {?MemizeCacheNode|undefined} [next] Next node.
482 * @property {Array<*>} args Function arguments for cache
483 * entry.
484 * @property {*} val Function result.
485 */
486
487 /**
488 * Properties of the enhanced function for controlling cache.
489 *
490 * @typedef MemizeMemoizedFunction
491 *
492 * @property {()=>void} clear Clear the cache.
493 */
494
495 /**
496 * Accepts a function to be memoized, and returns a new memoized function, with
497 * optional options.
498 *
499 * @template {Function} F
500 *
501 * @param {F} fn Function to memoize.
502 * @param {MemizeOptions} [options] Options object.
503 *
504 * @return {F & MemizeMemoizedFunction} Memoized function.
505 */
506 function memize( fn, options ) {
507 var size = 0;
508
509 /** @type {?MemizeCacheNode|undefined} */
510 var head;
511
512 /** @type {?MemizeCacheNode|undefined} */
513 var tail;
514
515 options = options || {};
516
517 function memoized( /* ...args */ ) {
518 var node = head,
519 len = arguments.length,
520 args, i;
521
522 searchCache: while ( node ) {
523 // Perform a shallow equality test to confirm that whether the node
524 // under test is a candidate for the arguments passed. Two arrays
525 // are shallowly equal if their length matches and each entry is
526 // strictly equal between the two sets. Avoid abstracting to a
527 // function which could incur an arguments leaking deoptimization.
528
529 // Check whether node arguments match arguments length
530 if ( node.args.length !== arguments.length ) {
531 node = node.next;
532 continue;
533 }
534
535 // Check whether node arguments match arguments values
536 for ( i = 0; i < len; i++ ) {
537 if ( node.args[ i ] !== arguments[ i ] ) {
538 node = node.next;
539 continue searchCache;
540 }
541 }
542
543 // At this point we can assume we've found a match
544
545 // Surface matched node to head if not already
546 if ( node !== head ) {
547 // As tail, shift to previous. Must only shift if not also
548 // head, since if both head and tail, there is no previous.
549 if ( node === tail ) {
550 tail = node.prev;
551 }
552
553 // Adjust siblings to point to each other. If node was tail,
554 // this also handles new tail's empty `next` assignment.
555 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
556 if ( node.next ) {
557 node.next.prev = node.prev;
558 }
559
560 node.next = head;
561 node.prev = null;
562 /** @type {MemizeCacheNode} */ ( head ).prev = node;
563 head = node;
564 }
565
566 // Return immediately
567 return node.val;
568 }
569
570 // No cached value found. Continue to insertion phase:
571
572 // Create a copy of arguments (avoid leaking deoptimization)
573 args = new Array( len );
574 for ( i = 0; i < len; i++ ) {
575 args[ i ] = arguments[ i ];
576 }
577
578 node = {
579 args: args,
580
581 // Generate the result from original function
582 val: fn.apply( null, args ),
583 };
584
585 // Don't need to check whether node is already head, since it would
586 // have been returned above already if it was
587
588 // Shift existing head down list
589 if ( head ) {
590 head.prev = node;
591 node.next = head;
592 } else {
593 // If no head, follows that there's no tail (at initial or reset)
594 tail = node;
595 }
596
597 // Trim tail if we're reached max size and are pending cache insertion
598 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
599 tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
600 /** @type {MemizeCacheNode} */ ( tail ).next = null;
601 } else {
602 size++;
603 }
604
605 head = node;
606
607 return node.val;
608 }
609
610 memoized.clear = function() {
611 head = null;
612 tail = null;
613 size = 0;
614 };
615
616 if ( false ) {}
617
618 // Ignore reason: There's not a clear solution to create an intersection of
619 // the function with additional properties, where the goal is to retain the
620 // function signature of the incoming argument and add control properties
621 // on the return value.
622
623 // @ts-ignore
624 return memoized;
625 }
626
627 module.exports = memize;
628
629
630 /***/ })
631
632 /******/ })["default"];