@wordpress/element 6.29.1-next.f34ab90e9.0 → 6.30.1-next.6870dfe5b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- 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 +39 -90
- 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 +39 -90
- 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} +136 -145
- 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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,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
|
+
{"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;E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,CAAC;EAE7B,IAAK6B,IAAI,EAAG;IACX3B,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;;AA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MAAM,CAAC,EAAED,GAAI,CAAC;IACtD;IACA,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,cA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]}
|
|
@@ -44,25 +44,23 @@ import RawHTML from './raw-html';
|
|
|
44
44
|
|
|
45
45
|
/** @typedef {import('react').ReactElement} ReactElement */
|
|
46
46
|
|
|
47
|
+
const Context = createContext(undefined);
|
|
48
|
+
Context.displayName = 'ElementContext';
|
|
47
49
|
const {
|
|
48
50
|
Provider,
|
|
49
51
|
Consumer
|
|
50
|
-
} =
|
|
52
|
+
} = Context;
|
|
51
53
|
const ForwardRef = forwardRef(() => {
|
|
52
54
|
return null;
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Valid attribute types.
|
|
57
|
-
*
|
|
58
|
-
* @type {Set<string>}
|
|
59
59
|
*/
|
|
60
60
|
const ATTRIBUTES_TYPES = new Set(['string', 'boolean', 'number']);
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Element tags which can be self-closing.
|
|
64
|
-
*
|
|
65
|
-
* @type {Set<string>}
|
|
66
64
|
*/
|
|
67
65
|
const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
68
66
|
|
|
@@ -78,8 +76,6 @@ const SELF_CLOSING_TAGS = new Set(['area', 'base', 'br', 'col', 'command', 'embe
|
|
|
78
76
|
* .reduce( ( result, tr ) => Object.assign( result, {
|
|
79
77
|
* [ tr.firstChild.textContent.trim() ]: true
|
|
80
78
|
* } ), {} ) ).sort();
|
|
81
|
-
*
|
|
82
|
-
* @type {Set<string>}
|
|
83
79
|
*/
|
|
84
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']);
|
|
85
81
|
|
|
@@ -100,8 +96,6 @@ const BOOLEAN_ATTRIBUTES = new Set(['allowfullscreen', 'allowpaymentrequest', 'a
|
|
|
100
96
|
* Some notable omissions:
|
|
101
97
|
*
|
|
102
98
|
* - `alt`: https://blog.whatwg.org/omit-alt
|
|
103
|
-
*
|
|
104
|
-
* @type {Set<string>}
|
|
105
99
|
*/
|
|
106
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']);
|
|
107
101
|
|
|
@@ -120,19 +114,14 @@ const ENUMERATED_ATTRIBUTES = new Set(['autocapitalize', 'autocomplete', 'charse
|
|
|
120
114
|
* ) )
|
|
121
115
|
* .map( ( [ key ] ) => key )
|
|
122
116
|
* .sort();
|
|
123
|
-
*
|
|
124
|
-
* @type {Set<string>}
|
|
125
117
|
*/
|
|
126
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']);
|
|
127
119
|
|
|
128
120
|
/**
|
|
129
121
|
* Returns true if the specified string is prefixed by one of an array of
|
|
130
122
|
* possible prefixes.
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
133
|
-
* @param {string[]} prefixes Possible prefixes.
|
|
134
|
-
*
|
|
135
|
-
* @return {boolean} Whether string has prefix.
|
|
123
|
+
* @param string
|
|
124
|
+
* @param prefixes
|
|
136
125
|
*/
|
|
137
126
|
export function hasPrefix(string, prefixes) {
|
|
138
127
|
return prefixes.some(prefix => string.indexOf(prefix) === 0);
|
|
@@ -141,10 +130,7 @@ export function hasPrefix(string, prefixes) {
|
|
|
141
130
|
/**
|
|
142
131
|
* Returns true if the given prop name should be ignored in attributes
|
|
143
132
|
* serialization, or false otherwise.
|
|
144
|
-
*
|
|
145
|
-
* @param {string} attribute Attribute to check.
|
|
146
|
-
*
|
|
147
|
-
* @return {boolean} Whether attribute should be ignored.
|
|
133
|
+
* @param attribute
|
|
148
134
|
*/
|
|
149
135
|
function isInternalAttribute(attribute) {
|
|
150
136
|
return 'key' === attribute || 'children' === attribute;
|
|
@@ -152,11 +138,8 @@ function isInternalAttribute(attribute) {
|
|
|
152
138
|
|
|
153
139
|
/**
|
|
154
140
|
* Returns the normal form of the element's attribute value for HTML.
|
|
155
|
-
*
|
|
156
|
-
* @param
|
|
157
|
-
* @param {*} value Non-normalized attribute value.
|
|
158
|
-
*
|
|
159
|
-
* @return {*} Normalized attribute value.
|
|
141
|
+
* @param attribute
|
|
142
|
+
* @param value
|
|
160
143
|
*/
|
|
161
144
|
function getNormalAttributeValue(attribute, value) {
|
|
162
145
|
switch (attribute) {
|
|
@@ -165,6 +148,7 @@ function getNormalAttributeValue(attribute, value) {
|
|
|
165
148
|
}
|
|
166
149
|
return value;
|
|
167
150
|
}
|
|
151
|
+
|
|
168
152
|
/**
|
|
169
153
|
* This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).
|
|
170
154
|
* We need this to render e.g strokeWidth as stroke-width.
|
|
@@ -200,10 +184,7 @@ const SVG_ATTRIBUTES_WITH_COLONS = ['xlink:actuate', 'xlink:arcrole', 'xlink:hre
|
|
|
200
184
|
|
|
201
185
|
/**
|
|
202
186
|
* Returns the normal form of the element's attribute name for HTML.
|
|
203
|
-
*
|
|
204
|
-
* @param {string} attribute Non-normalized attribute name.
|
|
205
|
-
*
|
|
206
|
-
* @return {string} Normalized attribute name.
|
|
187
|
+
* @param attribute
|
|
207
188
|
*/
|
|
208
189
|
function getNormalAttributeName(attribute) {
|
|
209
190
|
switch (attribute) {
|
|
@@ -229,10 +210,7 @@ function getNormalAttributeName(attribute) {
|
|
|
229
210
|
* - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'
|
|
230
211
|
* - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'
|
|
231
212
|
* - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'
|
|
232
|
-
*
|
|
233
|
-
* @param {string} property Property name.
|
|
234
|
-
*
|
|
235
|
-
* @return {string} Normalized property name.
|
|
213
|
+
* @param property
|
|
236
214
|
*/
|
|
237
215
|
function getNormalStylePropertyName(property) {
|
|
238
216
|
if (property.startsWith('--')) {
|
|
@@ -247,11 +225,8 @@ function getNormalStylePropertyName(property) {
|
|
|
247
225
|
/**
|
|
248
226
|
* Returns the normal form of the style property value for HTML. Appends a
|
|
249
227
|
* default pixel unit if numeric, not a unitless property, and not zero.
|
|
250
|
-
*
|
|
251
|
-
* @param
|
|
252
|
-
* @param {*} value Non-normalized property value.
|
|
253
|
-
*
|
|
254
|
-
* @return {*} Normalized property value.
|
|
228
|
+
* @param property
|
|
229
|
+
* @param value
|
|
255
230
|
*/
|
|
256
231
|
function getNormalStylePropertyValue(property, value) {
|
|
257
232
|
if (typeof value === 'number' && 0 !== value && !hasPrefix(property, ['--']) && !CSS_PROPERTIES_SUPPORTS_UNITLESS.has(property)) {
|
|
@@ -262,12 +237,9 @@ function getNormalStylePropertyValue(property, value) {
|
|
|
262
237
|
|
|
263
238
|
/**
|
|
264
239
|
* Serializes a React element to string.
|
|
265
|
-
*
|
|
266
|
-
* @param
|
|
267
|
-
* @param
|
|
268
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
269
|
-
*
|
|
270
|
-
* @return {string} Serialized element.
|
|
240
|
+
* @param element
|
|
241
|
+
* @param context
|
|
242
|
+
* @param legacyContext
|
|
271
243
|
*/
|
|
272
244
|
export function renderElement(element, context, legacyContext = {}) {
|
|
273
245
|
if (null === element || undefined === element || false === element) {
|
|
@@ -285,8 +257,7 @@ export function renderElement(element, context, legacyContext = {}) {
|
|
|
285
257
|
const {
|
|
286
258
|
type,
|
|
287
259
|
props
|
|
288
|
-
} =
|
|
289
|
-
element;
|
|
260
|
+
} = element;
|
|
290
261
|
switch (type) {
|
|
291
262
|
case StrictMode:
|
|
292
263
|
case Fragment:
|
|
@@ -325,14 +296,10 @@ export function renderElement(element, context, legacyContext = {}) {
|
|
|
325
296
|
|
|
326
297
|
/**
|
|
327
298
|
* Serializes a native component type to string.
|
|
328
|
-
*
|
|
329
|
-
* @param
|
|
330
|
-
*
|
|
331
|
-
* @param
|
|
332
|
-
* @param {Object} [context] Context object.
|
|
333
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
334
|
-
*
|
|
335
|
-
* @return {string} Serialized element.
|
|
299
|
+
* @param type
|
|
300
|
+
* @param props
|
|
301
|
+
* @param context
|
|
302
|
+
* @param legacyContext
|
|
336
303
|
*/
|
|
337
304
|
export function renderNativeComponent(type, props, context, legacyContext = {}) {
|
|
338
305
|
let content = '';
|
|
@@ -362,27 +329,17 @@ export function renderNativeComponent(type, props, context, legacyContext = {})
|
|
|
362
329
|
return '<' + type + attributes + '>' + content + '</' + type + '>';
|
|
363
330
|
}
|
|
364
331
|
|
|
365
|
-
/** @typedef {import('react').ComponentType} ComponentType */
|
|
366
|
-
|
|
367
332
|
/**
|
|
368
333
|
* Serializes a non-native component type to string.
|
|
369
|
-
*
|
|
370
|
-
* @param
|
|
371
|
-
* @param
|
|
372
|
-
* @param
|
|
373
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
374
|
-
*
|
|
375
|
-
* @return {string} Serialized element
|
|
334
|
+
* @param Component
|
|
335
|
+
* @param props
|
|
336
|
+
* @param context
|
|
337
|
+
* @param legacyContext
|
|
376
338
|
*/
|
|
377
339
|
export function renderComponent(Component, props, context, legacyContext = {}) {
|
|
378
|
-
const instance = new (
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
// Ignore reason: Current prettier reformats parens and mangles type assertion
|
|
382
|
-
// prettier-ignore
|
|
383
|
-
/** @type {{getChildContext?: () => unknown}} */
|
|
384
|
-
instance.getChildContext === 'function') {
|
|
385
|
-
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());
|
|
386
343
|
}
|
|
387
344
|
const html = renderElement(instance.render(), context, legacyContext);
|
|
388
345
|
return html;
|
|
@@ -390,18 +347,15 @@ export function renderComponent(Component, props, context, legacyContext = {}) {
|
|
|
390
347
|
|
|
391
348
|
/**
|
|
392
349
|
* Serializes an array of children to string.
|
|
393
|
-
*
|
|
394
|
-
* @param
|
|
395
|
-
* @param
|
|
396
|
-
* @param {Object} [legacyContext] Legacy context object.
|
|
397
|
-
*
|
|
398
|
-
* @return {string} Serialized children.
|
|
350
|
+
* @param children
|
|
351
|
+
* @param context
|
|
352
|
+
* @param legacyContext
|
|
399
353
|
*/
|
|
400
354
|
function renderChildren(children, context, legacyContext = {}) {
|
|
401
355
|
let result = '';
|
|
402
|
-
|
|
403
|
-
for (let i = 0; i <
|
|
404
|
-
const child =
|
|
356
|
+
const childrenArray = Array.isArray(children) ? children : [children];
|
|
357
|
+
for (let i = 0; i < childrenArray.length; i++) {
|
|
358
|
+
const child = childrenArray[i];
|
|
405
359
|
result += renderElement(child, context, legacyContext);
|
|
406
360
|
}
|
|
407
361
|
return result;
|
|
@@ -409,10 +363,7 @@ function renderChildren(children, context, legacyContext = {}) {
|
|
|
409
363
|
|
|
410
364
|
/**
|
|
411
365
|
* Renders a props object as a string of HTML attributes.
|
|
412
|
-
*
|
|
413
|
-
* @param {Object} props Props object.
|
|
414
|
-
*
|
|
415
|
-
* @return {string} Attributes string.
|
|
366
|
+
* @param props
|
|
416
367
|
*/
|
|
417
368
|
export function renderAttributes(props) {
|
|
418
369
|
let result = '';
|
|
@@ -461,10 +412,7 @@ export function renderAttributes(props) {
|
|
|
461
412
|
|
|
462
413
|
/**
|
|
463
414
|
* Renders a style object as a string attribute value.
|
|
464
|
-
*
|
|
465
|
-
* @param {Object} style Style object.
|
|
466
|
-
*
|
|
467
|
-
* @return {string} Style attribute value.
|
|
415
|
+
* @param style
|
|
468
416
|
*/
|
|
469
417
|
export function renderStyle(style) {
|
|
470
418
|
// Only generate from object, e.g. tolerate string value.
|
|
@@ -472,8 +420,9 @@ export function renderStyle(style) {
|
|
|
472
420
|
return style;
|
|
473
421
|
}
|
|
474
422
|
let result;
|
|
475
|
-
|
|
476
|
-
|
|
423
|
+
const styleObj = style;
|
|
424
|
+
for (const property in styleObj) {
|
|
425
|
+
const value = styleObj[property];
|
|
477
426
|
if (null === value || undefined === value) {
|
|
478
427
|
continue;
|
|
479
428
|
}
|