@wordpress/element 6.30.0 → 6.30.1-next.836ecdcae.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/README.md +10 -14
- package/build/create-interpolate-element.js +28 -53
- package/build/create-interpolate-element.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/platform.js +21 -5
- package/build/platform.js.map +1 -1
- package/build/raw-html.js +4 -2
- package/build/raw-html.js.map +1 -1
- package/build/react-platform.js.map +1 -1
- package/build/react.js +9 -22
- package/build/react.js.map +1 -1
- package/build/serialize.js +36 -89
- package/build/serialize.js.map +1 -1
- package/build/utils.js +2 -2
- package/build/utils.js.map +1 -1
- package/build-module/create-interpolate-element.js +28 -54
- package/build-module/create-interpolate-element.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/platform.js +21 -5
- package/build-module/platform.js.map +1 -1
- package/build-module/raw-html.js +4 -2
- package/build-module/raw-html.js.map +1 -1
- package/build-module/react-platform.js.map +1 -1
- package/build-module/react.js +9 -22
- package/build-module/react.js.map +1 -1
- package/build-module/serialize.js +36 -89
- package/build-module/serialize.js.map +1 -1
- package/build-module/utils.js +2 -2
- package/build-module/utils.js.map +1 -1
- package/build-types/create-interpolate-element.d.ts +8 -42
- package/build-types/create-interpolate-element.d.ts.map +1 -1
- package/build-types/index.d.ts +7 -7
- package/build-types/index.d.ts.map +1 -1
- package/build-types/platform.d.ts +48 -5
- package/build-types/platform.d.ts.map +1 -1
- package/build-types/raw-html.d.ts +7 -5
- package/build-types/raw-html.d.ts.map +1 -1
- package/build-types/react-platform.d.ts +62 -9
- package/build-types/react-platform.d.ts.map +1 -1
- package/build-types/react.d.ts +185 -58
- package/build-types/react.d.ts.map +1 -1
- package/build-types/serialize.d.ts +61 -43
- package/build-types/serialize.d.ts.map +1 -1
- package/build-types/utils.d.ts +7 -1
- package/build-types/utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/{create-interpolate-element.js → create-interpolate-element.ts} +95 -64
- package/src/{platform.js → platform.ts} +27 -4
- package/src/{raw-html.js → raw-html.ts} +11 -3
- package/src/{react.js → react.ts} +40 -37
- package/src/{serialize.js → serialize.ts} +131 -144
- package/src/{utils.js → utils.ts} +4 -4
- package/tsconfig.tsbuildinfo +1 -1
- /package/src/{index.js → index.ts} +0 -0
- /package/src/{react-platform.js → react-platform.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createElement","cloneElement","Fragment","isValidElement","indoc","offset","output","stack","tokenizer","createFrame","element","tokenStart","tokenLength","prevOffset","leadingTextStart","children","createInterpolateElement","interpolatedString","conversionMap","lastIndex","isValidConversionMap","TypeError","proceed","isObject","values","Object","length","every","next","nextToken","tokenType","name","startOffset","stackDepth","addText","stackLeadingText","pop","push","substr","addChild","closeOuterElement","stackTop","text","frame","matches","exec","startedAt","index","match","isClosing","isSelfClosed","parent","endOffset"],"sources":["@wordpress/element/src/create-interpolate-element.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createElement, cloneElement, Fragment, isValidElement } from './react';\n\n/**\n * Object containing a React element.\n *\n * @typedef {import('react').ReactElement} Element\n */\n\nlet indoc, offset, output, stack;\n\n/**\n * Matches tags in the localized string\n *\n * This is used for extracting the tag pattern groups for parsing the localized\n * string and along with the map converting it to a react element.\n *\n * There are four references extracted using this tokenizer:\n *\n * match: Full match of the tag (i.e. <strong>, </strong>, <br/>)\n * isClosing: The closing slash, if it exists.\n * name: The name portion of the tag (strong, br) (if )\n * isSelfClosed: The slash on a self closing tag, if it exists.\n *\n * @type {RegExp}\n */\nconst tokenizer = /<(\\/)?(\\w+)\\s*(\\/)?>/g;\n\n/**\n * The stack frame tracking parse progress.\n *\n * @typedef Frame\n *\n * @property {Element} element A parent element which may still have\n * @property {number} tokenStart Offset at which parent element first\n * appears.\n * @property {number} tokenLength Length of string marking start of parent\n * element.\n * @property {number} [prevOffset] Running offset at which parsing should\n * continue.\n * @property {number} [leadingTextStart] Offset at which last closing element\n * finished, used for finding text between\n * elements.\n * @property {Element[]} children Children.\n */\n\n/**\n * Tracks recursive-descent parse state.\n *\n * This is a Stack frame holding parent elements until all children have been\n * parsed.\n *\n * @private\n * @param {Element} element A parent element which may still have\n * nested children not yet parsed.\n * @param {number} tokenStart Offset at which parent element first\n * appears.\n * @param {number} tokenLength Length of string marking start of parent\n * element.\n * @param {number} [prevOffset] Running offset at which parsing should\n * continue.\n * @param {number} [leadingTextStart] Offset at which last closing element\n * finished, used for finding text between\n * elements.\n *\n * @return {Frame} The stack frame tracking parse progress.\n */\nfunction createFrame(\n\telement,\n\ttokenStart,\n\ttokenLength,\n\tprevOffset,\n\tleadingTextStart\n) {\n\treturn {\n\t\telement,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset,\n\t\tleadingTextStart,\n\t\tchildren: [],\n\t};\n}\n\n/**\n * This function creates an interpolated element from a passed in string with\n * specific tags matching how the string should be converted to an element via\n * the conversion map value.\n *\n * @example\n * For example, for the given string:\n *\n * \"This is a <span>string</span> with <a>a link</a> and a self-closing\n * <CustomComponentB/> tag\"\n *\n * You would have something like this as the conversionMap value:\n *\n * ```js\n * {\n * span: <span />,\n * a: <a href={ 'https://github.com' } />,\n * CustomComponentB: <CustomComponent />,\n * }\n * ```\n *\n * @param {string} interpolatedString The interpolation string to be parsed.\n * @param {Record<string, Element>} conversionMap The map used to convert the string to\n * a react element.\n * @throws {TypeError}\n * @return {Element} A wp element.\n */\nconst createInterpolateElement = ( interpolatedString, conversionMap ) => {\n\tindoc = interpolatedString;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tif ( ! isValidConversionMap( conversionMap ) ) {\n\t\tthrow new TypeError(\n\t\t\t'The conversionMap provided is not valid. It must be an object with values that are React Elements'\n\t\t);\n\t}\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed( conversionMap ) );\n\treturn createElement( Fragment, null, ...output );\n};\n\n/**\n * Validate conversion map.\n *\n * A map is considered valid if it's an object and every value in the object\n * is a React Element\n *\n * @private\n *\n * @param {Object} conversionMap The map being validated.\n *\n * @return {boolean} True means the map is valid.\n */\nconst isValidConversionMap = ( conversionMap ) => {\n\tconst isObject = typeof conversionMap === 'object';\n\tconst values = isObject && Object.values( conversionMap );\n\treturn (\n\t\tisObject &&\n\t\tvalues.length &&\n\t\tvalues.every( ( element ) => isValidElement( element ) )\n\t);\n};\n\n/**\n * This is the iterator over the matches in the string.\n *\n * @private\n *\n * @param {Object} conversionMap The conversion map for the string.\n *\n * @return {boolean} true for continuing to iterate, false for finished.\n */\nfunction proceed( conversionMap ) {\n\tconst next = nextToken();\n\tconst [ tokenType, name, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\tconst leadingTextStart = startOffset > offset ? offset : null;\n\tif ( ! conversionMap[ name ] ) {\n\t\taddText();\n\t\treturn false;\n\t}\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\tif ( stackDepth !== 0 ) {\n\t\t\t\tconst { leadingTextStart: stackLeadingText, tokenStart } =\n\t\t\t\t\tstack.pop();\n\t\t\t\toutput.push( indoc.substr( stackLeadingText, tokenStart ) );\n\t\t\t}\n\t\t\taddText();\n\t\t\treturn false;\n\n\t\tcase 'self-closed':\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingTextStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tindoc.substr(\n\t\t\t\t\t\t\tleadingTextStart,\n\t\t\t\t\t\t\tstartOffset - leadingTextStart\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( conversionMap[ name ] );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Otherwise we found an inner element.\n\t\t\taddChild(\n\t\t\t\tcreateFrame( conversionMap[ name ], startOffset, tokenLength )\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'opener':\n\t\t\tstack.push(\n\t\t\t\tcreateFrame(\n\t\t\t\t\tconversionMap[ name ],\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingTextStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'closer':\n\t\t\t// If we're not nesting then this is easy - close the block.\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\tcloseOuterElement( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent.\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst text = indoc.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.children.push( text );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\t\t\tconst frame = createFrame(\n\t\t\t\tstackTop.element,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\tframe.children = stackTop.children;\n\t\t\taddChild( frame );\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\taddText();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Grabs the next token match in the string and returns it's details.\n *\n * @private\n *\n * @return {Array} An array of details for the token matched.\n */\nfunction nextToken() {\n\tconst matches = tokenizer.exec( indoc );\n\t// We have no more tokens.\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\tconst startedAt = matches.index;\n\tconst [ match, isClosing, name, isSelfClosed ] = matches;\n\tconst length = match.length;\n\tif ( isSelfClosed ) {\n\t\treturn [ 'self-closed', name, startedAt, length ];\n\t}\n\tif ( isClosing ) {\n\t\treturn [ 'closer', name, startedAt, length ];\n\t}\n\treturn [ 'opener', name, startedAt, length ];\n}\n\n/**\n * Pushes text extracted from the indoc string to the output stack given the\n * current rawLength value and offset (if rawLength is provided ) or the\n * indoc.length and offset.\n *\n * @private\n */\nfunction addText() {\n\tconst length = indoc.length - offset;\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\toutput.push( indoc.substr( offset, length ) );\n}\n\n/**\n * Pushes a child element to the associated parent element's children for the\n * parent currently active in the stack.\n *\n * @private\n *\n * @param {Frame} frame The Frame containing the child element and it's\n * token information.\n */\nfunction addChild( frame ) {\n\tconst { element, tokenStart, tokenLength, prevOffset, children } = frame;\n\tconst parent = stack[ stack.length - 1 ];\n\tconst text = indoc.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( text ) {\n\t\tparent.children.push( text );\n\t}\n\n\tparent.children.push( cloneElement( element, null, ...children ) );\n\tparent.prevOffset = prevOffset ? prevOffset : tokenStart + tokenLength;\n}\n\n/**\n * This is called for closing tags. It creates the element currently active in\n * the stack.\n *\n * @private\n *\n * @param {number} endOffset Offset at which the closing tag for the element\n * begins in the string. If this is greater than the\n * prevOffset attached to the element, then this\n * helps capture any remaining nested text nodes in\n * the element.\n */\nfunction closeOuterElement( endOffset ) {\n\tconst { element, leadingTextStart, prevOffset, tokenStart, children } =\n\t\tstack.pop();\n\n\tconst text = endOffset\n\t\t? indoc.substr( prevOffset, endOffset - prevOffset )\n\t\t: indoc.substr( prevOffset );\n\n\tif ( text ) {\n\t\tchildren.push( text );\n\t}\n\n\tif ( null !== leadingTextStart ) {\n\t\toutput.push(\n\t\t\tindoc.substr( leadingTextStart, tokenStart - leadingTextStart )\n\t\t);\n\t}\n\n\toutput.push( cloneElement( element, null, ...children ) );\n}\n\nexport default createInterpolateElement;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,SAAS;;AAE/E;AACA;AACA;AACA;AACA;;AAEA,IAAIC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,KAAK;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG,uBAAuB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CACnBC,OAAO,EACPC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,gBAAgB,EACf;EACD,OAAO;IACNJ,OAAO;IACPC,UAAU;IACVC,WAAW;IACXC,UAAU;IACVC,gBAAgB;IAChBC,QAAQ,EAAE;EACX,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,GAAGA,CAAEC,kBAAkB,EAAEC,aAAa,KAAM;EACzEd,KAAK,GAAGa,kBAAkB;EAC1BZ,MAAM,GAAG,CAAC;EACVC,MAAM,GAAG,EAAE;EACXC,KAAK,GAAG,EAAE;EACVC,SAAS,CAACW,SAAS,GAAG,CAAC;EAEvB,IAAK,CAAEC,oBAAoB,CAAEF,aAAc,CAAC,EAAG;IAC9C,MAAM,IAAIG,SAAS,CAClB,mGACD,CAAC;EACF;EAEA,GAAG;IACF;EAAA,CACA,QAASC,OAAO,CAAEJ,aAAc,CAAC;EAClC,OAAOlB,aAAa,CAAEE,QAAQ,EAAE,IAAI,EAAE,GAAGI,MAAO,CAAC;AAClD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MA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EAR,MAAM,CAAC+B,IAAI,CAAEpC,YAAY,CAAES,OAAO,EAAE,IAAI,EAAE,GAAGK,QAAS,CAAE,CAAC;AAC1D;AAEA,eAAeC,wBAAwB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createElement","cloneElement","Fragment","isValidElement","indoc","offset","output","stack","tokenizer","createFrame","element","tokenStart","tokenLength","prevOffset","leadingTextStart","children","createInterpolateElement","interpolatedString","conversionMap","lastIndex","isValidConversionMap","TypeError","proceed","isObject","values","Object","length","every","next","nextToken","tokenType","name","startOffset","stackDepth","addText","stackLeadingText","pop","push","substr","addChild","closeOuterElement","stackTop","text","frame","matches","exec","startedAt","index","match","isClosing","isSelfClosed","parent","endOffset"],"sources":["@wordpress/element/src/create-interpolate-element.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateElement,\n\tcloneElement,\n\tFragment,\n\tisValidElement,\n\ttype Element as ReactElement,\n} from './react';\n\nlet indoc: string;\nlet offset: number;\nlet output: ( string | ReactElement )[];\nlet stack: Frame[];\n\n/**\n * Matches tags in the localized string\n *\n * This is used for extracting the tag pattern groups for parsing the localized\n * string and along with the map converting it to a react element.\n *\n * There are four references extracted using this tokenizer:\n *\n * match: Full match of the tag (i.e. <strong>, </strong>, <br/>)\n * isClosing: The closing slash, if it exists.\n * name: The name portion of the tag (strong, br) (if )\n * isSelfClosed: The slash on a self closing tag, if it exists.\n */\nconst tokenizer = /<(\\/)?(\\w+)\\s*(\\/)?>/g;\n\ninterface Frame {\n\t/**\n\t * A parent element which may still have nested children not yet parsed.\n\t */\n\telement: ReactElement;\n\n\t/**\n\t * Offset at which parent element first appears.\n\t */\n\ttokenStart: number;\n\n\t/**\n\t * Length of string marking start of parent element.\n\t */\n\ttokenLength: number;\n\n\t/**\n\t * Running offset at which parsing should continue.\n\t */\n\tprevOffset?: number;\n\n\t/**\n\t * Offset at which last closing element finished, used for finding text between elements.\n\t */\n\tleadingTextStart?: number | null;\n\n\t/**\n\t * Children.\n\t */\n\tchildren: ( string | ReactElement )[];\n}\n\n/**\n * Tracks recursive-descent parse state.\n *\n * This is a Stack frame holding parent elements until all children have been\n * parsed.\n *\n * @private\n * @param element A parent element which may still have\n * nested children not yet parsed.\n * @param tokenStart Offset at which parent element first\n * appears.\n * @param tokenLength Length of string marking start of parent\n * element.\n * @param prevOffset Running offset at which parsing should\n * continue.\n * @param leadingTextStart Offset at which last closing element\n * finished, used for finding text between\n * elements.\n *\n * @return The stack frame tracking parse progress.\n */\nfunction createFrame(\n\telement: ReactElement,\n\ttokenStart: number,\n\ttokenLength: number,\n\tprevOffset?: number,\n\tleadingTextStart?: number | null\n): Frame {\n\treturn {\n\t\telement,\n\t\ttokenStart,\n\t\ttokenLength,\n\t\tprevOffset,\n\t\tleadingTextStart,\n\t\tchildren: [],\n\t};\n}\n\n/**\n * This function creates an interpolated element from a passed in string with\n * specific tags matching how the string should be converted to an element via\n * the conversion map value.\n *\n * @example\n * For example, for the given string:\n *\n * \"This is a <span>string</span> with <a>a link</a> and a self-closing\n * <CustomComponentB/> tag\"\n *\n * You would have something like this as the conversionMap value:\n *\n * ```js\n * {\n * span: <span />,\n * a: <a href={ 'https://github.com' } />,\n * CustomComponentB: <CustomComponent />,\n * }\n * ```\n *\n * @param interpolatedString The interpolation string to be parsed.\n * @param conversionMap The map used to convert the string to\n * a react element.\n * @throws {TypeError}\n * @return A wp element.\n */\nconst createInterpolateElement = (\n\tinterpolatedString: string,\n\tconversionMap: Record< string, ReactElement >\n): ReactElement => {\n\tindoc = interpolatedString;\n\toffset = 0;\n\toutput = [];\n\tstack = [];\n\ttokenizer.lastIndex = 0;\n\n\tif ( ! isValidConversionMap( conversionMap ) ) {\n\t\tthrow new TypeError(\n\t\t\t'The conversionMap provided is not valid. It must be an object with values that are React Elements'\n\t\t);\n\t}\n\n\tdo {\n\t\t// twiddle our thumbs\n\t} while ( proceed( conversionMap ) );\n\treturn createElement( Fragment, null, ...output );\n};\n\n/**\n * Validate conversion map.\n *\n * A map is considered valid if it's an object and every value in the object\n * is a React Element\n *\n * @private\n *\n * @param conversionMap The map being validated.\n *\n * @return True means the map is valid.\n */\nconst isValidConversionMap = (\n\tconversionMap: Record< string, ReactElement >\n): boolean => {\n\tconst isObject =\n\t\ttypeof conversionMap === 'object' && conversionMap !== null;\n\tconst values = isObject && Object.values( conversionMap );\n\treturn (\n\t\tisObject &&\n\t\tvalues.length > 0 &&\n\t\tvalues.every( ( element ) => isValidElement( element ) )\n\t);\n};\n\ntype TokenType = 'no-more-tokens' | 'self-closed' | 'opener' | 'closer';\ntype TokenResult =\n\t| [ TokenType & 'no-more-tokens' ]\n\t| [\n\t\t\tTokenType & ( 'self-closed' | 'opener' | 'closer' ),\n\t\t\tstring,\n\t\t\tnumber,\n\t\t\tnumber,\n\t ];\n\n/**\n * This is the iterator over the matches in the string.\n *\n * @private\n *\n * @param conversionMap The conversion map for the string.\n *\n * @return true for continuing to iterate, false for finished.\n */\nfunction proceed( conversionMap: Record< string, ReactElement > ): boolean {\n\tconst next = nextToken();\n\tconst [ tokenType, name, startOffset, tokenLength ] = next;\n\tconst stackDepth = stack.length;\n\tconst leadingTextStart = startOffset > offset ? offset : null;\n\tif ( name && ! conversionMap[ name ] ) {\n\t\taddText();\n\t\treturn false;\n\t}\n\tswitch ( tokenType ) {\n\t\tcase 'no-more-tokens':\n\t\t\tif ( stackDepth !== 0 ) {\n\t\t\t\tconst { leadingTextStart: stackLeadingText, tokenStart } =\n\t\t\t\t\tstack.pop();\n\t\t\t\toutput.push( indoc.substr( stackLeadingText, tokenStart ) );\n\t\t\t}\n\t\t\taddText();\n\t\t\treturn false;\n\n\t\tcase 'self-closed':\n\t\t\tif ( 0 === stackDepth ) {\n\t\t\t\tif ( null !== leadingTextStart ) {\n\t\t\t\t\toutput.push(\n\t\t\t\t\t\tindoc.substr(\n\t\t\t\t\t\t\tleadingTextStart,\n\t\t\t\t\t\t\tstartOffset - leadingTextStart\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\toutput.push( conversionMap[ name ] );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Otherwise we found an inner element.\n\t\t\taddChild(\n\t\t\t\tcreateFrame( conversionMap[ name ], startOffset, tokenLength )\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'opener':\n\t\t\tstack.push(\n\t\t\t\tcreateFrame(\n\t\t\t\t\tconversionMap[ name ],\n\t\t\t\t\tstartOffset,\n\t\t\t\t\ttokenLength,\n\t\t\t\t\tstartOffset + tokenLength,\n\t\t\t\t\tleadingTextStart\n\t\t\t\t)\n\t\t\t);\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tcase 'closer':\n\t\t\t// If we're not nesting then this is easy - close the block.\n\t\t\tif ( 1 === stackDepth ) {\n\t\t\t\tcloseOuterElement( startOffset );\n\t\t\t\toffset = startOffset + tokenLength;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// Otherwise we're nested and we have to close out the current\n\t\t\t// block and add it as a innerBlock to the parent.\n\t\t\tconst stackTop = stack.pop();\n\t\t\tconst text = indoc.substr(\n\t\t\t\tstackTop.prevOffset,\n\t\t\t\tstartOffset - stackTop.prevOffset\n\t\t\t);\n\t\t\tstackTop.children.push( text );\n\t\t\tstackTop.prevOffset = startOffset + tokenLength;\n\t\t\tconst frame = createFrame(\n\t\t\t\tstackTop.element,\n\t\t\t\tstackTop.tokenStart,\n\t\t\t\tstackTop.tokenLength,\n\t\t\t\tstartOffset + tokenLength\n\t\t\t);\n\t\t\tframe.children = stackTop.children;\n\t\t\taddChild( frame );\n\t\t\toffset = startOffset + tokenLength;\n\t\t\treturn true;\n\n\t\tdefault:\n\t\t\taddText();\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Grabs the next token match in the string and returns it's details.\n *\n * @private\n *\n * @return An array of details for the token matched.\n */\nfunction nextToken(): TokenResult {\n\tconst matches = tokenizer.exec( indoc );\n\t// We have no more tokens.\n\tif ( null === matches ) {\n\t\treturn [ 'no-more-tokens' ];\n\t}\n\tconst startedAt = matches.index;\n\tconst [ match, isClosing, name, isSelfClosed ] = matches;\n\tconst length = match.length;\n\tif ( isSelfClosed ) {\n\t\treturn [ 'self-closed', name, startedAt, length ];\n\t}\n\tif ( isClosing ) {\n\t\treturn [ 'closer', name, startedAt, length ];\n\t}\n\treturn [ 'opener', name, startedAt, length ];\n}\n\n/**\n * Pushes text extracted from the indoc string to the output stack given the\n * current rawLength value and offset (if rawLength is provided ) or the\n * indoc.length and offset.\n *\n * @private\n */\nfunction addText(): void {\n\tconst length = indoc.length - offset;\n\tif ( 0 === length ) {\n\t\treturn;\n\t}\n\toutput.push( indoc.substr( offset, length ) );\n}\n\n/**\n * Pushes a child element to the associated parent element's children for the\n * parent currently active in the stack.\n *\n * @private\n *\n * @param {Frame} frame The Frame containing the child element and it's\n * token information.\n */\nfunction addChild( frame: Frame ): void {\n\tconst { element, tokenStart, tokenLength, prevOffset, children } = frame;\n\tconst parent = stack[ stack.length - 1 ];\n\tconst text = indoc.substr(\n\t\tparent.prevOffset,\n\t\ttokenStart - parent.prevOffset\n\t);\n\n\tif ( text ) {\n\t\tparent.children.push( text );\n\t}\n\n\tparent.children.push( cloneElement( element, null, ...children ) );\n\tparent.prevOffset = prevOffset ? prevOffset : tokenStart + tokenLength;\n}\n\n/**\n * This is called for closing tags. It creates the element currently active in\n * the stack.\n *\n * @private\n *\n * @param {number} endOffset Offset at which the closing tag for the element\n * begins in the string. If this is greater than the\n * prevOffset attached to the element, then this\n * helps capture any remaining nested text nodes in\n * the element.\n */\nfunction closeOuterElement( endOffset: number ): void {\n\tconst { element, leadingTextStart, prevOffset, tokenStart, children } =\n\t\tstack.pop();\n\n\tconst text = endOffset\n\t\t? indoc.substr( prevOffset, endOffset - prevOffset )\n\t\t: indoc.substr( prevOffset );\n\n\tif ( text ) {\n\t\tchildren.push( text );\n\t}\n\n\tif ( null !== leadingTextStart ) {\n\t\toutput.push(\n\t\t\tindoc.substr( leadingTextStart, tokenStart - leadingTextStart )\n\t\t);\n\t}\n\n\toutput.push( cloneElement( element, null, ...children ) );\n}\n\nexport default createInterpolateElement;\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,aAAa,EACbC,YAAY,EACZC,QAAQ,EACRC,cAAc,QAER,SAAS;AAEhB,IAAIC,KAAa;AACjB,IAAIC,MAAc;AAClB,IAAIC,MAAmC;AACvC,IAAIC,KAAc;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG,uBAAuB;AAkCzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CACnBC,OAAqB,EACrBC,UAAkB,EAClBC,WAAmB,EACnBC,UAAmB,EACnBC,gBAAgC,EACxB;EACR,OAAO;IACNJ,OAAO;IACPC,UAAU;IACVC,WAAW;IACXC,UAAU;IACVC,gBAAgB;IAChBC,QAAQ,EAAE;EACX,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,GAAGA,CAChCC,kBAA0B,EAC1BC,aAA6C,KAC3B;EAClBd,KAAK,GAAGa,kBAAkB;EAC1BZ,MAAM,GAAG,CAAC;EACVC,MAAM,GAAG,EAAE;EACXC,KAAK,GAAG,EAAE;EACVC,SAAS,CAACW,SAAS,GAAG,CAAC;EAEvB,IAAK,CAAEC,oBAAoB,CAAEF,aAAc,CAAC,EAAG;IAC9C,MAAM,IAAIG,SAAS,CAClB,mGACD,CAAC;EACF;EAEA,GAAG;IACF;EAAA,CACA,QAASC,OAAO,CAAEJ,aAAc,C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X3B,QAAQ,CAACsB,IAAI,CAAEK,IAAK,CAAC;EACtB;EAEA,IAAK,IAAI,KAAK5B,gBAAgB,EAAG;IAChCR,MAAM,CAAC+B,IAAI,CACVjC,KAAK,CAACkC,MAAM,CAAExB,gBAAgB,EAAEH,UAAU,GAAGG,gBAAiB,CAC/D,CAAC;EACF;EAEAR,MAAM,CAAC+B,IAAI,CAAEpC,YAAY,CAAES,OAAO,EAAE,IAAI,EAAE,GAAGK,QAAS,CAAE,CAAC;AAC1D;AAEA,eAAeC,wBAAwB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","createInterpolateElement","Platform","renderToString","RawHTML"],"sources":["@wordpress/element/src/index.
|
|
1
|
+
{"version":3,"names":["default","createInterpolateElement","Platform","renderToString","RawHTML"],"sources":["@wordpress/element/src/index.ts"],"sourcesContent":["export { default as createInterpolateElement } from './create-interpolate-element';\nexport * from './react';\nexport * from './react-platform';\nexport * from './utils';\nexport { default as Platform } from './platform';\nexport { default as renderToString } from './serialize';\nexport { default as RawHTML } from './raw-html';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,wBAAwB,QAAQ,8BAA8B;AAClF,cAAc,SAAS;AACvB,cAAc,kBAAkB;AAChC,cAAc,SAAS;AACvB,SAASD,OAAO,IAAIE,QAAQ,QAAQ,YAAY;AAChD,SAASF,OAAO,IAAIG,cAAc,QAAQ,aAAa;AACvD,SAASH,OAAO,IAAII,OAAO,QAAQ,YAAY","ignoreList":[]}
|
package/build-module/platform.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Specification for platform-specific value selection.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Component used to detect the current Platform being used.
|
|
16
16
|
* Use Platform.OS === 'web' to detect if running on web environment.
|
|
@@ -30,5 +30,21 @@ const Platform = {
|
|
|
30
30
|
* } );
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
+
const Platform = {
|
|
34
|
+
/** Platform identifier. Will always be `'web'` in this module. */
|
|
35
|
+
OS: 'web',
|
|
36
|
+
/**
|
|
37
|
+
* Select a value based on the platform.
|
|
38
|
+
*
|
|
39
|
+
* @template T
|
|
40
|
+
* @param spec - Object with optional platform-specific values.
|
|
41
|
+
* @return The selected value.
|
|
42
|
+
*/
|
|
43
|
+
select(spec) {
|
|
44
|
+
return 'web' in spec ? spec.web : spec.default;
|
|
45
|
+
},
|
|
46
|
+
/** Whether the platform is web */
|
|
47
|
+
isWeb: true
|
|
48
|
+
};
|
|
33
49
|
export default Platform;
|
|
34
50
|
//# sourceMappingURL=platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","OS","select","spec","web","default","isWeb"],"sources":["@wordpress/element/src/platform.
|
|
1
|
+
{"version":3,"names":["Platform","OS","select","spec","web","default","isWeb"],"sources":["@wordpress/element/src/platform.ts"],"sourcesContent":["/**\n * Parts of this source were derived and modified from react-native-web,\n * released under the MIT license.\n *\n * Copyright (c) 2016-present, Nicolas Gallagher.\n * Copyright (c) 2015-present, Facebook, Inc.\n *\n */\n\n/**\n * Specification for platform-specific value selection.\n */\ntype PlatformSelectSpec< T > = {\n\tweb?: T;\n\tdefault?: T;\n};\n\n/**\n * Component used to detect the current Platform being used.\n * Use Platform.OS === 'web' to detect if running on web environment.\n *\n * This is the same concept as the React Native implementation.\n *\n * @see https://reactnative.dev/docs/platform-specific-code#platform-module\n *\n * Here is an example of how to use the select method:\n * @example\n * ```js\n * import { Platform } from '@wordpress/element';\n *\n * const placeholderLabel = Platform.select( {\n * native: __( 'Add media' ),\n * web: __( 'Drag images, upload new ones or select files from your library.' ),\n * } );\n * ```\n */\nconst Platform = {\n\t/** Platform identifier. Will always be `'web'` in this module. */\n\tOS: 'web' as const,\n\n\t/**\n\t * Select a value based on the platform.\n\t *\n\t * @template T\n\t * @param spec - Object with optional platform-specific values.\n\t * @return The selected value.\n\t */\n\tselect< T >( spec: PlatformSelectSpec< T > ): T | undefined {\n\t\treturn 'web' in spec ? spec.web : spec.default;\n\t},\n\n\t/** Whether the platform is web */\n\tisWeb: true,\n};\n\nexport default Platform;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG;EAChB;EACAC,EAAE,EAAE,KAAc;EAElB;AACD;AACA;AACA;AACA;AACA;AACA;EACCC,MAAMA,CAAOC,IAA6B,EAAkB;IAC3D,OAAO,KAAK,IAAIA,IAAI,GAAGA,IAAI,CAACC,GAAG,GAAGD,IAAI,CAACE,OAAO;EAC/C,CAAC;EAED;EACAC,KAAK,EAAE;AACR,CAAC;AAED,eAAeN,QAAQ","ignoreList":[]}
|
package/build-module/raw-html.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Children, createElement } from './react';
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Props for the RawHTML component.
|
|
8
|
+
*/
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Component used to render unescaped HTML.
|
|
@@ -24,7 +26,7 @@ import { Children, createElement } from './react';
|
|
|
24
26
|
* of strings. Other props will be passed through
|
|
25
27
|
* to the div wrapper.
|
|
26
28
|
*
|
|
27
|
-
* @return
|
|
29
|
+
* @return Dangerously-rendering component.
|
|
28
30
|
*/
|
|
29
31
|
export default function RawHTML({
|
|
30
32
|
children,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Children","createElement","RawHTML","children","props","rawHtml","toArray","forEach","child","trim","dangerouslySetInnerHTML","__html"],"sources":["@wordpress/element/src/raw-html.
|
|
1
|
+
{"version":3,"names":["Children","createElement","RawHTML","children","props","rawHtml","toArray","forEach","child","trim","dangerouslySetInnerHTML","__html"],"sources":["@wordpress/element/src/raw-html.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { Children, createElement } from './react';\n\n/**\n * Props for the RawHTML component.\n */\nexport type RawHTMLProps = {\n\tchildren: string | string[];\n} & React.ComponentPropsWithoutRef< 'div' >;\n\n/**\n * Component used to render unescaped HTML.\n *\n * Note: The `renderElement` serializer will remove the `div` wrapper\n * unless non-children props are present; typically when preparing a block for saving.\n *\n * @example\n * ```jsx\n * import { RawHTML } from '@wordpress/element';\n *\n * const Component = () => <RawHTML><h3>Hello world</h3></RawHTML>;\n * // Edit: <div><h3>Hello world</h3></div>\n * // save: <h3>Hello world</h3>\n * ```\n *\n * @param {RawHTMLProps} props Children should be a string of HTML or an array\n * of strings. Other props will be passed through\n * to the div wrapper.\n *\n * @return Dangerously-rendering component.\n */\nexport default function RawHTML( {\n\tchildren,\n\t...props\n}: RawHTMLProps ): JSX.Element {\n\tlet rawHtml = '';\n\n\t// Cast children as an array, and concatenate each element if it is a string.\n\tChildren.toArray( children ).forEach( ( child ) => {\n\t\tif ( typeof child === 'string' && child.trim() !== '' ) {\n\t\t\trawHtml += child;\n\t\t}\n\t} );\n\n\t// The `div` wrapper will be stripped by the `renderElement` serializer in\n\t// `./serialize.js` unless there are non-children props present.\n\treturn createElement( 'div', {\n\t\tdangerouslySetInnerHTML: { __html: rawHtml },\n\t\t...props,\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,aAAa,QAAQ,SAAS;;AAEjD;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,OAAOA,CAAE;EAChCC,QAAQ;EACR,GAAGC;AACU,CAAC,EAAgB;EAC9B,IAAIC,OAAO,GAAG,EAAE;;EAEhB;EACAL,QAAQ,CAACM,OAAO,CAAEH,QAAS,CAAC,CAACI,OAAO,CAAIC,KAAK,IAAM;IAClD,IAAK,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAG;MACvDJ,OAAO,IAAIG,KAAK;IACjB;EACD,CAAE,CAAC;;EAEH;EACA;EACA,OAAOP,aAAa,CAAE,KAAK,EAAE;IAC5BS,uBAAuB,EAAE;MAAEC,MAAM,EAAEN;IAAQ,CAAC;IAC5C,GAAGD;EACJ,CAAE,CAAC;AACJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createPortal","findDOMNode","flushSync","render","hydrate","unmountComponentAtNode","createRoot","hydrateRoot"],"sources":["@wordpress/element/src/react-platform.
|
|
1
|
+
{"version":3,"names":["createPortal","findDOMNode","flushSync","render","hydrate","unmountComponentAtNode","createRoot","hydrateRoot"],"sources":["@wordpress/element/src/react-platform.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tcreatePortal,\n\tfindDOMNode,\n\tflushSync,\n\trender,\n\thydrate,\n\tunmountComponentAtNode,\n} from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\n\n/**\n * Creates a portal into which a component can be rendered.\n *\n * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235\n *\n * @param {import('react').ReactElement} child Any renderable child, such as an element,\n * string, or fragment.\n * @param {HTMLElement} container DOM node into which element should be rendered.\n */\nexport { createPortal };\n\n/**\n * Finds the dom node of a React component.\n *\n * @param {import('react').ComponentType} component Component's instance.\n */\nexport { findDOMNode };\n\n/**\n * Forces React to flush any updates inside the provided callback synchronously.\n *\n * @param {Function} callback Callback to run synchronously.\n */\nexport { flushSync };\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n */\nexport { render };\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n */\nexport { hydrate };\n\n/**\n * Creates a new React root for the target DOM node.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/createRoot\n */\nexport { createRoot };\n\n/**\n * Creates a new React root for the target DOM node and hydrates it with a pre-generated markup.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/hydrateRoot\n */\nexport { hydrateRoot };\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n */\nexport { unmountComponentAtNode };\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,OAAO,EACPC,sBAAsB,QAChB,WAAW;AAClB,SAASC,UAAU,EAAEC,WAAW,QAAQ,kBAAkB;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASP,YAAY;;AAErB;AACA;AACA;AACA;AACA;AACA,SAASC,WAAW;;AAEpB;AACA;AACA;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,MAAM;;AAEf;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,OAAO;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,UAAU;;AAEnB;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAW;;AAEpB;AACA;AACA;AACA;AACA;AACA;AACA,SAASF,sBAAsB","ignoreList":[]}
|
package/build-module/react.js
CHANGED
|
@@ -6,41 +6,26 @@ import { Children, cloneElement, Component, createContext, createElement, create
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Object containing a React element.
|
|
9
|
-
*
|
|
10
|
-
* @typedef {import('react').ReactElement} Element
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Object containing a React component.
|
|
15
|
-
*
|
|
16
|
-
* @typedef {import('react').ComponentType} ComponentType
|
|
17
13
|
*/
|
|
18
14
|
|
|
19
15
|
/**
|
|
20
16
|
* Object containing a React synthetic event.
|
|
21
|
-
*
|
|
22
|
-
* @typedef {import('react').SyntheticEvent} SyntheticEvent
|
|
23
17
|
*/
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
20
|
* Object containing a React ref object.
|
|
27
|
-
*
|
|
28
|
-
* @template T
|
|
29
|
-
* @typedef {import('react').RefObject<T>} RefObject<T>
|
|
30
21
|
*/
|
|
31
22
|
|
|
32
23
|
/**
|
|
33
24
|
* Object containing a React ref callback.
|
|
34
|
-
*
|
|
35
|
-
* @template T
|
|
36
|
-
* @typedef {import('react').RefCallback<T>} RefCallback<T>
|
|
37
25
|
*/
|
|
38
26
|
|
|
39
27
|
/**
|
|
40
28
|
* Object containing a React ref.
|
|
41
|
-
*
|
|
42
|
-
* @template T
|
|
43
|
-
* @typedef {import('react').Ref<T>} Ref<T>
|
|
44
29
|
*/
|
|
45
30
|
|
|
46
31
|
/**
|
|
@@ -230,14 +215,13 @@ export { PureComponent };
|
|
|
230
215
|
/**
|
|
231
216
|
* Concatenate two or more React children objects.
|
|
232
217
|
*
|
|
233
|
-
* @param
|
|
234
|
-
*
|
|
235
|
-
* @return {Array} The concatenated value.
|
|
218
|
+
* @param childrenArguments - Array of children arguments (array of arrays/strings/objects) to concatenate.
|
|
219
|
+
* @return The concatenated value.
|
|
236
220
|
*/
|
|
237
221
|
export function concatChildren(...childrenArguments) {
|
|
238
222
|
return childrenArguments.reduce((accumulator, children, i) => {
|
|
239
223
|
Children.forEach(children, (child, j) => {
|
|
240
|
-
if (child && 'string'
|
|
224
|
+
if (isValidElement(child) && typeof child !== 'string') {
|
|
241
225
|
child = cloneElement(child, {
|
|
242
226
|
key: [i, j].join()
|
|
243
227
|
});
|
|
@@ -251,10 +235,10 @@ export function concatChildren(...childrenArguments) {
|
|
|
251
235
|
/**
|
|
252
236
|
* Switches the nodeName of all the elements in the children object.
|
|
253
237
|
*
|
|
254
|
-
* @param
|
|
255
|
-
* @param
|
|
238
|
+
* @param children Children object.
|
|
239
|
+
* @param nodeName Node name.
|
|
256
240
|
*
|
|
257
|
-
* @return
|
|
241
|
+
* @return The updated children object.
|
|
258
242
|
*/
|
|
259
243
|
export function switchChildrenNodeName(children, nodeName) {
|
|
260
244
|
return children && Children.map(children, (elt, index) => {
|
|
@@ -263,6 +247,9 @@ export function switchChildrenNodeName(children, nodeName) {
|
|
|
263
247
|
key: index
|
|
264
248
|
}, elt);
|
|
265
249
|
}
|
|
250
|
+
if (!isValidElement(elt)) {
|
|
251
|
+
return elt;
|
|
252
|
+
}
|
|
266
253
|
const {
|
|
267
254
|
children: childrenProp,
|
|
268
255
|
...props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Children","cloneElement","Component","createContext","createElement","createRef","forwardRef","Fragment","isValidElement","memo","PureComponent","StrictMode","useCallback","useContext","useDebugValue","useDeferredValue","useEffect","useId","useMemo","useImperativeHandle","useInsertionEffect","useLayoutEffect","useReducer","useRef","useState","useSyncExternalStore","useTransition","startTransition","lazy","Suspense","concatChildren","childrenArguments","reduce","accumulator","children","i","forEach","child","j","key","join","push","switchChildrenNodeName","nodeName","map","elt","index","valueOf","childrenProp","props"],"sources":["@wordpress/element/src/react.js"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nimport {\n\tChildren,\n\tcloneElement,\n\tComponent,\n\tcreateContext,\n\tcreateElement,\n\tcreateRef,\n\tforwardRef,\n\tFragment,\n\tisValidElement,\n\tmemo,\n\tPureComponent,\n\tStrictMode,\n\tuseCallback,\n\tuseContext,\n\tuseDebugValue,\n\tuseDeferredValue,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseImperativeHandle,\n\tuseInsertionEffect,\n\tuseLayoutEffect,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n\tuseTransition,\n\tstartTransition,\n\tlazy,\n\tSuspense,\n} from 'react';\n\n/**\n * Object containing a React element.\n *\n * @typedef {import('react').ReactElement} Element\n */\n\n/**\n * Object containing a React component.\n *\n * @typedef {import('react').ComponentType} ComponentType\n */\n\n/**\n * Object containing a React synthetic event.\n *\n * @typedef {import('react').SyntheticEvent} SyntheticEvent\n */\n\n/**\n * Object containing a React ref object.\n *\n * @template T\n * @typedef {import('react').RefObject<T>} RefObject<T>\n */\n\n/**\n * Object containing a React ref callback.\n *\n * @template T\n * @typedef {import('react').RefCallback<T>} RefCallback<T>\n */\n\n/**\n * Object containing a React ref.\n *\n * @template T\n * @typedef {import('react').Ref<T>} Ref<T>\n */\n\n/**\n * Object that provides utilities for dealing with React children.\n */\nexport { Children };\n\n/**\n * Creates a copy of an element with extended props.\n *\n * @param {Element} element Element\n * @param {?Object} props Props to apply to cloned element\n *\n * @return {Element} Cloned element.\n */\nexport { cloneElement };\n\n/**\n * A base class to create WordPress Components (Refs, state and lifecycle hooks)\n */\nexport { Component };\n\n/**\n * Creates a context object containing two components: a provider and consumer.\n *\n * @param {Object} defaultValue A default data stored in the context.\n *\n * @return {Object} Context object.\n */\nexport { createContext };\n\n/**\n * Returns a new element of given type. Type can be either a string tag name or\n * another function which itself returns an element.\n *\n * @param {?(string|Function)} type Tag name or element creator\n * @param {Object} props Element properties, either attribute\n * set to apply to DOM node or values to\n * pass through to element creator\n * @param {...Element} children Descendant elements\n *\n * @return {Element} Element.\n */\nexport { createElement };\n\n/**\n * Returns an object tracking a reference to a rendered element via its\n * `current` property as either a DOMElement or Element, dependent upon the\n * type of element rendered with the ref attribute.\n *\n * @return {Object} Ref object.\n */\nexport { createRef };\n\n/**\n * Component enhancer used to enable passing a ref to its wrapped component.\n * Pass a function argument which receives `props` and `ref` as its arguments,\n * returning an element using the forwarded ref. The return value is a new\n * component which forwards its ref.\n *\n * @param {Function} forwarder Function passed `props` and `ref`, expected to\n * return an element.\n *\n * @return {Component} Enhanced component.\n */\nexport { forwardRef };\n\n/**\n * A component which renders its children without any wrapping element.\n */\nexport { Fragment };\n\n/**\n * Checks if an object is a valid React Element.\n *\n * @param {Object} objectToCheck The object to be checked.\n *\n * @return {boolean} true if objectToTest is a valid React Element and false otherwise.\n */\nexport { isValidElement };\n\n/**\n * @see https://react.dev/reference/react/memo\n */\nexport { memo };\n\n/**\n * Component that activates additional checks and warnings for its descendants.\n */\nexport { StrictMode };\n\n/**\n * @see https://react.dev/reference/react/useCallback\n */\nexport { useCallback };\n\n/**\n * @see https://react.dev/reference/react/useContext\n */\nexport { useContext };\n\n/**\n * @see https://react.dev/reference/react/useDebugValue\n */\nexport { useDebugValue };\n\n/**\n * @see https://react.dev/reference/react/useDeferredValue\n */\nexport { useDeferredValue };\n\n/**\n * @see https://react.dev/reference/react/useEffect\n */\nexport { useEffect };\n\n/**\n * @see https://react.dev/reference/react/useId\n */\nexport { useId };\n\n/**\n * @see https://react.dev/reference/react/useImperativeHandle\n */\nexport { useImperativeHandle };\n\n/**\n * @see https://react.dev/reference/react/useInsertionEffect\n */\nexport { useInsertionEffect };\n\n/**\n * @see https://react.dev/reference/react/useLayoutEffect\n */\nexport { useLayoutEffect };\n\n/**\n * @see https://react.dev/reference/react/useMemo\n */\nexport { useMemo };\n\n/**\n * @see https://react.dev/reference/react/useReducer\n */\nexport { useReducer };\n\n/**\n * @see https://react.dev/reference/react/useRef\n */\nexport { useRef };\n\n/**\n * @see https://react.dev/reference/react/useState\n */\nexport { useState };\n\n/**\n * @see https://react.dev/reference/react/useSyncExternalStore\n */\nexport { useSyncExternalStore };\n\n/**\n * @see https://react.dev/reference/react/useTransition\n */\nexport { useTransition };\n\n/**\n * @see https://react.dev/reference/react/startTransition\n */\nexport { startTransition };\n\n/**\n * @see https://react.dev/reference/react/lazy\n */\nexport { lazy };\n\n/**\n * @see https://react.dev/reference/react/Suspense\n */\nexport { Suspense };\n\n/**\n * @see https://react.dev/reference/react/PureComponent\n */\nexport { PureComponent };\n\n/**\n * Concatenate two or more React children objects.\n *\n * @param {...?Object} childrenArguments Array of children arguments (array of arrays/strings/objects) to concatenate.\n *\n * @return {Array} The concatenated value.\n */\nexport function concatChildren( ...childrenArguments ) {\n\treturn childrenArguments.reduce( ( accumulator, children, i ) => {\n\t\tChildren.forEach( children, ( child, j ) => {\n\t\t\tif ( child && 'string' !== typeof child ) {\n\t\t\t\tchild = cloneElement( child, {\n\t\t\t\t\tkey: [ i, j ].join(),\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\taccumulator.push( child );\n\t\t} );\n\n\t\treturn accumulator;\n\t}, [] );\n}\n\n/**\n * Switches the nodeName of all the elements in the children object.\n *\n * @param {?Object} children Children object.\n * @param {string} nodeName Node name.\n *\n * @return {?Object} The updated children object.\n */\nexport function switchChildrenNodeName( children, nodeName ) {\n\treturn (\n\t\tchildren &&\n\t\tChildren.map( children, ( elt, index ) => {\n\t\t\tif ( typeof elt?.valueOf() === 'string' ) {\n\t\t\t\treturn createElement( nodeName, { key: index }, elt );\n\t\t\t}\n\t\t\tconst { children: childrenProp, ...props } = elt.props;\n\t\t\treturn createElement(\n\t\t\t\tnodeName,\n\t\t\t\t{ key: index, ...props },\n\t\t\t\tchildrenProp\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SACCA,QAAQ,EACRC,YAAY,EACZC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,cAAc,EACdC,IAAI,EACJC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,aAAa,EACbC,gBAAgB,EAChBC,SAAS,EACTC,KAAK,EACLC,OAAO,EACPC,mBAAmB,EACnBC,kBAAkB,EAClBC,eAAe,EACfC,UAAU,EACVC,MAAM,EACNC,QAAQ,EACRC,oBAAoB,EACpBC,aAAa,EACbC,eAAe,EACfC,IAAI,EACJC,QAAQ,QACF,OAAO;;AAEd;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS7B,QAAQ;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAY;;AAErB;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAc;;AAEvB;AACA;AACA;AACA,SAASC,IAAI;;AAEb;AACA;AACA;AACA,SAASE,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,WAAW;;AAEpB;AACA;AACA;AACA,SAASC,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA,SAASC,gBAAgB;;AAEzB;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA,SAASC,KAAK;;AAEd;AACA;AACA;AACA,SAASE,mBAAmB;;AAE5B;AACA;AACA;AACA,SAASC,kBAAkB;;AAE3B;AACA;AACA;AACA,SAASC,eAAe;;AAExB;AACA;AACA;AACA,SAASH,OAAO;;AAEhB;AACA;AACA;AACA,SAASI,UAAU;;AAEn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ACA,MAAM;MAAEX,QAAQ,EAAEc,YAAY;MAAE,GAAGC;IAAM,CAAC,GAAGJ,GAAG,CAACI,KAAK;IACtD,OAAO7C,aAAa,CACnBuC,QAAQ,EACR;MAAEJ,GAAG,EAAEO,KAAK;MAAE,GAAGG;IAAM,CAAC,EACxBD,YACD,CAAC;EACF,CAAE,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["Children","cloneElement","Component","createContext","createElement","createRef","forwardRef","Fragment","isValidElement","memo","PureComponent","StrictMode","useCallback","useContext","useDebugValue","useDeferredValue","useEffect","useId","useMemo","useImperativeHandle","useInsertionEffect","useLayoutEffect","useReducer","useRef","useState","useSyncExternalStore","useTransition","startTransition","lazy","Suspense","concatChildren","childrenArguments","reduce","accumulator","children","i","forEach","child","j","key","join","push","switchChildrenNodeName","nodeName","map","elt","index","valueOf","childrenProp","props"],"sources":["@wordpress/element/src/react.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line @typescript-eslint/no-restricted-imports\nimport {\n\tChildren,\n\tcloneElement,\n\tComponent,\n\tcreateContext,\n\tcreateElement,\n\tcreateRef,\n\tforwardRef,\n\tFragment,\n\tisValidElement,\n\tmemo,\n\tPureComponent,\n\tStrictMode,\n\tuseCallback,\n\tuseContext,\n\tuseDebugValue,\n\tuseDeferredValue,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseImperativeHandle,\n\tuseInsertionEffect,\n\tuseLayoutEffect,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n\tuseTransition,\n\tstartTransition,\n\tlazy,\n\tSuspense,\n} from 'react';\nimport type { ReactNode } from 'react';\n\n/**\n * Object containing a React element.\n */\nexport type Element = React.ReactElement;\n\n/**\n * Object containing a React component.\n */\nexport type ComponentType< T = any > = React.ComponentType< T >;\n\n/**\n * Object containing a React synthetic event.\n */\nexport type SyntheticEvent< T = Element > = React.SyntheticEvent< T >;\n\n/**\n * Object containing a React ref object.\n */\nexport type RefObject< T > = React.RefObject< T >;\n\n/**\n * Object containing a React ref callback.\n */\nexport type RefCallback< T > = React.RefCallback< T >;\n\n/**\n * Object containing a React ref.\n */\nexport type Ref< T > = React.Ref< T >;\n\n/**\n * Object that provides utilities for dealing with React children.\n */\nexport { Children };\n\n/**\n * Creates a copy of an element with extended props.\n *\n * @param {Element} element Element\n * @param {?Object} props Props to apply to cloned element\n *\n * @return {Element} Cloned element.\n */\nexport { cloneElement };\n\n/**\n * A base class to create WordPress Components (Refs, state and lifecycle hooks)\n */\nexport { Component };\n\n/**\n * Creates a context object containing two components: a provider and consumer.\n *\n * @param {Object} defaultValue A default data stored in the context.\n *\n * @return {Object} Context object.\n */\nexport { createContext };\n\n/**\n * Returns a new element of given type. Type can be either a string tag name or\n * another function which itself returns an element.\n *\n * @param {?(string|Function)} type Tag name or element creator\n * @param {Object} props Element properties, either attribute\n * set to apply to DOM node or values to\n * pass through to element creator\n * @param {...Element} children Descendant elements\n *\n * @return {Element} Element.\n */\nexport { createElement };\n\n/**\n * Returns an object tracking a reference to a rendered element via its\n * `current` property as either a DOMElement or Element, dependent upon the\n * type of element rendered with the ref attribute.\n *\n * @return {Object} Ref object.\n */\nexport { createRef };\n\n/**\n * Component enhancer used to enable passing a ref to its wrapped component.\n * Pass a function argument which receives `props` and `ref` as its arguments,\n * returning an element using the forwarded ref. The return value is a new\n * component which forwards its ref.\n *\n * @param {Function} forwarder Function passed `props` and `ref`, expected to\n * return an element.\n *\n * @return {Component} Enhanced component.\n */\nexport { forwardRef };\n\n/**\n * A component which renders its children without any wrapping element.\n */\nexport { Fragment };\n\n/**\n * Checks if an object is a valid React Element.\n *\n * @param {Object} objectToCheck The object to be checked.\n *\n * @return {boolean} true if objectToTest is a valid React Element and false otherwise.\n */\nexport { isValidElement };\n\n/**\n * @see https://react.dev/reference/react/memo\n */\nexport { memo };\n\n/**\n * Component that activates additional checks and warnings for its descendants.\n */\nexport { StrictMode };\n\n/**\n * @see https://react.dev/reference/react/useCallback\n */\nexport { useCallback };\n\n/**\n * @see https://react.dev/reference/react/useContext\n */\nexport { useContext };\n\n/**\n * @see https://react.dev/reference/react/useDebugValue\n */\nexport { useDebugValue };\n\n/**\n * @see https://react.dev/reference/react/useDeferredValue\n */\nexport { useDeferredValue };\n\n/**\n * @see https://react.dev/reference/react/useEffect\n */\nexport { useEffect };\n\n/**\n * @see https://react.dev/reference/react/useId\n */\nexport { useId };\n\n/**\n * @see https://react.dev/reference/react/useImperativeHandle\n */\nexport { useImperativeHandle };\n\n/**\n * @see https://react.dev/reference/react/useInsertionEffect\n */\nexport { useInsertionEffect };\n\n/**\n * @see https://react.dev/reference/react/useLayoutEffect\n */\nexport { useLayoutEffect };\n\n/**\n * @see https://react.dev/reference/react/useMemo\n */\nexport { useMemo };\n\n/**\n * @see https://react.dev/reference/react/useReducer\n */\nexport { useReducer };\n\n/**\n * @see https://react.dev/reference/react/useRef\n */\nexport { useRef };\n\n/**\n * @see https://react.dev/reference/react/useState\n */\nexport { useState };\n\n/**\n * @see https://react.dev/reference/react/useSyncExternalStore\n */\nexport { useSyncExternalStore };\n\n/**\n * @see https://react.dev/reference/react/useTransition\n */\nexport { useTransition };\n\n/**\n * @see https://react.dev/reference/react/startTransition\n */\nexport { startTransition };\n\n/**\n * @see https://react.dev/reference/react/lazy\n */\nexport { lazy };\n\n/**\n * @see https://react.dev/reference/react/Suspense\n */\nexport { Suspense };\n\n/**\n * @see https://react.dev/reference/react/PureComponent\n */\nexport { PureComponent };\n\n/**\n * Concatenate two or more React children objects.\n *\n * @param childrenArguments - Array of children arguments (array of arrays/strings/objects) to concatenate.\n * @return The concatenated value.\n */\nexport function concatChildren(\n\t...childrenArguments: ReactNode[][]\n): ReactNode[] {\n\treturn childrenArguments.reduce< ReactNode[] >(\n\t\t( accumulator, children, i ) => {\n\t\t\tChildren.forEach( children, ( child, j ) => {\n\t\t\t\tif ( isValidElement( child ) && typeof child !== 'string' ) {\n\t\t\t\t\tchild = cloneElement( child, {\n\t\t\t\t\t\tkey: [ i, j ].join(),\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\taccumulator.push( child );\n\t\t\t} );\n\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n}\n\n/**\n * Switches the nodeName of all the elements in the children object.\n *\n * @param children Children object.\n * @param nodeName Node name.\n *\n * @return The updated children object.\n */\nexport function switchChildrenNodeName(\n\tchildren: ReactNode,\n\tnodeName: string\n): ReactNode {\n\treturn (\n\t\tchildren &&\n\t\tChildren.map( children, ( elt, index ) => {\n\t\t\tif ( typeof elt?.valueOf() === 'string' ) {\n\t\t\t\treturn createElement( nodeName, { key: index }, elt );\n\t\t\t}\n\t\t\tif ( ! isValidElement( elt ) ) {\n\t\t\t\treturn elt;\n\t\t\t}\n\n\t\t\tconst { children: childrenProp, ...props } = elt.props;\n\t\t\treturn createElement(\n\t\t\t\tnodeName,\n\t\t\t\t{ key: index, ...props },\n\t\t\t\tchildrenProp\n\t\t\t);\n\t\t} )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SACCA,QAAQ,EACRC,YAAY,EACZC,SAAS,EACTC,aAAa,EACbC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,cAAc,EACdC,IAAI,EACJC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,aAAa,EACbC,gBAAgB,EAChBC,SAAS,EACTC,KAAK,EACLC,OAAO,EACPC,mBAAmB,EACnBC,kBAAkB,EAClBC,eAAe,EACfC,UAAU,EACVC,MAAM,EACNC,QAAQ,EACRC,oBAAoB,EACpBC,aAAa,EACbC,eAAe,EACfC,IAAI,EACJC,QAAQ,QACF,OAAO;;AAGd;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAAS7B,QAAQ;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,YAAY;;AAErB;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAc;;AAEvB;AACA;AACA;AACA,SAASC,IAAI;;AAEb;AACA;AACA;AACA,SAASE,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,WAAW;;AAEpB;AACA;AACA;AACA,SAASC,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA,SAASC,gBAAgB;;AAEzB;AACA;AACA;AACA,SAASC,SAAS;;AAElB;AACA;AACA;AACA,SAASC,KAAK;;AAEd;AACA;AACA;AACA,SAASE,mBAAmB;;AAE5B;AACA;AACA;AACA,SAASC,kBAAkB;;AAE3B;AACA;AACA;AACA,SAASC,eAAe;;AAExB;AACA;AACA;AACA,SAASH,OAAO;;AAEhB;AACA;AACA;AACA,SAASI,UAAU;;AAEnB;AACA;AACA;AACA,SAASC,MAAM;;AAEf;AACA;AACA;AACA,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA,SAASC,oBAAoB;;AAE7B;AACA;AACA;AACA,SAASC,aAAa;;AAEtB;AACA;AACA;AACA,SAASC,eAAe;;AAExB;AACA;AACA;AACA,SAASC,IAAI;;AAEb;AACA;AACA;AACA,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA,SAASnB,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASoB,cAAcA,CAC7B,GAAGC,iBAAgC,EACrB;EACd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forwardRef(() => {
|
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* Valid attribute types.
|
|
59
|
-
*
|
|
60
|
-
* @type {Set<string>}
|
|
61
59
|
*/
|
|
62
60
|
const ATTRIBUTES_TYPES = new Set(['string', 'boolean', 'number']);
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Element tags which can be self-closing.
|
|
66
|
-
*
|
|
67
|
-
* @type {Set<string>}
|
|
68
64
|
*/
|
|
69
65
|
const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
70
66
|
|
|
@@ -80,8 +76,6 @@ const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embe
|
|
|
80
76
|
* .reduce( ( result, tr ) => Object.assign( result, {
|
|
81
77
|
* [ tr.firstChild.textContent.trim() ]: true
|
|
82
78
|
* } ), {} ) ).sort();
|
|
83
|
-
*
|
|
84
|
-
* @type {Set<string>}
|
|
85
79
|
*/
|
|
86
80
|
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']);
|
|
87
81
|
|
|
@@ -102,8 +96,6 @@ const BOOLEAN_ATTRIBUTES = new Set(['allowfullscreen', 'allowpaymentrequest', 'a
|
|
|
102
96
|
* Some notable omissions:
|
|
103
97
|
*
|
|
104
98
|
* - `alt`: https://blog.whatwg.org/omit-alt
|
|
105
|
-
*
|
|
106
|
-
* @type {Set<string>}
|
|
107
99
|
*/
|
|
108
100
|
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']);
|
|
109
101
|
|
|
@@ -122,19 +114,14 @@ const ENUMERATED_ATTRIBUTES = new Set(['autocapitalize', 'autocomplete', 'charse
|
|
|
122
114
|
* ) )
|
|
123
115
|
* .map( ( [ key ] ) => key )
|
|
124
116
|
* .sort();
|
|
125
|
-
*
|
|
126
|
-
* @type {Set<string>}
|
|
127
117
|
*/
|
|
128
118
|
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']);
|
|
129
119
|
|
|
130
120
|
/**
|
|
131
121
|
* Returns true if the specified string is prefixed by one of an array of
|
|
132
122
|
* possible prefixes.
|
|
133
|
-
*
|
|
134
|
-
* @param
|
|
135
|
-
* @param {string[]} prefixes Possible prefixes.
|
|
136
|
-
*
|
|
137
|
-
* @return {boolean} Whether string has prefix.
|
|
123
|
+
* @param string
|
|
124
|
+
* @param prefixes
|
|
138
125
|
*/
|
|
139
126
|
export function hasPrefix(string, prefixes) {
|
|
140
127
|
return prefixes.some(prefix => string.indexOf(prefix) === 0);
|
|
@@ -143,10 +130,7 @@ export function hasPrefix(string, prefixes) {
|
|
|
143
130
|
/**
|
|
144
131
|
* Returns true if the given prop name should be ignored in attributes
|
|
145
132
|
* serialization, or false otherwise.
|
|
146
|
-
*
|
|
147
|
-
* @param {string} attribute Attribute to check.
|
|
148
|
-
*
|
|
149
|
-
* @return {boolean} Whether attribute should be ignored.
|
|
133
|
+
* @param attribute
|
|
150
134
|
*/
|
|
151
135
|
function isInternalAttribute(attribute) {
|
|
152
136
|
return 'key' === attribute || 'children' === attribute;
|
|
@@ -154,11 +138,8 @@ function isInternalAttribute(attribute) {
|
|
|
154
138
|
|
|
155
139
|
/**
|
|
156
140
|
* Returns the normal form of the element's attribute value for HTML.
|
|
157
|
-
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param {*} value Non-normalized attribute value.
|
|
160
|
-
*
|
|
161
|
-
* @return {*} Normalized attribute value.
|
|
141
|
+
* @param attribute
|
|
142
|
+
* @param value
|
|
162
143
|
*/
|
|
163
144
|
function getNormalAttributeValue(attribute, value) {
|
|
164
145
|
switch (attribute) {
|
|
@@ -167,6 +148,7 @@ function getNormalAttributeValue(attribute, value) {
|
|
|
167
148
|
}
|
|
168
149
|
return value;
|
|
169
150
|
}
|
|
151
|
+
|
|
170
152
|
/**
|
|
171
153
|
* This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).
|
|
172
154
|
* We need this to render e.g strokeWidth as stroke-width.
|
|
@@ -202,10 +184,7 @@ const SVG_ATTRIBUTES_WITH_COLONS = ['xlink:actuate', 'xlink:arcrole', 'xlink:hre
|
|
|
202
184
|
|
|
203
185
|
/**
|
|
204
186
|
* Returns the normal form of the element's attribute name for HTML.
|
|
205
|
-
*
|
|
206
|
-
* @param {string} attribute Non-normalized attribute name.
|
|
207
|
-
*
|
|
208
|
-
* @return {string} Normalized attribute name.
|
|
187
|
+
* @param attribute
|
|
209
188
|
*/
|
|
210
189
|
function getNormalAttributeName(attribute) {
|
|
211
190
|
switch (attribute) {
|
|
@@ -231,10 +210,7 @@ function getNormalAttributeName(attribute) {
|
|
|
231
210
|
* - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'
|
|
232
211
|
* - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'
|
|
233
212
|
* - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'
|
|
234
|
-
*
|
|
235
|
-
* @param {string} property Property name.
|
|
236
|
-
*
|
|
237
|
-
* @return {string} Normalized property name.
|
|
213
|
+
* @param property
|
|
238
214
|
*/
|
|
239
215
|
function getNormalStylePropertyName(property) {
|
|
240
216
|
if (property.startsWith('--')) {
|
|
@@ -249,11 +225,8 @@ function getNormalStylePropertyName(property) {
|
|
|
249
225
|
/**
|
|
250
226
|
* Returns the normal form of the style property value for HTML. Appends a
|
|
251
227
|
* default pixel unit if numeric, not a unitless property, and not zero.
|
|
252
|
-
*
|
|
253
|
-
* @param
|
|
254
|
-
* @param {*} value Non-normalized property value.
|
|
255
|
-
*
|
|
256
|
-
* @return {*} Normalized property value.
|
|
228
|
+
* @param property
|
|
229
|
+
* @param value
|
|
257
230
|
*/
|
|
258
231
|
function getNormalStylePropertyValue(property, value) {
|
|
259
232
|
if (typeof value === 'number' && 0 !== value && !hasPrefix(property, ['--']) && !CSS_PROPERTIES_SUPPORTS_UNITLESS.has(property)) {
|
|
@@ -264,12 +237,9 @@ function getNormalStylePropertyValue(property, value) {
|
|
|
264
237
|
|
|
265
238
|
/**
|
|
266
239
|
* Serializes a React element to string.
|
|
267
|
-
*
|
|
268
|
-
* @param
|
|
269
|
-
* @param
|
|
270
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
271
|
-
*
|
|
272
|
-
* @return {string} Serialized element.
|
|
240
|
+
* @param element
|
|
241
|
+
* @param context
|
|
242
|
+
* @param legacyContext
|
|
273
243
|
*/
|
|
274
244
|
export function renderElement(element, context, legacyContext = {}) {
|
|
275
245
|
if (null === element || undefined === element || false === element) {
|
|
@@ -287,8 +257,7 @@ export function renderElement(element, context, legacyContext = {}) {
|
|
|
287
257
|
const {
|
|
288
258
|
type,
|
|
289
259
|
props
|
|
290
|
-
} =
|
|
291
|
-
element;
|
|
260
|
+
} = element;
|
|
292
261
|
switch (type) {
|
|
293
262
|
case StrictMode:
|
|
294
263
|
case Fragment:
|
|
@@ -327,14 +296,10 @@ export function renderElement(element, context, legacyContext = {}) {
|
|
|
327
296
|
|
|
328
297
|
/**
|
|
329
298
|
* Serializes a native component type to string.
|
|
330
|
-
*
|
|
331
|
-
* @param
|
|
332
|
-
*
|
|
333
|
-
* @param
|
|
334
|
-
* @param {Object} [context] Context object.
|
|
335
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
336
|
-
*
|
|
337
|
-
* @return {string} Serialized element.
|
|
299
|
+
* @param type
|
|
300
|
+
* @param props
|
|
301
|
+
* @param context
|
|
302
|
+
* @param legacyContext
|
|
338
303
|
*/
|
|
339
304
|
export function renderNativeComponent(type, props, context, legacyContext = {}) {
|
|
340
305
|
let content = '';
|
|
@@ -364,27 +329,17 @@ export function renderNativeComponent(type, props, context, legacyContext = {})
|
|
|
364
329
|
return '<' + type + attributes + '>' + content + '</' + type + '>';
|
|
365
330
|
}
|
|
366
331
|
|
|
367
|
-
/** @typedef {import('react').ComponentType} ComponentType */
|
|
368
|
-
|
|
369
332
|
/**
|
|
370
333
|
* Serializes a non-native component type to string.
|
|
371
|
-
*
|
|
372
|
-
* @param
|
|
373
|
-
* @param
|
|
374
|
-
* @param
|
|
375
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
376
|
-
*
|
|
377
|
-
* @return {string} Serialized element
|
|
334
|
+
* @param Component
|
|
335
|
+
* @param props
|
|
336
|
+
* @param context
|
|
337
|
+
* @param legacyContext
|
|
378
338
|
*/
|
|
379
339
|
export function renderComponent(Component, props, context, legacyContext = {}) {
|
|
380
|
-
const instance = new (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// Ignore reason: Current prettier reformats parens and mangles type assertion
|
|
384
|
-
// prettier-ignore
|
|
385
|
-
/** @type {{getChildContext?: () => unknown}} */
|
|
386
|
-
instance.getChildContext === 'function') {
|
|
387
|
-
Object.assign(legacyContext, /** @type {{getChildContext?: () => unknown}} */instance.getChildContext());
|
|
340
|
+
const instance = new Component(props, legacyContext);
|
|
341
|
+
if (typeof instance.getChildContext === 'function') {
|
|
342
|
+
Object.assign(legacyContext, instance.getChildContext());
|
|
388
343
|
}
|
|
389
344
|
const html = renderElement(instance.render(), context, legacyContext);
|
|
390
345
|
return html;
|
|
@@ -392,18 +347,15 @@ export function renderComponent(Component, props, context, legacyContext = {}) {
|
|
|
392
347
|
|
|
393
348
|
/**
|
|
394
349
|
* Serializes an array of children to string.
|
|
395
|
-
*
|
|
396
|
-
* @param
|
|
397
|
-
* @param
|
|
398
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
399
|
-
*
|
|
400
|
-
* @return {string} Serialized children.
|
|
350
|
+
* @param children
|
|
351
|
+
* @param context
|
|
352
|
+
* @param legacyContext
|
|
401
353
|
*/
|
|
402
354
|
function renderChildren(children, context, legacyContext = {}) {
|
|
403
355
|
let result = '';
|
|
404
|
-
|
|
405
|
-
for (let i = 0; i <
|
|
406
|
-
const child =
|
|
356
|
+
const childrenArray = Array.isArray(children) ? children : [children];
|
|
357
|
+
for (let i = 0; i < childrenArray.length; i++) {
|
|
358
|
+
const child = childrenArray[i];
|
|
407
359
|
result += renderElement(child, context, legacyContext);
|
|
408
360
|
}
|
|
409
361
|
return result;
|
|
@@ -411,10 +363,7 @@ function renderChildren(children, context, legacyContext = {}) {
|
|
|
411
363
|
|
|
412
364
|
/**
|
|
413
365
|
* Renders a props object as a string of HTML attributes.
|
|
414
|
-
*
|
|
415
|
-
* @param {Object} props Props object.
|
|
416
|
-
*
|
|
417
|
-
* @return {string} Attributes string.
|
|
366
|
+
* @param props
|
|
418
367
|
*/
|
|
419
368
|
export function renderAttributes(props) {
|
|
420
369
|
let result = '';
|
|
@@ -463,10 +412,7 @@ export function renderAttributes(props) {
|
|
|
463
412
|
|
|
464
413
|
/**
|
|
465
414
|
* Renders a style object as a string attribute value.
|
|
466
|
-
*
|
|
467
|
-
* @param {Object} style Style object.
|
|
468
|
-
*
|
|
469
|
-
* @return {string} Style attribute value.
|
|
415
|
+
* @param style
|
|
470
416
|
*/
|
|
471
417
|
export function renderStyle(style) {
|
|
472
418
|
// Only generate from object, e.g. tolerate string value.
|
|
@@ -474,8 +420,9 @@ export function renderStyle(style) {
|
|
|
474
420
|
return style;
|
|
475
421
|
}
|
|
476
422
|
let result;
|
|
477
|
-
|
|
478
|
-
|
|
423
|
+
const styleObj = style;
|
|
424
|
+
for (const property in styleObj) {
|
|
425
|
+
const value = styleObj[property];
|
|
479
426
|
if (null === value || undefined === value) {
|
|
480
427
|
continue;
|
|
481
428
|
}
|