説明なし

element.js 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(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. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. "Children": function() { return /* reexport */ external_React_namespaceObject.Children; },
  42. "Component": function() { return /* reexport */ external_React_namespaceObject.Component; },
  43. "Fragment": function() { return /* reexport */ external_React_namespaceObject.Fragment; },
  44. "Platform": function() { return /* reexport */ platform; },
  45. "RawHTML": function() { return /* reexport */ RawHTML; },
  46. "StrictMode": function() { return /* reexport */ external_React_namespaceObject.StrictMode; },
  47. "Suspense": function() { return /* reexport */ external_React_namespaceObject.Suspense; },
  48. "cloneElement": function() { return /* reexport */ external_React_namespaceObject.cloneElement; },
  49. "concatChildren": function() { return /* reexport */ concatChildren; },
  50. "createContext": function() { return /* reexport */ external_React_namespaceObject.createContext; },
  51. "createElement": function() { return /* reexport */ external_React_namespaceObject.createElement; },
  52. "createInterpolateElement": function() { return /* reexport */ create_interpolate_element; },
  53. "createPortal": function() { return /* reexport */ external_ReactDOM_namespaceObject.createPortal; },
  54. "createRef": function() { return /* reexport */ external_React_namespaceObject.createRef; },
  55. "findDOMNode": function() { return /* reexport */ external_ReactDOM_namespaceObject.findDOMNode; },
  56. "forwardRef": function() { return /* reexport */ external_React_namespaceObject.forwardRef; },
  57. "isEmptyElement": function() { return /* reexport */ isEmptyElement; },
  58. "isValidElement": function() { return /* reexport */ external_React_namespaceObject.isValidElement; },
  59. "lazy": function() { return /* reexport */ external_React_namespaceObject.lazy; },
  60. "memo": function() { return /* reexport */ external_React_namespaceObject.memo; },
  61. "render": function() { return /* reexport */ external_ReactDOM_namespaceObject.render; },
  62. "renderToString": function() { return /* reexport */ serialize; },
  63. "switchChildrenNodeName": function() { return /* reexport */ switchChildrenNodeName; },
  64. "unmountComponentAtNode": function() { return /* reexport */ external_ReactDOM_namespaceObject.unmountComponentAtNode; },
  65. "useCallback": function() { return /* reexport */ external_React_namespaceObject.useCallback; },
  66. "useContext": function() { return /* reexport */ external_React_namespaceObject.useContext; },
  67. "useDebugValue": function() { return /* reexport */ external_React_namespaceObject.useDebugValue; },
  68. "useEffect": function() { return /* reexport */ external_React_namespaceObject.useEffect; },
  69. "useImperativeHandle": function() { return /* reexport */ external_React_namespaceObject.useImperativeHandle; },
  70. "useLayoutEffect": function() { return /* reexport */ external_React_namespaceObject.useLayoutEffect; },
  71. "useMemo": function() { return /* reexport */ external_React_namespaceObject.useMemo; },
  72. "useReducer": function() { return /* reexport */ external_React_namespaceObject.useReducer; },
  73. "useRef": function() { return /* reexport */ external_React_namespaceObject.useRef; },
  74. "useState": function() { return /* reexport */ external_React_namespaceObject.useState; }
  75. });
  76. ;// CONCATENATED MODULE: external "React"
  77. var external_React_namespaceObject = window["React"];
  78. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/create-interpolate-element.js
  79. /**
  80. * Internal dependencies
  81. */
  82. /** @typedef {import('./react').WPElement} WPElement */
  83. let indoc, offset, output, stack;
  84. /**
  85. * Matches tags in the localized string
  86. *
  87. * This is used for extracting the tag pattern groups for parsing the localized
  88. * string and along with the map converting it to a react element.
  89. *
  90. * There are four references extracted using this tokenizer:
  91. *
  92. * match: Full match of the tag (i.e. <strong>, </strong>, <br/>)
  93. * isClosing: The closing slash, it it exists.
  94. * name: The name portion of the tag (strong, br) (if )
  95. * isSelfClosed: The slash on a self closing tag, if it exists.
  96. *
  97. * @type {RegExp}
  98. */
  99. const tokenizer = /<(\/)?(\w+)\s*(\/)?>/g;
  100. /**
  101. * The stack frame tracking parse progress.
  102. *
  103. * @typedef Frame
  104. *
  105. * @property {WPElement} element A parent element which may still have
  106. * @property {number} tokenStart Offset at which parent element first
  107. * appears.
  108. * @property {number} tokenLength Length of string marking start of parent
  109. * element.
  110. * @property {number} [prevOffset] Running offset at which parsing should
  111. * continue.
  112. * @property {number} [leadingTextStart] Offset at which last closing element
  113. * finished, used for finding text between
  114. * elements.
  115. * @property {WPElement[]} children Children.
  116. */
  117. /**
  118. * Tracks recursive-descent parse state.
  119. *
  120. * This is a Stack frame holding parent elements until all children have been
  121. * parsed.
  122. *
  123. * @private
  124. * @param {WPElement} element A parent element which may still have
  125. * nested children not yet parsed.
  126. * @param {number} tokenStart Offset at which parent element first
  127. * appears.
  128. * @param {number} tokenLength Length of string marking start of parent
  129. * element.
  130. * @param {number} [prevOffset] Running offset at which parsing should
  131. * continue.
  132. * @param {number} [leadingTextStart] Offset at which last closing element
  133. * finished, used for finding text between
  134. * elements.
  135. *
  136. * @return {Frame} The stack frame tracking parse progress.
  137. */
  138. function createFrame(element, tokenStart, tokenLength, prevOffset, leadingTextStart) {
  139. return {
  140. element,
  141. tokenStart,
  142. tokenLength,
  143. prevOffset,
  144. leadingTextStart,
  145. children: []
  146. };
  147. }
  148. /**
  149. * This function creates an interpolated element from a passed in string with
  150. * specific tags matching how the string should be converted to an element via
  151. * the conversion map value.
  152. *
  153. * @example
  154. * For example, for the given string:
  155. *
  156. * "This is a <span>string</span> with <a>a link</a> and a self-closing
  157. * <CustomComponentB/> tag"
  158. *
  159. * You would have something like this as the conversionMap value:
  160. *
  161. * ```js
  162. * {
  163. * span: <span />,
  164. * a: <a href={ 'https://github.com' } />,
  165. * CustomComponentB: <CustomComponent />,
  166. * }
  167. * ```
  168. *
  169. * @param {string} interpolatedString The interpolation string to be parsed.
  170. * @param {Object} conversionMap The map used to convert the string to
  171. * a react element.
  172. * @throws {TypeError}
  173. * @return {WPElement} A wp element.
  174. */
  175. const createInterpolateElement = (interpolatedString, conversionMap) => {
  176. indoc = interpolatedString;
  177. offset = 0;
  178. output = [];
  179. stack = [];
  180. tokenizer.lastIndex = 0;
  181. if (!isValidConversionMap(conversionMap)) {
  182. throw new TypeError('The conversionMap provided is not valid. It must be an object with values that are WPElements');
  183. }
  184. do {// twiddle our thumbs
  185. } while (proceed(conversionMap));
  186. return (0,external_React_namespaceObject.createElement)(external_React_namespaceObject.Fragment, null, ...output);
  187. };
  188. /**
  189. * Validate conversion map.
  190. *
  191. * A map is considered valid if it's an object and every value in the object
  192. * is a WPElement
  193. *
  194. * @private
  195. *
  196. * @param {Object} conversionMap The map being validated.
  197. *
  198. * @return {boolean} True means the map is valid.
  199. */
  200. const isValidConversionMap = conversionMap => {
  201. const isObject = typeof conversionMap === 'object';
  202. const values = isObject && Object.values(conversionMap);
  203. return isObject && values.length && values.every(element => (0,external_React_namespaceObject.isValidElement)(element));
  204. };
  205. /**
  206. * This is the iterator over the matches in the string.
  207. *
  208. * @private
  209. *
  210. * @param {Object} conversionMap The conversion map for the string.
  211. *
  212. * @return {boolean} true for continuing to iterate, false for finished.
  213. */
  214. function proceed(conversionMap) {
  215. const next = nextToken();
  216. const [tokenType, name, startOffset, tokenLength] = next;
  217. const stackDepth = stack.length;
  218. const leadingTextStart = startOffset > offset ? offset : null;
  219. if (!conversionMap[name]) {
  220. addText();
  221. return false;
  222. }
  223. switch (tokenType) {
  224. case 'no-more-tokens':
  225. if (stackDepth !== 0) {
  226. const {
  227. leadingTextStart: stackLeadingText,
  228. tokenStart
  229. } = stack.pop();
  230. output.push(indoc.substr(stackLeadingText, tokenStart));
  231. }
  232. addText();
  233. return false;
  234. case 'self-closed':
  235. if (0 === stackDepth) {
  236. if (null !== leadingTextStart) {
  237. output.push(indoc.substr(leadingTextStart, startOffset - leadingTextStart));
  238. }
  239. output.push(conversionMap[name]);
  240. offset = startOffset + tokenLength;
  241. return true;
  242. } // Otherwise we found an inner element.
  243. addChild(createFrame(conversionMap[name], startOffset, tokenLength));
  244. offset = startOffset + tokenLength;
  245. return true;
  246. case 'opener':
  247. stack.push(createFrame(conversionMap[name], startOffset, tokenLength, startOffset + tokenLength, leadingTextStart));
  248. offset = startOffset + tokenLength;
  249. return true;
  250. case 'closer':
  251. // If we're not nesting then this is easy - close the block.
  252. if (1 === stackDepth) {
  253. closeOuterElement(startOffset);
  254. offset = startOffset + tokenLength;
  255. return true;
  256. } // Otherwise we're nested and we have to close out the current
  257. // block and add it as a innerBlock to the parent.
  258. const stackTop = stack.pop();
  259. const text = indoc.substr(stackTop.prevOffset, startOffset - stackTop.prevOffset);
  260. stackTop.children.push(text);
  261. stackTop.prevOffset = startOffset + tokenLength;
  262. const frame = createFrame(stackTop.element, stackTop.tokenStart, stackTop.tokenLength, startOffset + tokenLength);
  263. frame.children = stackTop.children;
  264. addChild(frame);
  265. offset = startOffset + tokenLength;
  266. return true;
  267. default:
  268. addText();
  269. return false;
  270. }
  271. }
  272. /**
  273. * Grabs the next token match in the string and returns it's details.
  274. *
  275. * @private
  276. *
  277. * @return {Array} An array of details for the token matched.
  278. */
  279. function nextToken() {
  280. const matches = tokenizer.exec(indoc); // We have no more tokens.
  281. if (null === matches) {
  282. return ['no-more-tokens'];
  283. }
  284. const startedAt = matches.index;
  285. const [match, isClosing, name, isSelfClosed] = matches;
  286. const length = match.length;
  287. if (isSelfClosed) {
  288. return ['self-closed', name, startedAt, length];
  289. }
  290. if (isClosing) {
  291. return ['closer', name, startedAt, length];
  292. }
  293. return ['opener', name, startedAt, length];
  294. }
  295. /**
  296. * Pushes text extracted from the indoc string to the output stack given the
  297. * current rawLength value and offset (if rawLength is provided ) or the
  298. * indoc.length and offset.
  299. *
  300. * @private
  301. */
  302. function addText() {
  303. const length = indoc.length - offset;
  304. if (0 === length) {
  305. return;
  306. }
  307. output.push(indoc.substr(offset, length));
  308. }
  309. /**
  310. * Pushes a child element to the associated parent element's children for the
  311. * parent currently active in the stack.
  312. *
  313. * @private
  314. *
  315. * @param {Frame} frame The Frame containing the child element and it's
  316. * token information.
  317. */
  318. function addChild(frame) {
  319. const {
  320. element,
  321. tokenStart,
  322. tokenLength,
  323. prevOffset,
  324. children
  325. } = frame;
  326. const parent = stack[stack.length - 1];
  327. const text = indoc.substr(parent.prevOffset, tokenStart - parent.prevOffset);
  328. if (text) {
  329. parent.children.push(text);
  330. }
  331. parent.children.push((0,external_React_namespaceObject.cloneElement)(element, null, ...children));
  332. parent.prevOffset = prevOffset ? prevOffset : tokenStart + tokenLength;
  333. }
  334. /**
  335. * This is called for closing tags. It creates the element currently active in
  336. * the stack.
  337. *
  338. * @private
  339. *
  340. * @param {number} endOffset Offset at which the closing tag for the element
  341. * begins in the string. If this is greater than the
  342. * prevOffset attached to the element, then this
  343. * helps capture any remaining nested text nodes in
  344. * the element.
  345. */
  346. function closeOuterElement(endOffset) {
  347. const {
  348. element,
  349. leadingTextStart,
  350. prevOffset,
  351. tokenStart,
  352. children
  353. } = stack.pop();
  354. const text = endOffset ? indoc.substr(prevOffset, endOffset - prevOffset) : indoc.substr(prevOffset);
  355. if (text) {
  356. children.push(text);
  357. }
  358. if (null !== leadingTextStart) {
  359. output.push(indoc.substr(leadingTextStart, tokenStart - leadingTextStart));
  360. }
  361. output.push((0,external_React_namespaceObject.cloneElement)(element, null, ...children));
  362. }
  363. /* harmony default export */ var create_interpolate_element = (createInterpolateElement);
  364. ;// CONCATENATED MODULE: external "lodash"
  365. var external_lodash_namespaceObject = window["lodash"];
  366. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/react.js
  367. /**
  368. * External dependencies
  369. */
  370. // eslint-disable-next-line @typescript-eslint/no-restricted-imports
  371. /**
  372. * Object containing a React element.
  373. *
  374. * @typedef {import('react').ReactElement} WPElement
  375. */
  376. /**
  377. * Object containing a React component.
  378. *
  379. * @typedef {import('react').ComponentType} WPComponent
  380. */
  381. /**
  382. * Object containing a React synthetic event.
  383. *
  384. * @typedef {import('react').SyntheticEvent} WPSyntheticEvent
  385. */
  386. /**
  387. * Object that provides utilities for dealing with React children.
  388. */
  389. /**
  390. * Creates a copy of an element with extended props.
  391. *
  392. * @param {WPElement} element Element
  393. * @param {?Object} props Props to apply to cloned element
  394. *
  395. * @return {WPElement} Cloned element.
  396. */
  397. /**
  398. * A base class to create WordPress Components (Refs, state and lifecycle hooks)
  399. */
  400. /**
  401. * Creates a context object containing two components: a provider and consumer.
  402. *
  403. * @param {Object} defaultValue A default data stored in the context.
  404. *
  405. * @return {Object} Context object.
  406. */
  407. /**
  408. * Returns a new element of given type. Type can be either a string tag name or
  409. * another function which itself returns an element.
  410. *
  411. * @param {?(string|Function)} type Tag name or element creator
  412. * @param {Object} props Element properties, either attribute
  413. * set to apply to DOM node or values to
  414. * pass through to element creator
  415. * @param {...WPElement} children Descendant elements
  416. *
  417. * @return {WPElement} Element.
  418. */
  419. /**
  420. * Returns an object tracking a reference to a rendered element via its
  421. * `current` property as either a DOMElement or Element, dependent upon the
  422. * type of element rendered with the ref attribute.
  423. *
  424. * @return {Object} Ref object.
  425. */
  426. /**
  427. * Component enhancer used to enable passing a ref to its wrapped component.
  428. * Pass a function argument which receives `props` and `ref` as its arguments,
  429. * returning an element using the forwarded ref. The return value is a new
  430. * component which forwards its ref.
  431. *
  432. * @param {Function} forwarder Function passed `props` and `ref`, expected to
  433. * return an element.
  434. *
  435. * @return {WPComponent} Enhanced component.
  436. */
  437. /**
  438. * A component which renders its children without any wrapping element.
  439. */
  440. /**
  441. * Checks if an object is a valid WPElement.
  442. *
  443. * @param {Object} objectToCheck The object to be checked.
  444. *
  445. * @return {boolean} true if objectToTest is a valid WPElement and false otherwise.
  446. */
  447. /**
  448. * @see https://reactjs.org/docs/react-api.html#reactmemo
  449. */
  450. /**
  451. * Component that activates additional checks and warnings for its descendants.
  452. */
  453. /**
  454. * @see https://reactjs.org/docs/hooks-reference.html#usecallback
  455. */
  456. /**
  457. * @see https://reactjs.org/docs/hooks-reference.html#usecontext
  458. */
  459. /**
  460. * @see https://reactjs.org/docs/hooks-reference.html#usedebugvalue
  461. */
  462. /**
  463. * @see https://reactjs.org/docs/hooks-reference.html#useeffect
  464. */
  465. /**
  466. * @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
  467. */
  468. /**
  469. * @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
  470. */
  471. /**
  472. * @see https://reactjs.org/docs/hooks-reference.html#usememo
  473. */
  474. /**
  475. * @see https://reactjs.org/docs/hooks-reference.html#usereducer
  476. */
  477. /**
  478. * @see https://reactjs.org/docs/hooks-reference.html#useref
  479. */
  480. /**
  481. * @see https://reactjs.org/docs/hooks-reference.html#usestate
  482. */
  483. /**
  484. * @see https://reactjs.org/docs/react-api.html#reactlazy
  485. */
  486. /**
  487. * @see https://reactjs.org/docs/react-api.html#reactsuspense
  488. */
  489. /**
  490. * Concatenate two or more React children objects.
  491. *
  492. * @param {...?Object} childrenArguments Array of children arguments (array of arrays/strings/objects) to concatenate.
  493. *
  494. * @return {Array} The concatenated value.
  495. */
  496. function concatChildren() {
  497. for (var _len = arguments.length, childrenArguments = new Array(_len), _key = 0; _key < _len; _key++) {
  498. childrenArguments[_key] = arguments[_key];
  499. }
  500. return childrenArguments.reduce((accumulator, children, i) => {
  501. external_React_namespaceObject.Children.forEach(children, (child, j) => {
  502. if (child && 'string' !== typeof child) {
  503. child = (0,external_React_namespaceObject.cloneElement)(child, {
  504. key: [i, j].join()
  505. });
  506. }
  507. accumulator.push(child);
  508. });
  509. return accumulator;
  510. }, []);
  511. }
  512. /**
  513. * Switches the nodeName of all the elements in the children object.
  514. *
  515. * @param {?Object} children Children object.
  516. * @param {string} nodeName Node name.
  517. *
  518. * @return {?Object} The updated children object.
  519. */
  520. function switchChildrenNodeName(children, nodeName) {
  521. return children && external_React_namespaceObject.Children.map(children, (elt, index) => {
  522. if ((0,external_lodash_namespaceObject.isString)(elt)) {
  523. return (0,external_React_namespaceObject.createElement)(nodeName, {
  524. key: index
  525. }, elt);
  526. }
  527. const {
  528. children: childrenProp,
  529. ...props
  530. } = elt.props;
  531. return (0,external_React_namespaceObject.createElement)(nodeName, {
  532. key: index,
  533. ...props
  534. }, childrenProp);
  535. });
  536. }
  537. ;// CONCATENATED MODULE: external "ReactDOM"
  538. var external_ReactDOM_namespaceObject = window["ReactDOM"];
  539. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/react-platform.js
  540. /**
  541. * External dependencies
  542. */
  543. /**
  544. * Creates a portal into which a component can be rendered.
  545. *
  546. * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235
  547. *
  548. * @param {import('./react').WPElement} child Any renderable child, such as an element,
  549. * string, or fragment.
  550. * @param {HTMLElement} container DOM node into which element should be rendered.
  551. */
  552. /**
  553. * Finds the dom node of a React component.
  554. *
  555. * @param {import('./react').WPComponent} component Component's instance.
  556. */
  557. /**
  558. * Renders a given element into the target DOM node.
  559. *
  560. * @param {import('./react').WPElement} element Element to render.
  561. * @param {HTMLElement} target DOM node into which element should be rendered.
  562. */
  563. /**
  564. * Removes any mounted element from the target DOM node.
  565. *
  566. * @param {Element} target DOM node in which element is to be removed
  567. */
  568. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/utils.js
  569. /**
  570. * External dependencies
  571. */
  572. /**
  573. * Checks if the provided WP element is empty.
  574. *
  575. * @param {*} element WP element to check.
  576. * @return {boolean} True when an element is considered empty.
  577. */
  578. const isEmptyElement = element => {
  579. if ((0,external_lodash_namespaceObject.isNumber)(element)) {
  580. return false;
  581. }
  582. if ((0,external_lodash_namespaceObject.isString)(element) || (0,external_lodash_namespaceObject.isArray)(element)) {
  583. return !element.length;
  584. }
  585. return !element;
  586. };
  587. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/platform.js
  588. /**
  589. * Parts of this source were derived and modified from react-native-web,
  590. * released under the MIT license.
  591. *
  592. * Copyright (c) 2016-present, Nicolas Gallagher.
  593. * Copyright (c) 2015-present, Facebook, Inc.
  594. *
  595. */
  596. const Platform = {
  597. OS: 'web',
  598. select: spec => 'web' in spec ? spec.web : spec.default,
  599. isWeb: true
  600. };
  601. /**
  602. * Component used to detect the current Platform being used.
  603. * Use Platform.OS === 'web' to detect if running on web enviroment.
  604. *
  605. * This is the same concept as the React Native implementation.
  606. *
  607. * @see https://facebook.github.io/react-native/docs/platform-specific-code#platform-module
  608. *
  609. * Here is an example of how to use the select method:
  610. * @example
  611. * ```js
  612. * import { Platform } from '@wordpress/element';
  613. *
  614. * const placeholderLabel = Platform.select( {
  615. * native: __( 'Add media' ),
  616. * web: __( 'Drag images, upload new ones or select files from your library.' ),
  617. * } );
  618. * ```
  619. */
  620. /* harmony default export */ var platform = (Platform);
  621. ;// CONCATENATED MODULE: external ["wp","escapeHtml"]
  622. var external_wp_escapeHtml_namespaceObject = window["wp"]["escapeHtml"];
  623. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/raw-html.js
  624. /**
  625. * Internal dependencies
  626. */
  627. // Disable reason: JSDoc linter doesn't seem to parse the union (`&`) correctly.
  628. /** @typedef {{children: string} & import('react').ComponentPropsWithoutRef<'div'>} RawHTMLProps */
  629. /**
  630. * Component used as equivalent of Fragment with unescaped HTML, in cases where
  631. * it is desirable to render dangerous HTML without needing a wrapper element.
  632. * To preserve additional props, a `div` wrapper _will_ be created if any props
  633. * aside from `children` are passed.
  634. *
  635. * @param {RawHTMLProps} props Children should be a string of HTML or an array
  636. * of strings. Other props will be passed through
  637. * to the div wrapper.
  638. *
  639. * @return {JSX.Element} Dangerously-rendering component.
  640. */
  641. function RawHTML(_ref) {
  642. let {
  643. children,
  644. ...props
  645. } = _ref;
  646. let rawHtml = ''; // Cast children as an array, and concatenate each element if it is a string.
  647. external_React_namespaceObject.Children.toArray(children).forEach(child => {
  648. if (typeof child === 'string' && child.trim() !== '') {
  649. rawHtml += child;
  650. }
  651. }); // The `div` wrapper will be stripped by the `renderElement` serializer in
  652. // `./serialize.js` unless there are non-children props present.
  653. return (0,external_React_namespaceObject.createElement)('div', {
  654. dangerouslySetInnerHTML: {
  655. __html: rawHtml
  656. },
  657. ...props
  658. });
  659. }
  660. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/serialize.js
  661. /**
  662. * Parts of this source were derived and modified from fast-react-render,
  663. * released under the MIT license.
  664. *
  665. * https://github.com/alt-j/fast-react-render
  666. *
  667. * Copyright (c) 2016 Andrey Morozov
  668. *
  669. * Permission is hereby granted, free of charge, to any person obtaining a copy
  670. * of this software and associated documentation files (the "Software"), to deal
  671. * in the Software without restriction, including without limitation the rights
  672. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  673. * copies of the Software, and to permit persons to whom the Software is
  674. * furnished to do so, subject to the following conditions:
  675. *
  676. * The above copyright notice and this permission notice shall be included in
  677. * all copies or substantial portions of the Software.
  678. *
  679. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  680. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  681. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  682. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  683. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  684. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  685. * THE SOFTWARE.
  686. */
  687. /**
  688. * External dependencies
  689. */
  690. /**
  691. * WordPress dependencies
  692. */
  693. /**
  694. * Internal dependencies
  695. */
  696. /** @typedef {import('./react').WPElement} WPElement */
  697. const {
  698. Provider,
  699. Consumer
  700. } = (0,external_React_namespaceObject.createContext)(undefined);
  701. const ForwardRef = (0,external_React_namespaceObject.forwardRef)(() => {
  702. return null;
  703. });
  704. /**
  705. * Valid attribute types.
  706. *
  707. * @type {Set<string>}
  708. */
  709. const ATTRIBUTES_TYPES = new Set(['string', 'boolean', 'number']);
  710. /**
  711. * Element tags which can be self-closing.
  712. *
  713. * @type {Set<string>}
  714. */
  715. const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
  716. /**
  717. * Boolean attributes are attributes whose presence as being assigned is
  718. * meaningful, even if only empty.
  719. *
  720. * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
  721. * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
  722. *
  723. * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
  724. * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )
  725. * .reduce( ( result, tr ) => Object.assign( result, {
  726. * [ tr.firstChild.textContent.trim() ]: true
  727. * } ), {} ) ).sort();
  728. *
  729. * @type {Set<string>}
  730. */
  731. const BOOLEAN_ATTRIBUTES = new Set(['allowfullscreen', 'allowpaymentrequest', 'allowusermedia', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'default', 'defer', 'disabled', 'download', 'formnovalidate', 'hidden', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'playsinline', 'readonly', 'required', 'reversed', 'selected', 'typemustmatch']);
  732. /**
  733. * Enumerated attributes are attributes which must be of a specific value form.
  734. * Like boolean attributes, these are meaningful if specified, even if not of a
  735. * valid enumerated value.
  736. *
  737. * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute
  738. * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
  739. *
  740. * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]
  741. * .filter( ( tr ) => /^("(.+?)";?\s*)+/.test( tr.lastChild.textContent.trim() ) )
  742. * .reduce( ( result, tr ) => Object.assign( result, {
  743. * [ tr.firstChild.textContent.trim() ]: true
  744. * } ), {} ) ).sort();
  745. *
  746. * Some notable omissions:
  747. *
  748. * - `alt`: https://blog.whatwg.org/omit-alt
  749. *
  750. * @type {Set<string>}
  751. */
  752. const ENUMERATED_ATTRIBUTES = new Set(['autocapitalize', 'autocomplete', 'charset', 'contenteditable', 'crossorigin', 'decoding', 'dir', 'draggable', 'enctype', 'formenctype', 'formmethod', 'http-equiv', 'inputmode', 'kind', 'method', 'preload', 'scope', 'shape', 'spellcheck', 'translate', 'type', 'wrap']);
  753. /**
  754. * Set of CSS style properties which support assignment of unitless numbers.
  755. * Used in rendering of style properties, where `px` unit is assumed unless
  756. * property is included in this set or value is zero.
  757. *
  758. * Generated via:
  759. *
  760. * Object.entries( document.createElement( 'div' ).style )
  761. * .filter( ( [ key ] ) => (
  762. * ! /^(webkit|ms|moz)/.test( key ) &&
  763. * ( e.style[ key ] = 10 ) &&
  764. * e.style[ key ] === '10'
  765. * ) )
  766. * .map( ( [ key ] ) => key )
  767. * .sort();
  768. *
  769. * @type {Set<string>}
  770. */
  771. const CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set(['animation', 'animationIterationCount', 'baselineShift', 'borderImageOutset', 'borderImageSlice', 'borderImageWidth', 'columnCount', 'cx', 'cy', 'fillOpacity', 'flexGrow', 'flexShrink', 'floodOpacity', 'fontWeight', 'gridColumnEnd', 'gridColumnStart', 'gridRowEnd', 'gridRowStart', 'lineHeight', 'opacity', 'order', 'orphans', 'r', 'rx', 'ry', 'shapeImageThreshold', 'stopOpacity', 'strokeDasharray', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'tabSize', 'widows', 'x', 'y', 'zIndex', 'zoom']);
  772. /**
  773. * Returns true if the specified string is prefixed by one of an array of
  774. * possible prefixes.
  775. *
  776. * @param {string} string String to check.
  777. * @param {string[]} prefixes Possible prefixes.
  778. *
  779. * @return {boolean} Whether string has prefix.
  780. */
  781. function hasPrefix(string, prefixes) {
  782. return prefixes.some(prefix => string.indexOf(prefix) === 0);
  783. }
  784. /**
  785. * Returns true if the given prop name should be ignored in attributes
  786. * serialization, or false otherwise.
  787. *
  788. * @param {string} attribute Attribute to check.
  789. *
  790. * @return {boolean} Whether attribute should be ignored.
  791. */
  792. function isInternalAttribute(attribute) {
  793. return 'key' === attribute || 'children' === attribute;
  794. }
  795. /**
  796. * Returns the normal form of the element's attribute value for HTML.
  797. *
  798. * @param {string} attribute Attribute name.
  799. * @param {*} value Non-normalized attribute value.
  800. *
  801. * @return {*} Normalized attribute value.
  802. */
  803. function getNormalAttributeValue(attribute, value) {
  804. switch (attribute) {
  805. case 'style':
  806. return renderStyle(value);
  807. }
  808. return value;
  809. }
  810. /**
  811. * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).
  812. * We need this to render e.g strokeWidth as stroke-width.
  813. *
  814. * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.
  815. */
  816. const SVG_ATTRIBUTE_WITH_DASHES_LIST = ['accentHeight', 'alignmentBaseline', 'arabicForm', 'baselineShift', 'capHeight', 'clipPath', 'clipRule', 'colorInterpolation', 'colorInterpolationFilters', 'colorProfile', 'colorRendering', 'dominantBaseline', 'enableBackground', 'fillOpacity', 'fillRule', 'floodColor', 'floodOpacity', 'fontFamily', 'fontSize', 'fontSizeAdjust', 'fontStretch', 'fontStyle', 'fontVariant', 'fontWeight', 'glyphName', 'glyphOrientationHorizontal', 'glyphOrientationVertical', 'horizAdvX', 'horizOriginX', 'imageRendering', 'letterSpacing', 'lightingColor', 'markerEnd', 'markerMid', 'markerStart', 'overlinePosition', 'overlineThickness', 'paintOrder', 'panose1', 'pointerEvents', 'renderingIntent', 'shapeRendering', 'stopColor', 'stopOpacity', 'strikethroughPosition', 'strikethroughThickness', 'strokeDasharray', 'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'textAnchor', 'textDecoration', 'textRendering', 'underlinePosition', 'underlineThickness', 'unicodeBidi', 'unicodeRange', 'unitsPerEm', 'vAlphabetic', 'vHanging', 'vIdeographic', 'vMathematical', 'vectorEffect', 'vertAdvY', 'vertOriginX', 'vertOriginY', 'wordSpacing', 'writingMode', 'xmlnsXlink', 'xHeight'].reduce((map, attribute) => {
  817. // The keys are lower-cased for more robust lookup.
  818. map[attribute.toLowerCase()] = attribute;
  819. return map;
  820. }, {});
  821. /**
  822. * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).
  823. * The keys are lower-cased for more robust lookup.
  824. * Note that this list only contains attributes that contain at least one capital letter.
  825. * Lowercase attributes don't need mapping, since we lowercase all attributes by default.
  826. */
  827. const CASE_SENSITIVE_SVG_ATTRIBUTES = ['allowReorder', 'attributeName', 'attributeType', 'autoReverse', 'baseFrequency', 'baseProfile', 'calcMode', 'clipPathUnits', 'contentScriptType', 'contentStyleType', 'diffuseConstant', 'edgeMode', 'externalResourcesRequired', 'filterRes', 'filterUnits', 'glyphRef', 'gradientTransform', 'gradientUnits', 'kernelMatrix', 'kernelUnitLength', 'keyPoints', 'keySplines', 'keyTimes', 'lengthAdjust', 'limitingConeAngle', 'markerHeight', 'markerUnits', 'markerWidth', 'maskContentUnits', 'maskUnits', 'numOctaves', 'pathLength', 'patternContentUnits', 'patternTransform', 'patternUnits', 'pointsAtX', 'pointsAtY', 'pointsAtZ', 'preserveAlpha', 'preserveAspectRatio', 'primitiveUnits', 'refX', 'refY', 'repeatCount', 'repeatDur', 'requiredExtensions', 'requiredFeatures', 'specularConstant', 'specularExponent', 'spreadMethod', 'startOffset', 'stdDeviation', 'stitchTiles', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'surfaceScale', 'systemLanguage', 'tableValues', 'targetX', 'targetY', 'textLength', 'viewBox', 'viewTarget', 'xChannelSelector', 'yChannelSelector'].reduce((map, attribute) => {
  828. // The keys are lower-cased for more robust lookup.
  829. map[attribute.toLowerCase()] = attribute;
  830. return map;
  831. }, {});
  832. /**
  833. * This is a map of all SVG attributes that have colons.
  834. * Keys are lower-cased and stripped of their colons for more robust lookup.
  835. */
  836. const SVG_ATTRIBUTES_WITH_COLONS = ['xlink:actuate', 'xlink:arcrole', 'xlink:href', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type', 'xml:base', 'xml:lang', 'xml:space', 'xmlns:xlink'].reduce((map, attribute) => {
  837. map[attribute.replace(':', '').toLowerCase()] = attribute;
  838. return map;
  839. }, {});
  840. /**
  841. * Returns the normal form of the element's attribute name for HTML.
  842. *
  843. * @param {string} attribute Non-normalized attribute name.
  844. *
  845. * @return {string} Normalized attribute name.
  846. */
  847. function getNormalAttributeName(attribute) {
  848. switch (attribute) {
  849. case 'htmlFor':
  850. return 'for';
  851. case 'className':
  852. return 'class';
  853. }
  854. const attributeLowerCase = attribute.toLowerCase();
  855. if (CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase]) {
  856. return CASE_SENSITIVE_SVG_ATTRIBUTES[attributeLowerCase];
  857. } else if (SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]) {
  858. return (0,external_lodash_namespaceObject.kebabCase)(SVG_ATTRIBUTE_WITH_DASHES_LIST[attributeLowerCase]);
  859. } else if (SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase]) {
  860. return SVG_ATTRIBUTES_WITH_COLONS[attributeLowerCase];
  861. }
  862. return attributeLowerCase;
  863. }
  864. /**
  865. * Returns the normal form of the style property name for HTML.
  866. *
  867. * - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'
  868. * - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'
  869. * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'
  870. *
  871. * @param {string} property Property name.
  872. *
  873. * @return {string} Normalized property name.
  874. */
  875. function getNormalStylePropertyName(property) {
  876. if ((0,external_lodash_namespaceObject.startsWith)(property, '--')) {
  877. return property;
  878. }
  879. if (hasPrefix(property, ['ms', 'O', 'Moz', 'Webkit'])) {
  880. return '-' + (0,external_lodash_namespaceObject.kebabCase)(property);
  881. }
  882. return (0,external_lodash_namespaceObject.kebabCase)(property);
  883. }
  884. /**
  885. * Returns the normal form of the style property value for HTML. Appends a
  886. * default pixel unit if numeric, not a unitless property, and not zero.
  887. *
  888. * @param {string} property Property name.
  889. * @param {*} value Non-normalized property value.
  890. *
  891. * @return {*} Normalized property value.
  892. */
  893. function getNormalStylePropertyValue(property, value) {
  894. if (typeof value === 'number' && 0 !== value && !CSS_PROPERTIES_SUPPORTS_UNITLESS.has(property)) {
  895. return value + 'px';
  896. }
  897. return value;
  898. }
  899. /**
  900. * Serializes a React element to string.
  901. *
  902. * @param {import('react').ReactNode} element Element to serialize.
  903. * @param {Object} [context] Context object.
  904. * @param {Object} [legacyContext] Legacy context object.
  905. *
  906. * @return {string} Serialized element.
  907. */
  908. function renderElement(element, context) {
  909. let legacyContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  910. if (null === element || undefined === element || false === element) {
  911. return '';
  912. }
  913. if (Array.isArray(element)) {
  914. return renderChildren(element, context, legacyContext);
  915. }
  916. switch (typeof element) {
  917. case 'string':
  918. return (0,external_wp_escapeHtml_namespaceObject.escapeHTML)(element);
  919. case 'number':
  920. return element.toString();
  921. }
  922. const {
  923. type,
  924. props
  925. } =
  926. /** @type {{type?: any, props?: any}} */
  927. element;
  928. switch (type) {
  929. case external_React_namespaceObject.StrictMode:
  930. case external_React_namespaceObject.Fragment:
  931. return renderChildren(props.children, context, legacyContext);
  932. case RawHTML:
  933. const {
  934. children,
  935. ...wrapperProps
  936. } = props;
  937. return renderNativeComponent((0,external_lodash_namespaceObject.isEmpty)(wrapperProps) ? null : 'div', { ...wrapperProps,
  938. dangerouslySetInnerHTML: {
  939. __html: children
  940. }
  941. }, context, legacyContext);
  942. }
  943. switch (typeof type) {
  944. case 'string':
  945. return renderNativeComponent(type, props, context, legacyContext);
  946. case 'function':
  947. if (type.prototype && typeof type.prototype.render === 'function') {
  948. return renderComponent(type, props, context, legacyContext);
  949. }
  950. return renderElement(type(props, legacyContext), context, legacyContext);
  951. }
  952. switch (type && type.$$typeof) {
  953. case Provider.$$typeof:
  954. return renderChildren(props.children, props.value, legacyContext);
  955. case Consumer.$$typeof:
  956. return renderElement(props.children(context || type._currentValue), context, legacyContext);
  957. case ForwardRef.$$typeof:
  958. return renderElement(type.render(props), context, legacyContext);
  959. }
  960. return '';
  961. }
  962. /**
  963. * Serializes a native component type to string.
  964. *
  965. * @param {?string} type Native component type to serialize, or null if
  966. * rendering as fragment of children content.
  967. * @param {Object} props Props object.
  968. * @param {Object} [context] Context object.
  969. * @param {Object} [legacyContext] Legacy context object.
  970. *
  971. * @return {string} Serialized element.
  972. */
  973. function renderNativeComponent(type, props, context) {
  974. let legacyContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  975. let content = '';
  976. if (type === 'textarea' && props.hasOwnProperty('value')) {
  977. // Textarea children can be assigned as value prop. If it is, render in
  978. // place of children. Ensure to omit so it is not assigned as attribute
  979. // as well.
  980. content = renderChildren(props.value, context, legacyContext);
  981. props = (0,external_lodash_namespaceObject.omit)(props, 'value');
  982. } else if (props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML.__html === 'string') {
  983. // Dangerous content is left unescaped.
  984. content = props.dangerouslySetInnerHTML.__html;
  985. } else if (typeof props.children !== 'undefined') {
  986. content = renderChildren(props.children, context, legacyContext);
  987. }
  988. if (!type) {
  989. return content;
  990. }
  991. const attributes = renderAttributes(props);
  992. if (SELF_CLOSING_TAGS.has(type)) {
  993. return '<' + type + attributes + '/>';
  994. }
  995. return '<' + type + attributes + '>' + content + '</' + type + '>';
  996. }
  997. /** @typedef {import('./react').WPComponent} WPComponent */
  998. /**
  999. * Serializes a non-native component type to string.
  1000. *
  1001. * @param {WPComponent} Component Component type to serialize.
  1002. * @param {Object} props Props object.
  1003. * @param {Object} [context] Context object.
  1004. * @param {Object} [legacyContext] Legacy context object.
  1005. *
  1006. * @return {string} Serialized element
  1007. */
  1008. function renderComponent(Component, props, context) {
  1009. let legacyContext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  1010. const instance = new
  1011. /** @type {import('react').ComponentClass} */
  1012. Component(props, legacyContext);
  1013. if (typeof // Ignore reason: Current prettier reformats parens and mangles type assertion
  1014. // prettier-ignore
  1015. /** @type {{getChildContext?: () => unknown}} */
  1016. instance.getChildContext === 'function') {
  1017. Object.assign(legacyContext,
  1018. /** @type {{getChildContext?: () => unknown}} */
  1019. instance.getChildContext());
  1020. }
  1021. const html = renderElement(instance.render(), context, legacyContext);
  1022. return html;
  1023. }
  1024. /**
  1025. * Serializes an array of children to string.
  1026. *
  1027. * @param {import('react').ReactNodeArray} children Children to serialize.
  1028. * @param {Object} [context] Context object.
  1029. * @param {Object} [legacyContext] Legacy context object.
  1030. *
  1031. * @return {string} Serialized children.
  1032. */
  1033. function renderChildren(children, context) {
  1034. let legacyContext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1035. let result = '';
  1036. children = (0,external_lodash_namespaceObject.castArray)(children);
  1037. for (let i = 0; i < children.length; i++) {
  1038. const child = children[i];
  1039. result += renderElement(child, context, legacyContext);
  1040. }
  1041. return result;
  1042. }
  1043. /**
  1044. * Renders a props object as a string of HTML attributes.
  1045. *
  1046. * @param {Object} props Props object.
  1047. *
  1048. * @return {string} Attributes string.
  1049. */
  1050. function renderAttributes(props) {
  1051. let result = '';
  1052. for (const key in props) {
  1053. const attribute = getNormalAttributeName(key);
  1054. if (!(0,external_wp_escapeHtml_namespaceObject.isValidAttributeName)(attribute)) {
  1055. continue;
  1056. }
  1057. let value = getNormalAttributeValue(key, props[key]); // If value is not of serializeable type, skip.
  1058. if (!ATTRIBUTES_TYPES.has(typeof value)) {
  1059. continue;
  1060. } // Don't render internal attribute names.
  1061. if (isInternalAttribute(key)) {
  1062. continue;
  1063. }
  1064. const isBooleanAttribute = BOOLEAN_ATTRIBUTES.has(attribute); // Boolean attribute should be omitted outright if its value is false.
  1065. if (isBooleanAttribute && value === false) {
  1066. continue;
  1067. }
  1068. const isMeaningfulAttribute = isBooleanAttribute || hasPrefix(key, ['data-', 'aria-']) || ENUMERATED_ATTRIBUTES.has(attribute); // Only write boolean value as attribute if meaningful.
  1069. if (typeof value === 'boolean' && !isMeaningfulAttribute) {
  1070. continue;
  1071. }
  1072. result += ' ' + attribute; // Boolean attributes should write attribute name, but without value.
  1073. // Mere presence of attribute name is effective truthiness.
  1074. if (isBooleanAttribute) {
  1075. continue;
  1076. }
  1077. if (typeof value === 'string') {
  1078. value = (0,external_wp_escapeHtml_namespaceObject.escapeAttribute)(value);
  1079. }
  1080. result += '="' + value + '"';
  1081. }
  1082. return result;
  1083. }
  1084. /**
  1085. * Renders a style object as a string attribute value.
  1086. *
  1087. * @param {Object} style Style object.
  1088. *
  1089. * @return {string} Style attribute value.
  1090. */
  1091. function renderStyle(style) {
  1092. // Only generate from object, e.g. tolerate string value.
  1093. if (!(0,external_lodash_namespaceObject.isPlainObject)(style)) {
  1094. return style;
  1095. }
  1096. let result;
  1097. for (const property in style) {
  1098. const value = style[property];
  1099. if (null === value || undefined === value) {
  1100. continue;
  1101. }
  1102. if (result) {
  1103. result += ';';
  1104. } else {
  1105. result = '';
  1106. }
  1107. const normalName = getNormalStylePropertyName(property);
  1108. const normalValue = getNormalStylePropertyValue(property, value);
  1109. result += normalName + ':' + normalValue;
  1110. }
  1111. return result;
  1112. }
  1113. /* harmony default export */ var serialize = (renderElement);
  1114. ;// CONCATENATED MODULE: ./node_modules/@wordpress/element/build-module/index.js
  1115. (window.wp = window.wp || {}).element = __webpack_exports__;
  1116. /******/ })()
  1117. ;