@wordpress/element 8.0.1 → 8.0.2-next.v.202606191442.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/build/index.cjs.map +1 -1
- package/build/serialize.cjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/serialize.mjs.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +0 -6
- package/build/react-polyfill-base.cjs +0 -132
- package/build/react-polyfill-base.cjs.map +0 -7
- package/build/react-polyfill.cjs +0 -80
- package/build/react-polyfill.cjs.map +0 -7
- package/build-module/react-polyfill-base.mjs +0 -104
- package/build-module/react-polyfill-base.mjs.map +0 -7
- package/build-module/react-polyfill.mjs +0 -47
- package/build-module/react-polyfill.mjs.map +0 -7
- package/build-types/find-dom-node.d.ts +0 -10
- package/build-types/find-dom-node.d.ts.map +0 -1
- package/build-types/react-polyfill-base.d.ts +0 -5
- package/build-types/react-polyfill-base.d.ts.map +0 -1
- package/build-types/react-polyfill.d.ts +0 -42
- package/build-types/react-polyfill.d.ts.map +0 -1
- package/src/react-polyfill-base.ts +0 -133
- package/src/react-polyfill.ts +0 -99
- package/src/test/find-dom-node.js +0 -109
- package/src/test/react-polyfill.js +0 -77
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"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
|
|
4
|
+
"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"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wCAAoD;AACpD,0BAAc,wBADd;AAEA,0BAAc,iCAFd;AAGA,0BAAc,wBAHd;AAIA,sBAAoC;AACpC,uBAA0C;AAC1C,sBAAmC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/serialize.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/serialize.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Parts of this source were derived and modified from fast-react-render,\n * released under the MIT license.\n *\n * https://github.com/alt-j/fast-react-render\n *\n * Copyright (c) 2016 Andrey Morozov\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tescapeHTML,\n\tescapeAttribute,\n\tisValidAttributeName,\n} from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport { createContext, Fragment, StrictMode, forwardRef } from './react';\nimport RawHTML from './raw-html';\n\n/** @typedef {React.ReactElement} ReactElement */\n\nconst Context = createContext( undefined );\nContext.displayName = 'ElementContext';\n\ninterface ComponentInstance {\n\trender: () => React.ReactNode;\n\tgetChildContext?: () => Record< string, any >;\n}\n\ninterface RawHTMLProps {\n\tchildren: string;\n\t[ key: string ]: any;\n}\n\ninterface StyleObject {\n\t[ property: string ]: string | number | null | undefined;\n}\n\ninterface HTMLProps {\n\tdangerouslySetInnerHTML?: {\n\t\t__html: string;\n\t};\n\tchildren?: React.ReactNode;\n\tvalue?: React.ReactNode;\n\tstyle?: StyleObject | string;\n\tclassName?: string;\n\thtmlFor?: string;\n\t[ key: string ]: any;\n}\n\nconst { Provider, Consumer } = Context;\n\nconst ForwardRef = forwardRef( () => {\n\treturn null;\n} );\n\n/**\n * Valid attribute types.\n */\nconst ATTRIBUTES_TYPES = new Set< string >( [ 'string', 'boolean', 'number' ] );\n\n/**\n * Element tags which can be self-closing.\n */\nconst SELF_CLOSING_TAGS = new Set< string >( [\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'command',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'keygen',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n] );\n\n/**\n * Boolean attributes are attributes whose presence as being assigned is\n * meaningful, even if only empty.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n */\nconst BOOLEAN_ATTRIBUTES = new Set< string >( [\n\t'allowfullscreen',\n\t'allowpaymentrequest',\n\t'allowusermedia',\n\t'async',\n\t'autofocus',\n\t'autoplay',\n\t'checked',\n\t'controls',\n\t'default',\n\t'defer',\n\t'disabled',\n\t'download',\n\t'formnovalidate',\n\t'hidden',\n\t'ismap',\n\t'itemscope',\n\t'loop',\n\t'multiple',\n\t'muted',\n\t'nomodule',\n\t'novalidate',\n\t'open',\n\t'playsinline',\n\t'readonly',\n\t'required',\n\t'reversed',\n\t'selected',\n\t'typemustmatch',\n] );\n\n/**\n * Enumerated attributes are attributes which must be of a specific value form.\n * Like boolean attributes, these are meaningful if specified, even if not of a\n * valid enumerated value.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => /^(\"(.+?)\";?\\s*)+/.test( tr.lastChild.textContent.trim() ) )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n *\n * Some notable omissions:\n *\n * - `alt`: https://blog.whatwg.org/omit-alt\n */\nconst ENUMERATED_ATTRIBUTES = new Set< string >( [\n\t'autocapitalize',\n\t'autocomplete',\n\t'charset',\n\t'contenteditable',\n\t'crossorigin',\n\t'decoding',\n\t'dir',\n\t'draggable',\n\t'enctype',\n\t'formenctype',\n\t'formmethod',\n\t'http-equiv',\n\t'inputmode',\n\t'kind',\n\t'method',\n\t'preload',\n\t'scope',\n\t'shape',\n\t'spellcheck',\n\t'translate',\n\t'type',\n\t'wrap',\n] );\n\n/**\n * Set of CSS style properties which support assignment of unitless numbers.\n * Used in rendering of style properties, where `px` unit is assumed unless\n * property is included in this set or value is zero.\n *\n * Generated via:\n *\n * Object.entries( document.createElement( 'div' ).style )\n * .filter( ( [ key ] ) => (\n * ! /^(webkit|ms|moz)/.test( key ) &&\n * ( e.style[ key ] = 10 ) &&\n * e.style[ key ] === '10'\n * ) )\n * .map( ( [ key ] ) => key )\n * .sort();\n */\nconst CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set< string >( [\n\t'animation',\n\t'animationIterationCount',\n\t'baselineShift',\n\t'borderImageOutset',\n\t'borderImageSlice',\n\t'borderImageWidth',\n\t'columnCount',\n\t'cx',\n\t'cy',\n\t'fillOpacity',\n\t'flexGrow',\n\t'flexShrink',\n\t'floodOpacity',\n\t'fontWeight',\n\t'gridColumnEnd',\n\t'gridColumnStart',\n\t'gridRowEnd',\n\t'gridRowStart',\n\t'lineHeight',\n\t'opacity',\n\t'order',\n\t'orphans',\n\t'r',\n\t'rx',\n\t'ry',\n\t'shapeImageThreshold',\n\t'stopOpacity',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'tabSize',\n\t'widows',\n\t'x',\n\t'y',\n\t'zIndex',\n\t'zoom',\n] );\n\n/**\n * Returns true if the specified string is prefixed by one of an array of\n * possible prefixes.\n * @param string\n * @param prefixes\n */\nexport function hasPrefix( string: string, prefixes: string[] ): boolean {\n\treturn prefixes.some( ( prefix ) => string.indexOf( prefix ) === 0 );\n}\n\n/**\n * Returns true if the given prop name should be ignored in attributes\n * serialization, or false otherwise.\n * @param attribute\n */\nfunction isInternalAttribute( attribute: string ): boolean {\n\treturn 'key' === attribute || 'children' === attribute;\n}\n\n/**\n * Returns the normal form of the element's attribute value for HTML.\n * @param attribute\n * @param value\n */\nfunction getNormalAttributeValue( attribute: string, value: any ): any {\n\tswitch ( attribute ) {\n\t\tcase 'style':\n\t\t\treturn renderStyle( value );\n\t}\n\n\treturn value;\n}\n\n/**\n * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).\n * We need this to render e.g strokeWidth as stroke-width.\n *\n * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.\n */\nconst SVG_ATTRIBUTE_WITH_DASHES_LIST: Record< string, string > = [\n\t'accentHeight',\n\t'alignmentBaseline',\n\t'arabicForm',\n\t'baselineShift',\n\t'capHeight',\n\t'clipPath',\n\t'clipRule',\n\t'colorInterpolation',\n\t'colorInterpolationFilters',\n\t'colorProfile',\n\t'colorRendering',\n\t'dominantBaseline',\n\t'enableBackground',\n\t'fillOpacity',\n\t'fillRule',\n\t'floodColor',\n\t'floodOpacity',\n\t'fontFamily',\n\t'fontSize',\n\t'fontSizeAdjust',\n\t'fontStretch',\n\t'fontStyle',\n\t'fontVariant',\n\t'fontWeight',\n\t'glyphName',\n\t'glyphOrientationHorizontal',\n\t'glyphOrientationVertical',\n\t'horizAdvX',\n\t'horizOriginX',\n\t'imageRendering',\n\t'letterSpacing',\n\t'lightingColor',\n\t'markerEnd',\n\t'markerMid',\n\t'markerStart',\n\t'overlinePosition',\n\t'overlineThickness',\n\t'paintOrder',\n\t'panose1',\n\t'pointerEvents',\n\t'renderingIntent',\n\t'shapeRendering',\n\t'stopColor',\n\t'stopOpacity',\n\t'strikethroughPosition',\n\t'strikethroughThickness',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeLinecap',\n\t'strokeLinejoin',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'textAnchor',\n\t'textDecoration',\n\t'textRendering',\n\t'underlinePosition',\n\t'underlineThickness',\n\t'unicodeBidi',\n\t'unicodeRange',\n\t'unitsPerEm',\n\t'vAlphabetic',\n\t'vHanging',\n\t'vIdeographic',\n\t'vMathematical',\n\t'vectorEffect',\n\t'vertAdvY',\n\t'vertOriginX',\n\t'vertOriginY',\n\t'wordSpacing',\n\t'writingMode',\n\t'xmlnsXlink',\n\t'xHeight',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).\n * The keys are lower-cased for more robust lookup.\n * Note that this list only contains attributes that contain at least one capital letter.\n * Lowercase attributes don't need mapping, since we lowercase all attributes by default.\n */\nconst CASE_SENSITIVE_SVG_ATTRIBUTES: Record< string, string > = [\n\t'allowReorder',\n\t'attributeName',\n\t'attributeType',\n\t'autoReverse',\n\t'baseFrequency',\n\t'baseProfile',\n\t'calcMode',\n\t'clipPathUnits',\n\t'contentScriptType',\n\t'contentStyleType',\n\t'diffuseConstant',\n\t'edgeMode',\n\t'externalResourcesRequired',\n\t'filterRes',\n\t'filterUnits',\n\t'glyphRef',\n\t'gradientTransform',\n\t'gradientUnits',\n\t'kernelMatrix',\n\t'kernelUnitLength',\n\t'keyPoints',\n\t'keySplines',\n\t'keyTimes',\n\t'lengthAdjust',\n\t'limitingConeAngle',\n\t'markerHeight',\n\t'markerUnits',\n\t'markerWidth',\n\t'maskContentUnits',\n\t'maskUnits',\n\t'numOctaves',\n\t'pathLength',\n\t'patternContentUnits',\n\t'patternTransform',\n\t'patternUnits',\n\t'pointsAtX',\n\t'pointsAtY',\n\t'pointsAtZ',\n\t'preserveAlpha',\n\t'preserveAspectRatio',\n\t'primitiveUnits',\n\t'refX',\n\t'refY',\n\t'repeatCount',\n\t'repeatDur',\n\t'requiredExtensions',\n\t'requiredFeatures',\n\t'specularConstant',\n\t'specularExponent',\n\t'spreadMethod',\n\t'startOffset',\n\t'stdDeviation',\n\t'stitchTiles',\n\t'suppressContentEditableWarning',\n\t'suppressHydrationWarning',\n\t'surfaceScale',\n\t'systemLanguage',\n\t'tableValues',\n\t'targetX',\n\t'targetY',\n\t'textLength',\n\t'viewBox',\n\t'viewTarget',\n\t'xChannelSelector',\n\t'yChannelSelector',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all SVG attributes that have colons.\n * Keys are lower-cased and stripped of their colons for more robust lookup.\n */\nconst SVG_ATTRIBUTES_WITH_COLONS: Record< string, string > = [\n\t'xlink:actuate',\n\t'xlink:arcrole',\n\t'xlink:href',\n\t'xlink:role',\n\t'xlink:show',\n\t'xlink:title',\n\t'xlink:type',\n\t'xml:base',\n\t'xml:lang',\n\t'xml:space',\n\t'xmlns:xlink',\n].reduce(\n\t( map, attribute ) => {\n\t\tmap[ attribute.replace( ':', '' ).toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * Returns the normal form of the element's attribute name for HTML.\n * @param attribute\n */\nfunction getNormalAttributeName( attribute: string ): string {\n\tswitch ( attribute ) {\n\t\tcase 'htmlFor':\n\t\t\treturn 'for';\n\n\t\tcase 'className':\n\t\t\treturn 'class';\n\t}\n\tconst attributeLowerCase = attribute.toLowerCase();\n\n\tif ( CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ] ) {\n\t\treturn CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ];\n\t} else if ( SVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ] ) {\n\t\treturn kebabCase(\n\t\t\tSVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ]\n\t\t);\n\t} else if ( SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ] ) {\n\t\treturn SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ];\n\t}\n\n\treturn attributeLowerCase;\n}\n\n/**\n * Returns the normal form of the style property name for HTML.\n *\n * - Converts property names to kebab-case, e.g. 'backgroundColor' \u2192 'background-color'\n * - Leaves custom attributes alone, e.g. '--myBackgroundColor' \u2192 '--myBackgroundColor'\n * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' \u2192 '-moz-transform'\n * @param property\n */\nfunction getNormalStylePropertyName( property: string ): string {\n\tif ( property.startsWith( '--' ) ) {\n\t\treturn property;\n\t}\n\n\tif ( hasPrefix( property, [ 'ms', 'O', 'Moz', 'Webkit' ] ) ) {\n\t\treturn '-' + kebabCase( property );\n\t}\n\n\treturn kebabCase( property );\n}\n\n/**\n * Returns the normal form of the style property value for HTML. Appends a\n * default pixel unit if numeric, not a unitless property, and not zero.\n * @param property\n * @param value\n */\nfunction getNormalStylePropertyValue(\n\tproperty: string,\n\tvalue: any\n): string | number {\n\tif (\n\t\ttypeof value === 'number' &&\n\t\t0 !== value &&\n\t\t! hasPrefix( property, [ '--' ] ) &&\n\t\t! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property )\n\t) {\n\t\treturn value + 'px';\n\t}\n\n\treturn value;\n}\n\n/**\n * Serializes a React element to string.\n * @param element\n * @param context\n * @param legacyContext\n */\nexport function renderElement(\n\telement: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn '';\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn renderChildren( element, context, legacyContext );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\t\treturn escapeHTML( element );\n\n\t\tcase 'number':\n\t\t\treturn element.toString();\n\t}\n\n\tconst { type, props } = element as {\n\t\ttype?: any;\n\t\tprops?: any;\n\t};\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn renderChildren( props.children, context, legacyContext );\n\n\t\tcase RawHTML:\n\t\t\tconst { children, ...wrapperProps } = props as RawHTMLProps;\n\n\t\t\treturn renderNativeComponent(\n\t\t\t\t! Object.keys( wrapperProps ).length ? null : 'div',\n\t\t\t\t{\n\t\t\t\t\t...wrapperProps,\n\t\t\t\t\tdangerouslySetInnerHTML: { __html: children },\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\treturn renderNativeComponent( type, props, context, legacyContext );\n\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn renderComponent( type, props, context, legacyContext );\n\t\t\t}\n\n\t\t\treturn renderElement(\n\t\t\t\ttype( props, legacyContext ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( type && type.$$typeof ) {\n\t\tcase Provider.$$typeof:\n\t\t\treturn renderChildren( props.children, props.value, legacyContext );\n\n\t\tcase Consumer.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\tprops.children( context || type._currentValue ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\n\t\tcase ForwardRef.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\ttype.render( props ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\treturn '';\n}\n\n/**\n * Serializes a native component type to string.\n * @param type\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderNativeComponent(\n\ttype: string | null,\n\tprops: HTMLProps,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet content = '';\n\tif ( type === 'textarea' && props.hasOwnProperty( 'value' ) ) {\n\t\t// Textarea children can be assigned as value prop. If it is, render in\n\t\t// place of children. Ensure to omit so it is not assigned as attribute\n\t\t// as well.\n\t\tcontent = renderChildren( props.value, context, legacyContext );\n\t\tconst { value, ...restProps } = props;\n\t\tprops = restProps;\n\t} else if (\n\t\tprops.dangerouslySetInnerHTML &&\n\t\ttypeof props.dangerouslySetInnerHTML.__html === 'string'\n\t) {\n\t\t// Dangerous content is left unescaped.\n\t\tcontent = props.dangerouslySetInnerHTML.__html;\n\t} else if ( typeof props.children !== 'undefined' ) {\n\t\tcontent = renderChildren( props.children, context, legacyContext );\n\t}\n\n\tif ( ! type ) {\n\t\treturn content;\n\t}\n\n\tconst attributes = renderAttributes( props );\n\n\tif ( SELF_CLOSING_TAGS.has( type ) ) {\n\t\treturn '<' + type + attributes + '/>';\n\t}\n\n\treturn '<' + type + attributes + '>' + content + '</' + type + '>';\n}\n\n/**\n * Serializes a non-native component type to string.\n * @param Component\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderComponent(\n\tComponent: React.ComponentClass,\n\tprops: Record< string, any >,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tconst instance = new Component( props, legacyContext ) as ComponentInstance;\n\n\tif ( typeof instance.getChildContext === 'function' ) {\n\t\tObject.assign( legacyContext, instance.getChildContext() );\n\t}\n\n\tconst html = renderElement( instance.render(), context, legacyContext );\n\n\treturn html;\n}\n\n/**\n * Serializes an array of children to string.\n * @param children\n * @param context\n * @param legacyContext\n */\nfunction renderChildren(\n\tchildren: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet result = '';\n\n\tconst childrenArray = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < childrenArray.length; i++ ) {\n\t\tconst child = childrenArray[ i ];\n\n\t\tresult += renderElement( child, context, legacyContext );\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a props object as a string of HTML attributes.\n * @param props\n */\nexport function renderAttributes( props: Record< string, any > ): string {\n\tlet result = '';\n\n\tfor ( const key in props ) {\n\t\tconst attribute = getNormalAttributeName( key );\n\t\tif ( ! isValidAttributeName( attribute ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet value = getNormalAttributeValue( key, props[ key ] );\n\n\t\t// If value is not of serializable type, skip.\n\t\tif ( ! ATTRIBUTES_TYPES.has( typeof value ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Don't render internal attribute names.\n\t\tif ( isInternalAttribute( key ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isBooleanAttribute = BOOLEAN_ATTRIBUTES.has( attribute );\n\n\t\t// Boolean attribute should be omitted outright if its value is false.\n\t\tif ( isBooleanAttribute && value === false ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isMeaningfulAttribute =\n\t\t\tisBooleanAttribute ||\n\t\t\thasPrefix( key, [ 'data-', 'aria-' ] ) ||\n\t\t\tENUMERATED_ATTRIBUTES.has( attribute );\n\n\t\t// Only write boolean value as attribute if meaningful.\n\t\tif ( typeof value === 'boolean' && ! isMeaningfulAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += ' ' + attribute;\n\n\t\t// Boolean attributes should write attribute name, but without value.\n\t\t// Mere presence of attribute name is effective truthiness.\n\t\tif ( isBooleanAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( typeof value === 'string' ) {\n\t\t\tvalue = escapeAttribute( value );\n\t\t}\n\n\t\tresult += '=\"' + value + '\"';\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a style object as a string attribute value.\n * @param style\n */\nexport function renderStyle( style: StyleObject | string ): string | undefined {\n\t// Only generate from object, e.g. tolerate string value.\n\tif ( ! isPlainObject( style ) ) {\n\t\treturn style as string;\n\t}\n\n\tlet result: string | undefined;\n\n\tconst styleObj = style as StyleObject;\n\tfor ( const property in styleObj ) {\n\t\tconst value = styleObj[ property ];\n\t\tif ( null === value || undefined === value ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( result ) {\n\t\t\tresult += ';';\n\t\t} else {\n\t\t\tresult = '';\n\t\t}\n\n\t\tconst normalName = getNormalStylePropertyName( property );\n\t\tconst normalValue = getNormalStylePropertyValue( property, value );\n\t\tresult += normalName + ':' + normalValue;\n\t}\n\n\treturn result;\n}\n\nexport default renderElement;\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parts of this source were derived and modified from fast-react-render,\n * released under the MIT license.\n *\n * https://github.com/alt-j/fast-react-render\n *\n * Copyright (c) 2016 Andrey Morozov\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tescapeHTML,\n\tescapeAttribute,\n\tisValidAttributeName,\n} from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport { createContext, Fragment, StrictMode, forwardRef } from './react';\nimport RawHTML from './raw-html';\n\n/** @typedef {React.ReactElement} ReactElement */\n\nconst Context = createContext( undefined );\nContext.displayName = 'ElementContext';\n\ninterface ComponentInstance {\n\trender: () => React.ReactNode;\n\tgetChildContext?: () => Record< string, any >;\n}\n\ninterface RawHTMLProps {\n\tchildren: string;\n\t[ key: string ]: any;\n}\n\ninterface StyleObject {\n\t[ property: string ]: string | number | null | undefined;\n}\n\ninterface HTMLProps {\n\tdangerouslySetInnerHTML?: {\n\t\t__html: string;\n\t};\n\tchildren?: React.ReactNode;\n\tvalue?: React.ReactNode;\n\tstyle?: StyleObject | string;\n\tclassName?: string;\n\thtmlFor?: string;\n\t[ key: string ]: any;\n}\n\nconst { Provider, Consumer } = Context;\n\nconst ForwardRef = forwardRef( () => {\n\treturn null;\n} );\n\n/**\n * Valid attribute types.\n */\nconst ATTRIBUTES_TYPES = new Set< string >( [ 'string', 'boolean', 'number' ] );\n\n/**\n * Element tags which can be self-closing.\n */\nconst SELF_CLOSING_TAGS = new Set< string >( [\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'command',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'keygen',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n] );\n\n/**\n * Boolean attributes are attributes whose presence as being assigned is\n * meaningful, even if only empty.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n */\nconst BOOLEAN_ATTRIBUTES = new Set< string >( [\n\t'allowfullscreen',\n\t'allowpaymentrequest',\n\t'allowusermedia',\n\t'async',\n\t'autofocus',\n\t'autoplay',\n\t'checked',\n\t'controls',\n\t'default',\n\t'defer',\n\t'disabled',\n\t'download',\n\t'formnovalidate',\n\t'hidden',\n\t'ismap',\n\t'itemscope',\n\t'loop',\n\t'multiple',\n\t'muted',\n\t'nomodule',\n\t'novalidate',\n\t'open',\n\t'playsinline',\n\t'readonly',\n\t'required',\n\t'reversed',\n\t'selected',\n\t'typemustmatch',\n] );\n\n/**\n * Enumerated attributes are attributes which must be of a specific value form.\n * Like boolean attributes, these are meaningful if specified, even if not of a\n * valid enumerated value.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => /^(\"(.+?)\";?\\s*)+/.test( tr.lastChild.textContent.trim() ) )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n *\n * Some notable omissions:\n *\n * - `alt`: https://blog.whatwg.org/omit-alt\n */\nconst ENUMERATED_ATTRIBUTES = new Set< string >( [\n\t'autocapitalize',\n\t'autocomplete',\n\t'charset',\n\t'contenteditable',\n\t'crossorigin',\n\t'decoding',\n\t'dir',\n\t'draggable',\n\t'enctype',\n\t'formenctype',\n\t'formmethod',\n\t'http-equiv',\n\t'inputmode',\n\t'kind',\n\t'method',\n\t'preload',\n\t'scope',\n\t'shape',\n\t'spellcheck',\n\t'translate',\n\t'type',\n\t'wrap',\n] );\n\n/**\n * Set of CSS style properties which support assignment of unitless numbers.\n * Used in rendering of style properties, where `px` unit is assumed unless\n * property is included in this set or value is zero.\n *\n * Generated via:\n *\n * Object.entries( document.createElement( 'div' ).style )\n * .filter( ( [ key ] ) => (\n * ! /^(webkit|ms|moz)/.test( key ) &&\n * ( e.style[ key ] = 10 ) &&\n * e.style[ key ] === '10'\n * ) )\n * .map( ( [ key ] ) => key )\n * .sort();\n */\nconst CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set< string >( [\n\t'animation',\n\t'animationIterationCount',\n\t'baselineShift',\n\t'borderImageOutset',\n\t'borderImageSlice',\n\t'borderImageWidth',\n\t'columnCount',\n\t'cx',\n\t'cy',\n\t'fillOpacity',\n\t'flexGrow',\n\t'flexShrink',\n\t'floodOpacity',\n\t'fontWeight',\n\t'gridColumnEnd',\n\t'gridColumnStart',\n\t'gridRowEnd',\n\t'gridRowStart',\n\t'lineHeight',\n\t'opacity',\n\t'order',\n\t'orphans',\n\t'r',\n\t'rx',\n\t'ry',\n\t'shapeImageThreshold',\n\t'stopOpacity',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'tabSize',\n\t'widows',\n\t'x',\n\t'y',\n\t'zIndex',\n\t'zoom',\n] );\n\n/**\n * Returns true if the specified string is prefixed by one of an array of\n * possible prefixes.\n * @param string\n * @param prefixes\n */\nexport function hasPrefix( string: string, prefixes: string[] ): boolean {\n\treturn prefixes.some( ( prefix ) => string.indexOf( prefix ) === 0 );\n}\n\n/**\n * Returns true if the given prop name should be ignored in attributes\n * serialization, or false otherwise.\n * @param attribute\n */\nfunction isInternalAttribute( attribute: string ): boolean {\n\treturn 'key' === attribute || 'children' === attribute;\n}\n\n/**\n * Returns the normal form of the element's attribute value for HTML.\n * @param attribute\n * @param value\n */\nfunction getNormalAttributeValue( attribute: string, value: any ): any {\n\tswitch ( attribute ) {\n\t\tcase 'style':\n\t\t\treturn renderStyle( value );\n\t}\n\n\treturn value;\n}\n\n/**\n * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).\n * We need this to render e.g strokeWidth as stroke-width.\n *\n * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.\n */\nconst SVG_ATTRIBUTE_WITH_DASHES_LIST: Record< string, string > = [\n\t'accentHeight',\n\t'alignmentBaseline',\n\t'arabicForm',\n\t'baselineShift',\n\t'capHeight',\n\t'clipPath',\n\t'clipRule',\n\t'colorInterpolation',\n\t'colorInterpolationFilters',\n\t'colorProfile',\n\t'colorRendering',\n\t'dominantBaseline',\n\t'enableBackground',\n\t'fillOpacity',\n\t'fillRule',\n\t'floodColor',\n\t'floodOpacity',\n\t'fontFamily',\n\t'fontSize',\n\t'fontSizeAdjust',\n\t'fontStretch',\n\t'fontStyle',\n\t'fontVariant',\n\t'fontWeight',\n\t'glyphName',\n\t'glyphOrientationHorizontal',\n\t'glyphOrientationVertical',\n\t'horizAdvX',\n\t'horizOriginX',\n\t'imageRendering',\n\t'letterSpacing',\n\t'lightingColor',\n\t'markerEnd',\n\t'markerMid',\n\t'markerStart',\n\t'overlinePosition',\n\t'overlineThickness',\n\t'paintOrder',\n\t'panose1',\n\t'pointerEvents',\n\t'renderingIntent',\n\t'shapeRendering',\n\t'stopColor',\n\t'stopOpacity',\n\t'strikethroughPosition',\n\t'strikethroughThickness',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeLinecap',\n\t'strokeLinejoin',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'textAnchor',\n\t'textDecoration',\n\t'textRendering',\n\t'underlinePosition',\n\t'underlineThickness',\n\t'unicodeBidi',\n\t'unicodeRange',\n\t'unitsPerEm',\n\t'vAlphabetic',\n\t'vHanging',\n\t'vIdeographic',\n\t'vMathematical',\n\t'vectorEffect',\n\t'vertAdvY',\n\t'vertOriginX',\n\t'vertOriginY',\n\t'wordSpacing',\n\t'writingMode',\n\t'xmlnsXlink',\n\t'xHeight',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).\n * The keys are lower-cased for more robust lookup.\n * Note that this list only contains attributes that contain at least one capital letter.\n * Lowercase attributes don't need mapping, since we lowercase all attributes by default.\n */\nconst CASE_SENSITIVE_SVG_ATTRIBUTES: Record< string, string > = [\n\t'allowReorder',\n\t'attributeName',\n\t'attributeType',\n\t'autoReverse',\n\t'baseFrequency',\n\t'baseProfile',\n\t'calcMode',\n\t'clipPathUnits',\n\t'contentScriptType',\n\t'contentStyleType',\n\t'diffuseConstant',\n\t'edgeMode',\n\t'externalResourcesRequired',\n\t'filterRes',\n\t'filterUnits',\n\t'glyphRef',\n\t'gradientTransform',\n\t'gradientUnits',\n\t'kernelMatrix',\n\t'kernelUnitLength',\n\t'keyPoints',\n\t'keySplines',\n\t'keyTimes',\n\t'lengthAdjust',\n\t'limitingConeAngle',\n\t'markerHeight',\n\t'markerUnits',\n\t'markerWidth',\n\t'maskContentUnits',\n\t'maskUnits',\n\t'numOctaves',\n\t'pathLength',\n\t'patternContentUnits',\n\t'patternTransform',\n\t'patternUnits',\n\t'pointsAtX',\n\t'pointsAtY',\n\t'pointsAtZ',\n\t'preserveAlpha',\n\t'preserveAspectRatio',\n\t'primitiveUnits',\n\t'refX',\n\t'refY',\n\t'repeatCount',\n\t'repeatDur',\n\t'requiredExtensions',\n\t'requiredFeatures',\n\t'specularConstant',\n\t'specularExponent',\n\t'spreadMethod',\n\t'startOffset',\n\t'stdDeviation',\n\t'stitchTiles',\n\t'suppressContentEditableWarning',\n\t'suppressHydrationWarning',\n\t'surfaceScale',\n\t'systemLanguage',\n\t'tableValues',\n\t'targetX',\n\t'targetY',\n\t'textLength',\n\t'viewBox',\n\t'viewTarget',\n\t'xChannelSelector',\n\t'yChannelSelector',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all SVG attributes that have colons.\n * Keys are lower-cased and stripped of their colons for more robust lookup.\n */\nconst SVG_ATTRIBUTES_WITH_COLONS: Record< string, string > = [\n\t'xlink:actuate',\n\t'xlink:arcrole',\n\t'xlink:href',\n\t'xlink:role',\n\t'xlink:show',\n\t'xlink:title',\n\t'xlink:type',\n\t'xml:base',\n\t'xml:lang',\n\t'xml:space',\n\t'xmlns:xlink',\n].reduce(\n\t( map, attribute ) => {\n\t\tmap[ attribute.replace( ':', '' ).toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * Returns the normal form of the element's attribute name for HTML.\n * @param attribute\n */\nfunction getNormalAttributeName( attribute: string ): string {\n\tswitch ( attribute ) {\n\t\tcase 'htmlFor':\n\t\t\treturn 'for';\n\n\t\tcase 'className':\n\t\t\treturn 'class';\n\t}\n\tconst attributeLowerCase = attribute.toLowerCase();\n\n\tif ( CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ] ) {\n\t\treturn CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ];\n\t} else if ( SVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ] ) {\n\t\treturn kebabCase(\n\t\t\tSVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ]\n\t\t);\n\t} else if ( SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ] ) {\n\t\treturn SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ];\n\t}\n\n\treturn attributeLowerCase;\n}\n\n/**\n * Returns the normal form of the style property name for HTML.\n *\n * - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'\n * - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'\n * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'\n * @param property\n */\nfunction getNormalStylePropertyName( property: string ): string {\n\tif ( property.startsWith( '--' ) ) {\n\t\treturn property;\n\t}\n\n\tif ( hasPrefix( property, [ 'ms', 'O', 'Moz', 'Webkit' ] ) ) {\n\t\treturn '-' + kebabCase( property );\n\t}\n\n\treturn kebabCase( property );\n}\n\n/**\n * Returns the normal form of the style property value for HTML. Appends a\n * default pixel unit if numeric, not a unitless property, and not zero.\n * @param property\n * @param value\n */\nfunction getNormalStylePropertyValue(\n\tproperty: string,\n\tvalue: any\n): string | number {\n\tif (\n\t\ttypeof value === 'number' &&\n\t\t0 !== value &&\n\t\t! hasPrefix( property, [ '--' ] ) &&\n\t\t! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property )\n\t) {\n\t\treturn value + 'px';\n\t}\n\n\treturn value;\n}\n\n/**\n * Serializes a React element to string.\n * @param element\n * @param context\n * @param legacyContext\n */\nexport function renderElement(\n\telement: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn '';\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn renderChildren( element, context, legacyContext );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\t\treturn escapeHTML( element );\n\n\t\tcase 'number':\n\t\t\treturn element.toString();\n\t}\n\n\tconst { type, props } = element as {\n\t\ttype?: any;\n\t\tprops?: any;\n\t};\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn renderChildren( props.children, context, legacyContext );\n\n\t\tcase RawHTML:\n\t\t\tconst { children, ...wrapperProps } = props as RawHTMLProps;\n\n\t\t\treturn renderNativeComponent(\n\t\t\t\t! Object.keys( wrapperProps ).length ? null : 'div',\n\t\t\t\t{\n\t\t\t\t\t...wrapperProps,\n\t\t\t\t\tdangerouslySetInnerHTML: { __html: children },\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\treturn renderNativeComponent( type, props, context, legacyContext );\n\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn renderComponent( type, props, context, legacyContext );\n\t\t\t}\n\n\t\t\treturn renderElement(\n\t\t\t\ttype( props, legacyContext ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( type && type.$$typeof ) {\n\t\tcase Provider.$$typeof:\n\t\t\treturn renderChildren( props.children, props.value, legacyContext );\n\n\t\tcase Consumer.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\tprops.children( context || type._currentValue ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\n\t\tcase ForwardRef.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\ttype.render( props ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\treturn '';\n}\n\n/**\n * Serializes a native component type to string.\n * @param type\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderNativeComponent(\n\ttype: string | null,\n\tprops: HTMLProps,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet content = '';\n\tif ( type === 'textarea' && props.hasOwnProperty( 'value' ) ) {\n\t\t// Textarea children can be assigned as value prop. If it is, render in\n\t\t// place of children. Ensure to omit so it is not assigned as attribute\n\t\t// as well.\n\t\tcontent = renderChildren( props.value, context, legacyContext );\n\t\tconst { value, ...restProps } = props;\n\t\tprops = restProps;\n\t} else if (\n\t\tprops.dangerouslySetInnerHTML &&\n\t\ttypeof props.dangerouslySetInnerHTML.__html === 'string'\n\t) {\n\t\t// Dangerous content is left unescaped.\n\t\tcontent = props.dangerouslySetInnerHTML.__html;\n\t} else if ( typeof props.children !== 'undefined' ) {\n\t\tcontent = renderChildren( props.children, context, legacyContext );\n\t}\n\n\tif ( ! type ) {\n\t\treturn content;\n\t}\n\n\tconst attributes = renderAttributes( props );\n\n\tif ( SELF_CLOSING_TAGS.has( type ) ) {\n\t\treturn '<' + type + attributes + '/>';\n\t}\n\n\treturn '<' + type + attributes + '>' + content + '</' + type + '>';\n}\n\n/**\n * Serializes a non-native component type to string.\n * @param Component\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderComponent(\n\tComponent: React.ComponentClass,\n\tprops: Record< string, any >,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tconst instance = new Component( props, legacyContext ) as ComponentInstance;\n\n\tif ( typeof instance.getChildContext === 'function' ) {\n\t\tObject.assign( legacyContext, instance.getChildContext() );\n\t}\n\n\tconst html = renderElement( instance.render(), context, legacyContext );\n\n\treturn html;\n}\n\n/**\n * Serializes an array of children to string.\n * @param children\n * @param context\n * @param legacyContext\n */\nfunction renderChildren(\n\tchildren: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet result = '';\n\n\tconst childrenArray = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < childrenArray.length; i++ ) {\n\t\tconst child = childrenArray[ i ];\n\n\t\tresult += renderElement( child, context, legacyContext );\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a props object as a string of HTML attributes.\n * @param props\n */\nexport function renderAttributes( props: Record< string, any > ): string {\n\tlet result = '';\n\n\tfor ( const key in props ) {\n\t\tconst attribute = getNormalAttributeName( key );\n\t\tif ( ! isValidAttributeName( attribute ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet value = getNormalAttributeValue( key, props[ key ] );\n\n\t\t// If value is not of serializable type, skip.\n\t\tif ( ! ATTRIBUTES_TYPES.has( typeof value ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Don't render internal attribute names.\n\t\tif ( isInternalAttribute( key ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isBooleanAttribute = BOOLEAN_ATTRIBUTES.has( attribute );\n\n\t\t// Boolean attribute should be omitted outright if its value is false.\n\t\tif ( isBooleanAttribute && value === false ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isMeaningfulAttribute =\n\t\t\tisBooleanAttribute ||\n\t\t\thasPrefix( key, [ 'data-', 'aria-' ] ) ||\n\t\t\tENUMERATED_ATTRIBUTES.has( attribute );\n\n\t\t// Only write boolean value as attribute if meaningful.\n\t\tif ( typeof value === 'boolean' && ! isMeaningfulAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += ' ' + attribute;\n\n\t\t// Boolean attributes should write attribute name, but without value.\n\t\t// Mere presence of attribute name is effective truthiness.\n\t\tif ( isBooleanAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( typeof value === 'string' ) {\n\t\t\tvalue = escapeAttribute( value );\n\t\t}\n\n\t\tresult += '=\"' + value + '\"';\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a style object as a string attribute value.\n * @param style\n */\nexport function renderStyle( style: StyleObject | string ): string | undefined {\n\t// Only generate from object, e.g. tolerate string value.\n\tif ( ! isPlainObject( style ) ) {\n\t\treturn style as string;\n\t}\n\n\tlet result: string | undefined;\n\n\tconst styleObj = style as StyleObject;\n\tfor ( const property in styleObj ) {\n\t\tconst value = styleObj[ property ];\n\t\tif ( null === value || undefined === value ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( result ) {\n\t\t\tresult += ';';\n\t\t} else {\n\t\t\tresult = '';\n\t\t}\n\n\t\tconst normalName = getNormalStylePropertyName( property );\n\t\tconst normalValue = getNormalStylePropertyValue( property, value );\n\t\tresult += normalName + ':' + normalValue;\n\t}\n\n\treturn result;\n}\n\nexport default renderElement;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,6BAA8B;AAC9B,yBAAuC;AAKvC,yBAIO;AAKP,mBAAgE;AAChE,sBAAoB;AAIpB,IAAM,cAAU,4BAAe,MAAU;AACzC,QAAQ,cAAc;AA4BtB,IAAM,EAAE,UAAU,SAAS,IAAI;AAE/B,IAAM,iBAAa,yBAAY,MAAM;AACpC,SAAO;AACR,CAAE;AAKF,IAAM,mBAAmB,oBAAI,IAAe,CAAE,UAAU,WAAW,QAAS,CAAE;AAK9E,IAAM,oBAAoB,oBAAI,IAAe;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAeF,IAAM,qBAAqB,oBAAI,IAAe;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AQA,IAAM,iCAA2D;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,EAAE;AAAA,EACD,CAAE,KAAK,cAAe;AAErB,QAAK,UAAU,YAAY,CAAE,IAAI;AACjC,WAAO;AAAA,EACR;AAAA,EACA,CAAC;AACF;AAQA,IAAM,gCAA0D;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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AU,OAAO,QAAQ;AAAA,EAC1B;AAEA,SAAO;AACR;AAMO,SAAS,YAAa,OAAkD;AAE9E,MAAK,KAAE,sCAAe,KAAM,GAAI;AAC/B,WAAO;AAAA,EACR;AAEA,MAAI;AAEJ,QAAM,WAAW;AACjB,aAAY,YAAY,UAAW;AAClC,UAAM,QAAQ,SAAU,QAAS;AACjC,QAAK,SAAS,SAAS,WAAc,OAAQ;AAC5C;AAAA,IACD;AAEA,QAAK,QAAS;AACb,gBAAU;AAAA,IACX,OAAO;AACN,eAAS;AAAA,IACV;AAEA,UAAM,aAAa,2BAA4B,QAAS;AACxD,UAAM,cAAc,4BAA6B,UAAU,KAAM;AACjE,cAAU,aAAa,MAAM;AAAA,EAC9B;AAEA,SAAO;AACR;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": ["kebabCase", "RawHTML"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"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
|
|
4
|
+
"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"],
|
|
5
5
|
"mappings": ";AAAA,SAAoB,WAAXA,gBAA2C;AACpD,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAA0B;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/serialize.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Parts of this source were derived and modified from fast-react-render,\n * released under the MIT license.\n *\n * https://github.com/alt-j/fast-react-render\n *\n * Copyright (c) 2016 Andrey Morozov\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tescapeHTML,\n\tescapeAttribute,\n\tisValidAttributeName,\n} from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport { createContext, Fragment, StrictMode, forwardRef } from './react';\nimport RawHTML from './raw-html';\n\n/** @typedef {React.ReactElement} ReactElement */\n\nconst Context = createContext( undefined );\nContext.displayName = 'ElementContext';\n\ninterface ComponentInstance {\n\trender: () => React.ReactNode;\n\tgetChildContext?: () => Record< string, any >;\n}\n\ninterface RawHTMLProps {\n\tchildren: string;\n\t[ key: string ]: any;\n}\n\ninterface StyleObject {\n\t[ property: string ]: string | number | null | undefined;\n}\n\ninterface HTMLProps {\n\tdangerouslySetInnerHTML?: {\n\t\t__html: string;\n\t};\n\tchildren?: React.ReactNode;\n\tvalue?: React.ReactNode;\n\tstyle?: StyleObject | string;\n\tclassName?: string;\n\thtmlFor?: string;\n\t[ key: string ]: any;\n}\n\nconst { Provider, Consumer } = Context;\n\nconst ForwardRef = forwardRef( () => {\n\treturn null;\n} );\n\n/**\n * Valid attribute types.\n */\nconst ATTRIBUTES_TYPES = new Set< string >( [ 'string', 'boolean', 'number' ] );\n\n/**\n * Element tags which can be self-closing.\n */\nconst SELF_CLOSING_TAGS = new Set< string >( [\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'command',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'keygen',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n] );\n\n/**\n * Boolean attributes are attributes whose presence as being assigned is\n * meaningful, even if only empty.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n */\nconst BOOLEAN_ATTRIBUTES = new Set< string >( [\n\t'allowfullscreen',\n\t'allowpaymentrequest',\n\t'allowusermedia',\n\t'async',\n\t'autofocus',\n\t'autoplay',\n\t'checked',\n\t'controls',\n\t'default',\n\t'defer',\n\t'disabled',\n\t'download',\n\t'formnovalidate',\n\t'hidden',\n\t'ismap',\n\t'itemscope',\n\t'loop',\n\t'multiple',\n\t'muted',\n\t'nomodule',\n\t'novalidate',\n\t'open',\n\t'playsinline',\n\t'readonly',\n\t'required',\n\t'reversed',\n\t'selected',\n\t'typemustmatch',\n] );\n\n/**\n * Enumerated attributes are attributes which must be of a specific value form.\n * Like boolean attributes, these are meaningful if specified, even if not of a\n * valid enumerated value.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => /^(\"(.+?)\";?\\s*)+/.test( tr.lastChild.textContent.trim() ) )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n *\n * Some notable omissions:\n *\n * - `alt`: https://blog.whatwg.org/omit-alt\n */\nconst ENUMERATED_ATTRIBUTES = new Set< string >( [\n\t'autocapitalize',\n\t'autocomplete',\n\t'charset',\n\t'contenteditable',\n\t'crossorigin',\n\t'decoding',\n\t'dir',\n\t'draggable',\n\t'enctype',\n\t'formenctype',\n\t'formmethod',\n\t'http-equiv',\n\t'inputmode',\n\t'kind',\n\t'method',\n\t'preload',\n\t'scope',\n\t'shape',\n\t'spellcheck',\n\t'translate',\n\t'type',\n\t'wrap',\n] );\n\n/**\n * Set of CSS style properties which support assignment of unitless numbers.\n * Used in rendering of style properties, where `px` unit is assumed unless\n * property is included in this set or value is zero.\n *\n * Generated via:\n *\n * Object.entries( document.createElement( 'div' ).style )\n * .filter( ( [ key ] ) => (\n * ! /^(webkit|ms|moz)/.test( key ) &&\n * ( e.style[ key ] = 10 ) &&\n * e.style[ key ] === '10'\n * ) )\n * .map( ( [ key ] ) => key )\n * .sort();\n */\nconst CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set< string >( [\n\t'animation',\n\t'animationIterationCount',\n\t'baselineShift',\n\t'borderImageOutset',\n\t'borderImageSlice',\n\t'borderImageWidth',\n\t'columnCount',\n\t'cx',\n\t'cy',\n\t'fillOpacity',\n\t'flexGrow',\n\t'flexShrink',\n\t'floodOpacity',\n\t'fontWeight',\n\t'gridColumnEnd',\n\t'gridColumnStart',\n\t'gridRowEnd',\n\t'gridRowStart',\n\t'lineHeight',\n\t'opacity',\n\t'order',\n\t'orphans',\n\t'r',\n\t'rx',\n\t'ry',\n\t'shapeImageThreshold',\n\t'stopOpacity',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'tabSize',\n\t'widows',\n\t'x',\n\t'y',\n\t'zIndex',\n\t'zoom',\n] );\n\n/**\n * Returns true if the specified string is prefixed by one of an array of\n * possible prefixes.\n * @param string\n * @param prefixes\n */\nexport function hasPrefix( string: string, prefixes: string[] ): boolean {\n\treturn prefixes.some( ( prefix ) => string.indexOf( prefix ) === 0 );\n}\n\n/**\n * Returns true if the given prop name should be ignored in attributes\n * serialization, or false otherwise.\n * @param attribute\n */\nfunction isInternalAttribute( attribute: string ): boolean {\n\treturn 'key' === attribute || 'children' === attribute;\n}\n\n/**\n * Returns the normal form of the element's attribute value for HTML.\n * @param attribute\n * @param value\n */\nfunction getNormalAttributeValue( attribute: string, value: any ): any {\n\tswitch ( attribute ) {\n\t\tcase 'style':\n\t\t\treturn renderStyle( value );\n\t}\n\n\treturn value;\n}\n\n/**\n * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).\n * We need this to render e.g strokeWidth as stroke-width.\n *\n * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.\n */\nconst SVG_ATTRIBUTE_WITH_DASHES_LIST: Record< string, string > = [\n\t'accentHeight',\n\t'alignmentBaseline',\n\t'arabicForm',\n\t'baselineShift',\n\t'capHeight',\n\t'clipPath',\n\t'clipRule',\n\t'colorInterpolation',\n\t'colorInterpolationFilters',\n\t'colorProfile',\n\t'colorRendering',\n\t'dominantBaseline',\n\t'enableBackground',\n\t'fillOpacity',\n\t'fillRule',\n\t'floodColor',\n\t'floodOpacity',\n\t'fontFamily',\n\t'fontSize',\n\t'fontSizeAdjust',\n\t'fontStretch',\n\t'fontStyle',\n\t'fontVariant',\n\t'fontWeight',\n\t'glyphName',\n\t'glyphOrientationHorizontal',\n\t'glyphOrientationVertical',\n\t'horizAdvX',\n\t'horizOriginX',\n\t'imageRendering',\n\t'letterSpacing',\n\t'lightingColor',\n\t'markerEnd',\n\t'markerMid',\n\t'markerStart',\n\t'overlinePosition',\n\t'overlineThickness',\n\t'paintOrder',\n\t'panose1',\n\t'pointerEvents',\n\t'renderingIntent',\n\t'shapeRendering',\n\t'stopColor',\n\t'stopOpacity',\n\t'strikethroughPosition',\n\t'strikethroughThickness',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeLinecap',\n\t'strokeLinejoin',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'textAnchor',\n\t'textDecoration',\n\t'textRendering',\n\t'underlinePosition',\n\t'underlineThickness',\n\t'unicodeBidi',\n\t'unicodeRange',\n\t'unitsPerEm',\n\t'vAlphabetic',\n\t'vHanging',\n\t'vIdeographic',\n\t'vMathematical',\n\t'vectorEffect',\n\t'vertAdvY',\n\t'vertOriginX',\n\t'vertOriginY',\n\t'wordSpacing',\n\t'writingMode',\n\t'xmlnsXlink',\n\t'xHeight',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).\n * The keys are lower-cased for more robust lookup.\n * Note that this list only contains attributes that contain at least one capital letter.\n * Lowercase attributes don't need mapping, since we lowercase all attributes by default.\n */\nconst CASE_SENSITIVE_SVG_ATTRIBUTES: Record< string, string > = [\n\t'allowReorder',\n\t'attributeName',\n\t'attributeType',\n\t'autoReverse',\n\t'baseFrequency',\n\t'baseProfile',\n\t'calcMode',\n\t'clipPathUnits',\n\t'contentScriptType',\n\t'contentStyleType',\n\t'diffuseConstant',\n\t'edgeMode',\n\t'externalResourcesRequired',\n\t'filterRes',\n\t'filterUnits',\n\t'glyphRef',\n\t'gradientTransform',\n\t'gradientUnits',\n\t'kernelMatrix',\n\t'kernelUnitLength',\n\t'keyPoints',\n\t'keySplines',\n\t'keyTimes',\n\t'lengthAdjust',\n\t'limitingConeAngle',\n\t'markerHeight',\n\t'markerUnits',\n\t'markerWidth',\n\t'maskContentUnits',\n\t'maskUnits',\n\t'numOctaves',\n\t'pathLength',\n\t'patternContentUnits',\n\t'patternTransform',\n\t'patternUnits',\n\t'pointsAtX',\n\t'pointsAtY',\n\t'pointsAtZ',\n\t'preserveAlpha',\n\t'preserveAspectRatio',\n\t'primitiveUnits',\n\t'refX',\n\t'refY',\n\t'repeatCount',\n\t'repeatDur',\n\t'requiredExtensions',\n\t'requiredFeatures',\n\t'specularConstant',\n\t'specularExponent',\n\t'spreadMethod',\n\t'startOffset',\n\t'stdDeviation',\n\t'stitchTiles',\n\t'suppressContentEditableWarning',\n\t'suppressHydrationWarning',\n\t'surfaceScale',\n\t'systemLanguage',\n\t'tableValues',\n\t'targetX',\n\t'targetY',\n\t'textLength',\n\t'viewBox',\n\t'viewTarget',\n\t'xChannelSelector',\n\t'yChannelSelector',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all SVG attributes that have colons.\n * Keys are lower-cased and stripped of their colons for more robust lookup.\n */\nconst SVG_ATTRIBUTES_WITH_COLONS: Record< string, string > = [\n\t'xlink:actuate',\n\t'xlink:arcrole',\n\t'xlink:href',\n\t'xlink:role',\n\t'xlink:show',\n\t'xlink:title',\n\t'xlink:type',\n\t'xml:base',\n\t'xml:lang',\n\t'xml:space',\n\t'xmlns:xlink',\n].reduce(\n\t( map, attribute ) => {\n\t\tmap[ attribute.replace( ':', '' ).toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * Returns the normal form of the element's attribute name for HTML.\n * @param attribute\n */\nfunction getNormalAttributeName( attribute: string ): string {\n\tswitch ( attribute ) {\n\t\tcase 'htmlFor':\n\t\t\treturn 'for';\n\n\t\tcase 'className':\n\t\t\treturn 'class';\n\t}\n\tconst attributeLowerCase = attribute.toLowerCase();\n\n\tif ( CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ] ) {\n\t\treturn CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ];\n\t} else if ( SVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ] ) {\n\t\treturn kebabCase(\n\t\t\tSVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ]\n\t\t);\n\t} else if ( SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ] ) {\n\t\treturn SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ];\n\t}\n\n\treturn attributeLowerCase;\n}\n\n/**\n * Returns the normal form of the style property name for HTML.\n *\n * - Converts property names to kebab-case, e.g. 'backgroundColor' \u2192 'background-color'\n * - Leaves custom attributes alone, e.g. '--myBackgroundColor' \u2192 '--myBackgroundColor'\n * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' \u2192 '-moz-transform'\n * @param property\n */\nfunction getNormalStylePropertyName( property: string ): string {\n\tif ( property.startsWith( '--' ) ) {\n\t\treturn property;\n\t}\n\n\tif ( hasPrefix( property, [ 'ms', 'O', 'Moz', 'Webkit' ] ) ) {\n\t\treturn '-' + kebabCase( property );\n\t}\n\n\treturn kebabCase( property );\n}\n\n/**\n * Returns the normal form of the style property value for HTML. Appends a\n * default pixel unit if numeric, not a unitless property, and not zero.\n * @param property\n * @param value\n */\nfunction getNormalStylePropertyValue(\n\tproperty: string,\n\tvalue: any\n): string | number {\n\tif (\n\t\ttypeof value === 'number' &&\n\t\t0 !== value &&\n\t\t! hasPrefix( property, [ '--' ] ) &&\n\t\t! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property )\n\t) {\n\t\treturn value + 'px';\n\t}\n\n\treturn value;\n}\n\n/**\n * Serializes a React element to string.\n * @param element\n * @param context\n * @param legacyContext\n */\nexport function renderElement(\n\telement: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn '';\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn renderChildren( element, context, legacyContext );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\t\treturn escapeHTML( element );\n\n\t\tcase 'number':\n\t\t\treturn element.toString();\n\t}\n\n\tconst { type, props } = element as {\n\t\ttype?: any;\n\t\tprops?: any;\n\t};\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn renderChildren( props.children, context, legacyContext );\n\n\t\tcase RawHTML:\n\t\t\tconst { children, ...wrapperProps } = props as RawHTMLProps;\n\n\t\t\treturn renderNativeComponent(\n\t\t\t\t! Object.keys( wrapperProps ).length ? null : 'div',\n\t\t\t\t{\n\t\t\t\t\t...wrapperProps,\n\t\t\t\t\tdangerouslySetInnerHTML: { __html: children },\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\treturn renderNativeComponent( type, props, context, legacyContext );\n\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn renderComponent( type, props, context, legacyContext );\n\t\t\t}\n\n\t\t\treturn renderElement(\n\t\t\t\ttype( props, legacyContext ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( type && type.$$typeof ) {\n\t\tcase Provider.$$typeof:\n\t\t\treturn renderChildren( props.children, props.value, legacyContext );\n\n\t\tcase Consumer.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\tprops.children( context || type._currentValue ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\n\t\tcase ForwardRef.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\ttype.render( props ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\treturn '';\n}\n\n/**\n * Serializes a native component type to string.\n * @param type\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderNativeComponent(\n\ttype: string | null,\n\tprops: HTMLProps,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet content = '';\n\tif ( type === 'textarea' && props.hasOwnProperty( 'value' ) ) {\n\t\t// Textarea children can be assigned as value prop. If it is, render in\n\t\t// place of children. Ensure to omit so it is not assigned as attribute\n\t\t// as well.\n\t\tcontent = renderChildren( props.value, context, legacyContext );\n\t\tconst { value, ...restProps } = props;\n\t\tprops = restProps;\n\t} else if (\n\t\tprops.dangerouslySetInnerHTML &&\n\t\ttypeof props.dangerouslySetInnerHTML.__html === 'string'\n\t) {\n\t\t// Dangerous content is left unescaped.\n\t\tcontent = props.dangerouslySetInnerHTML.__html;\n\t} else if ( typeof props.children !== 'undefined' ) {\n\t\tcontent = renderChildren( props.children, context, legacyContext );\n\t}\n\n\tif ( ! type ) {\n\t\treturn content;\n\t}\n\n\tconst attributes = renderAttributes( props );\n\n\tif ( SELF_CLOSING_TAGS.has( type ) ) {\n\t\treturn '<' + type + attributes + '/>';\n\t}\n\n\treturn '<' + type + attributes + '>' + content + '</' + type + '>';\n}\n\n/**\n * Serializes a non-native component type to string.\n * @param Component\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderComponent(\n\tComponent: React.ComponentClass,\n\tprops: Record< string, any >,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tconst instance = new Component( props, legacyContext ) as ComponentInstance;\n\n\tif ( typeof instance.getChildContext === 'function' ) {\n\t\tObject.assign( legacyContext, instance.getChildContext() );\n\t}\n\n\tconst html = renderElement( instance.render(), context, legacyContext );\n\n\treturn html;\n}\n\n/**\n * Serializes an array of children to string.\n * @param children\n * @param context\n * @param legacyContext\n */\nfunction renderChildren(\n\tchildren: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet result = '';\n\n\tconst childrenArray = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < childrenArray.length; i++ ) {\n\t\tconst child = childrenArray[ i ];\n\n\t\tresult += renderElement( child, context, legacyContext );\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a props object as a string of HTML attributes.\n * @param props\n */\nexport function renderAttributes( props: Record< string, any > ): string {\n\tlet result = '';\n\n\tfor ( const key in props ) {\n\t\tconst attribute = getNormalAttributeName( key );\n\t\tif ( ! isValidAttributeName( attribute ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet value = getNormalAttributeValue( key, props[ key ] );\n\n\t\t// If value is not of serializable type, skip.\n\t\tif ( ! ATTRIBUTES_TYPES.has( typeof value ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Don't render internal attribute names.\n\t\tif ( isInternalAttribute( key ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isBooleanAttribute = BOOLEAN_ATTRIBUTES.has( attribute );\n\n\t\t// Boolean attribute should be omitted outright if its value is false.\n\t\tif ( isBooleanAttribute && value === false ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isMeaningfulAttribute =\n\t\t\tisBooleanAttribute ||\n\t\t\thasPrefix( key, [ 'data-', 'aria-' ] ) ||\n\t\t\tENUMERATED_ATTRIBUTES.has( attribute );\n\n\t\t// Only write boolean value as attribute if meaningful.\n\t\tif ( typeof value === 'boolean' && ! isMeaningfulAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += ' ' + attribute;\n\n\t\t// Boolean attributes should write attribute name, but without value.\n\t\t// Mere presence of attribute name is effective truthiness.\n\t\tif ( isBooleanAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( typeof value === 'string' ) {\n\t\t\tvalue = escapeAttribute( value );\n\t\t}\n\n\t\tresult += '=\"' + value + '\"';\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a style object as a string attribute value.\n * @param style\n */\nexport function renderStyle( style: StyleObject | string ): string | undefined {\n\t// Only generate from object, e.g. tolerate string value.\n\tif ( ! isPlainObject( style ) ) {\n\t\treturn style as string;\n\t}\n\n\tlet result: string | undefined;\n\n\tconst styleObj = style as StyleObject;\n\tfor ( const property in styleObj ) {\n\t\tconst value = styleObj[ property ];\n\t\tif ( null === value || undefined === value ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( result ) {\n\t\t\tresult += ';';\n\t\t} else {\n\t\t\tresult = '';\n\t\t}\n\n\t\tconst normalName = getNormalStylePropertyName( property );\n\t\tconst normalValue = getNormalStylePropertyValue( property, value );\n\t\tresult += normalName + ':' + normalValue;\n\t}\n\n\treturn result;\n}\n\nexport default renderElement;\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parts of this source were derived and modified from fast-react-render,\n * released under the MIT license.\n *\n * https://github.com/alt-j/fast-react-render\n *\n * Copyright (c) 2016 Andrey Morozov\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tescapeHTML,\n\tescapeAttribute,\n\tisValidAttributeName,\n} from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport { createContext, Fragment, StrictMode, forwardRef } from './react';\nimport RawHTML from './raw-html';\n\n/** @typedef {React.ReactElement} ReactElement */\n\nconst Context = createContext( undefined );\nContext.displayName = 'ElementContext';\n\ninterface ComponentInstance {\n\trender: () => React.ReactNode;\n\tgetChildContext?: () => Record< string, any >;\n}\n\ninterface RawHTMLProps {\n\tchildren: string;\n\t[ key: string ]: any;\n}\n\ninterface StyleObject {\n\t[ property: string ]: string | number | null | undefined;\n}\n\ninterface HTMLProps {\n\tdangerouslySetInnerHTML?: {\n\t\t__html: string;\n\t};\n\tchildren?: React.ReactNode;\n\tvalue?: React.ReactNode;\n\tstyle?: StyleObject | string;\n\tclassName?: string;\n\thtmlFor?: string;\n\t[ key: string ]: any;\n}\n\nconst { Provider, Consumer } = Context;\n\nconst ForwardRef = forwardRef( () => {\n\treturn null;\n} );\n\n/**\n * Valid attribute types.\n */\nconst ATTRIBUTES_TYPES = new Set< string >( [ 'string', 'boolean', 'number' ] );\n\n/**\n * Element tags which can be self-closing.\n */\nconst SELF_CLOSING_TAGS = new Set< string >( [\n\t'area',\n\t'base',\n\t'br',\n\t'col',\n\t'command',\n\t'embed',\n\t'hr',\n\t'img',\n\t'input',\n\t'keygen',\n\t'link',\n\t'meta',\n\t'param',\n\t'source',\n\t'track',\n\t'wbr',\n] );\n\n/**\n * Boolean attributes are attributes whose presence as being assigned is\n * meaningful, even if only empty.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n */\nconst BOOLEAN_ATTRIBUTES = new Set< string >( [\n\t'allowfullscreen',\n\t'allowpaymentrequest',\n\t'allowusermedia',\n\t'async',\n\t'autofocus',\n\t'autoplay',\n\t'checked',\n\t'controls',\n\t'default',\n\t'defer',\n\t'disabled',\n\t'download',\n\t'formnovalidate',\n\t'hidden',\n\t'ismap',\n\t'itemscope',\n\t'loop',\n\t'multiple',\n\t'muted',\n\t'nomodule',\n\t'novalidate',\n\t'open',\n\t'playsinline',\n\t'readonly',\n\t'required',\n\t'reversed',\n\t'selected',\n\t'typemustmatch',\n] );\n\n/**\n * Enumerated attributes are attributes which must be of a specific value form.\n * Like boolean attributes, these are meaningful if specified, even if not of a\n * valid enumerated value.\n *\n * See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute\n * Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n *\n * Object.keys( [ ...document.querySelectorAll( '#attributes-1 > tbody > tr' ) ]\n * .filter( ( tr ) => /^(\"(.+?)\";?\\s*)+/.test( tr.lastChild.textContent.trim() ) )\n * .reduce( ( result, tr ) => Object.assign( result, {\n * [ tr.firstChild.textContent.trim() ]: true\n * } ), {} ) ).sort();\n *\n * Some notable omissions:\n *\n * - `alt`: https://blog.whatwg.org/omit-alt\n */\nconst ENUMERATED_ATTRIBUTES = new Set< string >( [\n\t'autocapitalize',\n\t'autocomplete',\n\t'charset',\n\t'contenteditable',\n\t'crossorigin',\n\t'decoding',\n\t'dir',\n\t'draggable',\n\t'enctype',\n\t'formenctype',\n\t'formmethod',\n\t'http-equiv',\n\t'inputmode',\n\t'kind',\n\t'method',\n\t'preload',\n\t'scope',\n\t'shape',\n\t'spellcheck',\n\t'translate',\n\t'type',\n\t'wrap',\n] );\n\n/**\n * Set of CSS style properties which support assignment of unitless numbers.\n * Used in rendering of style properties, where `px` unit is assumed unless\n * property is included in this set or value is zero.\n *\n * Generated via:\n *\n * Object.entries( document.createElement( 'div' ).style )\n * .filter( ( [ key ] ) => (\n * ! /^(webkit|ms|moz)/.test( key ) &&\n * ( e.style[ key ] = 10 ) &&\n * e.style[ key ] === '10'\n * ) )\n * .map( ( [ key ] ) => key )\n * .sort();\n */\nconst CSS_PROPERTIES_SUPPORTS_UNITLESS = new Set< string >( [\n\t'animation',\n\t'animationIterationCount',\n\t'baselineShift',\n\t'borderImageOutset',\n\t'borderImageSlice',\n\t'borderImageWidth',\n\t'columnCount',\n\t'cx',\n\t'cy',\n\t'fillOpacity',\n\t'flexGrow',\n\t'flexShrink',\n\t'floodOpacity',\n\t'fontWeight',\n\t'gridColumnEnd',\n\t'gridColumnStart',\n\t'gridRowEnd',\n\t'gridRowStart',\n\t'lineHeight',\n\t'opacity',\n\t'order',\n\t'orphans',\n\t'r',\n\t'rx',\n\t'ry',\n\t'shapeImageThreshold',\n\t'stopOpacity',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'tabSize',\n\t'widows',\n\t'x',\n\t'y',\n\t'zIndex',\n\t'zoom',\n] );\n\n/**\n * Returns true if the specified string is prefixed by one of an array of\n * possible prefixes.\n * @param string\n * @param prefixes\n */\nexport function hasPrefix( string: string, prefixes: string[] ): boolean {\n\treturn prefixes.some( ( prefix ) => string.indexOf( prefix ) === 0 );\n}\n\n/**\n * Returns true if the given prop name should be ignored in attributes\n * serialization, or false otherwise.\n * @param attribute\n */\nfunction isInternalAttribute( attribute: string ): boolean {\n\treturn 'key' === attribute || 'children' === attribute;\n}\n\n/**\n * Returns the normal form of the element's attribute value for HTML.\n * @param attribute\n * @param value\n */\nfunction getNormalAttributeValue( attribute: string, value: any ): any {\n\tswitch ( attribute ) {\n\t\tcase 'style':\n\t\t\treturn renderStyle( value );\n\t}\n\n\treturn value;\n}\n\n/**\n * This is a map of all SVG attributes that have dashes. Map(lower case prop => dashed lower case attribute).\n * We need this to render e.g strokeWidth as stroke-width.\n *\n * List from: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute.\n */\nconst SVG_ATTRIBUTE_WITH_DASHES_LIST: Record< string, string > = [\n\t'accentHeight',\n\t'alignmentBaseline',\n\t'arabicForm',\n\t'baselineShift',\n\t'capHeight',\n\t'clipPath',\n\t'clipRule',\n\t'colorInterpolation',\n\t'colorInterpolationFilters',\n\t'colorProfile',\n\t'colorRendering',\n\t'dominantBaseline',\n\t'enableBackground',\n\t'fillOpacity',\n\t'fillRule',\n\t'floodColor',\n\t'floodOpacity',\n\t'fontFamily',\n\t'fontSize',\n\t'fontSizeAdjust',\n\t'fontStretch',\n\t'fontStyle',\n\t'fontVariant',\n\t'fontWeight',\n\t'glyphName',\n\t'glyphOrientationHorizontal',\n\t'glyphOrientationVertical',\n\t'horizAdvX',\n\t'horizOriginX',\n\t'imageRendering',\n\t'letterSpacing',\n\t'lightingColor',\n\t'markerEnd',\n\t'markerMid',\n\t'markerStart',\n\t'overlinePosition',\n\t'overlineThickness',\n\t'paintOrder',\n\t'panose1',\n\t'pointerEvents',\n\t'renderingIntent',\n\t'shapeRendering',\n\t'stopColor',\n\t'stopOpacity',\n\t'strikethroughPosition',\n\t'strikethroughThickness',\n\t'strokeDasharray',\n\t'strokeDashoffset',\n\t'strokeLinecap',\n\t'strokeLinejoin',\n\t'strokeMiterlimit',\n\t'strokeOpacity',\n\t'strokeWidth',\n\t'textAnchor',\n\t'textDecoration',\n\t'textRendering',\n\t'underlinePosition',\n\t'underlineThickness',\n\t'unicodeBidi',\n\t'unicodeRange',\n\t'unitsPerEm',\n\t'vAlphabetic',\n\t'vHanging',\n\t'vIdeographic',\n\t'vMathematical',\n\t'vectorEffect',\n\t'vertAdvY',\n\t'vertOriginX',\n\t'vertOriginY',\n\t'wordSpacing',\n\t'writingMode',\n\t'xmlnsXlink',\n\t'xHeight',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all case-sensitive SVG attributes. Map(lowercase key => proper case attribute).\n * The keys are lower-cased for more robust lookup.\n * Note that this list only contains attributes that contain at least one capital letter.\n * Lowercase attributes don't need mapping, since we lowercase all attributes by default.\n */\nconst CASE_SENSITIVE_SVG_ATTRIBUTES: Record< string, string > = [\n\t'allowReorder',\n\t'attributeName',\n\t'attributeType',\n\t'autoReverse',\n\t'baseFrequency',\n\t'baseProfile',\n\t'calcMode',\n\t'clipPathUnits',\n\t'contentScriptType',\n\t'contentStyleType',\n\t'diffuseConstant',\n\t'edgeMode',\n\t'externalResourcesRequired',\n\t'filterRes',\n\t'filterUnits',\n\t'glyphRef',\n\t'gradientTransform',\n\t'gradientUnits',\n\t'kernelMatrix',\n\t'kernelUnitLength',\n\t'keyPoints',\n\t'keySplines',\n\t'keyTimes',\n\t'lengthAdjust',\n\t'limitingConeAngle',\n\t'markerHeight',\n\t'markerUnits',\n\t'markerWidth',\n\t'maskContentUnits',\n\t'maskUnits',\n\t'numOctaves',\n\t'pathLength',\n\t'patternContentUnits',\n\t'patternTransform',\n\t'patternUnits',\n\t'pointsAtX',\n\t'pointsAtY',\n\t'pointsAtZ',\n\t'preserveAlpha',\n\t'preserveAspectRatio',\n\t'primitiveUnits',\n\t'refX',\n\t'refY',\n\t'repeatCount',\n\t'repeatDur',\n\t'requiredExtensions',\n\t'requiredFeatures',\n\t'specularConstant',\n\t'specularExponent',\n\t'spreadMethod',\n\t'startOffset',\n\t'stdDeviation',\n\t'stitchTiles',\n\t'suppressContentEditableWarning',\n\t'suppressHydrationWarning',\n\t'surfaceScale',\n\t'systemLanguage',\n\t'tableValues',\n\t'targetX',\n\t'targetY',\n\t'textLength',\n\t'viewBox',\n\t'viewTarget',\n\t'xChannelSelector',\n\t'yChannelSelector',\n].reduce(\n\t( map, attribute ) => {\n\t\t// The keys are lower-cased for more robust lookup.\n\t\tmap[ attribute.toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * This is a map of all SVG attributes that have colons.\n * Keys are lower-cased and stripped of their colons for more robust lookup.\n */\nconst SVG_ATTRIBUTES_WITH_COLONS: Record< string, string > = [\n\t'xlink:actuate',\n\t'xlink:arcrole',\n\t'xlink:href',\n\t'xlink:role',\n\t'xlink:show',\n\t'xlink:title',\n\t'xlink:type',\n\t'xml:base',\n\t'xml:lang',\n\t'xml:space',\n\t'xmlns:xlink',\n].reduce(\n\t( map, attribute ) => {\n\t\tmap[ attribute.replace( ':', '' ).toLowerCase() ] = attribute;\n\t\treturn map;\n\t},\n\t{} as Record< string, string >\n);\n\n/**\n * Returns the normal form of the element's attribute name for HTML.\n * @param attribute\n */\nfunction getNormalAttributeName( attribute: string ): string {\n\tswitch ( attribute ) {\n\t\tcase 'htmlFor':\n\t\t\treturn 'for';\n\n\t\tcase 'className':\n\t\t\treturn 'class';\n\t}\n\tconst attributeLowerCase = attribute.toLowerCase();\n\n\tif ( CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ] ) {\n\t\treturn CASE_SENSITIVE_SVG_ATTRIBUTES[ attributeLowerCase ];\n\t} else if ( SVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ] ) {\n\t\treturn kebabCase(\n\t\t\tSVG_ATTRIBUTE_WITH_DASHES_LIST[ attributeLowerCase ]\n\t\t);\n\t} else if ( SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ] ) {\n\t\treturn SVG_ATTRIBUTES_WITH_COLONS[ attributeLowerCase ];\n\t}\n\n\treturn attributeLowerCase;\n}\n\n/**\n * Returns the normal form of the style property name for HTML.\n *\n * - Converts property names to kebab-case, e.g. 'backgroundColor' → 'background-color'\n * - Leaves custom attributes alone, e.g. '--myBackgroundColor' → '--myBackgroundColor'\n * - Converts vendor-prefixed property names to -kebab-case, e.g. 'MozTransform' → '-moz-transform'\n * @param property\n */\nfunction getNormalStylePropertyName( property: string ): string {\n\tif ( property.startsWith( '--' ) ) {\n\t\treturn property;\n\t}\n\n\tif ( hasPrefix( property, [ 'ms', 'O', 'Moz', 'Webkit' ] ) ) {\n\t\treturn '-' + kebabCase( property );\n\t}\n\n\treturn kebabCase( property );\n}\n\n/**\n * Returns the normal form of the style property value for HTML. Appends a\n * default pixel unit if numeric, not a unitless property, and not zero.\n * @param property\n * @param value\n */\nfunction getNormalStylePropertyValue(\n\tproperty: string,\n\tvalue: any\n): string | number {\n\tif (\n\t\ttypeof value === 'number' &&\n\t\t0 !== value &&\n\t\t! hasPrefix( property, [ '--' ] ) &&\n\t\t! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property )\n\t) {\n\t\treturn value + 'px';\n\t}\n\n\treturn value;\n}\n\n/**\n * Serializes a React element to string.\n * @param element\n * @param context\n * @param legacyContext\n */\nexport function renderElement(\n\telement: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn '';\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn renderChildren( element, context, legacyContext );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\t\treturn escapeHTML( element );\n\n\t\tcase 'number':\n\t\t\treturn element.toString();\n\t}\n\n\tconst { type, props } = element as {\n\t\ttype?: any;\n\t\tprops?: any;\n\t};\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn renderChildren( props.children, context, legacyContext );\n\n\t\tcase RawHTML:\n\t\t\tconst { children, ...wrapperProps } = props as RawHTMLProps;\n\n\t\t\treturn renderNativeComponent(\n\t\t\t\t! Object.keys( wrapperProps ).length ? null : 'div',\n\t\t\t\t{\n\t\t\t\t\t...wrapperProps,\n\t\t\t\t\tdangerouslySetInnerHTML: { __html: children },\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\treturn renderNativeComponent( type, props, context, legacyContext );\n\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn renderComponent( type, props, context, legacyContext );\n\t\t\t}\n\n\t\t\treturn renderElement(\n\t\t\t\ttype( props, legacyContext ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\tswitch ( type && type.$$typeof ) {\n\t\tcase Provider.$$typeof:\n\t\t\treturn renderChildren( props.children, props.value, legacyContext );\n\n\t\tcase Consumer.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\tprops.children( context || type._currentValue ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\n\t\tcase ForwardRef.$$typeof:\n\t\t\treturn renderElement(\n\t\t\t\ttype.render( props ),\n\t\t\t\tcontext,\n\t\t\t\tlegacyContext\n\t\t\t);\n\t}\n\n\treturn '';\n}\n\n/**\n * Serializes a native component type to string.\n * @param type\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderNativeComponent(\n\ttype: string | null,\n\tprops: HTMLProps,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet content = '';\n\tif ( type === 'textarea' && props.hasOwnProperty( 'value' ) ) {\n\t\t// Textarea children can be assigned as value prop. If it is, render in\n\t\t// place of children. Ensure to omit so it is not assigned as attribute\n\t\t// as well.\n\t\tcontent = renderChildren( props.value, context, legacyContext );\n\t\tconst { value, ...restProps } = props;\n\t\tprops = restProps;\n\t} else if (\n\t\tprops.dangerouslySetInnerHTML &&\n\t\ttypeof props.dangerouslySetInnerHTML.__html === 'string'\n\t) {\n\t\t// Dangerous content is left unescaped.\n\t\tcontent = props.dangerouslySetInnerHTML.__html;\n\t} else if ( typeof props.children !== 'undefined' ) {\n\t\tcontent = renderChildren( props.children, context, legacyContext );\n\t}\n\n\tif ( ! type ) {\n\t\treturn content;\n\t}\n\n\tconst attributes = renderAttributes( props );\n\n\tif ( SELF_CLOSING_TAGS.has( type ) ) {\n\t\treturn '<' + type + attributes + '/>';\n\t}\n\n\treturn '<' + type + attributes + '>' + content + '</' + type + '>';\n}\n\n/**\n * Serializes a non-native component type to string.\n * @param Component\n * @param props\n * @param context\n * @param legacyContext\n */\nexport function renderComponent(\n\tComponent: React.ComponentClass,\n\tprops: Record< string, any >,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tconst instance = new Component( props, legacyContext ) as ComponentInstance;\n\n\tif ( typeof instance.getChildContext === 'function' ) {\n\t\tObject.assign( legacyContext, instance.getChildContext() );\n\t}\n\n\tconst html = renderElement( instance.render(), context, legacyContext );\n\n\treturn html;\n}\n\n/**\n * Serializes an array of children to string.\n * @param children\n * @param context\n * @param legacyContext\n */\nfunction renderChildren(\n\tchildren: React.ReactNode,\n\tcontext?: any,\n\tlegacyContext: Record< string, any > = {}\n): string {\n\tlet result = '';\n\n\tconst childrenArray = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < childrenArray.length; i++ ) {\n\t\tconst child = childrenArray[ i ];\n\n\t\tresult += renderElement( child, context, legacyContext );\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a props object as a string of HTML attributes.\n * @param props\n */\nexport function renderAttributes( props: Record< string, any > ): string {\n\tlet result = '';\n\n\tfor ( const key in props ) {\n\t\tconst attribute = getNormalAttributeName( key );\n\t\tif ( ! isValidAttributeName( attribute ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet value = getNormalAttributeValue( key, props[ key ] );\n\n\t\t// If value is not of serializable type, skip.\n\t\tif ( ! ATTRIBUTES_TYPES.has( typeof value ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Don't render internal attribute names.\n\t\tif ( isInternalAttribute( key ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isBooleanAttribute = BOOLEAN_ATTRIBUTES.has( attribute );\n\n\t\t// Boolean attribute should be omitted outright if its value is false.\n\t\tif ( isBooleanAttribute && value === false ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isMeaningfulAttribute =\n\t\t\tisBooleanAttribute ||\n\t\t\thasPrefix( key, [ 'data-', 'aria-' ] ) ||\n\t\t\tENUMERATED_ATTRIBUTES.has( attribute );\n\n\t\t// Only write boolean value as attribute if meaningful.\n\t\tif ( typeof value === 'boolean' && ! isMeaningfulAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult += ' ' + attribute;\n\n\t\t// Boolean attributes should write attribute name, but without value.\n\t\t// Mere presence of attribute name is effective truthiness.\n\t\tif ( isBooleanAttribute ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( typeof value === 'string' ) {\n\t\t\tvalue = escapeAttribute( value );\n\t\t}\n\n\t\tresult += '=\"' + value + '\"';\n\t}\n\n\treturn result;\n}\n\n/**\n * Renders a style object as a string attribute value.\n * @param style\n */\nexport function renderStyle( style: StyleObject | string ): string | undefined {\n\t// Only generate from object, e.g. tolerate string value.\n\tif ( ! isPlainObject( style ) ) {\n\t\treturn style as string;\n\t}\n\n\tlet result: string | undefined;\n\n\tconst styleObj = style as StyleObject;\n\tfor ( const property in styleObj ) {\n\t\tconst value = styleObj[ property ];\n\t\tif ( null === value || undefined === value ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( result ) {\n\t\t\tresult += ';';\n\t\t} else {\n\t\t\tresult = '';\n\t\t}\n\n\t\tconst normalName = getNormalStylePropertyName( property );\n\t\tconst normalValue = getNormalStylePropertyValue( property, value );\n\t\tresult += normalName + ':' + normalValue;\n\t}\n\n\treturn result;\n}\n\nexport default renderElement;\n"],
|
|
5
5
|
"mappings": ";AA8BA,SAAS,qBAAqB;AAC9B,SAAS,aAAa,iBAAiB;AAKvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,eAAe,UAAU,YAAY,kBAAkB;AAChE,OAAO,aAAa;AAIpB,IAAM,UAAU,cAAe,MAAU;AACzC,QAAQ,cAAc;AA4BtB,IAAM,EAAE,UAAU,SAAS,IAAI;AAE/B,IAAM,aAAa,WAAY,MAAM;AACpC,SAAO;AACR,CAAE;AAKF,IAAM,mBAAmB,oBAAI,IAAe,CAAE,UAAU,WAAW,QAAS,CAAE;AAK9E,IAAM,oBAAoB,oBAAI,IAAe;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAeF,IAAM,qBAAqB,oBAAI,IAAe;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAoBF,IAAM,wBAAwB,oBAAI,IAAe;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,EAAE;AAAA,EACD,CAAE,KAAK,cAAe;AAErB,QAAK,UAAU,YAAY,CAAE,IAAI;AACjC,WAAO;AAAA,EACR;AAAA,EACA,CAAC;AACF;AAQA,IAAM,gCAA0D;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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ACxD,UAAM,cAAc,4BAA6B,UAAU,KAAM;AACjE,cAAU,aAAa,MAAM;AAAA,EAC9B;AAEA,SAAO;AACR;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/element",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2-next.v.202606191442.0+17fe7db8a",
|
|
4
4
|
"description": "Element React module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"import": "./build-module/index.mjs",
|
|
39
39
|
"require": "./build/index.cjs"
|
|
40
40
|
},
|
|
41
|
-
"./react-polyfill": "./src/react-polyfill-base.ts",
|
|
42
41
|
"./package.json": "./package.json"
|
|
43
42
|
},
|
|
44
43
|
"wpScript": true,
|
|
@@ -47,8 +46,8 @@
|
|
|
47
46
|
"dependencies": {
|
|
48
47
|
"@types/react": "^18.3.27",
|
|
49
48
|
"@types/react-dom": "^18.3.1",
|
|
50
|
-
"@wordpress/deprecated": "^4.48.
|
|
51
|
-
"@wordpress/escape-html": "^3.48.
|
|
49
|
+
"@wordpress/deprecated": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
50
|
+
"@wordpress/escape-html": "^3.48.2-next.v.202606191442.0+17fe7db8a",
|
|
52
51
|
"change-case": "^4.1.2",
|
|
53
52
|
"is-plain-object": "^5.0.0",
|
|
54
53
|
"react": "^18.3.1",
|
|
@@ -61,5 +60,5 @@
|
|
|
61
60
|
"publishConfig": {
|
|
62
61
|
"access": "public"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
65
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,9 +5,3 @@ export * from './utils';
|
|
|
5
5
|
export { default as Platform } from './platform';
|
|
6
6
|
export { default as renderToString } from './serialize';
|
|
7
7
|
export { default as RawHTML } from './raw-html';
|
|
8
|
-
// export {
|
|
9
|
-
// findDOMNode,
|
|
10
|
-
// render,
|
|
11
|
-
// hydrate,
|
|
12
|
-
// unmountComponentAtNode,
|
|
13
|
-
// } from './react-polyfill';
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/element/src/react-polyfill-base.ts
|
|
21
|
-
var react_polyfill_base_exports = {};
|
|
22
|
-
__export(react_polyfill_base_exports, {
|
|
23
|
-
findDOMNode: () => findDOMNode,
|
|
24
|
-
hydrate: () => hydrate,
|
|
25
|
-
render: () => render,
|
|
26
|
-
unmountComponentAtNode: () => unmountComponentAtNode
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(react_polyfill_base_exports);
|
|
29
|
-
var import_react_dom = require("react-dom");
|
|
30
|
-
var import_client = require("react-dom/client");
|
|
31
|
-
var internalsKey = "_reactInternals";
|
|
32
|
-
var HostComponent = 5;
|
|
33
|
-
var HostText = 6;
|
|
34
|
-
function findCurrentFiber(fiber) {
|
|
35
|
-
if (!fiber.alternate) {
|
|
36
|
-
return fiber;
|
|
37
|
-
}
|
|
38
|
-
let node = fiber;
|
|
39
|
-
while (node.return) {
|
|
40
|
-
node = node.return;
|
|
41
|
-
}
|
|
42
|
-
if (node.stateNode.current === node) {
|
|
43
|
-
return fiber;
|
|
44
|
-
}
|
|
45
|
-
return fiber.alternate;
|
|
46
|
-
}
|
|
47
|
-
function findHostFiber(fiber) {
|
|
48
|
-
const current = findCurrentFiber(fiber);
|
|
49
|
-
if (!current) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return findHostFiberImpl(current);
|
|
53
|
-
}
|
|
54
|
-
function findHostFiberImpl(fiber) {
|
|
55
|
-
if (fiber.tag === HostComponent || fiber.tag === HostText) {
|
|
56
|
-
return fiber;
|
|
57
|
-
}
|
|
58
|
-
let child = fiber.child;
|
|
59
|
-
while (child) {
|
|
60
|
-
const hostFiber = findHostFiberImpl(child);
|
|
61
|
-
if (hostFiber) {
|
|
62
|
-
return hostFiber;
|
|
63
|
-
}
|
|
64
|
-
child = child.sibling;
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
function findDOMNode(instance) {
|
|
69
|
-
if (instance === null || instance === void 0) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
if (instance.nodeType !== void 0) {
|
|
73
|
-
return instance;
|
|
74
|
-
}
|
|
75
|
-
const fiber = instance[internalsKey];
|
|
76
|
-
if (fiber === void 0) {
|
|
77
|
-
if (typeof instance.render === "function") {
|
|
78
|
-
throw new Error("Unable to find node on an unmounted component.");
|
|
79
|
-
}
|
|
80
|
-
const keys = Object.keys(instance).join(",");
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Argument appears to not be a ReactComponent. Keys: ${keys}`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
const hostFiber = findHostFiber(fiber);
|
|
86
|
-
return hostFiber?.stateNode ?? null;
|
|
87
|
-
}
|
|
88
|
-
var roots = /* @__PURE__ */ new WeakMap();
|
|
89
|
-
function render(element, container, callback) {
|
|
90
|
-
let root = roots.get(container);
|
|
91
|
-
if (!root) {
|
|
92
|
-
root = (0, import_client.createRoot)(container);
|
|
93
|
-
roots.set(container, root);
|
|
94
|
-
}
|
|
95
|
-
(0, import_react_dom.flushSync)(() => {
|
|
96
|
-
root.render(element);
|
|
97
|
-
});
|
|
98
|
-
if (typeof callback === "function") {
|
|
99
|
-
callback();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function hydrate(element, container, callback) {
|
|
103
|
-
let root = roots.get(container);
|
|
104
|
-
if (!root) {
|
|
105
|
-
root = (0, import_client.hydrateRoot)(container, element);
|
|
106
|
-
roots.set(container, root);
|
|
107
|
-
} else {
|
|
108
|
-
root.render(element);
|
|
109
|
-
}
|
|
110
|
-
if (typeof callback === "function") {
|
|
111
|
-
callback();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function unmountComponentAtNode(container) {
|
|
115
|
-
const root = roots.get(container);
|
|
116
|
-
if (!root) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
(0, import_react_dom.flushSync)(() => {
|
|
120
|
-
root.unmount();
|
|
121
|
-
});
|
|
122
|
-
roots.delete(container);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
-
0 && (module.exports = {
|
|
127
|
-
findDOMNode,
|
|
128
|
-
hydrate,
|
|
129
|
-
render,
|
|
130
|
-
unmountComponentAtNode
|
|
131
|
-
});
|
|
132
|
-
//# sourceMappingURL=react-polyfill-base.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/react-polyfill-base.ts"],
|
|
4
|
-
"sourcesContent": ["import { flushSync } from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport type { Root } from 'react-dom/client';\n\nconst internalsKey = '_reactInternals';\n\n// HostComponent fiber tag, represents a DOM element like <div>.\nconst HostComponent = 5;\nconst HostText = 6;\n\nfunction findCurrentFiber( fiber: any ): any {\n\tif ( ! fiber.alternate ) {\n\t\t// First mount \u2014 only one version exists, and it's current.\n\t\treturn fiber;\n\t}\n\n\t// Walk up to the HostRoot to figure out which tree this fiber is on.\n\tlet node = fiber;\n\twhile ( node.return ) {\n\t\tnode = node.return;\n\t}\n\n\t// The root's stateNode.current points to the current tree's root fiber.\n\tif ( node.stateNode.current === node ) {\n\t\t// We walked up the current tree, so `fiber` is already current.\n\t\treturn fiber;\n\t}\n\n\t// We walked up the alternate tree \u2014 switch to the current version.\n\treturn fiber.alternate;\n}\n\nfunction findHostFiber( fiber: any ): any {\n\tconst current = findCurrentFiber( fiber );\n\tif ( ! current ) {\n\t\treturn null;\n\t}\n\treturn findHostFiberImpl( current );\n}\n\nfunction findHostFiberImpl( fiber: any ): any {\n\tif ( fiber.tag === HostComponent || fiber.tag === HostText ) {\n\t\treturn fiber;\n\t}\n\n\tlet child = fiber.child;\n\twhile ( child ) {\n\t\tconst hostFiber = findHostFiberImpl( child );\n\t\tif ( hostFiber ) {\n\t\t\treturn hostFiber;\n\t\t}\n\t\tchild = child.sibling;\n\t}\n\n\treturn null;\n}\n\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tif ( instance === null || instance === undefined ) {\n\t\treturn null;\n\t}\n\n\tif ( instance.nodeType !== undefined ) {\n\t\treturn instance as Element | Text;\n\t}\n\n\tconst fiber = instance[ internalsKey ];\n\tif ( fiber === undefined ) {\n\t\tif ( typeof instance.render === 'function' ) {\n\t\t\tthrow new Error( 'Unable to find node on an unmounted component.' );\n\t\t}\n\t\tconst keys = Object.keys( instance ).join( ',' );\n\t\tthrow new Error(\n\t\t\t`Argument appears to not be a ReactComponent. Keys: ${ keys }`\n\t\t);\n\t}\n\n\tconst hostFiber = findHostFiber( fiber );\n\treturn hostFiber?.stateNode ?? null;\n}\n\nconst roots = new WeakMap< Element, Root >();\n\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = createRoot( container );\n\t\troots.set( container, root );\n\t}\n\n\tflushSync( () => {\n\t\troot.render( element );\n\t} );\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = hydrateRoot( container, element );\n\t\troots.set( container, root );\n\t} else {\n\t\troot.render( element );\n\t}\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tconst root = roots.get( container );\n\tif ( ! root ) {\n\t\treturn false;\n\t}\n\n\tflushSync( () => {\n\t\troot.unmount();\n\t} );\n\troots.delete( container );\n\treturn true;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B;AAC1B,oBAAwC;AAGxC,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AACtB,IAAM,WAAW;AAEjB,SAAS,iBAAkB,OAAkB;AAC5C,MAAK,CAAE,MAAM,WAAY;AAExB,WAAO;AAAA,EACR;AAGA,MAAI,OAAO;AACX,SAAQ,KAAK,QAAS;AACrB,WAAO,KAAK;AAAA,EACb;AAGA,MAAK,KAAK,UAAU,YAAY,MAAO;AAEtC,WAAO;AAAA,EACR;AAGA,SAAO,MAAM;AACd;AAEA,SAAS,cAAe,OAAkB;AACzC,QAAM,UAAU,iBAAkB,KAAM;AACxC,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;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A,EAC5B,OAAO;AACN,SAAK,OAAQ,OAAQ;AAAA,EACtB;AAEA,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,uBAAwB,WAA8B;AACrE,QAAM,OAAO,MAAM,IAAK,SAAU;AAClC,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAEA,kCAAW,MAAM;AAChB,SAAK,QAAQ;AAAA,EACd,CAAE;AACF,QAAM,OAAQ,SAAU;AACxB,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/build/react-polyfill.cjs
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/element/src/react-polyfill.ts
|
|
31
|
-
var react_polyfill_exports = {};
|
|
32
|
-
__export(react_polyfill_exports, {
|
|
33
|
-
findDOMNode: () => findDOMNode,
|
|
34
|
-
hydrate: () => hydrate,
|
|
35
|
-
render: () => render,
|
|
36
|
-
unmountComponentAtNode: () => unmountComponentAtNode
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(react_polyfill_exports);
|
|
39
|
-
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
40
|
-
var import_react_polyfill_base = require("./react-polyfill-base.cjs");
|
|
41
|
-
function findDOMNode(instance) {
|
|
42
|
-
(0, import_deprecated.default)("wp.element.findDOMNode", {
|
|
43
|
-
since: "7.1",
|
|
44
|
-
alternative: "DOM refs",
|
|
45
|
-
link: "https://react.dev/reference/react-dom/findDOMNode"
|
|
46
|
-
});
|
|
47
|
-
return (0, import_react_polyfill_base.findDOMNode)(instance);
|
|
48
|
-
}
|
|
49
|
-
function render(element, container, callback) {
|
|
50
|
-
(0, import_deprecated.default)("wp.element.render", {
|
|
51
|
-
since: "6.2",
|
|
52
|
-
alternative: "wp.element.createRoot",
|
|
53
|
-
link: "https://react.dev/reference/react-dom/client/createRoot"
|
|
54
|
-
});
|
|
55
|
-
(0, import_react_polyfill_base.render)(element, container, callback);
|
|
56
|
-
}
|
|
57
|
-
function hydrate(element, container, callback) {
|
|
58
|
-
(0, import_deprecated.default)("wp.element.hydrate", {
|
|
59
|
-
since: "6.2",
|
|
60
|
-
alternative: "wp.element.hydrateRoot",
|
|
61
|
-
link: "https://react.dev/reference/react-dom/client/hydrateRoot"
|
|
62
|
-
});
|
|
63
|
-
(0, import_react_polyfill_base.hydrate)(element, container, callback);
|
|
64
|
-
}
|
|
65
|
-
function unmountComponentAtNode(container) {
|
|
66
|
-
(0, import_deprecated.default)("wp.element.unmountComponentAtNode", {
|
|
67
|
-
since: "6.2",
|
|
68
|
-
alternative: "root.unmount()",
|
|
69
|
-
link: "https://react.dev/reference/react-dom/client/createRoot#root-unmount"
|
|
70
|
-
});
|
|
71
|
-
return (0, import_react_polyfill_base.unmountComponentAtNode)(container);
|
|
72
|
-
}
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
findDOMNode,
|
|
76
|
-
hydrate,
|
|
77
|
-
render,
|
|
78
|
-
unmountComponentAtNode
|
|
79
|
-
});
|
|
80
|
-
//# sourceMappingURL=react-polyfill.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/react-polyfill.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfindDOMNode as findDOMNodeBase,\n\trender as renderBase,\n\thydrate as hydrateBase,\n\tunmountComponentAtNode as unmountComponentAtNodeBase,\n} from './react-polyfill-base';\n\n/**\n * Finds the DOM node of a React component instance.\n *\n * @deprecated since WordPress 7.1.0. Use DOM refs instead.\n * @see https://react.dev/reference/react-dom/findDOMNode\n *\n * @param instance Component's instance.\n */\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tdeprecated( 'wp.element.findDOMNode', {\n\t\tsince: '7.1',\n\t\talternative: 'DOM refs',\n\t\tlink: 'https://react.dev/reference/react-dom/findDOMNode',\n\t} );\n\n\treturn findDOMNodeBase( instance );\n}\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 *\n * @param element Element to render.\n * @param container DOM node into which to render.\n * @param callback Optional callback called after render.\n */\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.render', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.createRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot',\n\t} );\n\n\trenderBase( element, container, callback );\n}\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 *\n * @param element Element to hydrate.\n * @param container DOM node to hydrate.\n * @param callback Optional callback called after hydration.\n */\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.hydrate', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.hydrateRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/hydrateRoot',\n\t} );\n\n\thydrateBase( element, container, callback );\n}\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 *\n * @param container DOM node in which to unmount.\n * @return Whether the node was unmounted.\n */\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tdeprecated( 'wp.element.unmountComponentAtNode', {\n\t\tsince: '6.2',\n\t\talternative: 'root.unmount()',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',\n\t} );\n\n\treturn unmountComponentAtNodeBase( container );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,iCAKO;AAUA,SAAS,YAAa,UAAuC;AACnE,wBAAAA,SAAY,0BAA0B;AAAA,IACrC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAO,2BAAAC,aAAiB,QAAS;AAClC;AAYO,SAAS,OACf,SACA,WACA,UACO;AACP,wBAAAD,SAAY,qBAAqB;AAAA,IAChC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,iCAAAE,QAAY,SAAS,WAAW,QAAS;AAC1C;AAYO,SAAS,QACf,SACA,WACA,UACO;AACP,wBAAAF,SAAY,sBAAsB;AAAA,IACjC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,iCAAAG,SAAa,SAAS,WAAW,QAAS;AAC3C;AAWO,SAAS,uBAAwB,WAA8B;AACrE,wBAAAH,SAAY,qCAAqC;AAAA,IAChD,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAO,2BAAAI,wBAA4B,SAAU;AAC9C;",
|
|
6
|
-
"names": ["deprecated", "findDOMNodeBase", "renderBase", "hydrateBase", "unmountComponentAtNodeBase"]
|
|
7
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// packages/element/src/react-polyfill-base.ts
|
|
2
|
-
import { flushSync } from "react-dom";
|
|
3
|
-
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
4
|
-
var internalsKey = "_reactInternals";
|
|
5
|
-
var HostComponent = 5;
|
|
6
|
-
var HostText = 6;
|
|
7
|
-
function findCurrentFiber(fiber) {
|
|
8
|
-
if (!fiber.alternate) {
|
|
9
|
-
return fiber;
|
|
10
|
-
}
|
|
11
|
-
let node = fiber;
|
|
12
|
-
while (node.return) {
|
|
13
|
-
node = node.return;
|
|
14
|
-
}
|
|
15
|
-
if (node.stateNode.current === node) {
|
|
16
|
-
return fiber;
|
|
17
|
-
}
|
|
18
|
-
return fiber.alternate;
|
|
19
|
-
}
|
|
20
|
-
function findHostFiber(fiber) {
|
|
21
|
-
const current = findCurrentFiber(fiber);
|
|
22
|
-
if (!current) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
return findHostFiberImpl(current);
|
|
26
|
-
}
|
|
27
|
-
function findHostFiberImpl(fiber) {
|
|
28
|
-
if (fiber.tag === HostComponent || fiber.tag === HostText) {
|
|
29
|
-
return fiber;
|
|
30
|
-
}
|
|
31
|
-
let child = fiber.child;
|
|
32
|
-
while (child) {
|
|
33
|
-
const hostFiber = findHostFiberImpl(child);
|
|
34
|
-
if (hostFiber) {
|
|
35
|
-
return hostFiber;
|
|
36
|
-
}
|
|
37
|
-
child = child.sibling;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
function findDOMNode(instance) {
|
|
42
|
-
if (instance === null || instance === void 0) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
if (instance.nodeType !== void 0) {
|
|
46
|
-
return instance;
|
|
47
|
-
}
|
|
48
|
-
const fiber = instance[internalsKey];
|
|
49
|
-
if (fiber === void 0) {
|
|
50
|
-
if (typeof instance.render === "function") {
|
|
51
|
-
throw new Error("Unable to find node on an unmounted component.");
|
|
52
|
-
}
|
|
53
|
-
const keys = Object.keys(instance).join(",");
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Argument appears to not be a ReactComponent. Keys: ${keys}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
const hostFiber = findHostFiber(fiber);
|
|
59
|
-
return hostFiber?.stateNode ?? null;
|
|
60
|
-
}
|
|
61
|
-
var roots = /* @__PURE__ */ new WeakMap();
|
|
62
|
-
function render(element, container, callback) {
|
|
63
|
-
let root = roots.get(container);
|
|
64
|
-
if (!root) {
|
|
65
|
-
root = createRoot(container);
|
|
66
|
-
roots.set(container, root);
|
|
67
|
-
}
|
|
68
|
-
flushSync(() => {
|
|
69
|
-
root.render(element);
|
|
70
|
-
});
|
|
71
|
-
if (typeof callback === "function") {
|
|
72
|
-
callback();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function hydrate(element, container, callback) {
|
|
76
|
-
let root = roots.get(container);
|
|
77
|
-
if (!root) {
|
|
78
|
-
root = hydrateRoot(container, element);
|
|
79
|
-
roots.set(container, root);
|
|
80
|
-
} else {
|
|
81
|
-
root.render(element);
|
|
82
|
-
}
|
|
83
|
-
if (typeof callback === "function") {
|
|
84
|
-
callback();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function unmountComponentAtNode(container) {
|
|
88
|
-
const root = roots.get(container);
|
|
89
|
-
if (!root) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
flushSync(() => {
|
|
93
|
-
root.unmount();
|
|
94
|
-
});
|
|
95
|
-
roots.delete(container);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
export {
|
|
99
|
-
findDOMNode,
|
|
100
|
-
hydrate,
|
|
101
|
-
render,
|
|
102
|
-
unmountComponentAtNode
|
|
103
|
-
};
|
|
104
|
-
//# sourceMappingURL=react-polyfill-base.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/react-polyfill-base.ts"],
|
|
4
|
-
"sourcesContent": ["import { flushSync } from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport type { Root } from 'react-dom/client';\n\nconst internalsKey = '_reactInternals';\n\n// HostComponent fiber tag, represents a DOM element like <div>.\nconst HostComponent = 5;\nconst HostText = 6;\n\nfunction findCurrentFiber( fiber: any ): any {\n\tif ( ! fiber.alternate ) {\n\t\t// First mount \u2014 only one version exists, and it's current.\n\t\treturn fiber;\n\t}\n\n\t// Walk up to the HostRoot to figure out which tree this fiber is on.\n\tlet node = fiber;\n\twhile ( node.return ) {\n\t\tnode = node.return;\n\t}\n\n\t// The root's stateNode.current points to the current tree's root fiber.\n\tif ( node.stateNode.current === node ) {\n\t\t// We walked up the current tree, so `fiber` is already current.\n\t\treturn fiber;\n\t}\n\n\t// We walked up the alternate tree \u2014 switch to the current version.\n\treturn fiber.alternate;\n}\n\nfunction findHostFiber( fiber: any ): any {\n\tconst current = findCurrentFiber( fiber );\n\tif ( ! current ) {\n\t\treturn null;\n\t}\n\treturn findHostFiberImpl( current );\n}\n\nfunction findHostFiberImpl( fiber: any ): any {\n\tif ( fiber.tag === HostComponent || fiber.tag === HostText ) {\n\t\treturn fiber;\n\t}\n\n\tlet child = fiber.child;\n\twhile ( child ) {\n\t\tconst hostFiber = findHostFiberImpl( child );\n\t\tif ( hostFiber ) {\n\t\t\treturn hostFiber;\n\t\t}\n\t\tchild = child.sibling;\n\t}\n\n\treturn null;\n}\n\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tif ( instance === null || instance === undefined ) {\n\t\treturn null;\n\t}\n\n\tif ( instance.nodeType !== undefined ) {\n\t\treturn instance as Element | Text;\n\t}\n\n\tconst fiber = instance[ internalsKey ];\n\tif ( fiber === undefined ) {\n\t\tif ( typeof instance.render === 'function' ) {\n\t\t\tthrow new Error( 'Unable to find node on an unmounted component.' );\n\t\t}\n\t\tconst keys = Object.keys( instance ).join( ',' );\n\t\tthrow new Error(\n\t\t\t`Argument appears to not be a ReactComponent. Keys: ${ keys }`\n\t\t);\n\t}\n\n\tconst hostFiber = findHostFiber( fiber );\n\treturn hostFiber?.stateNode ?? null;\n}\n\nconst roots = new WeakMap< Element, Root >();\n\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = createRoot( container );\n\t\troots.set( container, root );\n\t}\n\n\tflushSync( () => {\n\t\troot.render( element );\n\t} );\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = hydrateRoot( container, element );\n\t\troots.set( container, root );\n\t} else {\n\t\troot.render( element );\n\t}\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tconst root = roots.get( container );\n\tif ( ! root ) {\n\t\treturn false;\n\t}\n\n\tflushSync( () => {\n\t\troot.unmount();\n\t} );\n\troots.delete( container );\n\treturn true;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY,mBAAmB;AAGxC,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AACtB,IAAM,WAAW;AAEjB,SAAS,iBAAkB,OAAkB;AAC5C,MAAK,CAAE,MAAM,WAAY;AAExB,WAAO;AAAA,EACR;AAGA,MAAI,OAAO;AACX,SAAQ,KAAK,QAAS;AACrB,WAAO,KAAK;AAAA,EACb;AAGA,MAAK,KAAK,UAAU,YAAY,MAAO;AAEtC,WAAO;AAAA,EACR;AAGA,SAAO,MAAM;AACd;AAEA,SAAS,cAAe,OAAkB;AACzC,QAAM,UAAU,iBAAkB,KAAM;AACxC,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AACA,SAAO,kBAAmB,OAAQ;AACnC;AAEA,SAAS,kBAAmB,OAAkB;AAC7C,MAAK,MAAM,QAAQ,iBAAiB,MAAM,QAAQ,UAAW;AAC5D,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,MAAM;AAClB,SAAQ,OAAQ;AACf,UAAM,YAAY,kBAAmB,KAAM;AAC3C,QAAK,WAAY;AAChB,aAAO;AAAA,IACR;AACA,YAAQ,MAAM;AAAA,EACf;AAEA,SAAO;AACR;AAEO,SAAS,YAAa,UAAuC;AACnE,MAAK,aAAa,QAAQ,aAAa,QAAY;AAClD,WAAO;AAAA,EACR;AAEA,MAAK,SAAS,aAAa,QAAY;AACtC,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,SAAU,YAAa;AACrC,MAAK,UAAU,QAAY;AAC1B,QAAK,OAAO,SAAS,WAAW,YAAa;AAC5C,YAAM,IAAI,MAAO,gDAAiD;AAAA,IACnE;AACA,UAAM,OAAO,OAAO,KAAM,QAAS,EAAE,KAAM,GAAI;AAC/C,UAAM,IAAI;AAAA,MACT,sDAAuD,IAAK;AAAA,IAC7D;AAAA,EACD;AAEA,QAAM,YAAY,cAAe,KAAM;AACvC,SAAO,WAAW,aAAa;AAChC;AAEA,IAAM,QAAQ,oBAAI,QAAyB;AAEpC,SAAS,OACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,WAAO,WAAY,SAAU;AAC7B,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B;AAEA,YAAW,MAAM;AAChB,SAAK,OAAQ,OAAQ;AAAA,EACtB,CAAE;AAEF,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,QACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,WAAO,YAAa,WAAW,OAAQ;AACvC,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B,OAAO;AACN,SAAK,OAAQ,OAAQ;AAAA,EACtB;AAEA,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,uBAAwB,WAA8B;AACrE,QAAM,OAAO,MAAM,IAAK,SAAU;AAClC,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAEA,YAAW,MAAM;AAChB,SAAK,QAAQ;AAAA,EACd,CAAE;AACF,QAAM,OAAQ,SAAU;AACxB,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// packages/element/src/react-polyfill.ts
|
|
2
|
-
import deprecated from "@wordpress/deprecated";
|
|
3
|
-
import {
|
|
4
|
-
findDOMNode as findDOMNodeBase,
|
|
5
|
-
render as renderBase,
|
|
6
|
-
hydrate as hydrateBase,
|
|
7
|
-
unmountComponentAtNode as unmountComponentAtNodeBase
|
|
8
|
-
} from "./react-polyfill-base.mjs";
|
|
9
|
-
function findDOMNode(instance) {
|
|
10
|
-
deprecated("wp.element.findDOMNode", {
|
|
11
|
-
since: "7.1",
|
|
12
|
-
alternative: "DOM refs",
|
|
13
|
-
link: "https://react.dev/reference/react-dom/findDOMNode"
|
|
14
|
-
});
|
|
15
|
-
return findDOMNodeBase(instance);
|
|
16
|
-
}
|
|
17
|
-
function render(element, container, callback) {
|
|
18
|
-
deprecated("wp.element.render", {
|
|
19
|
-
since: "6.2",
|
|
20
|
-
alternative: "wp.element.createRoot",
|
|
21
|
-
link: "https://react.dev/reference/react-dom/client/createRoot"
|
|
22
|
-
});
|
|
23
|
-
renderBase(element, container, callback);
|
|
24
|
-
}
|
|
25
|
-
function hydrate(element, container, callback) {
|
|
26
|
-
deprecated("wp.element.hydrate", {
|
|
27
|
-
since: "6.2",
|
|
28
|
-
alternative: "wp.element.hydrateRoot",
|
|
29
|
-
link: "https://react.dev/reference/react-dom/client/hydrateRoot"
|
|
30
|
-
});
|
|
31
|
-
hydrateBase(element, container, callback);
|
|
32
|
-
}
|
|
33
|
-
function unmountComponentAtNode(container) {
|
|
34
|
-
deprecated("wp.element.unmountComponentAtNode", {
|
|
35
|
-
since: "6.2",
|
|
36
|
-
alternative: "root.unmount()",
|
|
37
|
-
link: "https://react.dev/reference/react-dom/client/createRoot#root-unmount"
|
|
38
|
-
});
|
|
39
|
-
return unmountComponentAtNodeBase(container);
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
findDOMNode,
|
|
43
|
-
hydrate,
|
|
44
|
-
render,
|
|
45
|
-
unmountComponentAtNode
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=react-polyfill.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/react-polyfill.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfindDOMNode as findDOMNodeBase,\n\trender as renderBase,\n\thydrate as hydrateBase,\n\tunmountComponentAtNode as unmountComponentAtNodeBase,\n} from './react-polyfill-base';\n\n/**\n * Finds the DOM node of a React component instance.\n *\n * @deprecated since WordPress 7.1.0. Use DOM refs instead.\n * @see https://react.dev/reference/react-dom/findDOMNode\n *\n * @param instance Component's instance.\n */\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tdeprecated( 'wp.element.findDOMNode', {\n\t\tsince: '7.1',\n\t\talternative: 'DOM refs',\n\t\tlink: 'https://react.dev/reference/react-dom/findDOMNode',\n\t} );\n\n\treturn findDOMNodeBase( instance );\n}\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 *\n * @param element Element to render.\n * @param container DOM node into which to render.\n * @param callback Optional callback called after render.\n */\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.render', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.createRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot',\n\t} );\n\n\trenderBase( element, container, callback );\n}\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 *\n * @param element Element to hydrate.\n * @param container DOM node to hydrate.\n * @param callback Optional callback called after hydration.\n */\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.hydrate', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.hydrateRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/hydrateRoot',\n\t} );\n\n\thydrateBase( element, container, callback );\n}\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 *\n * @param container DOM node in which to unmount.\n * @return Whether the node was unmounted.\n */\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tdeprecated( 'wp.element.unmountComponentAtNode', {\n\t\tsince: '6.2',\n\t\talternative: 'root.unmount()',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',\n\t} );\n\n\treturn unmountComponentAtNodeBase( container );\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB;AAAA,EACC,eAAe;AAAA,EACf,UAAU;AAAA,EACV,WAAW;AAAA,EACX,0BAA0B;AAAA,OACpB;AAUA,SAAS,YAAa,UAAuC;AACnE,aAAY,0BAA0B;AAAA,IACrC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,SAAO,gBAAiB,QAAS;AAClC;AAYO,SAAS,OACf,SACA,WACA,UACO;AACP,aAAY,qBAAqB;AAAA,IAChC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAY,SAAS,WAAW,QAAS;AAC1C;AAYO,SAAS,QACf,SACA,WACA,UACO;AACP,aAAY,sBAAsB;AAAA,IACjC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,cAAa,SAAS,WAAW,QAAS;AAC3C;AAWO,SAAS,uBAAwB,WAA8B;AACrE,aAAY,qCAAqC;AAAA,IAChD,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,SAAO,2BAA4B,SAAU;AAC9C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds the DOM node of a React component instance.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated since WordPress 7.1.0. Use DOM refs instead.
|
|
5
|
-
* @see https://react.dev/reference/react-dom/findDOMNode
|
|
6
|
-
*
|
|
7
|
-
* @param instance Component's instance.
|
|
8
|
-
*/
|
|
9
|
-
export default function findDOMNode(instance: any): Element | Text | null;
|
|
10
|
-
//# sourceMappingURL=find-dom-node.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-dom-node.d.ts","sourceRoot":"","sources":["../src/find-dom-node.ts"],"names":[],"mappings":"AAuDA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,QAAQ,EAAE,GAAG,GAAI,OAAO,GAAG,IAAI,GAAG,IAAI,CA4B1E"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function findDOMNode(instance: any): Element | Text | null;
|
|
2
|
-
export declare function render(element: React.ReactNode, container: Element, callback?: () => void): void;
|
|
3
|
-
export declare function hydrate(element: React.ReactNode, container: Element, callback?: () => void): void;
|
|
4
|
-
export declare function unmountComponentAtNode(container: Element): boolean;
|
|
5
|
-
//# sourceMappingURL=react-polyfill-base.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-polyfill-base.d.ts","sourceRoot":"","sources":["../src/react-polyfill-base.ts"],"names":[],"mappings":"AAyDA,wBAAgB,WAAW,CAAE,QAAQ,EAAE,GAAG,GAAI,OAAO,GAAG,IAAI,GAAG,IAAI,CAsBlE;AAID,wBAAgB,MAAM,CACrB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAcN;AAED,wBAAgB,OAAO,CACtB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAYN;AAED,wBAAgB,sBAAsB,CAAE,SAAS,EAAE,OAAO,GAAI,OAAO,CAWpE"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds the DOM node of a React component instance.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated since WordPress 7.1.0. Use DOM refs instead.
|
|
5
|
-
* @see https://react.dev/reference/react-dom/findDOMNode
|
|
6
|
-
*
|
|
7
|
-
* @param instance Component's instance.
|
|
8
|
-
*/
|
|
9
|
-
export declare function findDOMNode(instance: any): Element | Text | null;
|
|
10
|
-
/**
|
|
11
|
-
* Renders a given element into the target DOM node.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated since WordPress 6.2.0. Use `createRoot` instead.
|
|
14
|
-
* @see https://react.dev/reference/react-dom/render
|
|
15
|
-
*
|
|
16
|
-
* @param element Element to render.
|
|
17
|
-
* @param container DOM node into which to render.
|
|
18
|
-
* @param callback Optional callback called after render.
|
|
19
|
-
*/
|
|
20
|
-
export declare function render(element: React.ReactNode, container: Element, callback?: () => void): void;
|
|
21
|
-
/**
|
|
22
|
-
* Hydrates a given element into the target DOM node.
|
|
23
|
-
*
|
|
24
|
-
* @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.
|
|
25
|
-
* @see https://react.dev/reference/react-dom/hydrate
|
|
26
|
-
*
|
|
27
|
-
* @param element Element to hydrate.
|
|
28
|
-
* @param container DOM node to hydrate.
|
|
29
|
-
* @param callback Optional callback called after hydration.
|
|
30
|
-
*/
|
|
31
|
-
export declare function hydrate(element: React.ReactNode, container: Element, callback?: () => void): void;
|
|
32
|
-
/**
|
|
33
|
-
* Removes any mounted element from the target DOM node.
|
|
34
|
-
*
|
|
35
|
-
* @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.
|
|
36
|
-
* @see https://react.dev/reference/react-dom/unmountComponentAtNode
|
|
37
|
-
*
|
|
38
|
-
* @param container DOM node in which to unmount.
|
|
39
|
-
* @return Whether the node was unmounted.
|
|
40
|
-
*/
|
|
41
|
-
export declare function unmountComponentAtNode(container: Element): boolean;
|
|
42
|
-
//# sourceMappingURL=react-polyfill.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-polyfill.d.ts","sourceRoot":"","sources":["../src/react-polyfill.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAE,QAAQ,EAAE,GAAG,GAAI,OAAO,GAAG,IAAI,GAAG,IAAI,CAQlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CACrB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAQN;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACtB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAQN;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAE,SAAS,EAAE,OAAO,GAAI,OAAO,CAQpE"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { flushSync } from 'react-dom';
|
|
2
|
-
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
3
|
-
import type { Root } from 'react-dom/client';
|
|
4
|
-
|
|
5
|
-
const internalsKey = '_reactInternals';
|
|
6
|
-
|
|
7
|
-
// HostComponent fiber tag, represents a DOM element like <div>.
|
|
8
|
-
const HostComponent = 5;
|
|
9
|
-
const HostText = 6;
|
|
10
|
-
|
|
11
|
-
function findCurrentFiber( fiber: any ): any {
|
|
12
|
-
if ( ! fiber.alternate ) {
|
|
13
|
-
// First mount — only one version exists, and it's current.
|
|
14
|
-
return fiber;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Walk up to the HostRoot to figure out which tree this fiber is on.
|
|
18
|
-
let node = fiber;
|
|
19
|
-
while ( node.return ) {
|
|
20
|
-
node = node.return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// The root's stateNode.current points to the current tree's root fiber.
|
|
24
|
-
if ( node.stateNode.current === node ) {
|
|
25
|
-
// We walked up the current tree, so `fiber` is already current.
|
|
26
|
-
return fiber;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// We walked up the alternate tree — switch to the current version.
|
|
30
|
-
return fiber.alternate;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function findHostFiber( fiber: any ): any {
|
|
34
|
-
const current = findCurrentFiber( fiber );
|
|
35
|
-
if ( ! current ) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return findHostFiberImpl( current );
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function findHostFiberImpl( fiber: any ): any {
|
|
42
|
-
if ( fiber.tag === HostComponent || fiber.tag === HostText ) {
|
|
43
|
-
return fiber;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let child = fiber.child;
|
|
47
|
-
while ( child ) {
|
|
48
|
-
const hostFiber = findHostFiberImpl( child );
|
|
49
|
-
if ( hostFiber ) {
|
|
50
|
-
return hostFiber;
|
|
51
|
-
}
|
|
52
|
-
child = child.sibling;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function findDOMNode( instance: any ): Element | Text | null {
|
|
59
|
-
if ( instance === null || instance === undefined ) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if ( instance.nodeType !== undefined ) {
|
|
64
|
-
return instance as Element | Text;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const fiber = instance[ internalsKey ];
|
|
68
|
-
if ( fiber === undefined ) {
|
|
69
|
-
if ( typeof instance.render === 'function' ) {
|
|
70
|
-
throw new Error( 'Unable to find node on an unmounted component.' );
|
|
71
|
-
}
|
|
72
|
-
const keys = Object.keys( instance ).join( ',' );
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Argument appears to not be a ReactComponent. Keys: ${ keys }`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const hostFiber = findHostFiber( fiber );
|
|
79
|
-
return hostFiber?.stateNode ?? null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const roots = new WeakMap< Element, Root >();
|
|
83
|
-
|
|
84
|
-
export function render(
|
|
85
|
-
element: React.ReactNode,
|
|
86
|
-
container: Element,
|
|
87
|
-
callback?: () => void
|
|
88
|
-
): void {
|
|
89
|
-
let root = roots.get( container );
|
|
90
|
-
if ( ! root ) {
|
|
91
|
-
root = createRoot( container );
|
|
92
|
-
roots.set( container, root );
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
flushSync( () => {
|
|
96
|
-
root.render( element );
|
|
97
|
-
} );
|
|
98
|
-
|
|
99
|
-
if ( typeof callback === 'function' ) {
|
|
100
|
-
callback();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function hydrate(
|
|
105
|
-
element: React.ReactNode,
|
|
106
|
-
container: Element,
|
|
107
|
-
callback?: () => void
|
|
108
|
-
): void {
|
|
109
|
-
let root = roots.get( container );
|
|
110
|
-
if ( ! root ) {
|
|
111
|
-
root = hydrateRoot( container, element );
|
|
112
|
-
roots.set( container, root );
|
|
113
|
-
} else {
|
|
114
|
-
root.render( element );
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if ( typeof callback === 'function' ) {
|
|
118
|
-
callback();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function unmountComponentAtNode( container: Element ): boolean {
|
|
123
|
-
const root = roots.get( container );
|
|
124
|
-
if ( ! root ) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
flushSync( () => {
|
|
129
|
-
root.unmount();
|
|
130
|
-
} );
|
|
131
|
-
roots.delete( container );
|
|
132
|
-
return true;
|
|
133
|
-
}
|
package/src/react-polyfill.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import deprecated from '@wordpress/deprecated';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import {
|
|
10
|
-
findDOMNode as findDOMNodeBase,
|
|
11
|
-
render as renderBase,
|
|
12
|
-
hydrate as hydrateBase,
|
|
13
|
-
unmountComponentAtNode as unmountComponentAtNodeBase,
|
|
14
|
-
} from './react-polyfill-base';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Finds the DOM node of a React component instance.
|
|
18
|
-
*
|
|
19
|
-
* @deprecated since WordPress 7.1.0. Use DOM refs instead.
|
|
20
|
-
* @see https://react.dev/reference/react-dom/findDOMNode
|
|
21
|
-
*
|
|
22
|
-
* @param instance Component's instance.
|
|
23
|
-
*/
|
|
24
|
-
export function findDOMNode( instance: any ): Element | Text | null {
|
|
25
|
-
deprecated( 'wp.element.findDOMNode', {
|
|
26
|
-
since: '7.1',
|
|
27
|
-
alternative: 'DOM refs',
|
|
28
|
-
link: 'https://react.dev/reference/react-dom/findDOMNode',
|
|
29
|
-
} );
|
|
30
|
-
|
|
31
|
-
return findDOMNodeBase( instance );
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Renders a given element into the target DOM node.
|
|
36
|
-
*
|
|
37
|
-
* @deprecated since WordPress 6.2.0. Use `createRoot` instead.
|
|
38
|
-
* @see https://react.dev/reference/react-dom/render
|
|
39
|
-
*
|
|
40
|
-
* @param element Element to render.
|
|
41
|
-
* @param container DOM node into which to render.
|
|
42
|
-
* @param callback Optional callback called after render.
|
|
43
|
-
*/
|
|
44
|
-
export function render(
|
|
45
|
-
element: React.ReactNode,
|
|
46
|
-
container: Element,
|
|
47
|
-
callback?: () => void
|
|
48
|
-
): void {
|
|
49
|
-
deprecated( 'wp.element.render', {
|
|
50
|
-
since: '6.2',
|
|
51
|
-
alternative: 'wp.element.createRoot',
|
|
52
|
-
link: 'https://react.dev/reference/react-dom/client/createRoot',
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
renderBase( element, container, callback );
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Hydrates a given element into the target DOM node.
|
|
60
|
-
*
|
|
61
|
-
* @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.
|
|
62
|
-
* @see https://react.dev/reference/react-dom/hydrate
|
|
63
|
-
*
|
|
64
|
-
* @param element Element to hydrate.
|
|
65
|
-
* @param container DOM node to hydrate.
|
|
66
|
-
* @param callback Optional callback called after hydration.
|
|
67
|
-
*/
|
|
68
|
-
export function hydrate(
|
|
69
|
-
element: React.ReactNode,
|
|
70
|
-
container: Element,
|
|
71
|
-
callback?: () => void
|
|
72
|
-
): void {
|
|
73
|
-
deprecated( 'wp.element.hydrate', {
|
|
74
|
-
since: '6.2',
|
|
75
|
-
alternative: 'wp.element.hydrateRoot',
|
|
76
|
-
link: 'https://react.dev/reference/react-dom/client/hydrateRoot',
|
|
77
|
-
} );
|
|
78
|
-
|
|
79
|
-
hydrateBase( element, container, callback );
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Removes any mounted element from the target DOM node.
|
|
84
|
-
*
|
|
85
|
-
* @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.
|
|
86
|
-
* @see https://react.dev/reference/react-dom/unmountComponentAtNode
|
|
87
|
-
*
|
|
88
|
-
* @param container DOM node in which to unmount.
|
|
89
|
-
* @return Whether the node was unmounted.
|
|
90
|
-
*/
|
|
91
|
-
export function unmountComponentAtNode( container: Element ): boolean {
|
|
92
|
-
deprecated( 'wp.element.unmountComponentAtNode', {
|
|
93
|
-
since: '6.2',
|
|
94
|
-
alternative: 'root.unmount()',
|
|
95
|
-
link: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',
|
|
96
|
-
} );
|
|
97
|
-
|
|
98
|
-
return unmountComponentAtNodeBase( container );
|
|
99
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { act, render } from '@testing-library/react';
|
|
2
|
-
import { Component } from '..';
|
|
3
|
-
import { findDOMNode as findDOMNodePolyfill } from '../react-polyfill';
|
|
4
|
-
|
|
5
|
-
describe.skip( 'findDOMNode', () => {
|
|
6
|
-
it( 'should return null when passed null', () => {
|
|
7
|
-
expect( findDOMNodePolyfill( null ) ).toBeNull();
|
|
8
|
-
expect( console ).toHaveWarned();
|
|
9
|
-
} );
|
|
10
|
-
|
|
11
|
-
it( 'should return the element when passed a DOM element', () => {
|
|
12
|
-
const div = document.createElement( 'div' );
|
|
13
|
-
expect( findDOMNodePolyfill( div ) ).toBe( div );
|
|
14
|
-
} );
|
|
15
|
-
|
|
16
|
-
it( 'should track the current DOM node across re-renders', () => {
|
|
17
|
-
class Toggle extends Component {
|
|
18
|
-
constructor( props ) {
|
|
19
|
-
super( props );
|
|
20
|
-
this.state = { count: 0 };
|
|
21
|
-
this.results = [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
componentDidMount() {
|
|
25
|
-
this.recordNode();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
componentDidUpdate() {
|
|
29
|
-
this.recordNode();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
recordNode() {
|
|
33
|
-
const node = findDOMNodePolyfill( this );
|
|
34
|
-
this.results.push( node.tagName );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
render() {
|
|
38
|
-
return this.state.count % 2 === 0 ? (
|
|
39
|
-
<div>even</div>
|
|
40
|
-
) : (
|
|
41
|
-
<span>odd</span>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let toggleRef;
|
|
47
|
-
render( <Toggle ref={ ( ref ) => ( toggleRef = ref ) } /> );
|
|
48
|
-
act( () => toggleRef.setState( { count: 1 } ) );
|
|
49
|
-
act( () => toggleRef.setState( { count: 2 } ) );
|
|
50
|
-
act( () => toggleRef.setState( { count: 3 } ) );
|
|
51
|
-
|
|
52
|
-
expect( toggleRef.results ).toEqual( [ 'DIV', 'SPAN', 'DIV', 'SPAN' ] );
|
|
53
|
-
} );
|
|
54
|
-
|
|
55
|
-
it( 'should return null for an unmounted component', () => {
|
|
56
|
-
class MyComponent extends Component {
|
|
57
|
-
render() {
|
|
58
|
-
return <div>hello</div>;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let instanceRef;
|
|
63
|
-
const { rerender } = render(
|
|
64
|
-
<MyComponent
|
|
65
|
-
ref={ ( ref ) => {
|
|
66
|
-
instanceRef = ref;
|
|
67
|
-
return () => {};
|
|
68
|
-
} }
|
|
69
|
-
/>
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
expect( findDOMNodePolyfill( instanceRef ) ).toBeInstanceOf(
|
|
73
|
-
window.HTMLDivElement
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
rerender( <p>replaced</p> );
|
|
77
|
-
|
|
78
|
-
expect( instanceRef ).not.toBeNull();
|
|
79
|
-
expect( findDOMNodePolyfill( instanceRef ) ).toBeNull();
|
|
80
|
-
} );
|
|
81
|
-
|
|
82
|
-
it( 'should find DOM node rendered by a nested child component', () => {
|
|
83
|
-
function Empty() {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function Inner() {
|
|
88
|
-
return <span className="inner">hello</span>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
class Outer extends Component {
|
|
92
|
-
render() {
|
|
93
|
-
return (
|
|
94
|
-
<>
|
|
95
|
-
<Empty />
|
|
96
|
-
<Inner />
|
|
97
|
-
</>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let outerRef;
|
|
103
|
-
render( <Outer ref={ ( ref ) => ( outerRef = ref ) } /> );
|
|
104
|
-
|
|
105
|
-
const node = findDOMNodePolyfill( outerRef );
|
|
106
|
-
expect( node ).toBeInstanceOf( window.HTMLSpanElement );
|
|
107
|
-
expect( node.className ).toBe( 'inner' );
|
|
108
|
-
} );
|
|
109
|
-
} );
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createElement } from '..';
|
|
5
|
-
import { render, hydrate, unmountComponentAtNode } from '../react-polyfill';
|
|
6
|
-
|
|
7
|
-
describe.skip( 'render', () => {
|
|
8
|
-
it( 'should render into a container', () => {
|
|
9
|
-
const container = document.createElement( 'div' );
|
|
10
|
-
|
|
11
|
-
render( createElement( 'p', null, 'hello' ), container );
|
|
12
|
-
|
|
13
|
-
expect( container ).toHaveTextContent( 'hello' );
|
|
14
|
-
expect( console ).toHaveWarned();
|
|
15
|
-
} );
|
|
16
|
-
|
|
17
|
-
it( 'should update the container on subsequent renders', () => {
|
|
18
|
-
const container = document.createElement( 'div' );
|
|
19
|
-
|
|
20
|
-
render( createElement( 'p', null, 'hello' ), container );
|
|
21
|
-
render( createElement( 'p', null, 'world' ), container );
|
|
22
|
-
|
|
23
|
-
expect( container ).toHaveTextContent( 'world' );
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
it( 'should call the callback after rendering', () => {
|
|
27
|
-
const container = document.createElement( 'div' );
|
|
28
|
-
const callback = jest.fn();
|
|
29
|
-
|
|
30
|
-
render( createElement( 'p', null, 'hello' ), container, callback );
|
|
31
|
-
|
|
32
|
-
expect( callback ).toHaveBeenCalledTimes( 1 );
|
|
33
|
-
expect( container ).toHaveTextContent( 'hello' );
|
|
34
|
-
} );
|
|
35
|
-
} );
|
|
36
|
-
|
|
37
|
-
describe.skip( 'hydrate', () => {
|
|
38
|
-
it( 'should hydrate into a container with matching markup', () => {
|
|
39
|
-
const container = document.createElement( 'div' );
|
|
40
|
-
container.innerHTML = '<p>hello</p>';
|
|
41
|
-
|
|
42
|
-
hydrate( createElement( 'p', null, 'hello' ), container );
|
|
43
|
-
|
|
44
|
-
expect( container ).toHaveTextContent( 'hello' );
|
|
45
|
-
expect( console ).toHaveWarned();
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
|
-
it( 'should call the callback after hydrating', () => {
|
|
49
|
-
const container = document.createElement( 'div' );
|
|
50
|
-
container.innerHTML = '<p>hello</p>';
|
|
51
|
-
const callback = jest.fn();
|
|
52
|
-
|
|
53
|
-
hydrate( createElement( 'p', null, 'hello' ), container, callback );
|
|
54
|
-
|
|
55
|
-
expect( callback ).toHaveBeenCalledTimes( 1 );
|
|
56
|
-
} );
|
|
57
|
-
} );
|
|
58
|
-
|
|
59
|
-
describe.skip( 'unmountComponentAtNode', () => {
|
|
60
|
-
it( 'should return false when the container has no root', () => {
|
|
61
|
-
const container = document.createElement( 'div' );
|
|
62
|
-
|
|
63
|
-
expect( unmountComponentAtNode( container ) ).toBe( false );
|
|
64
|
-
expect( console ).toHaveWarned();
|
|
65
|
-
} );
|
|
66
|
-
|
|
67
|
-
it( 'should unmount and return true when a root exists', () => {
|
|
68
|
-
const container = document.createElement( 'div' );
|
|
69
|
-
|
|
70
|
-
render( createElement( 'p', null, 'hello' ), container );
|
|
71
|
-
expect( container ).toHaveTextContent( 'hello' );
|
|
72
|
-
|
|
73
|
-
expect( unmountComponentAtNode( container ) ).toBe( true );
|
|
74
|
-
expect( container ).toHaveTextContent( '' );
|
|
75
|
-
expect( unmountComponentAtNode( container ) ).toBe( false );
|
|
76
|
-
} );
|
|
77
|
-
} );
|