@wordpress/element 8.0.0 → 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/CHANGELOG.md +3 -1
- package/README.md +2 -6
- package/build/index.cjs.map +1 -1
- package/build/platform.cjs.map +2 -2
- package/build/serialize.cjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/platform.mjs.map +2 -2
- package/build-module/serialize.mjs.map +1 -1
- package/build-types/platform.d.ts +1 -13
- package/build-types/platform.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/index.ts +0 -6
- package/src/platform.ts +1 -14
- package/src/test/platform.js +10 -2
- 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/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/platform.android.js +0 -21
- package/src/platform.ios.js +0 -21
- package/src/react-platform.native.js +0 -14
- 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/platform.native.js +0 -15
- package/src/test/react-polyfill.js +0 -77
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -238,11 +238,7 @@ _Related_
|
|
|
238
238
|
|
|
239
239
|
Component used to detect the current Platform being used. Use Platform.OS === 'web' to detect if running on web environment.
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_Related_
|
|
244
|
-
|
|
245
|
-
- <https://reactnative.dev/docs/platform-specific-code#platform-module> Here is an example of how to use the select method:
|
|
241
|
+
Here is an example of how to use the select method:
|
|
246
242
|
|
|
247
243
|
_Usage_
|
|
248
244
|
|
|
@@ -250,10 +246,10 @@ _Usage_
|
|
|
250
246
|
import { Platform } from '@wordpress/element';
|
|
251
247
|
|
|
252
248
|
const placeholderLabel = Platform.select( {
|
|
253
|
-
native: __( 'Add media' ),
|
|
254
249
|
web: __(
|
|
255
250
|
'Drag images, upload new ones or select files from your library.'
|
|
256
251
|
),
|
|
252
|
+
default: __( 'Add media' ),
|
|
257
253
|
} );
|
|
258
254
|
```
|
|
259
255
|
|
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/platform.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/platform.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n *
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Specification for platform-specific value selection.\n */\ntype PlatformSelectSpec< T > = {\n\tweb?: T;\n\tdefault?: T;\n};\n\n/**\n * Component used to detect the current Platform being used.\n * Use Platform.OS === 'web' to detect if running on web environment.\n *\n * Here is an example of how to use the select method:\n * @example\n * ```js\n * import { Platform } from '@wordpress/element';\n *\n * const placeholderLabel = Platform.select( {\n * web: __( 'Drag images, upload new ones or select files from your library.' ),\n * default: __( 'Add media' ),\n * } );\n * ```\n */\nconst Platform = {\n\t/** Platform identifier. Will always be `'web'` in this module. */\n\tOS: 'web' as const,\n\n\t/**\n\t * Select a value based on the platform.\n\t *\n\t * @template T\n\t * @param spec - Object with optional platform-specific values.\n\t * @return The selected value.\n\t */\n\tselect< T >( spec: PlatformSelectSpec< T > ): T | undefined {\n\t\treturn 'web' in spec ? spec.web : spec.default;\n\t},\n\n\t/** Whether the platform is web */\n\tisWeb: true,\n};\n\nexport default Platform;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,IAAM,WAAW;AAAA;AAAA,EAEhB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASJ,OAAa,MAA+C;AAC3D,WAAO,SAAS,OAAO,KAAK,MAAM,KAAK;AAAA,EACxC;AAAA;AAAA,EAGA,OAAO;AACR;AAEA,IAAO,mBAAQ;",
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA,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;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,IA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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/platform.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n *
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * Specification for platform-specific value selection.\n */\ntype PlatformSelectSpec< T > = {\n\tweb?: T;\n\tdefault?: T;\n};\n\n/**\n * Component used to detect the current Platform being used.\n * Use Platform.OS === 'web' to detect if running on web environment.\n *\n * Here is an example of how to use the select method:\n * @example\n * ```js\n * import { Platform } from '@wordpress/element';\n *\n * const placeholderLabel = Platform.select( {\n * web: __( 'Drag images, upload new ones or select files from your library.' ),\n * default: __( 'Add media' ),\n * } );\n * ```\n */\nconst Platform = {\n\t/** Platform identifier. Will always be `'web'` in this module. */\n\tOS: 'web' as const,\n\n\t/**\n\t * Select a value based on the platform.\n\t *\n\t * @template T\n\t * @param spec - Object with optional platform-specific values.\n\t * @return The selected value.\n\t */\n\tselect< T >( spec: PlatformSelectSpec< T > ): T | undefined {\n\t\treturn 'web' in spec ? spec.web : spec.default;\n\t},\n\n\t/** Whether the platform is web */\n\tisWeb: true,\n};\n\nexport default Platform;\n"],
|
|
5
|
+
"mappings": ";AAuBA,IAAM,WAAW;AAAA;AAAA,EAEhB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASJ,OAAa,MAA+C;AAC3D,WAAO,SAAS,OAAO,KAAK,MAAM,KAAK;AAAA,EACxC;AAAA;AAAA,EAGA,OAAO;AACR;AAEA,IAAO,mBAAQ;",
|
|
6
6
|
"names": []
|
|
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;A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AA,IACD;AAEA,cAAU,MAAM;AAIhB,QAAK,oBAAqB;AACzB;AAAA,IACD;AAEA,QAAK,OAAO,UAAU,UAAW;AAChC,cAAQ,gBAAiB,KAAM;AAAA,IAChC;AAEA,cAAU,OAAO,QAAQ;AAAA,EAC1B;AAEA,SAAO;AACR;AAMO,SAAS,YAAa,OAAkD;AAE9E,MAAK,CAAE,cAAe,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": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parts of this source were derived and modified from react-native-web,
|
|
3
|
-
* released under the MIT license.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2016-present, Nicolas Gallagher.
|
|
6
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
1
|
/**
|
|
10
2
|
* Specification for platform-specific value selection.
|
|
11
3
|
*/
|
|
@@ -17,18 +9,14 @@ type PlatformSelectSpec<T> = {
|
|
|
17
9
|
* Component used to detect the current Platform being used.
|
|
18
10
|
* Use Platform.OS === 'web' to detect if running on web environment.
|
|
19
11
|
*
|
|
20
|
-
* This is the same concept as the React Native implementation.
|
|
21
|
-
*
|
|
22
|
-
* @see https://reactnative.dev/docs/platform-specific-code#platform-module
|
|
23
|
-
*
|
|
24
12
|
* Here is an example of how to use the select method:
|
|
25
13
|
* @example
|
|
26
14
|
* ```js
|
|
27
15
|
* import { Platform } from '@wordpress/element';
|
|
28
16
|
*
|
|
29
17
|
* const placeholderLabel = Platform.select( {
|
|
30
|
-
* native: __( 'Add media' ),
|
|
31
18
|
* web: __( 'Drag images, upload new ones or select files from your library.' ),
|
|
19
|
+
* default: __( 'Add media' ),
|
|
32
20
|
* } );
|
|
33
21
|
* ```
|
|
34
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,kBAAkB,CAAE,CAAC,IAAK;IAC9B,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,OAAO,CAAC,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,QAAQ;IACb,kEAAkE;IAClE,EAAE,EAAE,KAAK;IAET;;;;;;OAMG;IACH,MAAM,CAAE,CAAC,QAAU,kBAAkB,CAAE,CAAC,CAAE,GAAI,CAAC,GAAG,SAAS;IAI3D,kCAAkC;IAClC,KAAK;CACL,CAAC;eAEa,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/element",
|
|
3
|
-
"version": "8.0.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,25 +38,27 @@
|
|
|
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
|
-
"react-native": "src/index",
|
|
45
43
|
"wpScript": true,
|
|
46
44
|
"types": "build-types",
|
|
47
45
|
"sideEffects": false,
|
|
48
46
|
"dependencies": {
|
|
49
47
|
"@types/react": "^18.3.27",
|
|
50
48
|
"@types/react-dom": "^18.3.1",
|
|
51
|
-
"@wordpress/deprecated": "^4.48.0",
|
|
52
|
-
"@wordpress/escape-html": "^3.48.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.48.2-next.v.202606191442.0+17fe7db8a",
|
|
50
|
+
"@wordpress/escape-html": "^3.48.2-next.v.202606191442.0+17fe7db8a",
|
|
53
51
|
"change-case": "^4.1.2",
|
|
54
52
|
"is-plain-object": "^5.0.0",
|
|
55
|
-
"react": "^18.3.
|
|
56
|
-
"react-dom": "^18.3.
|
|
53
|
+
"react": "^18.3.1",
|
|
54
|
+
"react-dom": "^18.3.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@testing-library/dom": "^10.4.1",
|
|
58
|
+
"@testing-library/react": "^16.3.2"
|
|
57
59
|
},
|
|
58
60
|
"publishConfig": {
|
|
59
61
|
"access": "public"
|
|
60
62
|
},
|
|
61
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "1b6a19222df5a88f161880b5789efb3171d8f425"
|
|
62
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';
|
package/src/platform.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parts of this source were derived and modified from react-native-web,
|
|
3
|
-
* released under the MIT license.
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2016-present, Nicolas Gallagher.
|
|
6
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
1
|
/**
|
|
11
2
|
* Specification for platform-specific value selection.
|
|
12
3
|
*/
|
|
@@ -19,18 +10,14 @@ type PlatformSelectSpec< T > = {
|
|
|
19
10
|
* Component used to detect the current Platform being used.
|
|
20
11
|
* Use Platform.OS === 'web' to detect if running on web environment.
|
|
21
12
|
*
|
|
22
|
-
* This is the same concept as the React Native implementation.
|
|
23
|
-
*
|
|
24
|
-
* @see https://reactnative.dev/docs/platform-specific-code#platform-module
|
|
25
|
-
*
|
|
26
13
|
* Here is an example of how to use the select method:
|
|
27
14
|
* @example
|
|
28
15
|
* ```js
|
|
29
16
|
* import { Platform } from '@wordpress/element';
|
|
30
17
|
*
|
|
31
18
|
* const placeholderLabel = Platform.select( {
|
|
32
|
-
* native: __( 'Add media' ),
|
|
33
19
|
* web: __( 'Drag images, upload new ones or select files from your library.' ),
|
|
20
|
+
* default: __( 'Add media' ),
|
|
34
21
|
* } );
|
|
35
22
|
* ```
|
|
36
23
|
*/
|
package/src/test/platform.js
CHANGED
|
@@ -4,12 +4,20 @@
|
|
|
4
4
|
import Platform from '../platform';
|
|
5
5
|
|
|
6
6
|
describe( 'Platform', () => {
|
|
7
|
-
it( '
|
|
7
|
+
it( 'selects the web value', () => {
|
|
8
8
|
const element = Platform.select( {
|
|
9
9
|
web: <div />,
|
|
10
|
-
|
|
10
|
+
default: <button />,
|
|
11
11
|
} );
|
|
12
12
|
|
|
13
13
|
expect( element ).toEqual( <div /> );
|
|
14
14
|
} );
|
|
15
|
+
|
|
16
|
+
it( 'falls back to the default value when no web value is provided', () => {
|
|
17
|
+
const element = Platform.select( {
|
|
18
|
+
default: <button />,
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
expect( element ).toEqual( <button /> );
|
|
22
|
+
} );
|
|
15
23
|
} );
|