@wordpress/block-library 9.43.0 → 9.43.1-next.v.202604091042.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/code/edit.cjs +2 -1
- package/build/code/edit.cjs.map +2 -2
- package/build/cover/edit/color-utils.cjs +1 -1
- package/build/cover/edit/color-utils.cjs.map +2 -2
- package/build/cover/edit/index.cjs +31 -25
- package/build/cover/edit/index.cjs.map +2 -2
- package/build/cover/embed-video-utils.cjs +9 -7
- package/build/cover/embed-video-utils.cjs.map +2 -2
- package/build/file/utils/index.cjs +1 -1
- package/build/file/utils/index.cjs.map +2 -2
- package/build/form/view.cjs +1 -1
- package/build/form/view.cjs.map +2 -2
- package/build/icon/edit.cjs +1 -3
- package/build/icon/edit.cjs.map +2 -2
- package/build/image/image.cjs +4 -3
- package/build/image/image.cjs.map +2 -2
- package/build/navigation-link/link-ui/page-creator.cjs +1 -1
- package/build/navigation-link/link-ui/page-creator.cjs.map +2 -2
- package/build/navigation-link/shared/update-attributes.cjs +1 -1
- package/build/navigation-link/shared/update-attributes.cjs.map +2 -2
- package/build/navigation-link/shared/use-link-preview.cjs +1 -1
- package/build/navigation-link/shared/use-link-preview.cjs.map +2 -2
- package/build/pattern/edit.cjs +1 -1
- package/build/pattern/edit.cjs.map +2 -2
- package/build/search/block.json +0 -4
- package/build/search/edit.cjs +6 -33
- package/build/search/edit.cjs.map +2 -2
- package/build-module/code/edit.mjs +2 -1
- package/build-module/code/edit.mjs.map +2 -2
- package/build-module/cover/edit/color-utils.mjs +1 -1
- package/build-module/cover/edit/color-utils.mjs.map +2 -2
- package/build-module/cover/edit/index.mjs +39 -28
- package/build-module/cover/edit/index.mjs.map +2 -2
- package/build-module/cover/embed-video-utils.mjs +8 -6
- package/build-module/cover/embed-video-utils.mjs.map +2 -2
- package/build-module/file/utils/index.mjs +1 -1
- package/build-module/file/utils/index.mjs.map +2 -2
- package/build-module/form/view.mjs +1 -1
- package/build-module/form/view.mjs.map +2 -2
- package/build-module/icon/edit.mjs +1 -3
- package/build-module/icon/edit.mjs.map +2 -2
- package/build-module/image/image.mjs +4 -3
- package/build-module/image/image.mjs.map +2 -2
- package/build-module/navigation-link/link-ui/page-creator.mjs +1 -1
- package/build-module/navigation-link/link-ui/page-creator.mjs.map +2 -2
- package/build-module/navigation-link/shared/update-attributes.mjs +1 -1
- package/build-module/navigation-link/shared/update-attributes.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-link-preview.mjs +1 -1
- package/build-module/navigation-link/shared/use-link-preview.mjs.map +2 -2
- package/build-module/pattern/edit.mjs +1 -1
- package/build-module/pattern/edit.mjs.map +2 -2
- package/build-module/search/block.json +0 -4
- package/build-module/search/edit.mjs +6 -33
- package/build-module/search/edit.mjs.map +2 -2
- package/build-style/code/style-rtl.css +1 -1
- package/build-style/code/style.css +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/package.json +38 -38
- package/src/code/edit.js +1 -0
- package/src/code/style.scss +1 -1
- package/src/cover/edit/color-utils.js +1 -1
- package/src/cover/edit/index.js +63 -34
- package/src/cover/embed-video-utils.js +10 -8
- package/src/embed/test/index.native.js +3 -2
- package/src/file/utils/index.js +1 -1
- package/src/form/view.js +1 -1
- package/src/icon/edit.js +1 -3
- package/src/image/image.js +6 -4
- package/src/image/index.php +4 -4
- package/src/navigation-link/link-ui/page-creator.js +1 -1
- package/src/navigation-link/shared/update-attributes.js +1 -1
- package/src/navigation-link/shared/use-link-preview.js +1 -1
- package/src/pattern/edit.js +1 -1
- package/src/search/block.json +0 -4
- package/src/search/edit.js +2 -35
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/use-link-preview.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Check if a URL points to the site homepage.\n * Handles protocol (http/https) and trailing slash variations.\n * Does not match subdomains unless they are the site URL.\n *\n * @param {string} url - The URL to check\n * @param {string} homeUrl - The WordPress site URL\n * @return {boolean} True if url is the homepage\n */\nexport function isHomepage( url, homeUrl ) {\n\tif ( url === '/' ) {\n\t\treturn true;\n\t}\n\tif ( ! url || ! homeUrl ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tconst urlParsed = new URL( url, homeUrl );\n\t\tconst homeParsed = new URL( homeUrl );\n\n\t\t// Same host, i.e. sub.homepage.com or homepage.com\n\t\tif ( urlParsed.hostname !== homeParsed.hostname ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Path must match site root (normalize trailing slash)\n\t\tconst urlPath = urlParsed.pathname.replace( /\\/$/, '' );\n\t\tconst homePath = homeParsed.pathname.replace( /\\/$/, '' );\n\n\t\treturn urlPath === homePath;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.homeUrl - The WordPress site URL (required for internal/external detection)\n * @return {Object} Object with displayUrl and isExternal flag\n */\nexport function computeDisplayUrl( { linkUrl, homeUrl } = {} ) {\n\tif ( ! linkUrl ) {\n\t\treturn { displayUrl: '', isExternal: false };\n\t}\n\n\tlet displayUrl = safeDecodeURI( linkUrl );\n\tlet isExternal = false;\n\n\t// Check hash links and relative paths first - these are always internal\n\tif ( isRelativePath( linkUrl ) || isHashLink( linkUrl ) ) {\n\t\treturn { displayUrl, isExternal: false };\n\t}\n\n\t// Try to parse as a full URL to determine if it's actually external\n\t// This must happen before trusting the type attribute\n\ttry {\n\t\tconst parsedUrl = new URL( linkUrl );\n\t\t// Compare by host (not origin) so http/https to same site both count as internal\n\t\tconst siteHost = new URL( homeUrl ).host;\n\n\t\tif ( parsedUrl.host === siteHost ) {\n\t\t\t// Show only the pathname (and search/hash if present)\n\t\t\tlet path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;\n\t\t\t// Remove trailing slash\n\t\t\tif ( path.endsWith( '/' ) && path.length > 1 ) {\n\t\t\t\tpath = path.slice( 0, -1 );\n\t\t\t}\n\t\t\tdisplayUrl = path;\n\t\t} else {\n\t\t\t// Different host - this is an external link\n\t\t\tisExternal = true;\n\t\t}\n\t} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,iBAA8B;AAC9B,0BAAsD;AACtD,kBAA0B;AAC1B,uBAAuC;AAKvC,yBAAuB;AAEvB,IAAM,EAAE,kBAAkB,YAAY,eAAe,QAAI;AAAA,EACxD,oBAAAA;AACD;AAQA,SAAS,WAAY,KAAM;AAC1B,SAAO,IAAI,OAAQ,CAAE,EAAE,YAAY,IAAI,IAAI,MAAO,CAAE;AACrD;AAWO,SAAS,WAAY,KAAK,SAAU;AAC1C,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,CAAE,OAAO,CAAE,SAAU;AACzB,WAAO;AAAA,EACR;AACA,MAAI;AACH,UAAM,YAAY,IAAI,IAAK,KAAK,OAAQ;AACxC,UAAM,aAAa,IAAI,IAAK,OAAQ;AAGpC,QAAK,UAAU,aAAa,WAAW,UAAW;AACjD,aAAO;AAAA,IACR;AAGA,UAAM,UAAU,UAAU,SAAS,QAAS,OAAO,EAAG;AACtD,UAAM,WAAW,WAAW,SAAS,QAAS,OAAO,EAAG;AAExD,WAAO,YAAY;AAAA,EACpB,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAUO,SAAS,kBAAmB,EAAE,SAAS,QAAQ,IAAI,CAAC,GAAI;AAC9D,MAAK,CAAE,SAAU;AAChB,WAAO,EAAE,YAAY,IAAI,YAAY,MAAM;AAAA,EAC5C;AAEA,MAAI,iBAAa,0BAAe,OAAQ;AACxC,MAAI,aAAa;AAGjB,MAAK,eAAgB,OAAQ,KAAK,WAAY,OAAQ,GAAI;AACzD,WAAO,EAAE,YAAY,YAAY,MAAM;AAAA,EACxC;AAIA,MAAI;AACH,UAAM,YAAY,IAAI,IAAK,OAAQ;AAEnC,UAAM,WAAW,IAAI,IAAK,OAAQ,EAAE;AAEpC,QAAK,UAAU,SAAS,UAAW;AAElC,UAAI,OAAO,UAAU,WAAW,UAAU,SAAS,UAAU;AAE7D,UAAK,KAAK,SAAU,GAAI,KAAK,KAAK,SAAS,GAAI;AAC9C,eAAO,KAAK,MAAO,GAAG,EAAG;AAAA,MAC1B;AACA,mBAAa;AAAA,IACd,OAAO;AAEN,mBAAa;AAAA,IACd;AAAA,EACD,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Check if a URL points to the site homepage.\n * Handles protocol (http/https) and trailing slash variations.\n * Does not match subdomains unless they are the site URL.\n *\n * @param {string} url - The URL to check\n * @param {string} homeUrl - The WordPress site URL\n * @return {boolean} True if url is the homepage\n */\nexport function isHomepage( url, homeUrl ) {\n\tif ( url === '/' ) {\n\t\treturn true;\n\t}\n\tif ( ! url || ! homeUrl ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tconst urlParsed = new URL( url, homeUrl );\n\t\tconst homeParsed = new URL( homeUrl );\n\n\t\t// Same host, i.e. sub.homepage.com or homepage.com\n\t\tif ( urlParsed.hostname !== homeParsed.hostname ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Path must match site root (normalize trailing slash)\n\t\tconst urlPath = urlParsed.pathname.replace( /\\/$/, '' );\n\t\tconst homePath = homeParsed.pathname.replace( /\\/$/, '' );\n\n\t\treturn urlPath === homePath;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.homeUrl - The WordPress site URL (required for internal/external detection)\n * @return {Object} Object with displayUrl and isExternal flag\n */\nexport function computeDisplayUrl( { linkUrl, homeUrl } = {} ) {\n\tif ( ! linkUrl ) {\n\t\treturn { displayUrl: '', isExternal: false };\n\t}\n\n\tlet displayUrl = safeDecodeURI( linkUrl );\n\tlet isExternal = false;\n\n\t// Check hash links and relative paths first - these are always internal\n\tif ( isRelativePath( linkUrl ) || isHashLink( linkUrl ) ) {\n\t\treturn { displayUrl, isExternal: false };\n\t}\n\n\t// Try to parse as a full URL to determine if it's actually external\n\t// This must happen before trusting the type attribute\n\ttry {\n\t\tconst parsedUrl = new URL( linkUrl );\n\t\t// Compare by host (not origin) so http/https to same site both count as internal\n\t\tconst siteHost = new URL( homeUrl ).host;\n\n\t\tif ( parsedUrl.host === siteHost ) {\n\t\t\t// Show only the pathname (and search/hash if present)\n\t\t\tlet path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;\n\t\t\t// Remove trailing slash\n\t\t\tif ( path.endsWith( '/' ) && path.length > 1 ) {\n\t\t\t\tpath = path.slice( 0, -1 );\n\t\t\t}\n\t\t\tdisplayUrl = path;\n\t\t} else {\n\t\t\t// Different host - this is an external link\n\t\t\tisExternal = true;\n\t\t}\n\t} catch {\n\t\t// URL parsing failed - treat as external (e.g. no homeUrl, or URL without protocol)\n\t\tisExternal = true;\n\t}\n\n\treturn { displayUrl, isExternal };\n}\n\n/**\n * Compute badges for the link preview.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.homeUrl - WordPress site URL (for homepage detection)\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {boolean} options.isExternal - Whether link is external\n * @param {string} options.entityStatus - Entity status (publish, draft, etc.)\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Array} Array of badge objects with label and intent\n */\nexport function computeBadges( {\n\turl,\n\thomeUrl,\n\ttype,\n\tisExternal,\n\tentityStatus,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\tconst badges = [];\n\t// Kind badge\n\tif ( url ) {\n\t\tif ( isExternal ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'External link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHashLink( url ) ) {\n\t\t\t// Hash links should be detected before type check\n\t\t\t// because they're not entity links even if type is set\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Internal link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHomepage( url, homeUrl ) ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Homepage' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( type && type !== 'custom' ) {\n\t\t\t// Show entity type badge (page, post, category, etc.)\n\t\t\t// but not 'custom' since that's just a manual link\n\t\t\tbadges.push( { label: capitalize( type ), intent: 'default' } );\n\t\t} else {\n\t\t\t// Internal link (not external, not hash, not entity)\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Page' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Status badge\n\tif ( hasBinding && ! isEntityAvailable ) {\n\t\tbadges.push( {\n\t\t\tlabel: sprintf(\n\t\t\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t__( 'Missing %s' ),\n\t\t\t\ttype\n\t\t\t),\n\t\t\tintent: 'error',\n\t\t} );\n\t} else if ( ! url ) {\n\t\tbadges.push( { label: __( 'No link selected' ), intent: 'error' } );\n\t} else if ( entityStatus ) {\n\t\tconst statusMap = {\n\t\t\tpublish: { label: __( 'Published' ), intent: 'success' },\n\t\t\tfuture: { label: __( 'Scheduled' ), intent: 'warning' },\n\t\t\tdraft: { label: __( 'Draft' ), intent: 'warning' },\n\t\t\tpending: { label: __( 'Pending' ), intent: 'warning' },\n\t\t\tprivate: { label: __( 'Private' ), intent: 'default' },\n\t\t\ttrash: { label: __( 'Trash' ), intent: 'error' },\n\t\t};\n\t\tconst badge = statusMap[ entityStatus ];\n\t\tif ( badge ) {\n\t\t\tbadges.push( badge );\n\t\t}\n\t}\n\n\treturn badges;\n}\n\n/**\n * Hook to compute link preview data for display.\n *\n * This hook takes raw link data and entity information and computes\n * presentation-ready preview data including formatted title, URL, and badges.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {Object} options.entityRecord - Entity record\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Object} Preview data object with title, url, image, and badges\n */\nexport function useLinkPreview( {\n\turl,\n\tentityRecord,\n\ttype,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\t// Get the WordPress homepage URL from settings\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreDataStore ).getEntityRecord(\n\t\t\t'root',\n\t\t\t'__unstableBase'\n\t\t)?.home;\n\t}, [] );\n\n\tconst title =\n\t\tentityRecord?.title?.rendered ||\n\t\tentityRecord?.title ||\n\t\tentityRecord?.name;\n\n\t// Fetch rich URL data if we don't have a title. Internal links should have passed a title.\n\tconst { richData } = useRemoteUrlData( title ? null : url );\n\n\t// Compute display URL and external flag\n\tconst { displayUrl, isExternal } = computeDisplayUrl( {\n\t\tlinkUrl: url,\n\t\thomeUrl,\n\t} );\n\n\tconst image = useSelect(\n\t\t( select ) => {\n\t\t\t// Only fetch for post-type entities with featured media\n\t\t\tif ( ! entityRecord?.featured_media ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\n\t\t\t// Get the media entity to fetch the image URL\n\t\t\tconst media = getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tentityRecord.featured_media\n\t\t\t);\n\n\t\t\t// Return the thumbnail or medium size URL, fallback to source_url\n\t\t\treturn (\n\t\t\t\tmedia?.media_details?.sizes?.thumbnail?.source_url ||\n\t\t\t\tmedia?.media_details?.sizes?.medium?.source_url ||\n\t\t\t\tmedia?.source_url ||\n\t\t\t\tnull\n\t\t\t);\n\t\t},\n\t\t[ entityRecord?.featured_media ]\n\t);\n\n\t// Compute badges\n\tconst badges = computeBadges( {\n\t\turl,\n\t\thomeUrl,\n\t\ttype,\n\t\tisExternal,\n\t\tentityStatus: entityRecord?.status,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\t// Get display title - use provided title, fallback to rich data, or URL\n\tconst displayTitle = url\n\t\t? title || richData?.title || safeDecodeURI( url )\n\t\t: __( 'Add link' );\n\n\treturn {\n\t\ttitle: displayTitle,\n\t\turl: displayUrl,\n\t\timage,\n\t\tbadges,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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OAAO,cACP;AAAA,IAEF;AAAA,IACA,CAAE,cAAc,cAAe;AAAA,EAChC;AAGA,QAAM,SAAS,cAAe;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACD,CAAE;AAGF,QAAM,eAAe,MAClB,SAAS,UAAU,aAAS,0BAAe,GAAI,QAC/C,gBAAI,UAAW;AAElB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "coreDataStore"]
|
|
7
7
|
}
|
package/build/pattern/edit.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/pattern/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { cloneBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tWarning,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useParsePatternDependencies } from './recursion-detector';\n\nconst PatternEdit = ( { attributes, clientId } ) => {\n\tconst registry = useRegistry();\n\tconst selectedPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tattributes.slug\n\t\t\t),\n\t\t[ attributes.slug ]\n\t);\n\n\tconst currentThemeStylesheet = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\n\tconst {\n\t\treplaceBlocks,\n\t\tsetBlockEditingMode,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = useDispatch( blockEditorStore );\n\tconst { getBlockRootClientId, getBlockEditingMode } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst [ hasRecursionError, setHasRecursionError ] = useState( false );\n\tconst parsePatternDependencies = useParsePatternDependencies();\n\n\t// Duplicated in packages/editor/src/components/start-template-options/index.js.\n\tfunction injectThemeAttributeInBlockTemplateContent( block ) {\n\t\tif (\n\t\t\tblock.innerBlocks.find(\n\t\t\t\t( innerBlock ) => innerBlock.name === 'core/template-part'\n\t\t\t)\n\t\t) {\n\t\t\tblock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\t\tif (\n\t\t\t\t\tinnerBlock.name === 'core/template-part' &&\n\t\t\t\t\tinnerBlock.attributes.theme === undefined\n\t\t\t\t) {\n\t\t\t\t\tinnerBlock.attributes.theme = currentThemeStylesheet;\n\t\t\t\t}\n\t\t\t\treturn innerBlock;\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\tblock.name === 'core/template-part' &&\n\t\t\tblock.attributes.theme === undefined\n\t\t) {\n\t\t\tblock.attributes.theme = currentThemeStylesheet;\n\t\t}\n\t\treturn block;\n\t}\n\n\t// Run this effect when the component loads.\n\t// This adds the Pattern's contents to the post.\n\t// This change won't be saved.\n\t// It will continue to pull from the pattern file unless changes are made to its respective template part.\n\tuseEffect( () => {\n\t\tif ( ! hasRecursionError && selectedPattern?.blocks ) {\n\t\t\ttry {\n\t\t\t\tparsePatternDependencies( selectedPattern );\n\t\t\t} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA2B;AAC3B,kBAAoD;AACpD,qBAAoC;AACpC,0BAIO;AACP,uBAAmC;AACnC,kBAA4B;AAK5B,gCAA4C;AAkIxC;AAhIJ,IAAM,cAAc,CAAE,EAAE,YAAY,SAAS,MAAO;AACnD,QAAM,eAAW,yBAAY;AAC7B,QAAM,sBAAkB;AAAA,IACvB,CAAE,WACD,OAAQ,oBAAAA,KAAiB,EAAE;AAAA,MAC1B,WAAW;AAAA,IACZ;AAAA,IACD,CAAE,WAAW,IAAK;AAAA,EACnB;AAEA,QAAM,6BAAyB;AAAA,IAC9B,CAAE,WAAY,OAAQ,iBAAAC,KAAU,EAAE,gBAAgB,GAAG;AAAA,IACrD,CAAC;AAAA,EACF;AAEA,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACD,QAAI,yBAAa,oBAAAD,KAAiB;AAClC,QAAM,EAAE,sBAAsB,oBAAoB,QACjD,uBAAW,oBAAAA,KAAiB;AAE7B,QAAM,CAAE,mBAAmB,oBAAqB,QAAI,yBAAU,KAAM;AACpE,QAAM,+BAA2B,uDAA4B;AAG7D,WAAS,2CAA4C,OAAQ;AAC5D,QACC,MAAM,YAAY;AAAA,MACjB,CAAE,eAAgB,WAAW,SAAS;AAAA,IACvC,GACC;AACD,YAAM,cAAc,MAAM,YAAY,IAAK,CAAE,eAAgB;AAC5D,YACC,WAAW,SAAS,wBACpB,WAAW,WAAW,UAAU,QAC/B;AACD,qBAAW,WAAW,QAAQ;AAAA,QAC/B;AACA,eAAO;AAAA,MACR,CAAE;AAAA,IACH;AAEA,QACC,MAAM,SAAS,wBACf,MAAM,WAAW,UAAU,QAC1B;AACD,YAAM,WAAW,QAAQ;AAAA,IAC1B;AACA,WAAO;AAAA,EACR;AAMA,gCAAW,MAAM;AAChB,QAAK,CAAE,qBAAqB,iBAAiB,QAAS;AACrD,UAAI;AACH,iCAA0B,eAAgB;AAAA,MAC3C,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { cloneBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tWarning,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useParsePatternDependencies } from './recursion-detector';\n\nconst PatternEdit = ( { attributes, clientId } ) => {\n\tconst registry = useRegistry();\n\tconst selectedPattern = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).__experimentalGetParsedPattern(\n\t\t\t\tattributes.slug\n\t\t\t),\n\t\t[ attributes.slug ]\n\t);\n\n\tconst currentThemeStylesheet = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\n\tconst {\n\t\treplaceBlocks,\n\t\tsetBlockEditingMode,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = useDispatch( blockEditorStore );\n\tconst { getBlockRootClientId, getBlockEditingMode } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst [ hasRecursionError, setHasRecursionError ] = useState( false );\n\tconst parsePatternDependencies = useParsePatternDependencies();\n\n\t// Duplicated in packages/editor/src/components/start-template-options/index.js.\n\tfunction injectThemeAttributeInBlockTemplateContent( block ) {\n\t\tif (\n\t\t\tblock.innerBlocks.find(\n\t\t\t\t( innerBlock ) => innerBlock.name === 'core/template-part'\n\t\t\t)\n\t\t) {\n\t\t\tblock.innerBlocks = block.innerBlocks.map( ( innerBlock ) => {\n\t\t\t\tif (\n\t\t\t\t\tinnerBlock.name === 'core/template-part' &&\n\t\t\t\t\tinnerBlock.attributes.theme === undefined\n\t\t\t\t) {\n\t\t\t\t\tinnerBlock.attributes.theme = currentThemeStylesheet;\n\t\t\t\t}\n\t\t\t\treturn innerBlock;\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\tblock.name === 'core/template-part' &&\n\t\t\tblock.attributes.theme === undefined\n\t\t) {\n\t\t\tblock.attributes.theme = currentThemeStylesheet;\n\t\t}\n\t\treturn block;\n\t}\n\n\t// Run this effect when the component loads.\n\t// This adds the Pattern's contents to the post.\n\t// This change won't be saved.\n\t// It will continue to pull from the pattern file unless changes are made to its respective template part.\n\tuseEffect( () => {\n\t\tif ( ! hasRecursionError && selectedPattern?.blocks ) {\n\t\t\ttry {\n\t\t\t\tparsePatternDependencies( selectedPattern );\n\t\t\t} catch {\n\t\t\t\tsetHasRecursionError( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We batch updates to block list settings to avoid triggering cascading renders\n\t\t\t// for each container block included in a tree and optimize initial render.\n\t\t\t// Since the above uses microtasks, we need to use a microtask here as well,\n\t\t\t// because nested pattern blocks cannot be inserted if the parent block supports\n\t\t\t// inner blocks but doesn't have blockSettings in the state.\n\t\t\twindow.queueMicrotask( () => {\n\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\t\t// Clone blocks from the pattern before insertion to ensure they receive\n\t\t\t\t// distinct client ids. See https://github.com/WordPress/gutenberg/issues/50628.\n\t\t\t\tconst clonedBlocks = selectedPattern.blocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock(\n\t\t\t\t\t\tinjectThemeAttributeInBlockTemplateContent( block )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\t// If the pattern has a single block and categories, we should add the\n\t\t\t\t// categories of the pattern to the block's metadata.\n\t\t\t\tif (\n\t\t\t\t\tclonedBlocks.length === 1 &&\n\t\t\t\t\tselectedPattern.categories?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tclonedBlocks[ 0 ].attributes = {\n\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t...clonedBlocks[ 0 ].attributes.metadata,\n\t\t\t\t\t\t\tcategories: selectedPattern.categories,\n\t\t\t\t\t\t\tpatternName: selectedPattern.name,\n\t\t\t\t\t\t\tname:\n\t\t\t\t\t\t\t\tclonedBlocks[ 0 ].attributes.metadata.name ||\n\t\t\t\t\t\t\t\tselectedPattern.title,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tconst rootEditingMode = getBlockEditingMode( rootClientId );\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Temporarily set the root block to default mode to allow replacing the pattern.\n\t\t\t\t\t// This could happen when the page is disabling edits of non-content blocks.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, 'default' );\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\treplaceBlocks( clientId, clonedBlocks );\n\t\t\t\t\t// Restore the root block's original mode.\n\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\tsetBlockEditingMode( rootClientId, rootEditingMode );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tclientId,\n\t\thasRecursionError,\n\t\tselectedPattern,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\treplaceBlocks,\n\t\tgetBlockEditingMode,\n\t\tsetBlockEditingMode,\n\t\tgetBlockRootClientId,\n\t] );\n\n\tconst props = useBlockProps();\n\n\tif ( hasRecursionError ) {\n\t\treturn (\n\t\t\t<div { ...props }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t// translators: A warning in which %s is the name of a pattern.\n\t\t\t\t\t\t__( 'Pattern \"%s\" cannot be rendered inside itself.' ),\n\t\t\t\t\t\tselectedPattern?.name\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn <div { ...props } />;\n};\n\nexport default PatternEdit;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA2B;AAC3B,kBAAoD;AACpD,qBAAoC;AACpC,0BAIO;AACP,uBAAmC;AACnC,kBAA4B;AAK5B,gCAA4C;AAkIxC;AAhIJ,IAAM,cAAc,CAAE,EAAE,YAAY,SAAS,MAAO;AACnD,QAAM,eAAW,yBAAY;AAC7B,QAAM,sBAAkB;AAAA,IACvB,CAAE,WACD,OAAQ,oBAAAA,KAAiB,EAAE;AAAA,MAC1B,WAAW;AAA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EAAE;AAAA,YACrB,UAAU;AAAA,cACT,GAAG,aAAc,CAAE,EAAE,WAAW;AAAA,cAChC,YAAY,gBAAgB;AAAA,cAC5B,aAAa,gBAAgB;AAAA,cAC7B,MACC,aAAc,CAAE,EAAE,WAAW,SAAS,QACtC,gBAAgB;AAAA,YAClB;AAAA,UACD;AAAA,QACD;AACA,cAAM,kBAAkB,oBAAqB,YAAa;AAC1D,iBAAS,MAAO,MAAM;AAGrB,kDAAwC;AACxC,8BAAqB,cAAc,SAAU;AAC7C,kDAAwC;AACxC,wBAAe,UAAU,YAAa;AAEtC,kDAAwC;AACxC,8BAAqB,cAAc,eAAgB;AAAA,QACpD,CAAE;AAAA,MACH,CAAE;AAAA,IACH;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,QAAM,YAAQ,mCAAc;AAE5B,MAAK,mBAAoB;AACxB,WACC,4CAAC,SAAM,GAAG,OACT,sDAAC,+BACE;AAAA;AAAA,UAED,gBAAI,gDAAiD;AAAA,MACrD,iBAAiB;AAAA,IAClB,GACD,GACD;AAAA,EAEF;AAEA,SAAO,4CAAC,SAAM,GAAG,OAAQ;AAC1B;AAEA,IAAO,eAAQ;",
|
|
6
6
|
"names": ["blockEditorStore", "coreStore"]
|
|
7
7
|
}
|
package/build/search/block.json
CHANGED
package/build/search/edit.cjs
CHANGED
|
@@ -65,7 +65,6 @@ function SearchEdit({
|
|
|
65
65
|
buttonText,
|
|
66
66
|
buttonPosition,
|
|
67
67
|
buttonUseIcon,
|
|
68
|
-
isSearchFieldHidden,
|
|
69
68
|
style
|
|
70
69
|
} = attributes;
|
|
71
70
|
const wasJustInsertedIntoNavigationBlock = (0, import_data.useSelect)(
|
|
@@ -120,27 +119,13 @@ function SearchEdit({
|
|
|
120
119
|
const isButtonPositionOutside = "button-outside" === buttonPosition;
|
|
121
120
|
const hasNoButton = "no-button" === buttonPosition;
|
|
122
121
|
const hasOnlyButton = "button-only" === buttonPosition;
|
|
122
|
+
const isSearchFieldHidden = hasOnlyButton && !isSelected;
|
|
123
123
|
const searchFieldRef = (0, import_element.useRef)();
|
|
124
124
|
const buttonRef = (0, import_element.useRef)();
|
|
125
125
|
const units = (0, import_components.__experimentalUseCustomUnits)({
|
|
126
126
|
availableUnits: ["%", "px"],
|
|
127
127
|
defaultValues: { "%": import_utils.PC_WIDTH_DEFAULT, px: import_utils.PX_WIDTH_DEFAULT }
|
|
128
128
|
});
|
|
129
|
-
(0, import_element.useEffect)(() => {
|
|
130
|
-
if (hasOnlyButton && !isSelected) {
|
|
131
|
-
setAttributes({
|
|
132
|
-
isSearchFieldHidden: true
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}, [hasOnlyButton, isSelected, setAttributes]);
|
|
136
|
-
(0, import_element.useEffect)(() => {
|
|
137
|
-
if (!hasOnlyButton || !isSelected) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
setAttributes({
|
|
141
|
-
isSearchFieldHidden: false
|
|
142
|
-
});
|
|
143
|
-
}, [hasOnlyButton, isSelected, setAttributes, width]);
|
|
144
129
|
const getBlockClassNames = () => {
|
|
145
130
|
return (0, import_clsx.default)(
|
|
146
131
|
className,
|
|
@@ -150,7 +135,7 @@ function SearchEdit({
|
|
|
150
135
|
hasOnlyButton ? "wp-block-search__button-only" : void 0,
|
|
151
136
|
!buttonUseIcon && !hasNoButton ? "wp-block-search__text-button" : void 0,
|
|
152
137
|
buttonUseIcon && !hasNoButton ? "wp-block-search__icon-button" : void 0,
|
|
153
|
-
|
|
138
|
+
isSearchFieldHidden ? "wp-block-search__searchfield-hidden" : void 0
|
|
154
139
|
);
|
|
155
140
|
};
|
|
156
141
|
const buttonPositionControls = [
|
|
@@ -231,13 +216,6 @@ function SearchEdit({
|
|
|
231
216
|
borderBottomRightRadius: borderProps.style?.borderBottomRightRadius
|
|
232
217
|
} : borderProps.style
|
|
233
218
|
};
|
|
234
|
-
const handleButtonClick = () => {
|
|
235
|
-
if (hasOnlyButton) {
|
|
236
|
-
setAttributes({
|
|
237
|
-
isSearchFieldHidden: !isSearchFieldHidden
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
219
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
242
220
|
buttonUseIcon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
243
221
|
"button",
|
|
@@ -246,7 +224,6 @@ function SearchEdit({
|
|
|
246
224
|
className: buttonClasses,
|
|
247
225
|
style: buttonStyles,
|
|
248
226
|
"aria-label": buttonText ? (0, import_dom.__unstableStripHTML)(buttonText) : (0, import_i18n.__)("Search"),
|
|
249
|
-
onClick: handleButtonClick,
|
|
250
227
|
ref: buttonRef,
|
|
251
228
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: import_icons.search })
|
|
252
229
|
}
|
|
@@ -261,8 +238,7 @@ function SearchEdit({
|
|
|
261
238
|
placeholder: (0, import_i18n.__)("Add button text\u2026"),
|
|
262
239
|
withoutInteractiveFormatting: true,
|
|
263
240
|
value: buttonText,
|
|
264
|
-
onChange: (html) => setAttributes({ buttonText: html })
|
|
265
|
-
onClick: handleButtonClick
|
|
241
|
+
onChange: (html) => setAttributes({ buttonText: html })
|
|
266
242
|
}
|
|
267
243
|
)
|
|
268
244
|
] });
|
|
@@ -278,8 +254,7 @@ function SearchEdit({
|
|
|
278
254
|
widthUnit: void 0,
|
|
279
255
|
showLabel: true,
|
|
280
256
|
buttonUseIcon: false,
|
|
281
|
-
buttonPosition: "button-outside"
|
|
282
|
-
isSearchFieldHidden: false
|
|
257
|
+
buttonPosition: "button-outside"
|
|
283
258
|
});
|
|
284
259
|
},
|
|
285
260
|
dropdownMenuProps,
|
|
@@ -314,8 +289,7 @@ function SearchEdit({
|
|
|
314
289
|
label: (0, import_i18n.__)("Button position"),
|
|
315
290
|
onDeselect: () => {
|
|
316
291
|
setAttributes({
|
|
317
|
-
buttonPosition: "button-outside"
|
|
318
|
-
isSearchFieldHidden: false
|
|
292
|
+
buttonPosition: "button-outside"
|
|
319
293
|
});
|
|
320
294
|
},
|
|
321
295
|
isShownByDefault: true,
|
|
@@ -327,8 +301,7 @@ function SearchEdit({
|
|
|
327
301
|
label: (0, import_i18n.__)("Button position"),
|
|
328
302
|
onChange: (value) => {
|
|
329
303
|
setAttributes({
|
|
330
|
-
buttonPosition: value
|
|
331
|
-
isSearchFieldHidden: value === "button-only"
|
|
304
|
+
buttonPosition: value
|
|
332
305
|
});
|
|
333
306
|
},
|
|
334
307
|
options: buttonPositionControls
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/search/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tInspectorControls,\n\tRichText,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalUseColorProps as useColorProps,\n\tgetTypographyClassesAndStyles as useTypographyProps,\n\tstore as blockEditorStore,\n\t__experimentalGetElementClassName,\n\tuseSettings,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tSelectControl,\n\tToggleControl,\n\tResizableBox,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { Icon, search } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPC_WIDTH_DEFAULT,\n\tPX_WIDTH_DEFAULT,\n\tMIN_WIDTH,\n\tisPercentageUnit,\n} from './utils.js';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\n// Used to calculate border radius adjustment to avoid \"fat\" corners when\n// button is placed inside wrapper.\nconst DEFAULT_INNER_PADDING = '4px';\nconst PERCENTAGE_WIDTHS = [ 25, 50, 75, 100 ];\n\nexport default function SearchEdit( {\n\tclassName,\n\tattributes,\n\tsetAttributes,\n\ttoggleSelection,\n\tisSelected,\n\tclientId,\n} ) {\n\tconst {\n\t\tlabel,\n\t\tshowLabel,\n\t\tplaceholder,\n\t\twidth,\n\t\twidthUnit,\n\t\talign,\n\t\tbuttonText,\n\t\tbuttonPosition,\n\t\tbuttonUseIcon,\n\t\tisSearchFieldHidden,\n\t\tstyle,\n\t} = attributes;\n\n\tconst wasJustInsertedIntoNavigationBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParentsByBlockName, wasBlockJustInserted } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\treturn (\n\t\t\t\t!! getBlockParentsByBlockName( clientId, 'core/navigation' )\n\t\t\t\t\t?.length && wasBlockJustInserted( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( wasJustInsertedIntoNavigationBlock ) {\n\t\t\t// This side-effect should not create an undo level.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\tshowLabel: false,\n\t\t\t\tbuttonUseIcon: true,\n\t\t\t\tbuttonPosition: 'button-inside',\n\t\t\t} );\n\t\t}\n\t}, [\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\twasJustInsertedIntoNavigationBlock,\n\t\tsetAttributes,\n\t] );\n\n\tconst borderRadius = style?.border?.radius;\n\tlet borderProps = useBorderProps( attributes );\n\n\t// Check for old deprecated numerical border radius. Done as a separate\n\t// check so that a borderRadius style won't overwrite the longhand\n\t// per-corner styles.\n\tif ( typeof borderRadius === 'number' ) {\n\t\tborderProps = {\n\t\t\t...borderProps,\n\t\t\tstyle: {\n\t\t\t\t...borderProps.style,\n\t\t\t\tborderRadius: `${ borderRadius }px`,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst colorProps = useColorProps( attributes );\n\tconst [ fluidTypographySettings, layout ] = useSettings(\n\t\t'typography.fluid',\n\t\t'layout'\n\t);\n\tconst typographyProps = useTypographyProps( attributes, {\n\t\ttypography: {\n\t\t\tfluid: fluidTypographySettings,\n\t\t},\n\t\tlayout: {\n\t\t\twideSize: layout?.wideSize,\n\t\t},\n\t} );\n\tconst unitControlInstanceId = useInstanceId( UnitControl );\n\tconst unitControlInputId = `wp-block-search__width-${ unitControlInstanceId }`;\n\tconst isButtonPositionInside = 'button-inside' === buttonPosition;\n\tconst isButtonPositionOutside = 'button-outside' === buttonPosition;\n\tconst hasNoButton = 'no-button' === buttonPosition;\n\tconst hasOnlyButton = 'button-only' === buttonPosition;\n\tconst searchFieldRef = useRef();\n\tconst buttonRef = useRef();\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: [ '%', 'px' ],\n\t\tdefaultValues: { '%': PC_WIDTH_DEFAULT, px: PX_WIDTH_DEFAULT },\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( hasOnlyButton && ! isSelected ) {\n\t\t\tsetAttributes( {\n\t\t\t\tisSearchFieldHidden: true,\n\t\t\t} );\n\t\t}\n\t}, [ hasOnlyButton, isSelected, setAttributes ] );\n\n\t// Show the search field when width changes.\n\tuseEffect( () => {\n\t\tif ( ! hasOnlyButton || ! isSelected ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tisSearchFieldHidden: false,\n\t\t} );\n\t}, [ hasOnlyButton, isSelected, setAttributes, width ] );\n\n\tconst getBlockClassNames = () => {\n\t\treturn clsx(\n\t\t\tclassName,\n\t\t\tisButtonPositionInside\n\t\t\t\t? 'wp-block-search__button-inside'\n\t\t\t\t: undefined,\n\t\t\tisButtonPositionOutside\n\t\t\t\t? 'wp-block-search__button-outside'\n\t\t\t\t: undefined,\n\t\t\thasNoButton ? 'wp-block-search__no-button' : undefined,\n\t\t\thasOnlyButton ? 'wp-block-search__button-only' : undefined,\n\t\t\t! buttonUseIcon && ! hasNoButton\n\t\t\t\t? 'wp-block-search__text-button'\n\t\t\t\t: undefined,\n\t\t\tbuttonUseIcon && ! hasNoButton\n\t\t\t\t? 'wp-block-search__icon-button'\n\t\t\t\t: undefined,\n\t\t\thasOnlyButton && isSearchFieldHidden\n\t\t\t\t? 'wp-block-search__searchfield-hidden'\n\t\t\t\t: undefined\n\t\t);\n\t};\n\n\tconst buttonPositionControls = [\n\t\t{\n\t\t\tlabel: __( 'Button outside' ),\n\t\t\tvalue: 'button-outside',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'Button inside' ),\n\t\t\tvalue: 'button-inside',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'No button' ),\n\t\t\tvalue: 'no-button',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'Button only' ),\n\t\t\tvalue: 'button-only',\n\t\t},\n\t];\n\n\tconst getResizableSides = () => {\n\t\tif ( hasOnlyButton ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn {\n\t\t\tright: align !== 'right',\n\t\t\tleft: align === 'right',\n\t\t};\n\t};\n\n\tconst renderTextField = () => {\n\t\t// If the input is inside the wrapper, the wrapper gets the border color styles/classes, not the input control.\n\t\tconst textFieldClasses = clsx(\n\t\t\t'wp-block-search__input',\n\t\t\tisButtonPositionInside ? undefined : borderProps.className,\n\t\t\ttypographyProps.className\n\t\t);\n\t\tconst textFieldStyles = {\n\t\t\t...( isButtonPositionInside\n\t\t\t\t? {\n\t\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\t\tborderTopLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopLeftRadius,\n\t\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t\t }\n\t\t\t\t: borderProps.style ),\n\t\t\t...typographyProps.style,\n\t\t\ttextDecoration: undefined,\n\t\t};\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\ttype=\"search\"\n\t\t\t\tclassName={ textFieldClasses }\n\t\t\t\tstyle={ textFieldStyles }\n\t\t\t\taria-label={ __( 'Optional placeholder text' ) }\n\t\t\t\t// We hide the placeholder field's placeholder when there is a value. This\n\t\t\t\t// stops screen readers from reading the placeholder field's placeholder\n\t\t\t\t// which is confusing.\n\t\t\t\tplaceholder={\n\t\t\t\t\tplaceholder ? undefined : __( 'Optional placeholder\u2026' )\n\t\t\t\t}\n\t\t\t\tvalue={ placeholder }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tsetAttributes( { placeholder: event.target.value } )\n\t\t\t\t}\n\t\t\t\tref={ searchFieldRef }\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst renderButton = () => {\n\t\t// If the button is inside the wrapper, the wrapper gets the border color styles/classes, not the button.\n\t\tconst buttonClasses = clsx(\n\t\t\t'wp-block-search__button',\n\t\t\tcolorProps.className,\n\t\t\ttypographyProps.className,\n\t\t\tisButtonPositionInside ? undefined : borderProps.className,\n\t\t\tbuttonUseIcon ? 'has-icon' : undefined,\n\t\t\t__experimentalGetElementClassName( 'button' )\n\t\t);\n\t\tconst buttonStyles = {\n\t\t\t...colorProps.style,\n\t\t\t...typographyProps.style,\n\t\t\t...( isButtonPositionInside\n\t\t\t\t? {\n\t\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\t\tborderTopLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopLeftRadius,\n\t\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t\t }\n\t\t\t\t: borderProps.style ),\n\t\t};\n\t\tconst handleButtonClick = () => {\n\t\t\tif ( hasOnlyButton ) {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tisSearchFieldHidden: ! isSearchFieldHidden,\n\t\t\t\t} );\n\t\t\t}\n\t\t};\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ buttonUseIcon && (\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ buttonClasses }\n\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\tbuttonText\n\t\t\t\t\t\t\t\t? stripHTML( buttonText )\n\t\t\t\t\t\t\t\t: __( 'Search' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonClick={ handleButtonClick }\n\t\t\t\t\t\tref={ buttonRef }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ search } />\n\t\t\t\t\t</button>\n\t\t\t\t) }\n\n\t\t\t\t{ ! buttonUseIcon && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"buttonText\"\n\t\t\t\t\t\tclassName={ buttonClasses }\n\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Add button text\u2026' ) }\n\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\tvalue={ buttonText }\n\t\t\t\t\t\tonChange={ ( html ) =>\n\t\t\t\t\t\t\tsetAttributes( { buttonText: html } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonClick={ handleButtonClick }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t};\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst controls = (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\twidth: undefined,\n\t\t\t\t\t\t\twidthUnit: undefined,\n\t\t\t\t\t\t\tshowLabel: true,\n\t\t\t\t\t\t\tbuttonUseIcon: false,\n\t\t\t\t\t\t\tbuttonPosition: 'button-outside',\n\t\t\t\t\t\t\tisSearchFieldHidden: false,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => ! showLabel }\n\t\t\t\t\t\tlabel={ __( 'Show label' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowLabel: true,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tchecked={ showLabel }\n\t\t\t\t\t\t\tlabel={ __( 'Show label' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowLabel: value,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => buttonPosition !== 'button-outside' }\n\t\t\t\t\t\tlabel={ __( 'Button position' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tbuttonPosition: 'button-outside',\n\t\t\t\t\t\t\t\tisSearchFieldHidden: false,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\tvalue={ buttonPosition }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Button position' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tbuttonPosition: value,\n\t\t\t\t\t\t\t\t\tisSearchFieldHidden:\n\t\t\t\t\t\t\t\t\t\tvalue === 'button-only',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\toptions={ buttonPositionControls }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ buttonPosition !== 'no-button' && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => !! buttonUseIcon }\n\t\t\t\t\t\t\tlabel={ __( 'Use button with icon' ) }\n\t\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tbuttonUseIcon: false,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tchecked={ buttonUseIcon }\n\t\t\t\t\t\t\t\tlabel={ __( 'Use button with icon' ) }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tbuttonUseIcon: value,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! width }\n\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\twidth: undefined,\n\t\t\t\t\t\t\t\twidthUnit: undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack>\n\t\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\t\t\tid={ unitControlInputId } // Unused, kept for backwards compatibility\n\t\t\t\t\t\t\t\tmin={\n\t\t\t\t\t\t\t\t\tisPercentageUnit( widthUnit )\n\t\t\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t\t\t: MIN_WIDTH\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\t\tisPercentageUnit( widthUnit )\n\t\t\t\t\t\t\t\t\t\t? 100\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\t\t\tonChange={ ( newWidth ) => {\n\t\t\t\t\t\t\t\t\tconst parsedNewWidth =\n\t\t\t\t\t\t\t\t\t\tnewWidth === ''\n\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t: parseInt( newWidth, 10 );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth: parsedNewWidth,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tonUnitChange={ ( newUnit ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth:\n\t\t\t\t\t\t\t\t\t\t\t'%' === newUnit\n\t\t\t\t\t\t\t\t\t\t\t\t? PC_WIDTH_DEFAULT\n\t\t\t\t\t\t\t\t\t\t\t\t: PX_WIDTH_DEFAULT,\n\t\t\t\t\t\t\t\t\t\twidthUnit: newUnit,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t__unstableInputWidth=\"80px\"\n\t\t\t\t\t\t\t\tvalue={ `${ width }${ widthUnit }` }\n\t\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Percentage Width' ) }\n\t\t\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\t\t\tPERCENTAGE_WIDTHS.includes( width ) &&\n\t\t\t\t\t\t\t\t\twidthUnit === '%'\n\t\t\t\t\t\t\t\t\t\t? width\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tonChange={ ( newWidth ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth: newWidth,\n\t\t\t\t\t\t\t\t\t\twidthUnit: '%',\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ PERCENTAGE_WIDTHS.map( ( widthValue ) => {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ widthValue }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %d: Percentage value. */\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%d%%' ),\n\t\t\t\t\t\t\t\t\t\t\t\twidthValue\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\n\tconst isNonZeroBorderRadius = ( radius ) =>\n\t\tradius !== undefined && parseInt( radius, 10 ) !== 0;\n\n\tconst padBorderRadius = ( radius ) =>\n\t\tisNonZeroBorderRadius( radius )\n\t\t\t? `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`\n\t\t\t: undefined;\n\n\tconst getWrapperStyles = () => {\n\t\tconst styles = isButtonPositionInside\n\t\t\t? borderProps.style\n\t\t\t: {\n\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\tborderTopLeftRadius: borderProps.style?.borderTopLeftRadius,\n\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t };\n\n\t\tif ( isButtonPositionInside ) {\n\t\t\t// We have button inside wrapper and a border radius value to apply.\n\t\t\t// Add default padding so we don't get \"fat\" corners.\n\t\t\t//\n\t\t\t// CSS calc() is used here to support non-pixel units. The inline\n\t\t\t// style using calc() will only apply if both values have units.\n\n\t\t\tif ( typeof borderRadius === 'object' ) {\n\t\t\t\t// Individual corner border radii present.\n\t\t\t\tconst {\n\t\t\t\t\tborderTopLeftRadius,\n\t\t\t\t\tborderTopRightRadius,\n\t\t\t\t\tborderBottomLeftRadius,\n\t\t\t\t\tborderBottomRightRadius,\n\t\t\t\t} = borderProps.style;\n\n\t\t\t\treturn {\n\t\t\t\t\t...styles,\n\t\t\t\t\tborderTopLeftRadius: padBorderRadius( borderTopLeftRadius ),\n\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\tpadBorderRadius( borderTopRightRadius ),\n\t\t\t\t\tborderBottomLeftRadius: padBorderRadius(\n\t\t\t\t\t\tborderBottomLeftRadius\n\t\t\t\t\t),\n\t\t\t\t\tborderBottomRightRadius: padBorderRadius(\n\t\t\t\t\t\tborderBottomRightRadius\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// The inline style using calc() will only apply if both values\n\t\t\t// supplied to calc() have units. Deprecated block's may have\n\t\t\t// unitless integer.\n\t\t\tconst radius = Number.isInteger( borderRadius )\n\t\t\t\t? `${ borderRadius }px`\n\t\t\t\t: borderRadius;\n\n\t\t\tstyles.borderRadius = `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`;\n\t\t}\n\n\t\treturn styles;\n\t};\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: getBlockClassNames(),\n\t\tstyle: {\n\t\t\t...typographyProps.style,\n\t\t\t// Input opts out of text decoration.\n\t\t\ttextDecoration: undefined,\n\t\t},\n\t} );\n\n\tconst labelClassnames = clsx(\n\t\t'wp-block-search__label',\n\t\ttypographyProps.className\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ controls }\n\n\t\t\t{ showLabel && (\n\t\t\t\t<RichText\n\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\tclassName={ labelClassnames }\n\t\t\t\t\taria-label={ __( 'Label text' ) }\n\t\t\t\t\tplaceholder={ __( 'Add label\u2026' ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tvalue={ label }\n\t\t\t\t\tonChange={ ( html ) => setAttributes( { label: html } ) }\n\t\t\t\t\tstyle={ typographyProps.style }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t<ResizableBox\n\t\t\t\tsize={ {\n\t\t\t\t\twidth:\n\t\t\t\t\t\twidth === undefined\n\t\t\t\t\t\t\t? 'auto'\n\t\t\t\t\t\t\t: `${ width }${ widthUnit }`,\n\t\t\t\t\theight: 'auto',\n\t\t\t\t} }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-block-search__inside-wrapper',\n\t\t\t\t\tisButtonPositionInside ? borderProps.className : undefined\n\t\t\t\t) }\n\t\t\t\tstyle={ getWrapperStyles() }\n\t\t\t\tminWidth={ MIN_WIDTH }\n\t\t\t\tenable={ getResizableSides() }\n\t\t\t\tonResizeStart={ ( event, direction, elt ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\twidth: parseInt( elt.offsetWidth, 10 ),\n\t\t\t\t\t\twidthUnit: 'px',\n\t\t\t\t\t} );\n\t\t\t\t\ttoggleSelection( false );\n\t\t\t\t} }\n\t\t\t\tonResizeStop={ ( event, direction, elt, delta ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\twidth: parseInt( width + delta.width, 10 ),\n\t\t\t\t\t} );\n\t\t\t\t\ttoggleSelection( true );\n\t\t\t\t} }\n\t\t\t\tshowHandle={ isSelected }\n\t\t\t>\n\t\t\t\t{ ( isButtonPositionInside ||\n\t\t\t\t\tisButtonPositionOutside ||\n\t\t\t\t\thasOnlyButton ) && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ renderTextField() }\n\t\t\t\t\t\t{ renderButton() }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t{ hasNoButton && renderTextField() }\n\t\t\t</ResizableBox>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,0BAUO;AACP,kBAAuC;AACvC,qBAAkC;AAClC,wBAWO;AACP,qBAA8B;AAC9B,mBAA6B;AAC7B,kBAA4B;AAC5B,iBAAiD;AAKjD,mBAKO;AACP,mBAA+C;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tInspectorControls,\n\tRichText,\n\t__experimentalUseBorderProps as useBorderProps,\n\t__experimentalUseColorProps as useColorProps,\n\tgetTypographyClassesAndStyles as useTypographyProps,\n\tstore as blockEditorStore,\n\t__experimentalGetElementClassName,\n\tuseSettings,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport {\n\tSelectControl,\n\tToggleControl,\n\tResizableBox,\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalUnitControl as UnitControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { Icon, search } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPC_WIDTH_DEFAULT,\n\tPX_WIDTH_DEFAULT,\n\tMIN_WIDTH,\n\tisPercentageUnit,\n} from './utils.js';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\n// Used to calculate border radius adjustment to avoid \"fat\" corners when\n// button is placed inside wrapper.\nconst DEFAULT_INNER_PADDING = '4px';\nconst PERCENTAGE_WIDTHS = [ 25, 50, 75, 100 ];\n\nexport default function SearchEdit( {\n\tclassName,\n\tattributes,\n\tsetAttributes,\n\ttoggleSelection,\n\tisSelected,\n\tclientId,\n} ) {\n\tconst {\n\t\tlabel,\n\t\tshowLabel,\n\t\tplaceholder,\n\t\twidth,\n\t\twidthUnit,\n\t\talign,\n\t\tbuttonText,\n\t\tbuttonPosition,\n\t\tbuttonUseIcon,\n\t\tstyle,\n\t} = attributes;\n\n\tconst wasJustInsertedIntoNavigationBlock = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParentsByBlockName, wasBlockJustInserted } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\treturn (\n\t\t\t\t!! getBlockParentsByBlockName( clientId, 'core/navigation' )\n\t\t\t\t\t?.length && wasBlockJustInserted( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( wasJustInsertedIntoNavigationBlock ) {\n\t\t\t// This side-effect should not create an undo level.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\tshowLabel: false,\n\t\t\t\tbuttonUseIcon: true,\n\t\t\t\tbuttonPosition: 'button-inside',\n\t\t\t} );\n\t\t}\n\t}, [\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\twasJustInsertedIntoNavigationBlock,\n\t\tsetAttributes,\n\t] );\n\n\tconst borderRadius = style?.border?.radius;\n\tlet borderProps = useBorderProps( attributes );\n\n\t// Check for old deprecated numerical border radius. Done as a separate\n\t// check so that a borderRadius style won't overwrite the longhand\n\t// per-corner styles.\n\tif ( typeof borderRadius === 'number' ) {\n\t\tborderProps = {\n\t\t\t...borderProps,\n\t\t\tstyle: {\n\t\t\t\t...borderProps.style,\n\t\t\t\tborderRadius: `${ borderRadius }px`,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst colorProps = useColorProps( attributes );\n\tconst [ fluidTypographySettings, layout ] = useSettings(\n\t\t'typography.fluid',\n\t\t'layout'\n\t);\n\tconst typographyProps = useTypographyProps( attributes, {\n\t\ttypography: {\n\t\t\tfluid: fluidTypographySettings,\n\t\t},\n\t\tlayout: {\n\t\t\twideSize: layout?.wideSize,\n\t\t},\n\t} );\n\tconst unitControlInstanceId = useInstanceId( UnitControl );\n\tconst unitControlInputId = `wp-block-search__width-${ unitControlInstanceId }`;\n\tconst isButtonPositionInside = 'button-inside' === buttonPosition;\n\tconst isButtonPositionOutside = 'button-outside' === buttonPosition;\n\tconst hasNoButton = 'no-button' === buttonPosition;\n\tconst hasOnlyButton = 'button-only' === buttonPosition;\n\tconst isSearchFieldHidden = hasOnlyButton && ! isSelected;\n\tconst searchFieldRef = useRef();\n\tconst buttonRef = useRef();\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: [ '%', 'px' ],\n\t\tdefaultValues: { '%': PC_WIDTH_DEFAULT, px: PX_WIDTH_DEFAULT },\n\t} );\n\n\tconst getBlockClassNames = () => {\n\t\treturn clsx(\n\t\t\tclassName,\n\t\t\tisButtonPositionInside\n\t\t\t\t? 'wp-block-search__button-inside'\n\t\t\t\t: undefined,\n\t\t\tisButtonPositionOutside\n\t\t\t\t? 'wp-block-search__button-outside'\n\t\t\t\t: undefined,\n\t\t\thasNoButton ? 'wp-block-search__no-button' : undefined,\n\t\t\thasOnlyButton ? 'wp-block-search__button-only' : undefined,\n\t\t\t! buttonUseIcon && ! hasNoButton\n\t\t\t\t? 'wp-block-search__text-button'\n\t\t\t\t: undefined,\n\t\t\tbuttonUseIcon && ! hasNoButton\n\t\t\t\t? 'wp-block-search__icon-button'\n\t\t\t\t: undefined,\n\t\t\tisSearchFieldHidden\n\t\t\t\t? 'wp-block-search__searchfield-hidden'\n\t\t\t\t: undefined\n\t\t);\n\t};\n\n\tconst buttonPositionControls = [\n\t\t{\n\t\t\tlabel: __( 'Button outside' ),\n\t\t\tvalue: 'button-outside',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'Button inside' ),\n\t\t\tvalue: 'button-inside',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'No button' ),\n\t\t\tvalue: 'no-button',\n\t\t},\n\t\t{\n\t\t\tlabel: __( 'Button only' ),\n\t\t\tvalue: 'button-only',\n\t\t},\n\t];\n\n\tconst getResizableSides = () => {\n\t\tif ( hasOnlyButton ) {\n\t\t\treturn {};\n\t\t}\n\n\t\treturn {\n\t\t\tright: align !== 'right',\n\t\t\tleft: align === 'right',\n\t\t};\n\t};\n\n\tconst renderTextField = () => {\n\t\t// If the input is inside the wrapper, the wrapper gets the border color styles/classes, not the input control.\n\t\tconst textFieldClasses = clsx(\n\t\t\t'wp-block-search__input',\n\t\t\tisButtonPositionInside ? undefined : borderProps.className,\n\t\t\ttypographyProps.className\n\t\t);\n\t\tconst textFieldStyles = {\n\t\t\t...( isButtonPositionInside\n\t\t\t\t? {\n\t\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\t\tborderTopLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopLeftRadius,\n\t\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t\t }\n\t\t\t\t: borderProps.style ),\n\t\t\t...typographyProps.style,\n\t\t\ttextDecoration: undefined,\n\t\t};\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\ttype=\"search\"\n\t\t\t\tclassName={ textFieldClasses }\n\t\t\t\tstyle={ textFieldStyles }\n\t\t\t\taria-label={ __( 'Optional placeholder text' ) }\n\t\t\t\t// We hide the placeholder field's placeholder when there is a value. This\n\t\t\t\t// stops screen readers from reading the placeholder field's placeholder\n\t\t\t\t// which is confusing.\n\t\t\t\tplaceholder={\n\t\t\t\t\tplaceholder ? undefined : __( 'Optional placeholder\u2026' )\n\t\t\t\t}\n\t\t\t\tvalue={ placeholder }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tsetAttributes( { placeholder: event.target.value } )\n\t\t\t\t}\n\t\t\t\tref={ searchFieldRef }\n\t\t\t/>\n\t\t);\n\t};\n\n\tconst renderButton = () => {\n\t\t// If the button is inside the wrapper, the wrapper gets the border color styles/classes, not the button.\n\t\tconst buttonClasses = clsx(\n\t\t\t'wp-block-search__button',\n\t\t\tcolorProps.className,\n\t\t\ttypographyProps.className,\n\t\t\tisButtonPositionInside ? undefined : borderProps.className,\n\t\t\tbuttonUseIcon ? 'has-icon' : undefined,\n\t\t\t__experimentalGetElementClassName( 'button' )\n\t\t);\n\t\tconst buttonStyles = {\n\t\t\t...colorProps.style,\n\t\t\t...typographyProps.style,\n\t\t\t...( isButtonPositionInside\n\t\t\t\t? {\n\t\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\t\tborderTopLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopLeftRadius,\n\t\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t\t }\n\t\t\t\t: borderProps.style ),\n\t\t};\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ buttonUseIcon && (\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ buttonClasses }\n\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\tbuttonText\n\t\t\t\t\t\t\t\t? stripHTML( buttonText )\n\t\t\t\t\t\t\t\t: __( 'Search' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tref={ buttonRef }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ search } />\n\t\t\t\t\t</button>\n\t\t\t\t) }\n\n\t\t\t\t{ ! buttonUseIcon && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"buttonText\"\n\t\t\t\t\t\tclassName={ buttonClasses }\n\t\t\t\t\t\tstyle={ buttonStyles }\n\t\t\t\t\t\taria-label={ __( 'Button text' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Add button text\u2026' ) }\n\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\tvalue={ buttonText }\n\t\t\t\t\t\tonChange={ ( html ) =>\n\t\t\t\t\t\t\tsetAttributes( { buttonText: html } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t};\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst controls = (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\twidth: undefined,\n\t\t\t\t\t\t\twidthUnit: undefined,\n\t\t\t\t\t\t\tshowLabel: true,\n\t\t\t\t\t\t\tbuttonUseIcon: false,\n\t\t\t\t\t\t\tbuttonPosition: 'button-outside',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => ! showLabel }\n\t\t\t\t\t\tlabel={ __( 'Show label' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowLabel: true,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tchecked={ showLabel }\n\t\t\t\t\t\t\tlabel={ __( 'Show label' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowLabel: value,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => buttonPosition !== 'button-outside' }\n\t\t\t\t\t\tlabel={ __( 'Button position' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tbuttonPosition: 'button-outside',\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\tvalue={ buttonPosition }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Button position' ) }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tbuttonPosition: value,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\toptions={ buttonPositionControls }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ buttonPosition !== 'no-button' && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => !! buttonUseIcon }\n\t\t\t\t\t\t\tlabel={ __( 'Use button with icon' ) }\n\t\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tbuttonUseIcon: false,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tchecked={ buttonUseIcon }\n\t\t\t\t\t\t\t\tlabel={ __( 'Use button with icon' ) }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tbuttonUseIcon: value,\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! width }\n\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\twidth: undefined,\n\t\t\t\t\t\t\t\twidthUnit: undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<VStack>\n\t\t\t\t\t\t\t<UnitControl\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\t\t\tid={ unitControlInputId } // Unused, kept for backwards compatibility\n\t\t\t\t\t\t\t\tmin={\n\t\t\t\t\t\t\t\t\tisPercentageUnit( widthUnit )\n\t\t\t\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t\t\t\t: MIN_WIDTH\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tmax={\n\t\t\t\t\t\t\t\t\tisPercentageUnit( widthUnit )\n\t\t\t\t\t\t\t\t\t\t? 100\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\t\t\tonChange={ ( newWidth ) => {\n\t\t\t\t\t\t\t\t\tconst parsedNewWidth =\n\t\t\t\t\t\t\t\t\t\tnewWidth === ''\n\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t: parseInt( newWidth, 10 );\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth: parsedNewWidth,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tonUnitChange={ ( newUnit ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth:\n\t\t\t\t\t\t\t\t\t\t\t'%' === newUnit\n\t\t\t\t\t\t\t\t\t\t\t\t? PC_WIDTH_DEFAULT\n\t\t\t\t\t\t\t\t\t\t\t\t: PX_WIDTH_DEFAULT,\n\t\t\t\t\t\t\t\t\t\twidthUnit: newUnit,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t__unstableInputWidth=\"80px\"\n\t\t\t\t\t\t\t\tvalue={ `${ width }${ widthUnit }` }\n\t\t\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Percentage Width' ) }\n\t\t\t\t\t\t\t\tvalue={\n\t\t\t\t\t\t\t\t\tPERCENTAGE_WIDTHS.includes( width ) &&\n\t\t\t\t\t\t\t\t\twidthUnit === '%'\n\t\t\t\t\t\t\t\t\t\t? width\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t\tonChange={ ( newWidth ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\twidth: newWidth,\n\t\t\t\t\t\t\t\t\t\twidthUnit: '%',\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ PERCENTAGE_WIDTHS.map( ( widthValue ) => {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\t\t\t\tkey={ widthValue }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ widthValue }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %d: Percentage value. */\n\t\t\t\t\t\t\t\t\t\t\t\t__( '%d%%' ),\n\t\t\t\t\t\t\t\t\t\t\t\twidthValue\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t\t</VStack>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t</>\n\t);\n\n\tconst isNonZeroBorderRadius = ( radius ) =>\n\t\tradius !== undefined && parseInt( radius, 10 ) !== 0;\n\n\tconst padBorderRadius = ( radius ) =>\n\t\tisNonZeroBorderRadius( radius )\n\t\t\t? `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`\n\t\t\t: undefined;\n\n\tconst getWrapperStyles = () => {\n\t\tconst styles = isButtonPositionInside\n\t\t\t? borderProps.style\n\t\t\t: {\n\t\t\t\t\tborderRadius: borderProps.style?.borderRadius,\n\t\t\t\t\tborderTopLeftRadius: borderProps.style?.borderTopLeftRadius,\n\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\tborderProps.style?.borderTopRightRadius,\n\t\t\t\t\tborderBottomLeftRadius:\n\t\t\t\t\t\tborderProps.style?.borderBottomLeftRadius,\n\t\t\t\t\tborderBottomRightRadius:\n\t\t\t\t\t\tborderProps.style?.borderBottomRightRadius,\n\t\t\t };\n\n\t\tif ( isButtonPositionInside ) {\n\t\t\t// We have button inside wrapper and a border radius value to apply.\n\t\t\t// Add default padding so we don't get \"fat\" corners.\n\t\t\t//\n\t\t\t// CSS calc() is used here to support non-pixel units. The inline\n\t\t\t// style using calc() will only apply if both values have units.\n\n\t\t\tif ( typeof borderRadius === 'object' ) {\n\t\t\t\t// Individual corner border radii present.\n\t\t\t\tconst {\n\t\t\t\t\tborderTopLeftRadius,\n\t\t\t\t\tborderTopRightRadius,\n\t\t\t\t\tborderBottomLeftRadius,\n\t\t\t\t\tborderBottomRightRadius,\n\t\t\t\t} = borderProps.style;\n\n\t\t\t\treturn {\n\t\t\t\t\t...styles,\n\t\t\t\t\tborderTopLeftRadius: padBorderRadius( borderTopLeftRadius ),\n\t\t\t\t\tborderTopRightRadius:\n\t\t\t\t\t\tpadBorderRadius( borderTopRightRadius ),\n\t\t\t\t\tborderBottomLeftRadius: padBorderRadius(\n\t\t\t\t\t\tborderBottomLeftRadius\n\t\t\t\t\t),\n\t\t\t\t\tborderBottomRightRadius: padBorderRadius(\n\t\t\t\t\t\tborderBottomRightRadius\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// The inline style using calc() will only apply if both values\n\t\t\t// supplied to calc() have units. Deprecated block's may have\n\t\t\t// unitless integer.\n\t\t\tconst radius = Number.isInteger( borderRadius )\n\t\t\t\t? `${ borderRadius }px`\n\t\t\t\t: borderRadius;\n\n\t\t\tstyles.borderRadius = `calc(${ radius } + ${ DEFAULT_INNER_PADDING })`;\n\t\t}\n\n\t\treturn styles;\n\t};\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: getBlockClassNames(),\n\t\tstyle: {\n\t\t\t...typographyProps.style,\n\t\t\t// Input opts out of text decoration.\n\t\t\ttextDecoration: undefined,\n\t\t},\n\t} );\n\n\tconst labelClassnames = clsx(\n\t\t'wp-block-search__label',\n\t\ttypographyProps.className\n\t);\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ controls }\n\n\t\t\t{ showLabel && (\n\t\t\t\t<RichText\n\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\tclassName={ labelClassnames }\n\t\t\t\t\taria-label={ __( 'Label text' ) }\n\t\t\t\t\tplaceholder={ __( 'Add label\u2026' ) }\n\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\tvalue={ label }\n\t\t\t\t\tonChange={ ( html ) => setAttributes( { label: html } ) }\n\t\t\t\t\tstyle={ typographyProps.style }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t<ResizableBox\n\t\t\t\tsize={ {\n\t\t\t\t\twidth:\n\t\t\t\t\t\twidth === undefined\n\t\t\t\t\t\t\t? 'auto'\n\t\t\t\t\t\t\t: `${ width }${ widthUnit }`,\n\t\t\t\t\theight: 'auto',\n\t\t\t\t} }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-block-search__inside-wrapper',\n\t\t\t\t\tisButtonPositionInside ? borderProps.className : undefined\n\t\t\t\t) }\n\t\t\t\tstyle={ getWrapperStyles() }\n\t\t\t\tminWidth={ MIN_WIDTH }\n\t\t\t\tenable={ getResizableSides() }\n\t\t\t\tonResizeStart={ ( event, direction, elt ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\twidth: parseInt( elt.offsetWidth, 10 ),\n\t\t\t\t\t\twidthUnit: 'px',\n\t\t\t\t\t} );\n\t\t\t\t\ttoggleSelection( false );\n\t\t\t\t} }\n\t\t\t\tonResizeStop={ ( event, direction, elt, delta ) => {\n\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\twidth: parseInt( width + delta.width, 10 ),\n\t\t\t\t\t} );\n\t\t\t\t\ttoggleSelection( true );\n\t\t\t\t} }\n\t\t\t\tshowHandle={ isSelected }\n\t\t\t>\n\t\t\t\t{ ( isButtonPositionInside ||\n\t\t\t\t\tisButtonPositionOutside ||\n\t\t\t\t\thasOnlyButton ) && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ renderTextField() }\n\t\t\t\t\t\t{ renderButton() }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t{ hasNoButton && renderTextField() }\n\t\t\t</ResizableBox>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,0BAUO;AACP,kBAAuC;AACvC,qBAAkC;AAClC,wBAWO;AACP,qBAA8B;AAC9B,mBAA6B;AAC7B,kBAA4B;AAC5B,iBAAiD;AAKjD,mBAKO;AACP,mBAA+C;AAqL5C;AAjLH,IAAM,wBAAwB;AAC9B,IAAM,oBAAoB,CAAE,IAAI,IAAI,IAAI,GAAI;AAE7B,SAAR,WAA6B;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AAEJ,QAAM,yCAAqC;AAAA,IAC1C,CAAE,WAAY;AACb,YAAM,EAAE,4BAA4B,qBAAqB,IACxD,OAAQ,oBAAAA,KAAiB;AAC1B,aACC,CAAC,CAAE,2BAA4B,UAAU,iBAAkB,GACxD,UAAU,qBAAsB,QAAS;AAAA,IAE9C;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AACA,QAAM,EAAE,wCAAwC,QAC/C,yBAAa,oBAAAA,KAAiB;AAE/B,gCAAW,MAAM;AAChB,QAAK,oCAAqC;AAEzC,8CAAwC;AACxC,oBAAe;AAAA,QACd,WAAW;AAAA,QACX,eAAe;AAAA,QACf,gBAA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AAE;AACF,0BAAiB,IAAK;AAAA,QACvB;AAAA,QACA,YAAa;AAAA,QAET;AAAA,qCACH,2BACA,kBACA,4EACG;AAAA,4BAAgB;AAAA,YAChB,aAAa;AAAA,aAChB;AAAA,UAGC,eAAe,gBAAgB;AAAA;AAAA;AAAA,IAClC;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": ["blockEditorStore", "useBorderProps", "useColorProps", "useTypographyProps", "UnitControl", "useCustomUnits", "clsx", "stripHTML", "ToolsPanel", "ToolsPanelItem", "VStack", "ToggleGroupControl", "ToggleGroupControlOption"]
|
|
7
7
|
}
|
|
@@ -24,7 +24,8 @@ function CodeEdit({
|
|
|
24
24
|
"aria-label": __("Code"),
|
|
25
25
|
preserveWhiteSpace: true,
|
|
26
26
|
__unstablePastePlainText: true,
|
|
27
|
-
__unstableOnSplitAtDoubleLineEnd: () => insertBlocksAfter(createBlock(getDefaultBlockName()))
|
|
27
|
+
__unstableOnSplitAtDoubleLineEnd: () => insertBlocksAfter(createBlock(getDefaultBlockName())),
|
|
28
|
+
style: { whiteSpace: "break-spaces" }
|
|
28
29
|
}
|
|
29
30
|
) });
|
|
30
31
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/code/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\nexport default function CodeEdit( {\n\tattributes,\n\tsetAttributes,\n\tonRemove,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n} ) {\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<pre { ...blockProps }>\n\t\t\t<RichText\n\t\t\t\ttagName=\"code\"\n\t\t\t\tidentifier=\"content\"\n\t\t\t\tvalue={ attributes.content }\n\t\t\t\tonChange={ ( content ) => setAttributes( { content } ) }\n\t\t\t\tonRemove={ onRemove }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tplaceholder={ __( 'Write code\u2026' ) }\n\t\t\t\taria-label={ __( 'Code' ) }\n\t\t\t\tpreserveWhiteSpace\n\t\t\t\t__unstablePastePlainText\n\t\t\t\t__unstableOnSplitAtDoubleLineEnd={ () =>\n\t\t\t\t\tinsertBlocksAfter( createBlock( getDefaultBlockName() ) )\n\t\t\t\t}\n\t\t\t/>\n\t\t</pre>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,UAAU,qBAAqB;AACxC,SAAS,aAAa,2BAA2B;AAY9C;AAVY,SAAR,SAA2B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,aAAa,cAAc;AACjC,SACC,oBAAC,SAAM,GAAG,YACT;AAAA,IAAC;AAAA;AAAA,MACA,SAAQ;AAAA,MACR,YAAW;AAAA,MACX,OAAQ,WAAW;AAAA,MACnB,UAAW,CAAE,YAAa,cAAe,EAAE,QAAQ,CAAE;AAAA,MACrD;AAAA,MACA,SAAU;AAAA,MACV,aAAc,GAAI,kBAAc;AAAA,MAChC,cAAa,GAAI,MAAO;AAAA,MACxB,oBAAkB;AAAA,MAClB,0BAAwB;AAAA,MACxB,kCAAmC,MAClC,kBAAmB,YAAa,oBAAoB,CAAE,CAAE;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\nexport default function CodeEdit( {\n\tattributes,\n\tsetAttributes,\n\tonRemove,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n} ) {\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<pre { ...blockProps }>\n\t\t\t<RichText\n\t\t\t\ttagName=\"code\"\n\t\t\t\tidentifier=\"content\"\n\t\t\t\tvalue={ attributes.content }\n\t\t\t\tonChange={ ( content ) => setAttributes( { content } ) }\n\t\t\t\tonRemove={ onRemove }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tplaceholder={ __( 'Write code\u2026' ) }\n\t\t\t\taria-label={ __( 'Code' ) }\n\t\t\t\tpreserveWhiteSpace\n\t\t\t\t__unstablePastePlainText\n\t\t\t\t__unstableOnSplitAtDoubleLineEnd={ () =>\n\t\t\t\t\tinsertBlocksAfter( createBlock( getDefaultBlockName() ) )\n\t\t\t\t}\n\t\t\t\tstyle={ { whiteSpace: 'break-spaces' } }\n\t\t\t/>\n\t\t</pre>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,UAAU,qBAAqB;AACxC,SAAS,aAAa,2BAA2B;AAY9C;AAVY,SAAR,SAA2B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,aAAa,cAAc;AACjC,SACC,oBAAC,SAAM,GAAG,YACT;AAAA,IAAC;AAAA;AAAA,MACA,SAAQ;AAAA,MACR,YAAW;AAAA,MACX,OAAQ,WAAW;AAAA,MACnB,UAAW,CAAE,YAAa,cAAe,EAAE,QAAQ,CAAE;AAAA,MACrD;AAAA,MACA,SAAU;AAAA,MACV,aAAc,GAAI,kBAAc;AAAA,MAChC,cAAa,GAAI,MAAO;AAAA,MACxB,oBAAkB;AAAA,MAClB,0BAAwB;AAAA,MACxB,kCAAmC,MAClC,kBAAmB,YAAa,oBAAoB,CAAE,CAAE;AAAA,MAEzD,OAAQ,EAAE,YAAY,eAAe;AAAA;AAAA,EACtC,GACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cover/edit/color-utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport { FastAverageColor } from 'fast-average-color';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { applyFilters } from '@wordpress/hooks';\n\n/**\n * @typedef {import('colord').RgbaColor} RgbaColor\n */\n\nextend( [ namesPlugin ] );\n\n/**\n * Fallback color when the average color can't be computed. The image may be\n * rendering as transparent, and most sites have a light color background.\n */\nexport const DEFAULT_BACKGROUND_COLOR = '#FFF';\n\n/**\n * Default dim color specified in style.css.\n */\nexport const DEFAULT_OVERLAY_COLOR = '#000';\n\n/**\n * Performs a Porter Duff composite source over operation on two rgba colors.\n *\n * @see {@link https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcover}\n *\n * @param {RgbaColor} source Source color.\n * @param {RgbaColor} dest Destination color.\n *\n * @return {RgbaColor} Composite color.\n */\nexport function compositeSourceOver( source, dest ) {\n\treturn {\n\t\tr: source.r * source.a + dest.r * dest.a * ( 1 - source.a ),\n\t\tg: source.g * source.a + dest.g * dest.a * ( 1 - source.a ),\n\t\tb: source.b * source.a + dest.b * dest.a * ( 1 - source.a ),\n\t\ta: source.a + dest.a * ( 1 - source.a ),\n\t};\n}\n\n/**\n * Retrieves the FastAverageColor singleton.\n *\n * @return {FastAverageColor} The FastAverageColor singleton.\n */\nexport function retrieveFastAverageColor() {\n\tif ( ! retrieveFastAverageColor.fastAverageColor ) {\n\t\tretrieveFastAverageColor.fastAverageColor = new FastAverageColor();\n\t}\n\treturn retrieveFastAverageColor.fastAverageColor;\n}\n\n/**\n * Computes the average color of an image.\n *\n * @param {string} url The url of the image.\n *\n * @return {Promise<string>} Promise of an average color as a hex string.\n */\nexport const getMediaColor = memoize( async ( url ) => {\n\tif ( ! url ) {\n\t\treturn DEFAULT_BACKGROUND_COLOR;\n\t}\n\n\t// making the default color rgb for compat with FAC\n\tconst { r, g, b, a } = colord( DEFAULT_BACKGROUND_COLOR ).toRgb();\n\n\ttry {\n\t\tconst imgCrossOrigin = applyFilters(\n\t\t\t'media.crossOrigin',\n\t\t\tundefined,\n\t\t\turl\n\t\t);\n\t\tconst color = await retrieveFastAverageColor().getColorAsync( url, {\n\t\t\t// The default color is white, which is the color\n\t\t\t// that is returned if there's an error.\n\t\t\t// colord returns alpga 0-1, FAC needs 0-255\n\t\t\tdefaultColor: [ r, g, b, a * 255 ],\n\t\t\t// Errors that come up don't reject the promise,\n\t\t\t// so error logging has to be silenced\n\t\t\t// with this option.\n\t\t\tsilent: process.env.NODE_ENV === 'production',\n\t\t\tcrossOrigin: imgCrossOrigin,\n\t\t} );\n\t\treturn color.hex;\n\t} catch
|
|
5
|
-
"mappings": ";AAGA,SAAS,QAAQ,cAAc;AAC/B,OAAO,iBAAiB;AACxB,SAAS,wBAAwB;AACjC,OAAO,aAAa;AAKpB,SAAS,oBAAoB;AAM7B,OAAQ,CAAE,WAAY,CAAE;AAMjB,IAAM,2BAA2B;AAKjC,IAAM,wBAAwB;AAY9B,SAAS,oBAAqB,QAAQ,MAAO;AACnD,SAAO;AAAA,IACN,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,EACrC;AACD;AAOO,SAAS,2BAA2B;AAC1C,MAAK,CAAE,yBAAyB,kBAAmB;AAClD,6BAAyB,mBAAmB,IAAI,iBAAiB;AAAA,EAClE;AACA,SAAO,yBAAyB;AACjC;AASO,IAAM,gBAAgB,QAAS,OAAQ,QAAS;AACtD,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,QAAM,EAAE,GAAG,GAAG,GAAG,EAAE,IAAI,OAAQ,wBAAyB,EAAE,MAAM;AAEhE,MAAI;AACH,UAAM,iBAAiB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,UAAM,QAAQ,MAAM,yBAAyB,EAAE,cAAe,KAAK;AAAA;AAAA;AAAA;AAAA,MAIlE,cAAc,CAAE,GAAG,GAAG,GAAG,IAAI,GAAI;AAAA;AAAA;AAAA;AAAA,MAIjC,QAAQ,QAAQ,IAAI,aAAa;AAAA,MACjC,aAAa;AAAA,IACd,CAAE;AACF,WAAO,MAAM;AAAA,EACd,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { colord, extend } from 'colord';\nimport namesPlugin from 'colord/plugins/names';\nimport { FastAverageColor } from 'fast-average-color';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { applyFilters } from '@wordpress/hooks';\n\n/**\n * @typedef {import('colord').RgbaColor} RgbaColor\n */\n\nextend( [ namesPlugin ] );\n\n/**\n * Fallback color when the average color can't be computed. The image may be\n * rendering as transparent, and most sites have a light color background.\n */\nexport const DEFAULT_BACKGROUND_COLOR = '#FFF';\n\n/**\n * Default dim color specified in style.css.\n */\nexport const DEFAULT_OVERLAY_COLOR = '#000';\n\n/**\n * Performs a Porter Duff composite source over operation on two rgba colors.\n *\n * @see {@link https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcover}\n *\n * @param {RgbaColor} source Source color.\n * @param {RgbaColor} dest Destination color.\n *\n * @return {RgbaColor} Composite color.\n */\nexport function compositeSourceOver( source, dest ) {\n\treturn {\n\t\tr: source.r * source.a + dest.r * dest.a * ( 1 - source.a ),\n\t\tg: source.g * source.a + dest.g * dest.a * ( 1 - source.a ),\n\t\tb: source.b * source.a + dest.b * dest.a * ( 1 - source.a ),\n\t\ta: source.a + dest.a * ( 1 - source.a ),\n\t};\n}\n\n/**\n * Retrieves the FastAverageColor singleton.\n *\n * @return {FastAverageColor} The FastAverageColor singleton.\n */\nexport function retrieveFastAverageColor() {\n\tif ( ! retrieveFastAverageColor.fastAverageColor ) {\n\t\tretrieveFastAverageColor.fastAverageColor = new FastAverageColor();\n\t}\n\treturn retrieveFastAverageColor.fastAverageColor;\n}\n\n/**\n * Computes the average color of an image.\n *\n * @param {string} url The url of the image.\n *\n * @return {Promise<string>} Promise of an average color as a hex string.\n */\nexport const getMediaColor = memoize( async ( url ) => {\n\tif ( ! url ) {\n\t\treturn DEFAULT_BACKGROUND_COLOR;\n\t}\n\n\t// making the default color rgb for compat with FAC\n\tconst { r, g, b, a } = colord( DEFAULT_BACKGROUND_COLOR ).toRgb();\n\n\ttry {\n\t\tconst imgCrossOrigin = applyFilters(\n\t\t\t'media.crossOrigin',\n\t\t\tundefined,\n\t\t\turl\n\t\t);\n\t\tconst color = await retrieveFastAverageColor().getColorAsync( url, {\n\t\t\t// The default color is white, which is the color\n\t\t\t// that is returned if there's an error.\n\t\t\t// colord returns alpga 0-1, FAC needs 0-255\n\t\t\tdefaultColor: [ r, g, b, a * 255 ],\n\t\t\t// Errors that come up don't reject the promise,\n\t\t\t// so error logging has to be silenced\n\t\t\t// with this option.\n\t\t\tsilent: process.env.NODE_ENV === 'production',\n\t\t\tcrossOrigin: imgCrossOrigin,\n\t\t} );\n\t\treturn color.hex;\n\t} catch {\n\t\t// If there's an error return the fallback color.\n\t\treturn DEFAULT_BACKGROUND_COLOR;\n\t}\n} );\n\n/**\n * Computes if the color combination of the overlay and background color is dark.\n *\n * @param {number} dimRatio Opacity of the overlay between 0 and 100.\n * @param {string} overlayColor CSS color string for the overlay.\n * @param {string} backgroundColor CSS color string for the background.\n *\n * @return {boolean} true if the color combination composite result is dark.\n */\nexport function compositeIsDark( dimRatio, overlayColor, backgroundColor ) {\n\t// Opacity doesn't matter if you're overlaying the same color on top of itself.\n\t// And background doesn't matter when overlay is fully opaque.\n\tif ( overlayColor === backgroundColor || dimRatio === 100 ) {\n\t\treturn colord( overlayColor ).isDark();\n\t}\n\tconst overlay = colord( overlayColor )\n\t\t.alpha( dimRatio / 100 )\n\t\t.toRgb();\n\tconst background = colord( backgroundColor ).toRgb();\n\tconst composite = compositeSourceOver( overlay, background );\n\treturn colord( composite ).isDark();\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,QAAQ,cAAc;AAC/B,OAAO,iBAAiB;AACxB,SAAS,wBAAwB;AACjC,OAAO,aAAa;AAKpB,SAAS,oBAAoB;AAM7B,OAAQ,CAAE,WAAY,CAAE;AAMjB,IAAM,2BAA2B;AAKjC,IAAM,wBAAwB;AAY9B,SAAS,oBAAqB,QAAQ,MAAO;AACnD,SAAO;AAAA,IACN,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,OAAO,IAAI,KAAK,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,IACxD,GAAG,OAAO,IAAI,KAAK,KAAM,IAAI,OAAO;AAAA,EACrC;AACD;AAOO,SAAS,2BAA2B;AAC1C,MAAK,CAAE,yBAAyB,kBAAmB;AAClD,6BAAyB,mBAAmB,IAAI,iBAAiB;AAAA,EAClE;AACA,SAAO,yBAAyB;AACjC;AASO,IAAM,gBAAgB,QAAS,OAAQ,QAAS;AACtD,MAAK,CAAE,KAAM;AACZ,WAAO;AAAA,EACR;AAGA,QAAM,EAAE,GAAG,GAAG,GAAG,EAAE,IAAI,OAAQ,wBAAyB,EAAE,MAAM;AAEhE,MAAI;AACH,UAAM,iBAAiB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,UAAM,QAAQ,MAAM,yBAAyB,EAAE,cAAe,KAAK;AAAA;AAAA;AAAA;AAAA,MAIlE,cAAc,CAAE,GAAG,GAAG,GAAG,IAAI,GAAI;AAAA;AAAA;AAAA;AAAA,MAIjC,QAAQ,QAAQ,IAAI,aAAa;AAAA,MACjC,aAAa;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