@wordpress/block-library 9.12.1-next.082ed6819.0 → 9.13.1-next.a9f418477.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/block/edit.js +2 -29
- package/build/block/edit.js.map +1 -1
- package/build/cover/edit/index.js +4 -2
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +6 -4
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/form/index.js +1 -2
- package/build/form/index.js.map +1 -1
- package/build/form/view.js +10 -5
- package/build/form/view.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +2 -2
- package/build/list-item/hooks/use-merge.js.map +1 -1
- package/build/navigation/edit/deleted-navigation-warning.js +9 -2
- package/build/navigation/edit/deleted-navigation-warning.js.map +1 -1
- package/build/navigation-link/edit.js +1 -2
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +3 -1
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/pattern/recursion-detector.js +0 -1
- package/build/pattern/recursion-detector.js.map +1 -1
- package/build/query/edit/index.js +2 -2
- package/build/query/edit/index.js.map +1 -1
- package/build/query/edit/inspector-controls/author-control.js +0 -1
- package/build/query/edit/inspector-controls/author-control.js.map +1 -1
- package/build/query/edit/inspector-controls/parent-control.js +0 -1
- package/build/query/edit/inspector-controls/parent-control.js.map +1 -1
- package/build/query/edit/inspector-controls/taxonomy-controls.js +0 -1
- package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build/query/edit/{pattern-selection-modal.js → pattern-selection.js} +55 -36
- package/build/query/edit/pattern-selection.js.map +1 -0
- package/build/query/edit/query-content.js +5 -8
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/edit/query-placeholder.js +5 -11
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/edit/query-toolbar.js +31 -11
- package/build/query/edit/query-toolbar.js.map +1 -1
- package/build/separator/deprecated.js +2 -1
- package/build/separator/deprecated.js.map +1 -1
- package/build/separator/edit.js +29 -4
- package/build/separator/edit.js.map +1 -1
- package/build/separator/index.js +5 -0
- package/build/separator/index.js.map +1 -1
- package/build/separator/save.js +3 -2
- package/build/separator/save.js.map +1 -1
- package/build/social-link/edit.js +35 -1
- package/build/social-link/edit.js.map +1 -1
- package/build/social-link/index.js +4 -2
- package/build/social-link/index.js.map +1 -1
- package/build/template-part/edit/import-controls.js +0 -1
- package/build/template-part/edit/import-controls.js.map +1 -1
- package/build-module/block/edit.js +3 -30
- package/build-module/block/edit.js.map +1 -1
- package/build-module/cover/edit/index.js +4 -2
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +6 -4
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/form/index.js +1 -2
- package/build-module/form/index.js.map +1 -1
- package/build-module/form/view.js +10 -5
- package/build-module/form/view.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +2 -2
- package/build-module/list-item/hooks/use-merge.js.map +1 -1
- package/build-module/navigation/edit/deleted-navigation-warning.js +10 -3
- package/build-module/navigation/edit/deleted-navigation-warning.js.map +1 -1
- package/build-module/navigation-link/edit.js +1 -2
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +3 -1
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/pattern/recursion-detector.js +0 -1
- package/build-module/pattern/recursion-detector.js.map +1 -1
- package/build-module/query/edit/index.js +1 -1
- package/build-module/query/edit/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/author-control.js +0 -1
- package/build-module/query/edit/inspector-controls/author-control.js.map +1 -1
- package/build-module/query/edit/inspector-controls/parent-control.js +0 -1
- package/build-module/query/edit/inspector-controls/parent-control.js.map +1 -1
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js +0 -1
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build-module/query/edit/{pattern-selection-modal.js → pattern-selection.js} +53 -36
- package/build-module/query/edit/pattern-selection.js.map +1 -0
- package/build-module/query/edit/query-content.js +5 -8
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +6 -12
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/edit/query-toolbar.js +31 -13
- package/build-module/query/edit/query-toolbar.js.map +1 -1
- package/build-module/separator/deprecated.js +2 -1
- package/build-module/separator/deprecated.js.map +1 -1
- package/build-module/separator/edit.js +32 -7
- package/build-module/separator/edit.js.map +1 -1
- package/build-module/separator/index.js +5 -0
- package/build-module/separator/index.js.map +1 -1
- package/build-module/separator/save.js +3 -2
- package/build-module/separator/save.js.map +1 -1
- package/build-module/social-link/edit.js +37 -3
- package/build-module/social-link/edit.js.map +1 -1
- package/build-module/social-link/index.js +4 -2
- package/build-module/social-link/index.js.map +1 -1
- package/build-module/template-part/edit/import-controls.js +0 -1
- package/build-module/template-part/edit/import-controls.js.map +1 -1
- package/build-style/button/style-rtl.css +3 -3
- package/build-style/button/style.css +3 -3
- package/build-style/comments/editor-rtl.css +1 -1
- package/build-style/comments/editor.css +1 -1
- package/build-style/comments/style-rtl.css +1 -1
- package/build-style/comments/style.css +1 -1
- package/build-style/comments-pagination/editor-rtl.css +1 -0
- package/build-style/comments-pagination/editor.css +1 -0
- package/build-style/comments-pagination/style-rtl.css +1 -0
- package/build-style/comments-pagination/style.css +1 -0
- package/build-style/common-rtl.css +17 -17
- package/build-style/common.css +17 -17
- package/build-style/editor-rtl.css +76 -41
- package/build-style/editor.css +76 -41
- package/build-style/gallery/style-rtl.css +2 -2
- package/build-style/gallery/style.css +2 -2
- package/build-style/heading/style-rtl.css +11 -11
- package/build-style/heading/style.css +11 -11
- package/build-style/image/style-rtl.css +4 -3
- package/build-style/image/style.css +4 -3
- package/build-style/latest-comments/style-rtl.css +4 -4
- package/build-style/latest-comments/style.css +4 -4
- package/build-style/latest-posts/style-rtl.css +2 -1
- package/build-style/latest-posts/style.css +2 -1
- package/build-style/more/editor-rtl.css +1 -1
- package/build-style/more/editor.css +1 -1
- package/build-style/nextpage/editor-rtl.css +1 -1
- package/build-style/nextpage/editor.css +1 -1
- package/build-style/post-comments-form/style-rtl.css +2 -2
- package/build-style/post-comments-form/style.css +2 -2
- package/build-style/post-featured-image/editor-rtl.css +27 -27
- package/build-style/post-featured-image/editor.css +27 -27
- package/build-style/pullquote/style-rtl.css +1 -0
- package/build-style/pullquote/style.css +1 -0
- package/build-style/query/editor-rtl.css +30 -0
- package/build-style/query/editor.css +30 -0
- package/build-style/read-more/style-rtl.css +2 -2
- package/build-style/read-more/style.css +2 -2
- package/build-style/social-link/editor-rtl.css +6 -2
- package/build-style/social-link/editor.css +6 -2
- package/build-style/social-links/editor-rtl.css +2 -2
- package/build-style/social-links/editor.css +2 -2
- package/build-style/social-links/style-rtl.css +2 -2
- package/build-style/social-links/style.css +2 -2
- package/build-style/style-rtl.css +55 -51
- package/build-style/style.css +55 -51
- package/build-style/text-columns/style-rtl.css +3 -3
- package/build-style/text-columns/style.css +3 -3
- package/build-types/lock-unlock.d.ts +1 -1
- package/build-types/lock-unlock.d.ts.map +1 -1
- package/package.json +35 -34
- package/src/block/edit.js +6 -51
- package/src/comments-pagination/editor.scss +1 -0
- package/src/comments-pagination/style.scss +1 -0
- package/src/cover/edit/index.js +4 -1
- package/src/cover/edit/inspector-controls.js +10 -3
- package/src/cover/index.php +2 -2
- package/src/form/block.json +1 -2
- package/src/form/index.php +1 -20
- package/src/form/view.js +18 -5
- package/src/image/style.scss +4 -3
- package/src/latest-posts/style.scss +2 -1
- package/src/list-item/hooks/use-merge.js +2 -2
- package/src/missing/test/edit.native.js +0 -1
- package/src/navigation/README.md +1 -0
- package/src/navigation/edit/deleted-navigation-warning.js +11 -2
- package/src/navigation/index.php +9 -35
- package/src/navigation-link/edit.js +0 -6
- package/src/navigation-submenu/edit.js +5 -6
- package/src/navigation-submenu/index.php +17 -1
- package/src/pullquote/style.scss +1 -0
- package/src/query/edit/index.js +1 -1
- package/src/query/edit/{pattern-selection-modal.js → pattern-selection.js} +53 -33
- package/src/query/edit/query-content.js +4 -10
- package/src/query/edit/query-placeholder.js +5 -14
- package/src/query/edit/query-toolbar.js +38 -17
- package/src/query/editor.scss +30 -0
- package/src/search/index.php +3 -3
- package/src/separator/block.json +5 -0
- package/src/separator/deprecated.js +1 -0
- package/src/separator/edit.js +28 -3
- package/src/separator/save.js +2 -2
- package/src/separator/test/edit.js +1 -0
- package/src/social-link/block.json +4 -2
- package/src/social-link/edit.js +40 -0
- package/src/social-link/editor.scss +5 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/query/edit/pattern-selection-modal.js.map +0 -1
- package/build-module/query/edit/pattern-selection-modal.js.map +0 -1
|
@@ -10,7 +10,7 @@ var _element = require("@wordpress/element");
|
|
|
10
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
11
11
|
var _queryContent = _interopRequireDefault(require("./query-content"));
|
|
12
12
|
var _queryPlaceholder = _interopRequireDefault(require("./query-placeholder"));
|
|
13
|
-
var
|
|
13
|
+
var _patternSelection = require("./pattern-selection");
|
|
14
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
15
|
/**
|
|
16
16
|
* WordPress dependencies
|
|
@@ -32,7 +32,7 @@ const QueryEdit = props => {
|
|
|
32
32
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
33
33
|
...props,
|
|
34
34
|
openPatternSelectionModal: () => setIsPatternSelectionModalOpen(true)
|
|
35
|
-
}), isPatternSelectionModalOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
35
|
+
}), isPatternSelectionModalOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_patternSelection.PatternSelectionModal, {
|
|
36
36
|
clientId: clientId,
|
|
37
37
|
attributes: attributes,
|
|
38
38
|
setIsPatternSelectionModalOpen: setIsPatternSelectionModalOpen
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_element","_blockEditor","_queryContent","_interopRequireDefault","_queryPlaceholder","
|
|
1
|
+
{"version":3,"names":["_data","require","_element","_blockEditor","_queryContent","_interopRequireDefault","_queryPlaceholder","_patternSelection","_jsxRuntime","QueryEdit","props","clientId","attributes","isPatternSelectionModalOpen","setIsPatternSelectionModalOpen","useState","hasInnerBlocks","useSelect","select","blockEditorStore","getBlocks","length","Component","QueryContent","QueryPlaceholder","jsxs","Fragment","children","jsx","openPatternSelectionModal","PatternSelectionModal","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport QueryContent from './query-content';\nimport QueryPlaceholder from './query-placeholder';\nimport { PatternSelectionModal } from './pattern-selection';\n\nconst QueryEdit = ( props ) => {\n\tconst { clientId, attributes } = props;\n\tconst [ isPatternSelectionModalOpen, setIsPatternSelectionModalOpen ] =\n\t\tuseState( false );\n\tconst hasInnerBlocks = useSelect(\n\t\t( select ) =>\n\t\t\t!! select( blockEditorStore ).getBlocks( clientId ).length,\n\t\t[ clientId ]\n\t);\n\tconst Component = hasInnerBlocks ? QueryContent : QueryPlaceholder;\n\treturn (\n\t\t<>\n\t\t\t<Component\n\t\t\t\t{ ...props }\n\t\t\t\topenPatternSelectionModal={ () =>\n\t\t\t\t\tsetIsPatternSelectionModalOpen( true )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isPatternSelectionModalOpen && (\n\t\t\t\t<PatternSelectionModal\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetIsPatternSelectionModalOpen={\n\t\t\t\t\t\tsetIsPatternSelectionModalOpen\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport default QueryEdit;\n"],"mappings":";;;;;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1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_data","_coreData","_utils","_jsxRuntime","AUTHORS_QUERY","who","per_page","_fields","context","AuthorControl","value","onChange","authorsList","useSelect","select","getUsers","coreStore","authorsInfo","getEntitiesInfo","normalizedValue","toString","split","sanitizedValue","reduce","accumulator","authorId","author","mapById","push","id","name","getIdByValue","entitiesMappedByName","authorValue","onAuthorChange","newValue","ids","Array","from","mapByName","add","Set","join","jsx","FormTokenField","label","__","suggestions","names","__experimentalShowHowTo","__nextHasNoMarginBottom","__next40pxDefaultSize","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/author-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getEntitiesInfo } from '../../utils';\n\nconst AUTHORS_QUERY = {\n\twho: 'authors',\n\tper_page: -1,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nfunction AuthorControl( { value, onChange } ) {\n\tconst authorsList = useSelect( ( select ) => {\n\t\tconst { getUsers } = select( coreStore );\n\t\treturn getUsers( AUTHORS_QUERY );\n\t}, [] );\n\n\tif ( ! authorsList ) {\n\t\treturn null;\n\t}\n\tconst authorsInfo = getEntitiesInfo( authorsList );\n\t/**\n\t * We need to normalize the value because the block operates on a\n\t * comma(`,`) separated string value and `FormTokenFiels` needs an\n\t * array.\n\t */\n\tconst normalizedValue = ! value ? [] : value.toString().split( ',' );\n\t// Returns only the existing authors ids. This prevents the component\n\t// from crashing in the editor, when non existing ids are provided.\n\tconst sanitizedValue = normalizedValue.reduce(\n\t\t( accumulator, authorId ) => {\n\t\t\tconst author = authorsInfo.mapById[ authorId ];\n\t\t\tif ( author ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid: authorId,\n\t\t\t\t\tvalue: author.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\n\tconst getIdByValue = ( entitiesMappedByName, authorValue ) => {\n\t\tconst id = authorValue?.id || entitiesMappedByName[ authorValue ]?.id;\n\t\tif ( id ) {\n\t\t\treturn id;\n\t\t}\n\t};\n\tconst onAuthorChange = ( newValue ) => {\n\t\tconst ids = Array.from(\n\t\t\tnewValue.reduce( ( accumulator, author ) => {\n\t\t\t\t// Verify that new values point to existing entities.\n\t\t\t\tconst id = getIdByValue( authorsInfo.mapByName, author );\n\t\t\t\tif ( id ) {\n\t\t\t\t\taccumulator.add( id );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, new Set() )\n\t\t);\n\t\tonChange( { author: ids.join( ',' ) } );\n\t};\n\treturn (\n\t\t<FormTokenField\n\t\t\tlabel={ __( 'Authors' ) }\n\t\t\tvalue={ sanitizedValue }\n\t\t\tsuggestions={ authorsInfo.names }\n\t\t\tonChange={ onAuthorChange }\n\t\t\t__experimentalShowHowTo={ false }\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t/>\n\t);\n}\n\nexport default AuthorControl;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_data","_coreData","_utils","_jsxRuntime","AUTHORS_QUERY","who","per_page","_fields","context","AuthorControl","value","onChange","authorsList","useSelect","select","getUsers","coreStore","authorsInfo","getEntitiesInfo","normalizedValue","toString","split","sanitizedValue","reduce","accumulator","authorId","author","mapById","push","id","name","getIdByValue","entitiesMappedByName","authorValue","onAuthorChange","newValue","ids","Array","from","mapByName","add","Set","join","jsx","FormTokenField","label","__","suggestions","names","__experimentalShowHowTo","__nextHasNoMarginBottom","__next40pxDefaultSize","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/author-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getEntitiesInfo } from '../../utils';\n\nconst AUTHORS_QUERY = {\n\twho: 'authors',\n\tper_page: -1,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nfunction AuthorControl( { value, onChange } ) {\n\tconst authorsList = useSelect( ( select ) => {\n\t\tconst { getUsers } = select( coreStore );\n\t\treturn getUsers( AUTHORS_QUERY );\n\t}, [] );\n\n\tif ( ! authorsList ) {\n\t\treturn null;\n\t}\n\tconst authorsInfo = getEntitiesInfo( authorsList );\n\t/**\n\t * We need to normalize the value because the block operates on a\n\t * comma(`,`) separated string value and `FormTokenFiels` needs an\n\t * array.\n\t */\n\tconst normalizedValue = ! value ? [] : value.toString().split( ',' );\n\t// Returns only the existing authors ids. This prevents the component\n\t// from crashing in the editor, when non existing ids are provided.\n\tconst sanitizedValue = normalizedValue.reduce(\n\t\t( accumulator, authorId ) => {\n\t\t\tconst author = authorsInfo.mapById[ authorId ];\n\t\t\tif ( author ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid: authorId,\n\t\t\t\t\tvalue: author.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\n\tconst getIdByValue = ( entitiesMappedByName, authorValue ) => {\n\t\tconst id = authorValue?.id || entitiesMappedByName[ authorValue ]?.id;\n\t\tif ( id ) {\n\t\t\treturn id;\n\t\t}\n\t};\n\tconst onAuthorChange = ( newValue ) => {\n\t\tconst ids = Array.from(\n\t\t\tnewValue.reduce( ( accumulator, author ) => {\n\t\t\t\t// Verify that new values point to existing entities.\n\t\t\t\tconst id = getIdByValue( authorsInfo.mapByName, author );\n\t\t\t\tif ( id ) {\n\t\t\t\t\taccumulator.add( id );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, new Set() )\n\t\t);\n\t\tonChange( { author: ids.join( ',' ) } );\n\t};\n\treturn (\n\t\t<FormTokenField\n\t\t\tlabel={ __( 'Authors' ) }\n\t\t\tvalue={ sanitizedValue }\n\t\t\tsuggestions={ authorsInfo.names }\n\t\t\tonChange={ onAuthorChange }\n\t\t\t__experimentalShowHowTo={ false }\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t/>\n\t);\n}\n\nexport default AuthorControl;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAA8C,IAAAK,WAAA,GAAAL,OAAA;AAX9C;AACA;AACA;;AAMA;AACA;AACA;;AAGA,MAAMM,aAAa,GAAG;EACrBC,GAAG,EAAE,SAAS;EACdC,QAAQ,EAAE,CAAC,CAAC;EACZC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE;AACV,CAAC;AAED,SAASC,aAAaA,CAAE;EAAEC,KAAK;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAMC,WAAW,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC5C,MAAM;MAAEC;IAAS,CAAC,GAAGD,MAAM,CAAEE,eAAU,CAAC;IACxC,OAAOD,QAAQ,CAAEX,aAAc,CAAC;EACjC,CAAC,EAAE,EAAG,CAAC;EAEP,IAAK,CAAEQ,WAAW,EAAG;IACpB,OAAO,IAAI;EACZ;EACA,MAAMK,WAAW,GAAG,IAAAC,sBAAe,EAAEN,WAAY,CAAC;EAClD;AACD;AACA;AACA;AACA;EACC,MAAMO,eAAe,GAAG,CAAET,KAAK,GAAG,EAAE,GAAGA,KAAK,CAACU,QAAQ,CAAC,CAAC,CAACC,KAAK,CAAE,GAAI,CAAC;EACpE;EACA;EACA,MAAMC,cAAc,GAAGH,eAAe,CAACI,MAAM,CAC5C,CAAEC,WAAW,EAAEC,QAAQ,KAAM;IAC5B,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CACrB,CAAC;AAEJ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc7C,aAAa","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_data","_coreData","_element","_compose","_utils","_jsxRuntime","EMPTY_ARRAY","BASE_QUERY","order","_fields","context","ParentControl","parents","postType","onChange","search","setSearch","useState","value","setValue","suggestions","setSuggestions","debouncedSearch","useDebounce","searchResults","searchHasResolved","useSelect","select","getEntityRecords","hasFinishedResolution","coreStore","selectorArgs","orderby","exclude","per_page","currentParents","length","include","useEffect","currentParentsInfo","getEntitiesInfo","mapToIHasNameAndId","sanitizedValue","reduce","accumulator","id","entity","mapById","push","name","entitiesInfo","useMemo","names","getIdByValue","entitiesMappedByName","onParentChange","newValue","ids","Array","from","mapByName","add","Set","jsx","FormTokenField","__next40pxDefaultSize","label","__","onInputChange","__experimentalShowHowTo","__nextHasNoMarginBottom","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/parent-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState, useEffect, useMemo } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getEntitiesInfo, mapToIHasNameAndId } from '../../utils';\n\nconst EMPTY_ARRAY = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,title',\n\tcontext: 'view',\n};\n\nfunction ParentControl( { parents, postType, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ value, setValue ] = useState( EMPTY_ARRAY );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst { searchResults, searchHasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! search ) {\n\t\t\t\treturn { searchResults: EMPTY_ARRAY, searchHasResolved: true };\n\t\t\t}\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst selectorArgs = [\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\t...BASE_QUERY,\n\t\t\t\t\tsearch,\n\t\t\t\t\torderby: 'relevance',\n\t\t\t\t\texclude: parents,\n\t\t\t\t\tper_page: 20,\n\t\t\t\t},\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tsearchResults: getEntityRecords( ...selectorArgs ),\n\t\t\t\tsearchHasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tselectorArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ search, parents ]\n\t);\n\tconst currentParents = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! parents?.length ) {\n\t\t\t\treturn EMPTY_ARRAY;\n\t\t\t}\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\treturn getEntityRecords( 'postType', postType, {\n\t\t\t\t...BASE_QUERY,\n\t\t\t\tinclude: parents,\n\t\t\t\tper_page: parents.length,\n\t\t\t} );\n\t\t},\n\t\t[ parents ]\n\t);\n\t// Update the `value` state only after the selectors are resolved\n\t// to avoid emptying the input when we're changing parents.\n\tuseEffect( () => {\n\t\tif ( ! parents?.length ) {\n\t\t\tsetValue( EMPTY_ARRAY );\n\t\t}\n\t\tif ( ! currentParents?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst currentParentsInfo = getEntitiesInfo(\n\t\t\tmapToIHasNameAndId( currentParents, 'title.rendered' )\n\t\t);\n\t\t// Returns only the existing entity ids. This prevents the component\n\t\t// from crashing in the editor, when non existing ids are provided.\n\t\tconst sanitizedValue = parents.reduce( ( accumulator, id ) => {\n\t\t\tconst entity = currentParentsInfo.mapById[ id ];\n\t\t\tif ( entity ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid,\n\t\t\t\t\tvalue: entity.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tsetValue( sanitizedValue );\n\t}, [ parents, currentParents ] );\n\n\tconst entitiesInfo = useMemo( () => {\n\t\tif ( ! searchResults?.length ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\t\treturn getEntitiesInfo(\n\t\t\tmapToIHasNameAndId( searchResults, 'title.rendered' )\n\t\t);\n\t}, [ searchResults ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tsetSuggestions( entitiesInfo.names );\n\t}, [ entitiesInfo.names, searchHasResolved ] );\n\n\tconst getIdByValue = ( entitiesMappedByName, entity ) => {\n\t\tconst id = entity?.id || entitiesMappedByName?.[ entity ]?.id;\n\t\tif ( id ) {\n\t\t\treturn id;\n\t\t}\n\t};\n\tconst onParentChange = ( newValue ) => {\n\t\tconst ids = Array.from(\n\t\t\tnewValue.reduce( ( accumulator, entity ) => {\n\t\t\t\t// Verify that new values point to existing entities.\n\t\t\t\tconst id = getIdByValue( entitiesInfo.mapByName, entity );\n\t\t\t\tif ( id ) {\n\t\t\t\t\taccumulator.add( id );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, new Set() )\n\t\t);\n\t\tsetSuggestions( EMPTY_ARRAY );\n\t\tonChange( { parents: ids } );\n\t};\n\treturn (\n\t\t<FormTokenField\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Parents' ) }\n\t\t\tvalue={ value }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ onParentChange }\n\t\t\t__experimentalShowHowTo={ false }\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\nexport default ParentControl;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_data","_coreData","_element","_compose","_utils","_jsxRuntime","EMPTY_ARRAY","BASE_QUERY","order","_fields","context","ParentControl","parents","postType","onChange","search","setSearch","useState","value","setValue","suggestions","setSuggestions","debouncedSearch","useDebounce","searchResults","searchHasResolved","useSelect","select","getEntityRecords","hasFinishedResolution","coreStore","selectorArgs","orderby","exclude","per_page","currentParents","length","include","useEffect","currentParentsInfo","getEntitiesInfo","mapToIHasNameAndId","sanitizedValue","reduce","accumulator","id","entity","mapById","push","name","entitiesInfo","useMemo","names","getIdByValue","entitiesMappedByName","onParentChange","newValue","ids","Array","from","mapByName","add","Set","jsx","FormTokenField","__next40pxDefaultSize","label","__","onInputChange","__experimentalShowHowTo","__nextHasNoMarginBottom","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/parent-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState, useEffect, useMemo } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getEntitiesInfo, mapToIHasNameAndId } from '../../utils';\n\nconst EMPTY_ARRAY = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,title',\n\tcontext: 'view',\n};\n\nfunction ParentControl( { parents, postType, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ value, setValue ] = useState( EMPTY_ARRAY );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst { searchResults, searchHasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! search ) {\n\t\t\t\treturn { searchResults: EMPTY_ARRAY, searchHasResolved: true };\n\t\t\t}\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst selectorArgs = [\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\t...BASE_QUERY,\n\t\t\t\t\tsearch,\n\t\t\t\t\torderby: 'relevance',\n\t\t\t\t\texclude: parents,\n\t\t\t\t\tper_page: 20,\n\t\t\t\t},\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tsearchResults: getEntityRecords( ...selectorArgs ),\n\t\t\t\tsearchHasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tselectorArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ search, parents ]\n\t);\n\tconst currentParents = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! parents?.length ) {\n\t\t\t\treturn EMPTY_ARRAY;\n\t\t\t}\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\treturn getEntityRecords( 'postType', postType, {\n\t\t\t\t...BASE_QUERY,\n\t\t\t\tinclude: parents,\n\t\t\t\tper_page: parents.length,\n\t\t\t} );\n\t\t},\n\t\t[ parents ]\n\t);\n\t// Update the `value` state only after the selectors are resolved\n\t// to avoid emptying the input when we're changing parents.\n\tuseEffect( () => {\n\t\tif ( ! parents?.length ) {\n\t\t\tsetValue( EMPTY_ARRAY );\n\t\t}\n\t\tif ( ! currentParents?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst currentParentsInfo = getEntitiesInfo(\n\t\t\tmapToIHasNameAndId( currentParents, 'title.rendered' )\n\t\t);\n\t\t// Returns only the existing entity ids. This prevents the component\n\t\t// from crashing in the editor, when non existing ids are provided.\n\t\tconst sanitizedValue = parents.reduce( ( accumulator, id ) => {\n\t\t\tconst entity = currentParentsInfo.mapById[ id ];\n\t\t\tif ( entity ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid,\n\t\t\t\t\tvalue: entity.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tsetValue( sanitizedValue );\n\t}, [ parents, currentParents ] );\n\n\tconst entitiesInfo = useMemo( () => {\n\t\tif ( ! searchResults?.length ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\t\treturn getEntitiesInfo(\n\t\t\tmapToIHasNameAndId( searchResults, 'title.rendered' )\n\t\t);\n\t}, [ searchResults ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tsetSuggestions( entitiesInfo.names );\n\t}, [ entitiesInfo.names, searchHasResolved ] );\n\n\tconst getIdByValue = ( entitiesMappedByName, entity ) => {\n\t\tconst id = entity?.id || entitiesMappedByName?.[ entity ]?.id;\n\t\tif ( id ) {\n\t\t\treturn id;\n\t\t}\n\t};\n\tconst onParentChange = ( newValue ) => {\n\t\tconst ids = Array.from(\n\t\t\tnewValue.reduce( ( accumulator, entity ) => {\n\t\t\t\t// Verify that new values point to existing entities.\n\t\t\t\tconst id = getIdByValue( entitiesInfo.mapByName, entity );\n\t\t\t\tif ( id ) {\n\t\t\t\t\taccumulator.add( id );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, new Set() )\n\t\t);\n\t\tsetSuggestions( EMPTY_ARRAY );\n\t\tonChange( { parents: ids } );\n\t};\n\treturn (\n\t\t<FormTokenField\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Parents' ) }\n\t\t\tvalue={ value }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ onParentChange }\n\t\t\t__experimentalShowHowTo={ false }\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n\nexport default ParentControl;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;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ACzBjD,KAAK,EAAGA,KAAO;IACfkD,aAAa,EAAG9C,eAAiB;IACjCF,WAAW,EAAGA,WAAa;IAC3BN,QAAQ,EAAGyC,cAAgB;IAC3Bc,uBAAuB,EAAG,KAAO;IACjCC,uBAAuB;EAAA,CACvB,CAAC;AAEJ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc9D,aAAa","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_data","_coreData","_element","_compose","_htmlEntities","_utils","_jsxRuntime","EMPTY_ARRAY","BASE_QUERY","order","_fields","context","getTermIdByTermValue","terms","termValue","termId","id","find","term","name","termValueLower","toLocaleLowerCase","TaxonomyControls","onChange","query","postType","taxQuery","taxonomies","useTaxonomies","length","jsx","__experimentalVStack","spacing","children","map","taxonomy","termIds","slug","handleChange","newTermIds","TaxonomyItem","search","setSearch","useState","value","setValue","suggestions","setSuggestions","debouncedSearch","useDebounce","searchResults","searchHasResolved","useSelect","select","getEntityRecords","hasFinishedResolution","coreStore","selectorArgs","orderby","exclude","per_page","existingTerms","include","useEffect","sanitizedValue","reduce","accumulator","entity","push","result","onTermsChange","newTermValues","Set","add","Array","from","className","FormTokenField","label","onInputChange","displayTransform","decodeEntities","__experimentalShowHowTo","__nextHasNoMarginBottom","__next40pxDefaultSize"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/taxonomy-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tFormTokenField,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { useTaxonomies } from '../../utils';\n\nconst EMPTY_ARRAY = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\n// Helper function to get the term id based on user input in terms `FormTokenField`.\nconst getTermIdByTermValue = ( terms, termValue ) => {\n\t// First we check for exact match by `term.id` or case sensitive `term.name` match.\n\tconst termId =\n\t\ttermValue?.id || terms?.find( ( term ) => term.name === termValue )?.id;\n\tif ( termId ) {\n\t\treturn termId;\n\t}\n\n\t/**\n\t * Here we make an extra check for entered terms in a non case sensitive way,\n\t * to match user expectations, due to `FormTokenField` behaviour that shows\n\t * suggestions which are case insensitive.\n\t *\n\t * Although WP tries to discourage users to add terms with the same name (case insensitive),\n\t * it's still possible if you manually change the name, as long as the terms have different slugs.\n\t * In this edge case we always apply the first match from the terms list.\n\t */\n\tconst termValueLower = termValue.toLocaleLowerCase();\n\treturn terms?.find(\n\t\t( term ) => term.name.toLocaleLowerCase() === termValueLower\n\t)?.id;\n};\n\nexport function TaxonomyControls( { onChange, query } ) {\n\tconst { postType, taxQuery } = query;\n\n\tconst taxonomies = useTaxonomies( postType );\n\tif ( ! taxonomies || taxonomies.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 4 }>\n\t\t\t{ taxonomies.map( ( taxonomy ) => {\n\t\t\t\tconst termIds = taxQuery?.[ taxonomy.slug ] || [];\n\t\t\t\tconst handleChange = ( newTermIds ) =>\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\ttaxQuery: {\n\t\t\t\t\t\t\t...taxQuery,\n\t\t\t\t\t\t\t[ taxonomy.slug ]: newTermIds,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\treturn (\n\t\t\t\t\t<TaxonomyItem\n\t\t\t\t\t\tkey={ taxonomy.slug }\n\t\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\t\ttermIds={ termIds }\n\t\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</VStack>\n\t);\n}\n\n/**\n * Renders a `FormTokenField` for a given taxonomy.\n *\n * @param {Object} props The props for the component.\n * @param {Object} props.taxonomy The taxonomy object.\n * @param {number[]} props.termIds An array with the block's term ids for the given taxonomy.\n * @param {Function} props.onChange Callback `onChange` function.\n * @return {JSX.Element} The rendered component.\n */\nfunction TaxonomyItem( { taxonomy, termIds, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ value, setValue ] = useState( EMPTY_ARRAY );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst { searchResults, searchHasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! search ) {\n\t\t\t\treturn { searchResults: EMPTY_ARRAY, searchHasResolved: true };\n\t\t\t}\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst selectorArgs = [\n\t\t\t\t'taxonomy',\n\t\t\t\ttaxonomy.slug,\n\t\t\t\t{\n\t\t\t\t\t...BASE_QUERY,\n\t\t\t\t\tsearch,\n\t\t\t\t\torderby: 'name',\n\t\t\t\t\texclude: termIds,\n\t\t\t\t\tper_page: 20,\n\t\t\t\t},\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tsearchResults: getEntityRecords( ...selectorArgs ),\n\t\t\t\tsearchHasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tselectorArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ search, termIds ]\n\t);\n\t// `existingTerms` are the ones fetched from the API and their type is `{ id: number; name: string }`.\n\t// They are used to extract the terms' names to populate the `FormTokenField` properly\n\t// and to sanitize the provided `termIds`, by setting only the ones that exist.\n\tconst existingTerms = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termIds?.length ) {\n\t\t\t\treturn EMPTY_ARRAY;\n\t\t\t}\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\treturn getEntityRecords( 'taxonomy', taxonomy.slug, {\n\t\t\t\t...BASE_QUERY,\n\t\t\t\tinclude: termIds,\n\t\t\t\tper_page: termIds.length,\n\t\t\t} );\n\t\t},\n\t\t[ termIds ]\n\t);\n\t// Update the `value` state only after the selectors are resolved\n\t// to avoid emptying the input when we're changing terms.\n\tuseEffect( () => {\n\t\tif ( ! termIds?.length ) {\n\t\t\tsetValue( EMPTY_ARRAY );\n\t\t}\n\t\tif ( ! existingTerms?.length ) {\n\t\t\treturn;\n\t\t}\n\t\t// Returns only the existing entity ids. This prevents the component\n\t\t// from crashing in the editor, when non existing ids are provided.\n\t\tconst sanitizedValue = termIds.reduce( ( accumulator, id ) => {\n\t\t\tconst entity = existingTerms.find( ( term ) => term.id === id );\n\t\t\tif ( entity ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid,\n\t\t\t\t\tvalue: entity.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tsetValue( sanitizedValue );\n\t}, [ termIds, existingTerms ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tsetSuggestions( searchResults.map( ( result ) => result.name ) );\n\t}, [ searchResults, searchHasResolved ] );\n\tconst onTermsChange = ( newTermValues ) => {\n\t\tconst newTermIds = new Set();\n\t\tfor ( const termValue of newTermValues ) {\n\t\t\tconst termId = getTermIdByTermValue( searchResults, termValue );\n\t\t\tif ( termId ) {\n\t\t\t\tnewTermIds.add( termId );\n\t\t\t}\n\t\t}\n\t\tsetSuggestions( EMPTY_ARRAY );\n\t\tonChange( Array.from( newTermIds ) );\n\t};\n\treturn (\n\t\t<div className=\"block-library-query-inspector__taxonomy-control\">\n\t\t\t<FormTokenField\n\t\t\t\tlabel={ taxonomy.name }\n\t\t\t\tvalue={ value }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tdisplayTransform={ decodeEntities }\n\t\t\t\tonChange={ onTermsChange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,cAAc;MACdC,KAAK,EAAG3C,QAAQ,CAAChB,IAAM;MACvByB,KAAK,EAAGA,KAAO;MACfmC,aAAa,EAAG/B,eAAiB;MACjCF,WAAW,EAAGA,WAAa;MAC3BkC,gBAAgB,EAAGC,4BAAgB;MACnC1D,QAAQ,EAAG+C,aAAe;MAC1BY,uBAAuB,EAAG,KAAO;MACjCC,uBAAuB;MACvBC,qBAAqB;IAAA,CACrB;EAAC,CACE,CAAC;AAER","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_components","require","_data","_coreData","_element","_compose","_htmlEntities","_utils","_jsxRuntime","EMPTY_ARRAY","BASE_QUERY","order","_fields","context","getTermIdByTermValue","terms","termValue","termId","id","find","term","name","termValueLower","toLocaleLowerCase","TaxonomyControls","onChange","query","postType","taxQuery","taxonomies","useTaxonomies","length","jsx","__experimentalVStack","spacing","children","map","taxonomy","termIds","slug","handleChange","newTermIds","TaxonomyItem","search","setSearch","useState","value","setValue","suggestions","setSuggestions","debouncedSearch","useDebounce","searchResults","searchHasResolved","useSelect","select","getEntityRecords","hasFinishedResolution","coreStore","selectorArgs","orderby","exclude","per_page","existingTerms","include","useEffect","sanitizedValue","reduce","accumulator","entity","push","result","onTermsChange","newTermValues","Set","add","Array","from","className","FormTokenField","label","onInputChange","displayTransform","decodeEntities","__experimentalShowHowTo","__nextHasNoMarginBottom","__next40pxDefaultSize"],"sources":["@wordpress/block-library/src/query/edit/inspector-controls/taxonomy-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tFormTokenField,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport { useTaxonomies } from '../../utils';\n\nconst EMPTY_ARRAY = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\n// Helper function to get the term id based on user input in terms `FormTokenField`.\nconst getTermIdByTermValue = ( terms, termValue ) => {\n\t// First we check for exact match by `term.id` or case sensitive `term.name` match.\n\tconst termId =\n\t\ttermValue?.id || terms?.find( ( term ) => term.name === termValue )?.id;\n\tif ( termId ) {\n\t\treturn termId;\n\t}\n\n\t/**\n\t * Here we make an extra check for entered terms in a non case sensitive way,\n\t * to match user expectations, due to `FormTokenField` behaviour that shows\n\t * suggestions which are case insensitive.\n\t *\n\t * Although WP tries to discourage users to add terms with the same name (case insensitive),\n\t * it's still possible if you manually change the name, as long as the terms have different slugs.\n\t * In this edge case we always apply the first match from the terms list.\n\t */\n\tconst termValueLower = termValue.toLocaleLowerCase();\n\treturn terms?.find(\n\t\t( term ) => term.name.toLocaleLowerCase() === termValueLower\n\t)?.id;\n};\n\nexport function TaxonomyControls( { onChange, query } ) {\n\tconst { postType, taxQuery } = query;\n\n\tconst taxonomies = useTaxonomies( postType );\n\tif ( ! taxonomies || taxonomies.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 4 }>\n\t\t\t{ taxonomies.map( ( taxonomy ) => {\n\t\t\t\tconst termIds = taxQuery?.[ taxonomy.slug ] || [];\n\t\t\t\tconst handleChange = ( newTermIds ) =>\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\ttaxQuery: {\n\t\t\t\t\t\t\t...taxQuery,\n\t\t\t\t\t\t\t[ taxonomy.slug ]: newTermIds,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\treturn (\n\t\t\t\t\t<TaxonomyItem\n\t\t\t\t\t\tkey={ taxonomy.slug }\n\t\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\t\ttermIds={ termIds }\n\t\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</VStack>\n\t);\n}\n\n/**\n * Renders a `FormTokenField` for a given taxonomy.\n *\n * @param {Object} props The props for the component.\n * @param {Object} props.taxonomy The taxonomy object.\n * @param {number[]} props.termIds An array with the block's term ids for the given taxonomy.\n * @param {Function} props.onChange Callback `onChange` function.\n * @return {JSX.Element} The rendered component.\n */\nfunction TaxonomyItem( { taxonomy, termIds, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ value, setValue ] = useState( EMPTY_ARRAY );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst { searchResults, searchHasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! search ) {\n\t\t\t\treturn { searchResults: EMPTY_ARRAY, searchHasResolved: true };\n\t\t\t}\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst selectorArgs = [\n\t\t\t\t'taxonomy',\n\t\t\t\ttaxonomy.slug,\n\t\t\t\t{\n\t\t\t\t\t...BASE_QUERY,\n\t\t\t\t\tsearch,\n\t\t\t\t\torderby: 'name',\n\t\t\t\t\texclude: termIds,\n\t\t\t\t\tper_page: 20,\n\t\t\t\t},\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tsearchResults: getEntityRecords( ...selectorArgs ),\n\t\t\t\tsearchHasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tselectorArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ search, termIds ]\n\t);\n\t// `existingTerms` are the ones fetched from the API and their type is `{ id: number; name: string }`.\n\t// They are used to extract the terms' names to populate the `FormTokenField` properly\n\t// and to sanitize the provided `termIds`, by setting only the ones that exist.\n\tconst existingTerms = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termIds?.length ) {\n\t\t\t\treturn EMPTY_ARRAY;\n\t\t\t}\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\treturn getEntityRecords( 'taxonomy', taxonomy.slug, {\n\t\t\t\t...BASE_QUERY,\n\t\t\t\tinclude: termIds,\n\t\t\t\tper_page: termIds.length,\n\t\t\t} );\n\t\t},\n\t\t[ termIds ]\n\t);\n\t// Update the `value` state only after the selectors are resolved\n\t// to avoid emptying the input when we're changing terms.\n\tuseEffect( () => {\n\t\tif ( ! termIds?.length ) {\n\t\t\tsetValue( EMPTY_ARRAY );\n\t\t}\n\t\tif ( ! existingTerms?.length ) {\n\t\t\treturn;\n\t\t}\n\t\t// Returns only the existing entity ids. This prevents the component\n\t\t// from crashing in the editor, when non existing ids are provided.\n\t\tconst sanitizedValue = termIds.reduce( ( accumulator, id ) => {\n\t\t\tconst entity = existingTerms.find( ( term ) => term.id === id );\n\t\t\tif ( entity ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid,\n\t\t\t\t\tvalue: entity.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tsetValue( sanitizedValue );\n\t}, [ termIds, existingTerms ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tsetSuggestions( searchResults.map( ( result ) => result.name ) );\n\t}, [ searchResults, searchHasResolved ] );\n\tconst onTermsChange = ( newTermValues ) => {\n\t\tconst newTermIds = new Set();\n\t\tfor ( const termValue of newTermValues ) {\n\t\t\tconst termId = getTermIdByTermValue( searchResults, termValue );\n\t\t\tif ( termId ) {\n\t\t\t\tnewTermIds.add( termId );\n\t\t\t}\n\t\t}\n\t\tsetSuggestions( EMPTY_ARRAY );\n\t\tonChange( Array.from( newTermIds ) );\n\t};\n\treturn (\n\t\t<div className=\"block-library-query-inspector__taxonomy-control\">\n\t\t\t<FormTokenField\n\t\t\t\tlabel={ taxonomy.name }\n\t\t\t\tvalue={ value }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tdisplayTransform={ decodeEntities }\n\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EAAChC,WAAA,CAAA+E,cAAc;MACdC,KAAK,EAAG3C,QAAQ,CAAChB,IAAM;MACvByB,KAAK,EAAGA,KAAO;MACfmC,aAAa,EAAG/B,eAAiB;MACjCF,WAAW,EAAGA,WAAa;MAC3BkC,gBAAgB,EAAGC,4BAAgB;MACnC1D,QAAQ,EAAG+C,aAAe;MAC1BY,uBAAuB,EAAG,KAAO;MACjCC,uBAAuB;MACvBC,qBAAqB;IAAA,CACrB;EAAC,CACE,CAAC;AAER","ignoreList":[]}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.PatternSelectionModal = PatternSelectionModal;
|
|
7
|
+
exports.default = PatternSelection;
|
|
8
|
+
exports.useBlockPatterns = useBlockPatterns;
|
|
7
9
|
var _element = require("@wordpress/element");
|
|
8
10
|
var _data = require("@wordpress/data");
|
|
9
11
|
var _components = require("@wordpress/components");
|
|
@@ -24,12 +26,44 @@ function PatternSelectionModal({
|
|
|
24
26
|
clientId,
|
|
25
27
|
attributes,
|
|
26
28
|
setIsPatternSelectionModalOpen
|
|
29
|
+
}) {
|
|
30
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
|
|
31
|
+
overlayClassName: "block-library-query-pattern__selection-modal",
|
|
32
|
+
title: (0, _i18n.__)('Choose a pattern'),
|
|
33
|
+
onRequestClose: () => setIsPatternSelectionModalOpen(false),
|
|
34
|
+
isFullScreen: true,
|
|
35
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PatternSelection, {
|
|
36
|
+
clientId: clientId,
|
|
37
|
+
attributes: attributes
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useBlockPatterns(clientId, attributes) {
|
|
42
|
+
const blockNameForPatterns = (0, _utils.useBlockNameForPatterns)(clientId, attributes);
|
|
43
|
+
return (0, _utils.usePatterns)(clientId, blockNameForPatterns);
|
|
44
|
+
}
|
|
45
|
+
function PatternSelection({
|
|
46
|
+
clientId,
|
|
47
|
+
attributes,
|
|
48
|
+
showTitlesAsTooltip = false,
|
|
49
|
+
showSearch = true
|
|
27
50
|
}) {
|
|
28
51
|
const [searchValue, setSearchValue] = (0, _element.useState)('');
|
|
29
52
|
const {
|
|
30
53
|
replaceBlock,
|
|
31
54
|
selectBlock
|
|
32
55
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
56
|
+
const blockPatterns = useBlockPatterns(clientId, attributes);
|
|
57
|
+
/*
|
|
58
|
+
* When we preview Query Loop blocks we should prefer the current
|
|
59
|
+
* block's postType, which is passed through block context.
|
|
60
|
+
*/
|
|
61
|
+
const blockPreviewContext = (0, _element.useMemo)(() => ({
|
|
62
|
+
previewPostType: attributes.query.postType
|
|
63
|
+
}), [attributes.query.postType]);
|
|
64
|
+
const filteredBlockPatterns = (0, _element.useMemo)(() => {
|
|
65
|
+
return (0, _searchPatterns.searchPatterns)(blockPatterns, searchValue);
|
|
66
|
+
}, [blockPatterns, searchValue]);
|
|
33
67
|
const onBlockPatternSelect = (pattern, blocks) => {
|
|
34
68
|
const {
|
|
35
69
|
newBlocks,
|
|
@@ -40,40 +74,25 @@ function PatternSelectionModal({
|
|
|
40
74
|
selectBlock(queryClientIds[0]);
|
|
41
75
|
}
|
|
42
76
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SearchControl, {
|
|
63
|
-
__nextHasNoMarginBottom: true,
|
|
64
|
-
onChange: setSearchValue,
|
|
65
|
-
value: searchValue,
|
|
66
|
-
label: (0, _i18n.__)('Search'),
|
|
67
|
-
placeholder: (0, _i18n.__)('Search')
|
|
68
|
-
})
|
|
69
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockContextProvider, {
|
|
70
|
-
value: blockPreviewContext,
|
|
71
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.__experimentalBlockPatternsList, {
|
|
72
|
-
blockPatterns: filteredBlockPatterns,
|
|
73
|
-
onClickPattern: onBlockPatternSelect
|
|
74
|
-
})
|
|
75
|
-
})]
|
|
76
|
-
})
|
|
77
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
78
|
+
className: "block-library-query-pattern__selection-content",
|
|
79
|
+
children: [showSearch && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
80
|
+
className: "block-library-query-pattern__selection-search",
|
|
81
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SearchControl, {
|
|
82
|
+
__nextHasNoMarginBottom: true,
|
|
83
|
+
onChange: setSearchValue,
|
|
84
|
+
value: searchValue,
|
|
85
|
+
label: (0, _i18n.__)('Search'),
|
|
86
|
+
placeholder: (0, _i18n.__)('Search')
|
|
87
|
+
})
|
|
88
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockContextProvider, {
|
|
89
|
+
value: blockPreviewContext,
|
|
90
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.__experimentalBlockPatternsList, {
|
|
91
|
+
blockPatterns: filteredBlockPatterns,
|
|
92
|
+
onClickPattern: onBlockPatternSelect,
|
|
93
|
+
showTitlesAsTooltip: showTitlesAsTooltip
|
|
94
|
+
})
|
|
95
|
+
})]
|
|
77
96
|
});
|
|
78
97
|
}
|
|
79
|
-
//# sourceMappingURL=pattern-selection
|
|
98
|
+
//# sourceMappingURL=pattern-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_components","_blockEditor","_i18n","_utils","_searchPatterns","_jsxRuntime","PatternSelectionModal","clientId","attributes","setIsPatternSelectionModalOpen","jsx","Modal","overlayClassName","title","__","onRequestClose","isFullScreen","children","PatternSelection","useBlockPatterns","blockNameForPatterns","useBlockNameForPatterns","usePatterns","showTitlesAsTooltip","showSearch","searchValue","setSearchValue","useState","replaceBlock","selectBlock","useDispatch","blockEditorStore","blockPatterns","blockPreviewContext","useMemo","previewPostType","query","postType","filteredBlockPatterns","searchPatterns","onBlockPatternSelect","pattern","blocks","newBlocks","queryClientIds","getTransformedBlocksFromPattern","jsxs","className","SearchControl","__nextHasNoMarginBottom","onChange","value","label","placeholder","BlockContextProvider","__experimentalBlockPatternsList","onClickPattern"],"sources":["@wordpress/block-library/src/query/edit/pattern-selection.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { Modal, SearchControl } from '@wordpress/components';\nimport {\n\tBlockContextProvider,\n\tstore as blockEditorStore,\n\t__experimentalBlockPatternsList as BlockPatternsList,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseBlockNameForPatterns,\n\tgetTransformedBlocksFromPattern,\n\tusePatterns,\n} from '../utils';\nimport { searchPatterns } from '../../utils/search-patterns';\n\nexport function PatternSelectionModal( {\n\tclientId,\n\tattributes,\n\tsetIsPatternSelectionModalOpen,\n} ) {\n\treturn (\n\t\t<Modal\n\t\t\toverlayClassName=\"block-library-query-pattern__selection-modal\"\n\t\t\ttitle={ __( 'Choose a pattern' ) }\n\t\t\tonRequestClose={ () => setIsPatternSelectionModalOpen( false ) }\n\t\t\tisFullScreen\n\t\t>\n\t\t\t<PatternSelection clientId={ clientId } attributes={ attributes } />\n\t\t</Modal>\n\t);\n}\n\nexport function useBlockPatterns( clientId, attributes ) {\n\tconst blockNameForPatterns = useBlockNameForPatterns(\n\t\tclientId,\n\t\tattributes\n\t);\n\treturn usePatterns( clientId, blockNameForPatterns );\n}\n\nexport default function PatternSelection( {\n\tclientId,\n\tattributes,\n\tshowTitlesAsTooltip = false,\n\tshowSearch = true,\n} ) {\n\tconst [ searchValue, setSearchValue ] = useState( '' );\n\tconst { replaceBlock, selectBlock } = useDispatch( blockEditorStore );\n\tconst blockPatterns = useBlockPatterns( clientId, attributes );\n\t/*\n\t * When we preview Query Loop blocks we should prefer the current\n\t * block's postType, which is passed through block context.\n\t */\n\tconst blockPreviewContext = useMemo(\n\t\t() => ( {\n\t\t\tpreviewPostType: attributes.query.postType,\n\t\t} ),\n\t\t[ attributes.query.postType ]\n\t);\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\treturn searchPatterns( blockPatterns, searchValue );\n\t}, [ blockPatterns, searchValue ] );\n\n\tconst onBlockPatternSelect = ( pattern, blocks ) => {\n\t\tconst { newBlocks, queryClientIds } = getTransformedBlocksFromPattern(\n\t\t\tblocks,\n\t\t\tattributes\n\t\t);\n\t\treplaceBlock( clientId, newBlocks );\n\t\tif ( queryClientIds[ 0 ] ) {\n\t\t\tselectBlock( queryClientIds[ 0 ] );\n\t\t}\n\t};\n\treturn (\n\t\t<div className=\"block-library-query-pattern__selection-content\">\n\t\t\t{ showSearch && (\n\t\t\t\t<div className=\"block-library-query-pattern__selection-search\">\n\t\t\t\t\t<SearchControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tonChange={ setSearchValue }\n\t\t\t\t\t\tvalue={ searchValue }\n\t\t\t\t\t\tlabel={ __( 'Search' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Search' ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<BlockContextProvider value={ blockPreviewContext }>\n\t\t\t\t<BlockPatternsList\n\t\t\t\t\tblockPatterns={ filteredBlockPatterns }\n\t\t\t\t\tonClickPattern={ onBlockPatternSelect }\n\t\t\t\t\tshowTitlesAsTooltip={ showTitles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,QAAE,EAAE,QAAS;MAAG,CAC9B;IAAC,CACE,CACL,eACD,IAAAT,WAAA,CAAAK,GAAA,EAACT,YAAA,CAAAqD,oBAAoB;MAACH,KAAK,EAAGlB,mBAAqB;MAAAhB,QAAA,eAClD,IAAAZ,WAAA,CAAAK,GAAA,EAACT,YAAA,CAAAsD,+BAAiB;QACjBvB,aAAa,EAAGM,qBAAuB;QACvCkB,cAAc,EAAGhB,oBAAsB;QACvCjB,mBAAmB,EAAGA;MAAqB,CAC3C;IAAC,CACmB,CAAC;EAAA,CACnB,CAAC;AAER","ignoreList":[]}
|
|
@@ -13,10 +13,10 @@ var _components = require("@wordpress/components");
|
|
|
13
13
|
var _i18n = require("@wordpress/i18n");
|
|
14
14
|
var _coreData = require("@wordpress/core-data");
|
|
15
15
|
var _enhancedPaginationControl = _interopRequireDefault(require("./inspector-controls/enhanced-pagination-control"));
|
|
16
|
-
var _queryToolbar = _interopRequireDefault(require("./query-toolbar"));
|
|
17
16
|
var _inspectorControls = _interopRequireDefault(require("./inspector-controls"));
|
|
18
17
|
var _enhancedPaginationModal = _interopRequireDefault(require("./enhanced-pagination-modal"));
|
|
19
18
|
var _utils = require("../utils");
|
|
19
|
+
var _queryToolbar = _interopRequireDefault(require("./query-toolbar"));
|
|
20
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
21
|
/**
|
|
22
22
|
* WordPress dependencies
|
|
@@ -31,10 +31,9 @@ const TEMPLATE = [['core/post-template']];
|
|
|
31
31
|
function QueryContent({
|
|
32
32
|
attributes,
|
|
33
33
|
setAttributes,
|
|
34
|
-
openPatternSelectionModal,
|
|
35
|
-
name,
|
|
36
34
|
clientId,
|
|
37
|
-
context
|
|
35
|
+
context,
|
|
36
|
+
name
|
|
38
37
|
}) {
|
|
39
38
|
const {
|
|
40
39
|
queryId,
|
|
@@ -146,6 +145,7 @@ function QueryContent({
|
|
|
146
145
|
clientId: clientId
|
|
147
146
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
|
|
148
147
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_inspectorControls.default, {
|
|
148
|
+
name: name,
|
|
149
149
|
attributes: attributes,
|
|
150
150
|
setQuery: updateQuery,
|
|
151
151
|
setDisplayLayout: updateDisplayLayout,
|
|
@@ -155,11 +155,8 @@ function QueryContent({
|
|
|
155
155
|
})
|
|
156
156
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
|
|
157
157
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_queryToolbar.default, {
|
|
158
|
-
name: name,
|
|
159
|
-
clientId: clientId,
|
|
160
158
|
attributes: attributes,
|
|
161
|
-
|
|
162
|
-
openPatternSelectionModal: openPatternSelectionModal
|
|
159
|
+
clientId: clientId
|
|
163
160
|
})
|
|
164
161
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_blockEditor.InspectorControls, {
|
|
165
162
|
group: "advanced",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_compose","_element","_blockEditor","_components","_i18n","_coreData","_enhancedPaginationControl","_interopRequireDefault","_queryToolbar","_inspectorControls","_enhancedPaginationModal","_utils","_jsxRuntime","DEFAULTS_POSTS_PER_PAGE","TEMPLATE","QueryContent","attributes","setAttributes","openPatternSelectionModal","name","clientId","context","queryId","query","displayLayout","enhancedPagination","tagName","TagName","inherit","templateSlug","isSingular","getQueryContextFromTemplate","__unstableMarkNextChangeAsNotPersistent","useDispatch","blockEditorStore","instanceId","useInstanceId","blockProps","useBlockProps","innerBlocksProps","useInnerBlocksProps","template","postsPerPage","useSelect","select","getSettings","getEntityRecord","getEntityRecordEdits","canUser","coreStore","settingPerPage","kind","posts_per_page","editedSettingPerPage","updateQuery","useCallback","newQuery","useEffect","perPage","Object","keys","length","Number","isFinite","updateDisplayLayout","newDisplayLayout","htmlElementMessages","main","__","section","aside","jsxs","Fragment","children","jsx","default","InspectorControls","setQuery","setDisplayLayout","BlockControls","group","SelectControl","__nextHasNoMarginBottom","__next40pxDefaultSize","label","options","value","onChange","help"],"sources":["@wordpress/block-library/src/query/edit/query-content.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useEffect, useCallback } from '@wordpress/element';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport EnhancedPaginationControl from './inspector-controls/enhanced-pagination-control';\nimport QueryToolbar from './query-toolbar';\nimport QueryInspectorControls from './inspector-controls';\nimport EnhancedPaginationModal from './enhanced-pagination-modal';\nimport { getQueryContextFromTemplate } from '../utils';\n\nconst DEFAULTS_POSTS_PER_PAGE = 3;\n\nconst TEMPLATE = [ [ 'core/post-template' ] ];\nexport default function QueryContent( {\n\tattributes,\n\tsetAttributes,\n\topenPatternSelectionModal,\n\tname,\n\tclientId,\n\tcontext,\n} ) {\n\tconst {\n\t\tqueryId,\n\t\tquery,\n\t\tdisplayLayout,\n\t\tenhancedPagination,\n\t\ttagName: TagName = 'div',\n\t\tquery: { inherit } = {},\n\t} = attributes;\n\tconst { templateSlug } = context;\n\tconst { isSingular } = getQueryContextFromTemplate( templateSlug );\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst instanceId = useInstanceId( QueryContent );\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\tconst { postsPerPage } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { getEntityRecord, getEntityRecordEdits, canUser } =\n\t\t\tselect( coreStore );\n\t\tconst settingPerPage = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? +getEntityRecord( 'root', 'site' )?.posts_per_page\n\t\t\t: +getSettings().postsPerPage;\n\n\t\t// Gets changes made via the template area posts per page setting. These won't be saved\n\t\t// until the page is saved, but we should reflect this setting within the query loops\n\t\t// that inherit it.\n\t\tconst editedSettingPerPage = +getEntityRecordEdits( 'root', 'site' )\n\t\t\t?.posts_per_page;\n\n\t\treturn {\n\t\t\tpostsPerPage:\n\t\t\t\teditedSettingPerPage ||\n\t\t\t\tsettingPerPage ||\n\t\t\t\tDEFAULTS_POSTS_PER_PAGE,\n\t\t};\n\t}, [] );\n\t// There are some effects running where some initialization logic is\n\t// happening and setting some values to some attributes (ex. queryId).\n\t// These updates can cause an `undo trap` where undoing will result in\n\t// resetting again, so we need to mark these changes as not persistent\n\t// with `__unstableMarkNextChangeAsNotPersistent`.\n\n\t// Changes in query property (which is an object) need to be in the same callback,\n\t// because updates are batched after the render and changes in different query properties\n\t// would cause to override previous wanted changes.\n\tconst updateQuery = useCallback(\n\t\t( newQuery ) => setAttributes( { query: { ...query, ...newQuery } } ),\n\t\t[ query, setAttributes ]\n\t);\n\tuseEffect( () => {\n\t\tconst newQuery = {};\n\t\t// When we inherit from global query always need to set the `perPage`\n\t\t// based on the reading settings.\n\t\tif ( inherit && query.perPage !== postsPerPage ) {\n\t\t\tnewQuery.perPage = postsPerPage;\n\t\t} else if ( ! query.perPage && postsPerPage ) {\n\t\t\tnewQuery.perPage = postsPerPage;\n\t\t}\n\t\t// We need to reset the `inherit` value if in a singular template, as queries\n\t\t// are not inherited when in singular content (e.g. post, page, 404, blank).\n\t\tif ( isSingular && query.inherit ) {\n\t\t\tnewQuery.inherit = false;\n\t\t}\n\t\tif ( !! Object.keys( newQuery ).length ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tupdateQuery( newQuery );\n\t\t}\n\t}, [\n\t\tquery.perPage,\n\t\tquery.inherit,\n\t\tpostsPerPage,\n\t\tinherit,\n\t\tisSingular,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tupdateQuery,\n\t] );\n\t// We need this for multi-query block pagination.\n\t// Query parameters for each block are scoped to their ID.\n\tuseEffect( () => {\n\t\tif ( ! Number.isFinite( queryId ) ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { queryId: instanceId } );\n\t\t}\n\t}, [\n\t\tqueryId,\n\t\tinstanceId,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tsetAttributes,\n\t] );\n\tconst updateDisplayLayout = ( newDisplayLayout ) =>\n\t\tsetAttributes( {\n\t\t\tdisplayLayout: { ...displayLayout, ...newDisplayLayout },\n\t\t} );\n\tconst htmlElementMessages = {\n\t\tmain: __(\n\t\t\t'The <main> element should be used for the primary content of your document only.'\n\t\t),\n\t\tsection: __(\n\t\t\t\"The <section> element should represent a standalone portion of the document that can't be better represented by another element.\"\n\t\t),\n\t\taside: __(\n\t\t\t\"The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content.\"\n\t\t),\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<EnhancedPaginationModal\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tclientId={ clientId }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<QueryInspectorControls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetQuery={ updateQuery }\n\t\t\t\t\tsetDisplayLayout={ updateDisplayLayout }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tisSingular={ isSingular }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockControls>\n\t\t\t\t<QueryToolbar\n\t\t\t\t\tname={ name }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetQuery={ updateQuery }\n\t\t\t\t\topenPatternSelectionModal={ openPatternSelectionModal }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'HTML element' ) }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{ label: __( 'Default (<div>)' ), value: 'div' },\n\t\t\t\t\t\t{ label: '<main>', value: 'main' },\n\t\t\t\t\t\t{ label: '<section>', value: 'section' },\n\t\t\t\t\t\t{ label: '<aside>', value: 'aside' },\n\t\t\t\t\t] }\n\t\t\t\t\tvalue={ TagName }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { tagName: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={ htmlElementMessages[ TagName ] }\n\t\t\t\t/>\n\t\t\t\t<EnhancedPaginationControl\n\t\t\t\t\tenhancedPagination={ enhancedPagination }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAOA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,0BAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,aAAA,GAAAD,sBAAA,CAAAR,OAAA;AACA,IAAAU,kBAAA,GAAAF,sBAAA,CAAAR,OAAA;AACA,IAAAW,wBAAA,GAAAH,sBAAA,CAAAR,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AAAuD,IAAAa,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,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_data","require","_compose","_element","_blockEditor","_components","_i18n","_coreData","_enhancedPaginationControl","_interopRequireDefault","_inspectorControls","_enhancedPaginationModal","_utils","_queryToolbar","_jsxRuntime","DEFAULTS_POSTS_PER_PAGE","TEMPLATE","QueryContent","attributes","setAttributes","clientId","context","name","queryId","query","displayLayout","enhancedPagination","tagName","TagName","inherit","templateSlug","isSingular","getQueryContextFromTemplate","__unstableMarkNextChangeAsNotPersistent","useDispatch","blockEditorStore","instanceId","useInstanceId","blockProps","useBlockProps","innerBlocksProps","useInnerBlocksProps","template","postsPerPage","useSelect","select","getSettings","getEntityRecord","getEntityRecordEdits","canUser","coreStore","settingPerPage","kind","posts_per_page","editedSettingPerPage","updateQuery","useCallback","newQuery","useEffect","perPage","Object","keys","length","Number","isFinite","updateDisplayLayout","newDisplayLayout","htmlElementMessages","main","__","section","aside","jsxs","Fragment","children","jsx","default","InspectorControls","setQuery","setDisplayLayout","BlockControls","group","SelectControl","__nextHasNoMarginBottom","__next40pxDefaultSize","label","options","value","onChange","help"],"sources":["@wordpress/block-library/src/query/edit/query-content.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useEffect, useCallback } from '@wordpress/element';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport EnhancedPaginationControl from './inspector-controls/enhanced-pagination-control';\nimport QueryInspectorControls from './inspector-controls';\nimport EnhancedPaginationModal from './enhanced-pagination-modal';\nimport { getQueryContextFromTemplate } from '../utils';\nimport QueryToolbar from './query-toolbar';\n\nconst DEFAULTS_POSTS_PER_PAGE = 3;\n\nconst TEMPLATE = [ [ 'core/post-template' ] ];\nexport default function QueryContent( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n\tcontext,\n\tname,\n} ) {\n\tconst {\n\t\tqueryId,\n\t\tquery,\n\t\tdisplayLayout,\n\t\tenhancedPagination,\n\t\ttagName: TagName = 'div',\n\t\tquery: { inherit } = {},\n\t} = attributes;\n\tconst { templateSlug } = context;\n\tconst { isSingular } = getQueryContextFromTemplate( templateSlug );\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst instanceId = useInstanceId( QueryContent );\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\tconst { postsPerPage } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { getEntityRecord, getEntityRecordEdits, canUser } =\n\t\t\tselect( coreStore );\n\t\tconst settingPerPage = canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} )\n\t\t\t? +getEntityRecord( 'root', 'site' )?.posts_per_page\n\t\t\t: +getSettings().postsPerPage;\n\n\t\t// Gets changes made via the template area posts per page setting. These won't be saved\n\t\t// until the page is saved, but we should reflect this setting within the query loops\n\t\t// that inherit it.\n\t\tconst editedSettingPerPage = +getEntityRecordEdits( 'root', 'site' )\n\t\t\t?.posts_per_page;\n\n\t\treturn {\n\t\t\tpostsPerPage:\n\t\t\t\teditedSettingPerPage ||\n\t\t\t\tsettingPerPage ||\n\t\t\t\tDEFAULTS_POSTS_PER_PAGE,\n\t\t};\n\t}, [] );\n\t// There are some effects running where some initialization logic is\n\t// happening and setting some values to some attributes (ex. queryId).\n\t// These updates can cause an `undo trap` where undoing will result in\n\t// resetting again, so we need to mark these changes as not persistent\n\t// with `__unstableMarkNextChangeAsNotPersistent`.\n\n\t// Changes in query property (which is an object) need to be in the same callback,\n\t// because updates are batched after the render and changes in different query properties\n\t// would cause to override previous wanted changes.\n\tconst updateQuery = useCallback(\n\t\t( newQuery ) => setAttributes( { query: { ...query, ...newQuery } } ),\n\t\t[ query, setAttributes ]\n\t);\n\tuseEffect( () => {\n\t\tconst newQuery = {};\n\t\t// When we inherit from global query always need to set the `perPage`\n\t\t// based on the reading settings.\n\t\tif ( inherit && query.perPage !== postsPerPage ) {\n\t\t\tnewQuery.perPage = postsPerPage;\n\t\t} else if ( ! query.perPage && postsPerPage ) {\n\t\t\tnewQuery.perPage = postsPerPage;\n\t\t}\n\t\t// We need to reset the `inherit` value if in a singular template, as queries\n\t\t// are not inherited when in singular content (e.g. post, page, 404, blank).\n\t\tif ( isSingular && query.inherit ) {\n\t\t\tnewQuery.inherit = false;\n\t\t}\n\t\tif ( !! Object.keys( newQuery ).length ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tupdateQuery( newQuery );\n\t\t}\n\t}, [\n\t\tquery.perPage,\n\t\tquery.inherit,\n\t\tpostsPerPage,\n\t\tinherit,\n\t\tisSingular,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tupdateQuery,\n\t] );\n\t// We need this for multi-query block pagination.\n\t// Query parameters for each block are scoped to their ID.\n\tuseEffect( () => {\n\t\tif ( ! Number.isFinite( queryId ) ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { queryId: instanceId } );\n\t\t}\n\t}, [\n\t\tqueryId,\n\t\tinstanceId,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tsetAttributes,\n\t] );\n\tconst updateDisplayLayout = ( newDisplayLayout ) =>\n\t\tsetAttributes( {\n\t\t\tdisplayLayout: { ...displayLayout, ...newDisplayLayout },\n\t\t} );\n\tconst htmlElementMessages = {\n\t\tmain: __(\n\t\t\t'The <main> element should be used for the primary content of your document only.'\n\t\t),\n\t\tsection: __(\n\t\t\t\"The <section> element should represent a standalone portion of the document that can't be better represented by another element.\"\n\t\t),\n\t\taside: __(\n\t\t\t\"The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content.\"\n\t\t),\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<EnhancedPaginationModal\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tclientId={ clientId }\n\t\t\t/>\n\t\t\t<InspectorControls>\n\t\t\t\t<QueryInspectorControls\n\t\t\t\t\tname={ name }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetQuery={ updateQuery }\n\t\t\t\t\tsetDisplayLayout={ updateDisplayLayout }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tisSingular={ isSingular }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockControls>\n\t\t\t\t<QueryToolbar attributes={ attributes } clientId={ clientId } />\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'HTML element' ) }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{ label: __( 'Default (<div>)' ), value: 'div' },\n\t\t\t\t\t\t{ label: '<main>', value: 'main' },\n\t\t\t\t\t\t{ label: '<section>', value: 'section' },\n\t\t\t\t\t\t{ label: '<aside>', value: 'aside' },\n\t\t\t\t\t] }\n\t\t\t\t\tvalue={ TagName }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { tagName: value } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={ htmlElementMessages[ TagName ] }\n\t\t\t\t/>\n\t\t\t\t<EnhancedPaginationControl\n\t\t\t\t\tenhancedPagination={ enhancedPagination }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\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4D,QAAQ,EAAKD,KAAK,IACjBpE,aAAa,CAAE;UAAEQ,OAAO,EAAE4D;QAAM,CAAE,CAClC;QACDE,IAAI,EAAGtB,mBAAmB,CAAEvC,OAAO;MAAI,CACvC,CAAC,eACF,IAAAd,WAAA,CAAA6D,GAAA,EAACnE,0BAAA,CAAAoE,OAAyB;QACzBlD,kBAAkB,EAAGA,kBAAoB;QACzCP,aAAa,EAAGA,aAAe;QAC/BC,QAAQ,EAAGA;MAAU,CACrB,CAAC;IAAA,CACgB,CAAC,eACpB,IAAAN,WAAA,CAAA6D,GAAA,EAAC/C,OAAO;MAAA,GAAMY;IAAgB,CAAI,CAAC;EAAA,CAClC,CAAC;AAEL","ignoreList":[]}
|
|
@@ -11,6 +11,7 @@ var _blockEditor = require("@wordpress/block-editor");
|
|
|
11
11
|
var _components = require("@wordpress/components");
|
|
12
12
|
var _i18n = require("@wordpress/i18n");
|
|
13
13
|
var _utils = require("../utils");
|
|
14
|
+
var _patternSelection = require("./pattern-selection");
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
/**
|
|
16
17
|
* WordPress dependencies
|
|
@@ -28,27 +29,20 @@ function QueryPlaceholder({
|
|
|
28
29
|
}) {
|
|
29
30
|
const [isStartingBlank, setIsStartingBlank] = (0, _element.useState)(false);
|
|
30
31
|
const blockProps = (0, _blockEditor.useBlockProps)();
|
|
31
|
-
const blockNameForPatterns = (0, _utils.useBlockNameForPatterns)(clientId, attributes);
|
|
32
32
|
const {
|
|
33
33
|
blockType,
|
|
34
|
-
activeBlockVariation
|
|
35
|
-
hasPatterns
|
|
34
|
+
activeBlockVariation
|
|
36
35
|
} = (0, _data.useSelect)(select => {
|
|
37
36
|
const {
|
|
38
37
|
getActiveBlockVariation,
|
|
39
38
|
getBlockType
|
|
40
39
|
} = select(_blocks.store);
|
|
41
|
-
const {
|
|
42
|
-
getBlockRootClientId,
|
|
43
|
-
getPatternsByBlockTypes
|
|
44
|
-
} = select(_blockEditor.store);
|
|
45
|
-
const rootClientId = getBlockRootClientId(clientId);
|
|
46
40
|
return {
|
|
47
41
|
blockType: getBlockType(name),
|
|
48
|
-
activeBlockVariation: getActiveBlockVariation(name, attributes)
|
|
49
|
-
hasPatterns: !!getPatternsByBlockTypes(blockNameForPatterns, rootClientId).length
|
|
42
|
+
activeBlockVariation: getActiveBlockVariation(name, attributes)
|
|
50
43
|
};
|
|
51
|
-
}, [name,
|
|
44
|
+
}, [name, attributes]);
|
|
45
|
+
const hasPatterns = !!(0, _patternSelection.useBlockPatterns)(clientId, attributes).length;
|
|
52
46
|
const icon = activeBlockVariation?.icon?.src || activeBlockVariation?.icon || blockType?.icon?.src;
|
|
53
47
|
const label = activeBlockVariation?.title || blockType?.title;
|
|
54
48
|
if (isStartingBlank) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_blocks","_element","_blockEditor","_components","_i18n","_utils","_jsxRuntime","QueryPlaceholder","attributes","clientId","name","openPatternSelectionModal","isStartingBlank","setIsStartingBlank","useState","blockProps","useBlockProps","
|
|
1
|
+
{"version":3,"names":["_data","require","_blocks","_element","_blockEditor","_components","_i18n","_utils","_patternSelection","_jsxRuntime","QueryPlaceholder","attributes","clientId","name","openPatternSelectionModal","isStartingBlank","setIsStartingBlank","useState","blockProps","useBlockProps","blockType","activeBlockVariation","useSelect","select","getActiveBlockVariation","getBlockType","blocksStore","hasPatterns","useBlockPatterns","length","icon","src","label","title","jsx","QueryVariationPicker","children","jsxs","Placeholder","instructions","__","Button","__next40pxDefaultSize","variant","onClick","scopeVariations","useScopedBlockVariations","replaceInnerBlocks","useDispatch","blockEditorStore","__experimentalBlockVariationPicker","variations","onSelect","variation","innerBlocks","createBlocksFromInnerBlocksTemplate"],"sources":["@wordpress/block-library/src/query/edit/query-placeholder.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tcreateBlocksFromInnerBlocksTemplate,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { useState } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalBlockVariationPicker,\n} from '@wordpress/block-editor';\nimport { Button, Placeholder } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useScopedBlockVariations } from '../utils';\nimport { useBlockPatterns } from './pattern-selection';\n\nexport default function QueryPlaceholder( {\n\tattributes,\n\tclientId,\n\tname,\n\topenPatternSelectionModal,\n} ) {\n\tconst [ isStartingBlank, setIsStartingBlank ] = useState( false );\n\tconst blockProps = useBlockProps();\n\tconst { blockType, activeBlockVariation } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getActiveBlockVariation, getBlockType } =\n\t\t\t\tselect( blocksStore );\n\t\t\treturn {\n\t\t\t\tblockType: getBlockType( name ),\n\t\t\t\tactiveBlockVariation: getActiveBlockVariation(\n\t\t\t\t\tname,\n\t\t\t\t\tattributes\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ name, attributes ]\n\t);\n\tconst hasPatterns = !! useBlockPatterns( clientId, attributes ).length;\n\tconst icon =\n\t\tactiveBlockVariation?.icon?.src ||\n\t\tactiveBlockVariation?.icon ||\n\t\tblockType?.icon?.src;\n\tconst label = activeBlockVariation?.title || blockType?.title;\n\tif ( isStartingBlank ) {\n\t\treturn (\n\t\t\t<QueryVariationPicker\n\t\t\t\tclientId={ clientId }\n\t\t\t\tattributes={ attributes }\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Placeholder\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t\tinstructions={ __(\n\t\t\t\t\t'Choose a pattern for the query loop or start blank.'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ !! hasPatterns && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ openPatternSelectionModal }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Choose' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetIsStartingBlank( true );\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Start blank' ) }\n\t\t\t\t</Button>\n\t\t\t</Placeholder>\n\t\t</div>\n\t);\n}\n\nfunction QueryVariationPicker( { clientId, attributes, icon, label } ) {\n\tconst scopeVariations = useScopedBlockVariations( attributes );\n\tconst { replaceInnerBlocks } = useDispatch( blockEditorStore );\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<__experimentalBlockVariationPicker\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t\tvariations={ scopeVariations }\n\t\t\t\tonSelect={ ( variation ) => {\n\t\t\t\t\tif ( variation.innerBlocks ) {\n\t\t\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlocksFromInnerBlocksTemplate(\n\t\t\t\t\t\t\t\tvariation.innerBlocks\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tfalse\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</div>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,iBA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B,IAAKA,SAAS,CAACC,WAAW,EAAG;UAC5BP,kBAAkB,CACjBnC,QAAQ,EACR,IAAA2C,2CAAmC,EAClCF,SAAS,CAACC,WACX,CAAC,EACD,KACD,CAAC;QACF;MACD;IAAG,CACH;EAAC,CACE,CAAC;AAER","ignoreList":[]}
|
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = QueryToolbar;
|
|
7
7
|
var _components = require("@wordpress/components");
|
|
8
8
|
var _i18n = require("@wordpress/i18n");
|
|
9
|
-
var
|
|
9
|
+
var _patternSelection = _interopRequireWildcard(require("./pattern-selection"));
|
|
10
10
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
13
|
/**
|
|
12
14
|
* WordPress dependencies
|
|
13
15
|
*/
|
|
@@ -17,17 +19,35 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
function QueryToolbar({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clientId
|
|
22
|
+
clientId,
|
|
23
|
+
attributes
|
|
23
24
|
}) {
|
|
24
|
-
const hasPatterns =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const hasPatterns = (0, _patternSelection.useBlockPatterns)(clientId, attributes).length;
|
|
26
|
+
if (!hasPatterns) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
|
|
30
|
+
className: "wp-block-template-part__block-control-group",
|
|
31
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalDropdownContentWrapper, {
|
|
32
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, {
|
|
33
|
+
contentClassName: "block-editor-block-settings-menu__popover",
|
|
34
|
+
focusOnMount: "firstElement",
|
|
35
|
+
expandOnMobile: true,
|
|
36
|
+
renderToggle: ({
|
|
37
|
+
isOpen,
|
|
38
|
+
onToggle
|
|
39
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
|
|
40
|
+
"aria-haspopup": "true",
|
|
41
|
+
"aria-expanded": isOpen,
|
|
42
|
+
onClick: onToggle,
|
|
43
|
+
children: (0, _i18n.__)('Change design')
|
|
44
|
+
}),
|
|
45
|
+
renderContent: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_patternSelection.default, {
|
|
46
|
+
clientId: clientId,
|
|
47
|
+
attributes: attributes,
|
|
48
|
+
showSearch: false,
|
|
49
|
+
showTitlesAsTooltip: true
|
|
50
|
+
})
|
|
31
51
|
})
|
|
32
52
|
})
|
|
33
53
|
});
|