@wordpress/shortcode 3.11.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.14.0 (2022-07-27)
6
+
7
+ ## 3.13.0 (2022-07-13)
8
+
9
+ ## 3.12.0 (2022-06-29)
10
+
5
11
  ## 3.11.0 (2022-06-15)
6
12
 
7
13
  ## 3.10.0 (2022-06-01)
package/build/index.js CHANGED
@@ -12,8 +12,6 @@ exports.regexp = regexp;
12
12
  exports.replace = replace;
13
13
  exports.string = string;
14
14
 
15
- var _lodash = require("lodash");
16
-
17
15
  var _memize = _interopRequireDefault(require("memize"));
18
16
 
19
17
  /**
@@ -270,9 +268,18 @@ function fromMatch(match) {
270
268
  */
271
269
 
272
270
 
273
- const shortcode = (0, _lodash.extend)(function (options) {
274
- (0, _lodash.extend)(this, (0, _lodash.pick)(options || {}, 'tag', 'attrs', 'type', 'content'));
275
- const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
271
+ const shortcode = Object.assign(function (options) {
272
+ const {
273
+ tag,
274
+ attrs: attributes,
275
+ type,
276
+ content
277
+ } = options || {};
278
+ Object.assign(this, {
279
+ tag,
280
+ type,
281
+ content
282
+ }); // Ensure we have a correctly formatted `attrs` object.
276
283
 
277
284
  this.attrs = {
278
285
  named: {},
@@ -281,15 +288,17 @@ const shortcode = (0, _lodash.extend)(function (options) {
281
288
 
282
289
  if (!attributes) {
283
290
  return;
284
- } // Parse a string of attributes.
291
+ }
285
292
 
293
+ const attributeTypes = ['named', 'numeric']; // Parse a string of attributes.
286
294
 
287
- if ((0, _lodash.isString)(attributes)) {
295
+ if (typeof attributes === 'string') {
288
296
  this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
289
- } else if ((0, _lodash.isEqual)(Object.keys(attributes), ['named', 'numeric'])) {
297
+ } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
290
298
  this.attrs = attributes; // Handle a flat object of attributes.
291
299
  } else {
292
- (0, _lodash.forEach)(attributes, (value, key) => {
300
+ Object.entries(attributes).forEach(_ref => {
301
+ let [key, value] = _ref;
293
302
  this.set(key, value);
294
303
  });
295
304
  }
@@ -301,7 +310,7 @@ const shortcode = (0, _lodash.extend)(function (options) {
301
310
  attrs,
302
311
  fromMatch
303
312
  });
304
- (0, _lodash.extend)(shortcode.prototype, {
313
+ Object.assign(shortcode.prototype, {
305
314
  /**
306
315
  * Get a shortcode attribute.
307
316
  *
@@ -313,7 +322,7 @@ const shortcode = (0, _lodash.extend)(function (options) {
313
322
  * @return {string} Attribute value.
314
323
  */
315
324
  get(attr) {
316
- return this.attrs[(0, _lodash.isNumber)(attr) ? 'numeric' : 'named'][attr];
325
+ return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
317
326
  },
318
327
 
319
328
  /**
@@ -328,7 +337,7 @@ const shortcode = (0, _lodash.extend)(function (options) {
328
337
  * @return {WPShortcode} Shortcode instance.
329
338
  */
330
339
  set(attr, value) {
331
- this.attrs[(0, _lodash.isNumber)(attr) ? 'numeric' : 'named'][attr] = value;
340
+ this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
332
341
  return this;
333
342
  },
334
343
 
@@ -339,14 +348,15 @@ const shortcode = (0, _lodash.extend)(function (options) {
339
348
  */
340
349
  string() {
341
350
  let text = '[' + this.tag;
342
- (0, _lodash.forEach)(this.attrs.numeric, value => {
351
+ this.attrs.numeric.forEach(value => {
343
352
  if (/\s/.test(value)) {
344
353
  text += ' "' + value + '"';
345
354
  } else {
346
355
  text += ' ' + value;
347
356
  }
348
357
  });
349
- (0, _lodash.forEach)(this.attrs.named, (value, name) => {
358
+ Object.entries(this.attrs.named).forEach(_ref2 => {
359
+ let [name, value] = _ref2;
350
360
  text += ' ' + name + '="' + value + '"';
351
361
  }); // If the tag is marked as `single` or `self-closing`, close the tag and
352
362
  // ignore any additional content.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":";;;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAAsC;AAAA,MAAZC,KAAY,uEAAJ,CAAI;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;AACdN,IAAAA,KAAK,EAAEI,KAAK,CAACJ,KADC;AAEdO,IAAAA,OAAO,EAAEH,KAAK,CAAE,CAAF,CAFA;AAGdI,IAAAA,SAAS,EAAEC,SAAS,CAAEL,KAAF;AAHN,GAAf,CAhB4C,CAsB5C;AACA;;AACA,MAAKA,KAAK,CAAE,CAAF,CAAV,EAAkB;AACjBE,IAAAA,MAAM,CAACC,OAAP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AG;AACR,QAAIrB,IAAI,GAAG,MAAM,KAAKD,GAAtB;AAEA,yBAAS,KAAKiB,KAAL,CAAWS,OAApB,EAA+BQ,KAAF,IAAa;AACzC,UAAK,KAAKM,IAAL,CAAWN,KAAX,CAAL,EAA0B;AACzBjC,QAAAA,IAAI,IAAI,OAAOiC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNjC,QAAAA,IAAI,IAAI,MAAMiC,KAAd;AACA;AACD,KAND;AAQA,yBAAS,KAAKjB,KAAL,CAAWQ,KAApB,EAA2B,CAAES,KAAF,EAASO,IAAT,KAAmB;AAC7CxC,MAAAA,IAAI,IAAI,MAAMwC,IAAN,GAAa,IAAb,GAAoBP,KAApB,GAA4B,GAApC;AACA,KAFD,EAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKJ,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAA7B;eAuEeU,S","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
1
+ {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name"],"mappings":";;;;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAAsC;AAAA,MAAZC,KAAY,uEAAJ,CAAI;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;AACdN,IAAAA,KAAK,EAAEI,KAAK,CAACJ,KADC;AAEdO,IAAAA,OAAO,EAAEH,KAAK,CAAE,CAAF,CAFA;AAGdI,IAAAA,SAAS,EAAEC,SAAS,CAAEL,KAAF;AAHN,GAAf,CAhB4C,CAsB5C;AACA;;AACA,MAAKA,KAAK,CAAE,CAAF,CAAV,EAAkB;AACjBE,IAAAA,MAAM,CAACC,OAAP,GAAiBD,MAAM,CAACC,OAAP,CAAeG,KAAf,CAAsB,CAAtB,CAAjB;AACAJ,IAAAA,MAAM,CAACN,KAAP;AACA,GA3B2C,CA6B5C;;;AACA,MAAKI,KAAK,CAAE,CAAF,CAAV,EAAkB;AACjBE,IAAAA,MAAM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AAClB,SAAKxB,KAAL,CAAY,OAAO4B,IAAP,KAAgB,QAAhB,GAA2B,SAA3B,GAAuC,OAAnD,EAA8DA,IAA9D,IACCJ,KADD;AAEA,WAAO,IAAP;AACA,GAhCkC;;AAkCnC;AACD;AACA;AACA;AACA;AACCnB,EAAAA,MAAM,GAAG;AACR,QAAIrB,IAAI,GAAG,MAAM,KAAKD,GAAtB;AAEA,SAAKiB,KAAL,CAAWS,OAAX,CAAmBc,OAAnB,CAA8BC,KAAF,IAAa;AACxC,UAAK,KAAKK,IAAL,CAAWL,KAAX,CAAL,EAA0B;AACzBxC,QAAAA,IAAI,IAAI,OAAOwC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNxC,QAAAA,IAAI,IAAI,MAAMwC,KAAd;AACA;AACD,KAND;AAQAV,IAAAA,MAAM,CAACQ,OAAP,CAAgB,KAAKtB,KAAL,CAAWQ,KAA3B,EAAmCe,OAAnC,CAA4C,SAAuB;AAAA,UAArB,CAAEO,IAAF,EAAQN,KAAR,CAAqB;AAClExC,MAAAA,IAAI,IAAI,MAAM8C,IAAN,GAAa,IAAb,GAAoBN,KAApB,GAA4B,GAApC;AACA,KAFD,EAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKX,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AAvEkC,CAApC;eA0EeU,S","sourcesContent":["/**\n * External dependencies\n */\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nObject.assign( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';
5
4
  import memize from 'memize';
6
5
  /**
7
6
  * Shortcode attributes object.
@@ -247,9 +246,18 @@ export function fromMatch(match) {
247
246
  * @return {WPShortcode} Shortcode instance.
248
247
  */
249
248
 
250
- const shortcode = extend(function (options) {
251
- extend(this, pick(options || {}, 'tag', 'attrs', 'type', 'content'));
252
- const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object.
249
+ const shortcode = Object.assign(function (options) {
250
+ const {
251
+ tag,
252
+ attrs: attributes,
253
+ type,
254
+ content
255
+ } = options || {};
256
+ Object.assign(this, {
257
+ tag,
258
+ type,
259
+ content
260
+ }); // Ensure we have a correctly formatted `attrs` object.
253
261
 
254
262
  this.attrs = {
255
263
  named: {},
@@ -258,15 +266,17 @@ const shortcode = extend(function (options) {
258
266
 
259
267
  if (!attributes) {
260
268
  return;
261
- } // Parse a string of attributes.
269
+ }
262
270
 
271
+ const attributeTypes = ['named', 'numeric']; // Parse a string of attributes.
263
272
 
264
- if (isString(attributes)) {
273
+ if (typeof attributes === 'string') {
265
274
  this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object.
266
- } else if (isEqual(Object.keys(attributes), ['named', 'numeric'])) {
275
+ } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
267
276
  this.attrs = attributes; // Handle a flat object of attributes.
268
277
  } else {
269
- forEach(attributes, (value, key) => {
278
+ Object.entries(attributes).forEach(_ref => {
279
+ let [key, value] = _ref;
270
280
  this.set(key, value);
271
281
  });
272
282
  }
@@ -278,7 +288,7 @@ const shortcode = extend(function (options) {
278
288
  attrs,
279
289
  fromMatch
280
290
  });
281
- extend(shortcode.prototype, {
291
+ Object.assign(shortcode.prototype, {
282
292
  /**
283
293
  * Get a shortcode attribute.
284
294
  *
@@ -290,7 +300,7 @@ extend(shortcode.prototype, {
290
300
  * @return {string} Attribute value.
291
301
  */
292
302
  get(attr) {
293
- return this.attrs[isNumber(attr) ? 'numeric' : 'named'][attr];
303
+ return this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr];
294
304
  },
295
305
 
296
306
  /**
@@ -305,7 +315,7 @@ extend(shortcode.prototype, {
305
315
  * @return {WPShortcode} Shortcode instance.
306
316
  */
307
317
  set(attr, value) {
308
- this.attrs[isNumber(attr) ? 'numeric' : 'named'][attr] = value;
318
+ this.attrs[typeof attr === 'number' ? 'numeric' : 'named'][attr] = value;
309
319
  return this;
310
320
  },
311
321
 
@@ -316,14 +326,15 @@ extend(shortcode.prototype, {
316
326
  */
317
327
  string() {
318
328
  let text = '[' + this.tag;
319
- forEach(this.attrs.numeric, value => {
329
+ this.attrs.numeric.forEach(value => {
320
330
  if (/\s/.test(value)) {
321
331
  text += ' "' + value + '"';
322
332
  } else {
323
333
  text += ' ' + value;
324
334
  }
325
335
  });
326
- forEach(this.attrs.named, (value, name) => {
336
+ Object.entries(this.attrs.named).forEach(_ref2 => {
337
+ let [name, value] = _ref2;
327
338
  text += ' ' + name + '="' + value + '"';
328
339
  }); // If the tag is marked as `single` or `self-closing`, close the tag and
329
340
  // ignore any additional content.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["extend","pick","isString","isEqual","forEach","isNumber","memize","next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","attributes","Object","keys","value","key","set","prototype","get","attr","test","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,EAAiCC,O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AA,OAAO,CAAE,KAAKqB,KAAL,CAAWS,OAAb,EAAwBQ,KAAF,IAAa;AACzC,UAAK,KAAKM,IAAL,CAAWN,KAAX,CAAL,EAA0B;AACzBjC,QAAAA,IAAI,IAAI,OAAOiC,KAAP,GAAe,GAAvB;AACA,OAFD,MAEO;AACNjC,QAAAA,IAAI,IAAI,MAAMiC,KAAd;AACA;AACD,KANM,CAAP;AAQAtC,IAAAA,OAAO,CAAE,KAAKqB,KAAL,CAAWQ,KAAb,EAAoB,CAAES,KAAF,EAASO,IAAT,KAAmB;AAC7CxC,MAAAA,IAAI,IAAI,MAAMwC,IAAN,GAAa,IAAb,GAAoBP,KAApB,GAA4B,GAApC;AACA,KAFM,CAAP,CAXQ,CAeR;AACA;;AACA,QAAK,aAAa,KAAKJ,IAAvB,EAA8B;AAC7B,aAAO7B,IAAI,GAAG,GAAd;AACA,KAFD,MAEO,IAAK,mBAAmB,KAAK6B,IAA7B,EAAoC;AAC1C,aAAO7B,IAAI,GAAG,KAAd;AACA,KArBO,CAuBR;;;AACAA,IAAAA,IAAI,IAAI,GAAR;;AAEA,QAAK,KAAKQ,OAAV,EAAoB;AACnBR,MAAAA,IAAI,IAAI,KAAKQ,OAAb;AACA,KA5BO,CA8BR;;;AACA,WAAOR,IAAI,GAAG,IAAP,GAAc,KAAKD,GAAnB,GAAyB,GAAhC;AACA;;AApE2B,CAAvB,CAAN;AAuEA,eAAeU,SAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = extend(\n\tfunction ( options ) {\n\t\textend(\n\t\t\tthis,\n\t\t\tpick( options || {}, 'tag', 'attrs', 'type', 'content' )\n\t\t);\n\n\t\tconst attributes = this.attrs;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( isString( attributes ) ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tisEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tforEach( attributes, ( value, key ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nextend( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tforEach( this.attrs.numeric, ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tforEach( this.attrs.named, ( value, name ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
1
+ {"version":3,"sources":["@wordpress/shortcode/src/index.js"],"names":["memize","next","tag","text","index","re","regexp","lastIndex","match","exec","result","content","shortcode","fromMatch","slice","replace","callback","left","$3","attrs","slash","closing","right","arguments","string","options","RegExp","named","numeric","pattern","toLowerCase","push","type","Object","assign","attributes","attributeTypes","length","every","t","key","entries","forEach","value","set","prototype","get","attr","test","name"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAeC,GAAf,EAAoBC,IAApB,EAAsC;AAAA,MAAZC,KAAY,uEAAJ,CAAI;AAC5C,QAAMC,EAAE,GAAGC,MAAM,CAAEJ,GAAF,CAAjB;AAEAG,EAAAA,EAAE,CAACE,SAAH,GAAeH,KAAf;AAEA,QAAMI,KAAK,GAAGH,EAAE,CAACI,IAAH,CAASN,IAAT,CAAd;;AAEA,MAAK,CAAEK,KAAP,EAAe;AACd;AACA,GAT2C,CAW5C;;;AACA,MAAK,QAAQA,KAAK,CAAE,CAAF,CAAb,IAAsB,QAAQA,KAAK,CAAE,CAAF,CAAxC,EAAgD;AAC/C,WAAOP,IAAI,CAAEC,GAAF,EAAOC,IAAP,EAAaE,EAAE,CAACE,SAAhB,CAAX;AACA;;AAED,QAAMG,MAAM,GAAG;AACdN,IAAAA,KAAK,EAAEI,KAAK,CAACJ,KADC;AAEdO,IAAAA,OAAO,EAAEH,KAAK,CAAE,CAAF,CAFA;AAGdI,IAAAA,SAAS,EAAEC,SAAS,CAAEL,KAAF;AAHN,GAAf,CAhB4C,CAsB5C;AACA;;AACA,MAAKA,KAAK,CAAE,CAAF,CAAV,EAAkB;AACjBE,IAAAA,MAAM,CAACC,OAAP,GAAiBD,MAAM,CAACC,OAAP,CAAeG,KAAf,CAAsB,CAAtB,CAAjB;AACAJ,IAAAA,MAAM,CAACN,KAAP;AACA,GA3B2C,CA6B5C;;;AACA,MAAKI,KAAK,CAAE,CAAF,CAAV,EAAkB;AACjB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*/\nimport memize from 'memize';\n\n/**\n * Shortcode attributes object.\n *\n * @typedef {Object} WPShortcodeAttrs\n *\n * @property {Object} named Object with named attributes.\n * @property {Array} numeric Array with numeric attributes.\n */\n\n/**\n * Shortcode object.\n *\n * @typedef {Object} WPShortcode\n *\n * @property {string} tag Shortcode tag.\n * @property {WPShortcodeAttrs} attrs Shortcode attributes.\n * @property {string} content Shortcode content.\n * @property {string} type Shortcode type: `self-closing`,\n * `closed`, or `single`.\n */\n\n/**\n * @typedef {Object} WPShortcodeMatch\n *\n * @property {number} index Index the shortcode is found at.\n * @property {string} content Matched content.\n * @property {WPShortcode} shortcode Shortcode instance of the match.\n */\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {?WPShortcodeMatch} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {Function} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {WPShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {Array} match Match array.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @param {Object} options Options as described.\n *\n * @return {WPShortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nObject.assign( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {WPShortcode} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/shortcode",
3
- "version": "3.11.0",
3
+ "version": "3.14.0",
4
4
  "description": "Shortcode module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,11 +26,10 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "lodash": "^4.17.21",
30
29
  "memize": "^1.1.0"
31
30
  },
32
31
  "publishConfig": {
33
32
  "access": "public"
34
33
  },
35
- "gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
34
+ "gitHead": "0315dbc240cb2aa146d7c1bafd251f004b88300e"
36
35
  }
package/src/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { extend, pick, isString, isEqual, forEach, isNumber } from 'lodash';
5
4
  import memize from 'memize';
6
5
 
7
6
  /**
@@ -260,14 +259,10 @@ export function fromMatch( match ) {
260
259
  *
261
260
  * @return {WPShortcode} Shortcode instance.
262
261
  */
263
- const shortcode = extend(
262
+ const shortcode = Object.assign(
264
263
  function ( options ) {
265
- extend(
266
- this,
267
- pick( options || {}, 'tag', 'attrs', 'type', 'content' )
268
- );
269
-
270
- const attributes = this.attrs;
264
+ const { tag, attrs: attributes, type, content } = options || {};
265
+ Object.assign( this, { tag, type, content } );
271
266
 
272
267
  // Ensure we have a correctly formatted `attrs` object.
273
268
  this.attrs = {
@@ -279,17 +274,20 @@ const shortcode = extend(
279
274
  return;
280
275
  }
281
276
 
277
+ const attributeTypes = [ 'named', 'numeric' ];
278
+
282
279
  // Parse a string of attributes.
283
- if ( isString( attributes ) ) {
280
+ if ( typeof attributes === 'string' ) {
284
281
  this.attrs = attrs( attributes );
285
282
  // Identify a correctly formatted `attrs` object.
286
283
  } else if (
287
- isEqual( Object.keys( attributes ), [ 'named', 'numeric' ] )
284
+ attributes.length === attributeTypes.length &&
285
+ attributeTypes.every( ( t, key ) => t === attributes[ key ] )
288
286
  ) {
289
287
  this.attrs = attributes;
290
288
  // Handle a flat object of attributes.
291
289
  } else {
292
- forEach( attributes, ( value, key ) => {
290
+ Object.entries( attributes ).forEach( ( [ key, value ] ) => {
293
291
  this.set( key, value );
294
292
  } );
295
293
  }
@@ -304,7 +302,7 @@ const shortcode = extend(
304
302
  }
305
303
  );
306
304
 
307
- extend( shortcode.prototype, {
305
+ Object.assign( shortcode.prototype, {
308
306
  /**
309
307
  * Get a shortcode attribute.
310
308
  *
@@ -316,7 +314,9 @@ extend( shortcode.prototype, {
316
314
  * @return {string} Attribute value.
317
315
  */
318
316
  get( attr ) {
319
- return this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ];
317
+ return this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][
318
+ attr
319
+ ];
320
320
  },
321
321
 
322
322
  /**
@@ -331,7 +331,8 @@ extend( shortcode.prototype, {
331
331
  * @return {WPShortcode} Shortcode instance.
332
332
  */
333
333
  set( attr, value ) {
334
- this.attrs[ isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;
334
+ this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =
335
+ value;
335
336
  return this;
336
337
  },
337
338
 
@@ -343,7 +344,7 @@ extend( shortcode.prototype, {
343
344
  string() {
344
345
  let text = '[' + this.tag;
345
346
 
346
- forEach( this.attrs.numeric, ( value ) => {
347
+ this.attrs.numeric.forEach( ( value ) => {
347
348
  if ( /\s/.test( value ) ) {
348
349
  text += ' "' + value + '"';
349
350
  } else {
@@ -351,7 +352,7 @@ extend( shortcode.prototype, {
351
352
  }
352
353
  } );
353
354
 
354
- forEach( this.attrs.named, ( value, name ) => {
355
+ Object.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {
355
356
  text += ' ' + name + '="' + value + '"';
356
357
  } );
357
358