@wordpress/block-editor 12.10.0 → 12.10.1
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/components/block-patterns-list/index.js +9 -4
- package/build/components/block-patterns-list/index.js.map +1 -1
- package/build/components/block-patterns-paging/index.js +3 -1
- package/build/components/block-patterns-paging/index.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +19 -30
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/sidebar.js +0 -15
- package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build/components/inserter/block-patterns-filter.js +137 -0
- package/build/components/inserter/block-patterns-filter.js.map +1 -0
- package/build/components/inserter/block-patterns-tab.js +77 -37
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-paging.js +4 -0
- package/build/components/inserter/hooks/use-patterns-paging.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/hooks/background.js +28 -23
- package/build/hooks/background.js.map +1 -1
- package/build/hooks/block-rename-ui.js +2 -1
- package/build/hooks/block-rename-ui.js.map +1 -1
- package/build/store/private-selectors.js +2 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build-module/components/block-patterns-list/index.js +10 -5
- package/build-module/components/block-patterns-list/index.js.map +1 -1
- package/build-module/components/block-patterns-paging/index.js +3 -1
- package/build-module/components/block-patterns-paging/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +20 -31
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js +0 -14
- package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
- package/build-module/components/inserter/block-patterns-filter.js +128 -0
- package/build-module/components/inserter/block-patterns-filter.js.map +1 -0
- package/build-module/components/inserter/block-patterns-tab.js +75 -35
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-paging.js +5 -1
- package/build-module/components/inserter/hooks/use-patterns-paging.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/hooks/background.js +30 -25
- package/build-module/hooks/background.js.map +1 -1
- package/build-module/hooks/block-rename-ui.js +2 -1
- package/build-module/hooks/block-rename-ui.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -3
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-style/style-rtl.css +53 -26
- package/build-style/style.css +53 -26
- package/package.json +32 -32
- package/src/components/block-patterns-list/index.js +21 -12
- package/src/components/block-patterns-paging/index.js +1 -1
- package/src/components/block-patterns-paging/style.scss +16 -13
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +23 -67
- package/src/components/inserter/block-patterns-explorer/sidebar.js +0 -15
- package/src/components/inserter/block-patterns-filter.js +183 -0
- package/src/components/inserter/block-patterns-tab.js +106 -58
- package/src/components/inserter/hooks/use-patterns-paging.js +12 -1
- package/src/components/inserter/style.scss +13 -5
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/src/hooks/background.js +57 -46
- package/src/hooks/background.scss +36 -18
- package/src/hooks/block-rename-ui.js +1 -0
- package/src/store/private-selectors.js +7 -3
- package/build/components/inserter/block-patterns-source-filter.js +0 -54
- package/build/components/inserter/block-patterns-source-filter.js.map +0 -1
- package/build/components/inserter/block-patterns-sync-filter.js +0 -46
- package/build/components/inserter/block-patterns-sync-filter.js.map +0 -1
- package/build-module/components/inserter/block-patterns-source-filter.js +0 -44
- package/build-module/components/inserter/block-patterns-source-filter.js.map +0 -1
- package/build-module/components/inserter/block-patterns-sync-filter.js +0 -38
- package/build-module/components/inserter/block-patterns-sync-filter.js.map +0 -1
- package/src/components/inserter/block-patterns-source-filter.js +0 -40
- package/src/components/inserter/block-patterns-sync-filter.js +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_compose","_hooks","_i18n","_blocks","_components","_a11y","_components2","emptyString","testString","trim","length","RenameModal","blockName","originalBlockName","onClose","onSave","editedBlockName","setEditedBlockName","useState","nameHasChanged","nameIsOriginal","nameIsEmpty","isNameValid","autoSelectInputText","event","target","select","dialogDescription","useInstanceId","handleSubmit","speak","sprintf","__","createElement","Modal","title","onRequestClose","overlayClassName","aria","describedby","id","onSubmit","e","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","value","label","hideLabelFromVision","placeholder","onChange","onFocus","__experimentalHStack","justify","Button","variant","onClick","type","BlockRenameControl","props","renamingBlock","setRenamingBlock","clientId","customName","blockInformation","useBlockDisplayInformation","Fragment","InspectorControls","group","BlockSettingsMenuControls","selectedClientIds","canRename","MenuItem","newName","undefined","withBlockRenameControl","createHigherOrderComponent","BlockEdit","name","attributes","setAttributes","metaDataSupport","getBlockSupport","supportsBlockNaming","metadata","key","exports","addFilter"],"sources":["@wordpress/block-editor/src/hooks/block-rename-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\tMenuItem,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tButton,\n\tTextControl,\n\tModal,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport {\n\tBlockSettingsMenuControls,\n\tuseBlockDisplayInformation,\n\tInspectorControls,\n} from '../components';\n\nconst emptyString = ( testString ) => testString?.trim()?.length === 0;\n\nfunction RenameModal( { blockName, originalBlockName, onClose, onSave } ) {\n\tconst [ editedBlockName, setEditedBlockName ] = useState( blockName );\n\n\tconst nameHasChanged = editedBlockName !== blockName;\n\tconst nameIsOriginal = editedBlockName === originalBlockName;\n\tconst nameIsEmpty = emptyString( editedBlockName );\n\n\tconst isNameValid = nameHasChanged || nameIsOriginal;\n\n\tconst autoSelectInputText = ( event ) => event.target.select();\n\n\tconst dialogDescription = useInstanceId(\n\t\tRenameModal,\n\t\t`block-editor-rename-modal__description`\n\t);\n\n\tconst handleSubmit = () => {\n\t\t// Must be assertive to immediately announce change.\n\t\tspeak(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %1$s: type of update (either reset of changed). %2$s: new name/label for the block */\n\t\t\t\t__( 'Block name %1$s to: \"%2$s\".' ),\n\t\t\t\tnameIsOriginal || nameIsEmpty ? __( 'reset' ) : __( 'changed' ),\n\t\t\t\teditedBlockName\n\t\t\t),\n\t\t\t'assertive'\n\t\t);\n\n\t\tonSave( editedBlockName );\n\n\t\t// Immediate close avoids ability to hit save multiple times.\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t\toverlayClassName=\"block-editor-block-rename-modal\"\n\t\t\taria={ {\n\t\t\t\tdescribedby: dialogDescription,\n\t\t\t} }\n\t\t>\n\t\t\t<p id={ dialogDescription }>\n\t\t\t\t{ __( 'Enter a custom name for this block.' ) }\n\t\t\t</p>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\n\t\t\t\t\tif ( ! isNameValid ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\thandleSubmit();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ editedBlockName }\n\t\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tplaceholder={ originalBlockName }\n\t\t\t\t\t\tonChange={ setEditedBlockName }\n\t\t\t\t\t\tonFocus={ autoSelectInputText }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onClose }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\taria-disabled={ ! isNameValid }\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n\nfunction BlockRenameControl( props ) {\n\tconst [ renamingBlock, setRenamingBlock ] = useState( false );\n\n\tconst { clientId, customName, onChange } = props;\n\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\tvalue={ customName || '' }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t{ ( { selectedClientIds } ) => {\n\t\t\t\t\t// Only enabled for single selections.\n\t\t\t\t\tconst canRename =\n\t\t\t\t\t\tselectedClientIds.length === 1 &&\n\t\t\t\t\t\tclientId === selectedClientIds[ 0 ];\n\n\t\t\t\t\t// This check ensures the `BlockSettingsMenuControls` fill\n\t\t\t\t\t// doesn't render multiple times and also that it renders for\n\t\t\t\t\t// the block from which the menu was triggered.\n\t\t\t\t\tif ( ! canRename ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetRenamingBlock( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-expanded={ renamingBlock }\n\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rename' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</BlockSettingsMenuControls>\n\n\t\t\t{ renamingBlock && (\n\t\t\t\t<RenameModal\n\t\t\t\t\tblockName={ customName || '' }\n\t\t\t\t\toriginalBlockName={ blockInformation?.title }\n\t\t\t\t\tonClose={ () => setRenamingBlock( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\t// If the new value is the block's original name (e.g. `Group`)\n\t\t\t\t\t\t// or it is an empty string then assume the intent is to reset\n\t\t\t\t\t\t// the value. Therefore reset the metadata.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnewName === blockInformation?.title ||\n\t\t\t\t\t\t\temptyString( newName )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewName = undefined;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const withBlockRenameControl = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name, attributes, setAttributes } = props;\n\n\t\tconst metaDataSupport = getBlockSupport(\n\t\t\tname,\n\t\t\t'__experimentalMetadata',\n\t\t\tfalse\n\t\t);\n\n\t\tconst supportsBlockNaming = !! (\n\t\t\ttrue === metaDataSupport || metaDataSupport?.name\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ supportsBlockNaming && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockRenameControl\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tcustomName={ attributes?.metadata?.name }\n\t\t\t\t\t\t\tonChange={ ( newName ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t...( attributes?.metadata &&\n\t\t\t\t\t\t\t\t\t\t\tattributes?.metadata ),\n\t\t\t\t\t\t\t\t\t\tname: newName,\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/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-rename-ui/with-block-rename-control',\n\twithBlockRenameControl\n);\n"],"mappings":";;;;;;AAeA,IAAAA,QAAA,GAAAC,OAAA;AAZA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AASA,IAAAM,KAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AArBA;AACA;AACA;;AAgBA;AACA;AACA;;AAOA,MAAMQ,WAAW,GAAKC,UAAU,IAAMA,UAAU,EAAEC,IAAI,CAAC,CAAC,EAAEC,MAAM,KAAK,CAAC;AAEtE,SAASC,WAAWA,CAAE;EAAEC,SAAS;EAAEC,iBAAiB;EAAEC,OAAO;EAAEC;AAAO,CAAC,EAAG;EACzE,MAAM,CAAEC,eAAe,EAAEC,kBAAkB,CAAE,GAAG,IAAAC,iBAAQ,EAAEN,SAAU,CAAC;EAErE,MAAMO,cAAc,GAAGH,eAAe,KAAKJ,SAAS;EACpD,MAAMQ,cAAc,GAAGJ,eAAe,KAAKH,iBAAiB;EAC5D,MAAMQ,WAAW,GAAGd,WAAW,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EgB,IAAI;IAAEC,UAAU;IAAEC;EAAc,CAAC,GAAGrB,KAAK;EAE3D,MAAMsB,eAAe,GAAG,IAAAC,uBAAe,EACtCJ,IAAI,EACJ,wBAAwB,EACxB,KACD,CAAC;EAED,MAAMK,mBAAmB,GAAG,CAAC,EAC5B,IAAI,KAAKF,eAAe,IAAIA,eAAe,EAAEH,IAAI,CACjD;EAED,OACC,IAAAlF,QAAA,CAAAmC,aAAA,EAAAnC,QAAA,CAAAsE,QAAA,QACGiB,mBAAmB,IACpB,IAAAvF,QAAA,CAAAmC,aAAA,EAAAnC,QAAA,CAAAsE,QAAA,QACC,IAAAtE,QAAA,CAAAmC,aAAA,EAAC2B,kBAAkB;IAClBI,QAAQ,EAAGA,QAAU;IACrBC,UAAU,EAAGgB,UAAU,EAAEK,QAAQ,EAAEN,IAAM;IACzC5B,QAAQ,EAAKuB,OAAO,IAAM;MACzBO,aAAa,CAAE;QACdI,QAAQ,EAAE;UACT,IAAKL,UAAU,EAAEK,QAAQ,IACxBL,UAAU,EAAEK,QAAQ,CAAE;UACvBN,IAAI,EAAEL;QACP;MACD,CAAE,CAAC;IACJ;EAAG,CACH,CACA,CACF,EAED,IAAA7E,QAAA,CAAAmC,aAAA,EAAC8C,SAAS;IAACQ,GAAG,EAAC,MAAM;IAAA,GAAM1B;EAAK,CAAI,CACnC,CAAC;AAEL,CAAC,EACD,qBACD,CAAC;AAAC2B,OAAA,CAAAX,sBAAA,GAAAA,sBAAA;AAEF,IAAAY,gBAAS,EACR,kBAAkB,EAClB,gDAAgD,EAChDZ,sBACD,CAAC"}
|
|
1
|
+
{"version":3,"names":["_element","require","_compose","_hooks","_i18n","_blocks","_components","_a11y","_components2","emptyString","testString","trim","length","RenameModal","blockName","originalBlockName","onClose","onSave","editedBlockName","setEditedBlockName","useState","nameHasChanged","nameIsOriginal","nameIsEmpty","isNameValid","autoSelectInputText","event","target","select","dialogDescription","useInstanceId","handleSubmit","speak","sprintf","__","createElement","Modal","title","onRequestClose","overlayClassName","aria","describedby","focusOnMount","id","onSubmit","e","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","value","label","hideLabelFromVision","placeholder","onChange","onFocus","__experimentalHStack","justify","Button","variant","onClick","type","BlockRenameControl","props","renamingBlock","setRenamingBlock","clientId","customName","blockInformation","useBlockDisplayInformation","Fragment","InspectorControls","group","BlockSettingsMenuControls","selectedClientIds","canRename","MenuItem","newName","undefined","withBlockRenameControl","createHigherOrderComponent","BlockEdit","name","attributes","setAttributes","metaDataSupport","getBlockSupport","supportsBlockNaming","metadata","key","exports","addFilter"],"sources":["@wordpress/block-editor/src/hooks/block-rename-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\tMenuItem,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tButton,\n\tTextControl,\n\tModal,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport {\n\tBlockSettingsMenuControls,\n\tuseBlockDisplayInformation,\n\tInspectorControls,\n} from '../components';\n\nconst emptyString = ( testString ) => testString?.trim()?.length === 0;\n\nfunction RenameModal( { blockName, originalBlockName, onClose, onSave } ) {\n\tconst [ editedBlockName, setEditedBlockName ] = useState( blockName );\n\n\tconst nameHasChanged = editedBlockName !== blockName;\n\tconst nameIsOriginal = editedBlockName === originalBlockName;\n\tconst nameIsEmpty = emptyString( editedBlockName );\n\n\tconst isNameValid = nameHasChanged || nameIsOriginal;\n\n\tconst autoSelectInputText = ( event ) => event.target.select();\n\n\tconst dialogDescription = useInstanceId(\n\t\tRenameModal,\n\t\t`block-editor-rename-modal__description`\n\t);\n\n\tconst handleSubmit = () => {\n\t\t// Must be assertive to immediately announce change.\n\t\tspeak(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %1$s: type of update (either reset of changed). %2$s: new name/label for the block */\n\t\t\t\t__( 'Block name %1$s to: \"%2$s\".' ),\n\t\t\t\tnameIsOriginal || nameIsEmpty ? __( 'reset' ) : __( 'changed' ),\n\t\t\t\teditedBlockName\n\t\t\t),\n\t\t\t'assertive'\n\t\t);\n\n\t\tonSave( editedBlockName );\n\n\t\t// Immediate close avoids ability to hit save multiple times.\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t\toverlayClassName=\"block-editor-block-rename-modal\"\n\t\t\taria={ {\n\t\t\t\tdescribedby: dialogDescription,\n\t\t\t} }\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t>\n\t\t\t<p id={ dialogDescription }>\n\t\t\t\t{ __( 'Enter a custom name for this block.' ) }\n\t\t\t</p>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\n\t\t\t\t\tif ( ! isNameValid ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\thandleSubmit();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tvalue={ editedBlockName }\n\t\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\t\thideLabelFromVision={ true }\n\t\t\t\t\t\tplaceholder={ originalBlockName }\n\t\t\t\t\t\tonChange={ setEditedBlockName }\n\t\t\t\t\t\tonFocus={ autoSelectInputText }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onClose }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\taria-disabled={ ! isNameValid }\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n\nfunction BlockRenameControl( props ) {\n\tconst [ renamingBlock, setRenamingBlock ] = useState( false );\n\n\tconst { clientId, customName, onChange } = props;\n\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\tvalue={ customName || '' }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t{ ( { selectedClientIds } ) => {\n\t\t\t\t\t// Only enabled for single selections.\n\t\t\t\t\tconst canRename =\n\t\t\t\t\t\tselectedClientIds.length === 1 &&\n\t\t\t\t\t\tclientId === selectedClientIds[ 0 ];\n\n\t\t\t\t\t// This check ensures the `BlockSettingsMenuControls` fill\n\t\t\t\t\t// doesn't render multiple times and also that it renders for\n\t\t\t\t\t// the block from which the menu was triggered.\n\t\t\t\t\tif ( ! canRename ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetRenamingBlock( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-expanded={ renamingBlock }\n\t\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rename' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</BlockSettingsMenuControls>\n\n\t\t\t{ renamingBlock && (\n\t\t\t\t<RenameModal\n\t\t\t\t\tblockName={ customName || '' }\n\t\t\t\t\toriginalBlockName={ blockInformation?.title }\n\t\t\t\t\tonClose={ () => setRenamingBlock( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\t// If the new value is the block's original name (e.g. `Group`)\n\t\t\t\t\t\t// or it is an empty string then assume the intent is to reset\n\t\t\t\t\t\t// the value. Therefore reset the metadata.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnewName === blockInformation?.title ||\n\t\t\t\t\t\t\temptyString( newName )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewName = undefined;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const withBlockRenameControl = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { clientId, name, attributes, setAttributes } = props;\n\n\t\tconst metaDataSupport = getBlockSupport(\n\t\t\tname,\n\t\t\t'__experimentalMetadata',\n\t\t\tfalse\n\t\t);\n\n\t\tconst supportsBlockNaming = !! (\n\t\t\ttrue === metaDataSupport || metaDataSupport?.name\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ supportsBlockNaming && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockRenameControl\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tcustomName={ attributes?.metadata?.name }\n\t\t\t\t\t\t\tonChange={ ( newName ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t...( attributes?.metadata &&\n\t\t\t\t\t\t\t\t\t\t\tattributes?.metadata ),\n\t\t\t\t\t\t\t\t\t\tname: newName,\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/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-rename-ui/with-block-rename-control',\n\twithBlockRenameControl\n);\n"],"mappings":";;;;;;AAeA,IAAAA,QAAA,GAAAC,OAAA;AAZA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AASA,IAAAM,KAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AArBA;AACA;AACA;;AAgBA;AACA;AACA;;AAOA,MAAMQ,WAAW,GAAKC,UAAU,IAAMA,UAAU,EAAEC,IAAI,CAAC,CAAC,EAAEC,MAAM,KAAK,CAAC;AAEtE,SAASC,WAAWA,CAAE;EAAEC,SAAS;EAAEC,iBAAiB;EAAEC,OAAO;EAAEC;AAAO,CAAC,EAAG;EACzE,MAAM,CAAEC,eAAe,EAAEC,kBAAkB,CAAE,GAAG,IAAAC,iBAAQ,EAAEN,SAAU,CAAC;EAErE,MAAMO,cAAc,GAAGH,eAAe,KAAKJ,SAAS;EACpD,MAAMQ,cAAc,GAAGJ,eAAe,KAAKH,iBAAiB;EAC5D,MAAMQ,WAAW,GAAGd,WAAW,CAAES,eAAgB,CAAC;EAElD,MAAMM,WAAW,GAAGH,cAAc,IAAIC,cAAc;EAEpD,MAAMG,mBAAmB,GAAKC,KAAK,IAAMA,KAAK,CAACC,MAAM,CAACC,MAAM,CAAC,CAAC;EAE9D,MAAMC,iBAAiB,GAAG,IAAAC,sBAAa,EACtCjB,WAAW,EACV,wCACF,CAAC;EAED,MAAMkB,YAAY,GAAGA,CAAA,KAAM;I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EAED,OACC,IAAAnF,QAAA,CAAAmC,aAAA,EAAAnC,QAAA,CAAAuE,QAAA,QACGiB,mBAAmB,IACpB,IAAAxF,QAAA,CAAAmC,aAAA,EAAAnC,QAAA,CAAAuE,QAAA,QACC,IAAAvE,QAAA,CAAAmC,aAAA,EAAC4B,kBAAkB;IAClBI,QAAQ,EAAGA,QAAU;IACrBC,UAAU,EAAGgB,UAAU,EAAEK,QAAQ,EAAEN,IAAM;IACzC5B,QAAQ,EAAKuB,OAAO,IAAM;MACzBO,aAAa,CAAE;QACdI,QAAQ,EAAE;UACT,IAAKL,UAAU,EAAEK,QAAQ,IACxBL,UAAU,EAAEK,QAAQ,CAAE;UACvBN,IAAI,EAAEL;QACP;MACD,CAAE,CAAC;IACJ;EAAG,CACH,CACA,CACF,EAED,IAAA9E,QAAA,CAAAmC,aAAA,EAAC+C,SAAS;IAACQ,GAAG,EAAC,MAAM;IAAA,GAAM1B;EAAK,CAAI,CACnC,CAAC;AAEL,CAAC,EACD,qBACD,CAAC;AAAC2B,OAAA,CAAAX,sBAAA,GAAAA,sBAAA;AAEF,IAAAY,gBAAS,EACR,kBAAkB,EAClB,gDAAgD,EAChDZ,sBACD,CAAC"}
|
|
@@ -54,11 +54,10 @@ function getLastInsertedBlocksClientIds(state) {
|
|
|
54
54
|
*/
|
|
55
55
|
const isBlockSubtreeDisabled = (0, _rememo.default)((state, clientId) => {
|
|
56
56
|
const isChildSubtreeDisabled = childClientId => {
|
|
57
|
-
|
|
58
|
-
return (mode === undefined || mode === 'disabled') && (0, _selectors.getBlockOrder)(state, childClientId).every(isChildSubtreeDisabled);
|
|
57
|
+
return (0, _selectors.getBlockEditingMode)(state, childClientId) === 'disabled' && (0, _selectors.getBlockOrder)(state, childClientId).every(isChildSubtreeDisabled);
|
|
59
58
|
};
|
|
60
59
|
return (0, _selectors.getBlockEditingMode)(state, clientId) === 'disabled' && (0, _selectors.getBlockOrder)(state, clientId).every(isChildSubtreeDisabled);
|
|
61
|
-
}, state => [state.
|
|
60
|
+
}, state => [state.blocks.parents, state.blocks.order, state.blockEditingModes, state.blockListSettings]);
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
63
|
* Returns a tree of block objects with only clientID and innerBlocks set.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_rememo","_interopRequireDefault","require","_selectors","isBlockInterfaceHidden","state","getLastInsertedBlocksClientIds","lastBlockInserted","clientIds","isBlockSubtreeDisabled","createSelector","clientId","isChildSubtreeDisabled","childClientId","
|
|
1
|
+
{"version":3,"names":["_rememo","_interopRequireDefault","require","_selectors","isBlockInterfaceHidden","state","getLastInsertedBlocksClientIds","lastBlockInserted","clientIds","isBlockSubtreeDisabled","createSelector","clientId","isChildSubtreeDisabled","childClientId","getBlockEditingMode","getBlockOrder","every","blocks","parents","order","blockEditingModes","blockListSettings","exports","getEnabledClientIdsTree","rootClientId","flatMap","innerBlocks","settings","templateLock","getEnabledBlockParents","ascending","getBlockParents","filter","parent","getRemovalPromptData","removalPromptData","getBlockRemovalRules","blockRemovalRules","getOpenedBlockSettingsMenu","openedBlockSettingsMenu","getStyleOverrides","styleOverrides"],"sources":["@wordpress/block-editor/src/store/private-selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetBlockOrder,\n\tgetBlockParents,\n\tgetBlockEditingMode,\n} from './selectors';\n\n/**\n * Returns true if the block interface is hidden, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the block toolbar is hidden.\n */\nexport function isBlockInterfaceHidden( state ) {\n\treturn state.isBlockInterfaceHidden;\n}\n\n/**\n * Gets the client ids of the last inserted blocks.\n *\n * @param {Object} state Global application state.\n * @return {Array|undefined} Client Ids of the last inserted block(s).\n */\nexport function getLastInsertedBlocksClientIds( state ) {\n\treturn state?.lastBlockInserted?.clientIds;\n}\n\n/**\n * Returns true if the block with the given client ID and all of its descendants\n * have an editing mode of 'disabled', or false otherwise.\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n *\n * @return {boolean} Whether the block and its descendants are disabled.\n */\nexport const isBlockSubtreeDisabled = createSelector(\n\t( state, clientId ) => {\n\t\tconst isChildSubtreeDisabled = ( childClientId ) => {\n\t\t\treturn (\n\t\t\t\tgetBlockEditingMode( state, childClientId ) === 'disabled' &&\n\t\t\t\tgetBlockOrder( state, childClientId ).every(\n\t\t\t\t\tisChildSubtreeDisabled\n\t\t\t\t)\n\t\t\t);\n\t\t};\n\t\treturn (\n\t\t\tgetBlockEditingMode( state, clientId ) === 'disabled' &&\n\t\t\tgetBlockOrder( state, clientId ).every( isChildSubtreeDisabled )\n\t\t);\n\t},\n\t( state ) => [\n\t\tstate.blocks.parents,\n\t\tstate.blocks.order,\n\t\tstate.blockEditingModes,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Returns a tree of block objects with only clientID and innerBlocks set.\n * Blocks with a 'disabled' editing mode are not included.\n *\n * @param {Object} state Global application state.\n * @param {?string} rootClientId Optional root client ID of block list.\n *\n * @return {Object[]} Tree of block objects with only clientID and innerBlocks set.\n */\nexport const getEnabledClientIdsTree = createSelector(\n\t( state, rootClientId = '' ) => {\n\t\treturn getBlockOrder( state, rootClientId ).flatMap( ( clientId ) => {\n\t\t\tif ( getBlockEditingMode( state, clientId ) !== 'disabled' ) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tinnerBlocks: getEnabledClientIdsTree( state, clientId ),\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn getEnabledClientIdsTree( state, clientId );\n\t\t} );\n\t},\n\t( state ) => [\n\t\tstate.blocks.order,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Returns a list of a given block's ancestors, from top to bottom. Blocks with\n * a 'disabled' editing mode are excluded.\n *\n * @see getBlockParents\n *\n * @param {Object} state Global application state.\n * @param {string} clientId The block client ID.\n * @param {boolean} ascending Order results from bottom to top (true) or top\n * to bottom (false).\n */\nexport const getEnabledBlockParents = createSelector(\n\t( state, clientId, ascending = false ) => {\n\t\treturn getBlockParents( state, clientId, ascending ).filter(\n\t\t\t( parent ) => getBlockEditingMode( state, parent ) !== 'disabled'\n\t\t);\n\t},\n\t( state ) => [\n\t\tstate.blocks.parents,\n\t\tstate.blockEditingModes,\n\t\tstate.settings.templateLock,\n\t\tstate.blockListSettings,\n\t]\n);\n\n/**\n * Selector that returns the data needed to display a prompt when certain\n * blocks are removed, or `false` if no such prompt is requested.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object|false} Data for removal prompt display, if any.\n */\nexport function getRemovalPromptData( state ) {\n\treturn state.removalPromptData;\n}\n\n/**\n * Returns true if removal prompt exists, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether removal prompt exists.\n */\nexport function getBlockRemovalRules( state ) {\n\treturn state.blockRemovalRules;\n}\n\n/**\n * Returns the client ID of the block settings menu that is currently open.\n *\n * @param {Object} state Global application state.\n * @return {string|null} The client ID of the block menu that is currently open.\n */\nexport function getOpenedBlockSettingsMenu( state ) {\n\treturn state.openedBlockSettingsMenu;\n}\n\n/**\n * Returns all style overrides, intended to be merged with global editor styles.\n *\n * @param {Object} state Global application state.\n *\n * @return {Map} A map of style IDs to style overrides.\n */\nexport function getStyleOverrides( state ) {\n\treturn state.styleOverrides;\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,sBAAsBA,CAAEC,KAAK,EAAG;EAC/C,OAAOA,KAAK,CAACD,sBAAsB;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,8BAA8BA,CAAED,KAAK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AAG;EAC1C,OAAOA,KAAK,CAACoC,cAAc;AAC5B"}
|
|
@@ -7,7 +7,7 @@ import classnames from 'classnames';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { useState } from '@wordpress/element';
|
|
10
|
+
import { useState, forwardRef } from '@wordpress/element';
|
|
11
11
|
import { VisuallyHidden, __unstableComposite as Composite, __unstableUseCompositeState as useCompositeState, __unstableCompositeItem as CompositeItem, Tooltip, __experimentalHStack as HStack } from '@wordpress/components';
|
|
12
12
|
import { useInstanceId } from '@wordpress/compose';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
@@ -18,6 +18,7 @@ import { Icon, symbol } from '@wordpress/icons';
|
|
|
18
18
|
*/
|
|
19
19
|
import BlockPreview from '../block-preview';
|
|
20
20
|
import InserterDraggableBlocks from '../inserter-draggable-blocks';
|
|
21
|
+
import BlockPatternsPaging from '../block-patterns-paging';
|
|
21
22
|
const WithToolTip = ({
|
|
22
23
|
showTooltip,
|
|
23
24
|
title,
|
|
@@ -121,8 +122,9 @@ function BlockPatternList({
|
|
|
121
122
|
onClickPattern,
|
|
122
123
|
orientation,
|
|
123
124
|
label = __('Block Patterns'),
|
|
124
|
-
showTitlesAsTooltip
|
|
125
|
-
|
|
125
|
+
showTitlesAsTooltip,
|
|
126
|
+
pagingProps
|
|
127
|
+
}, ref) {
|
|
126
128
|
const composite = useCompositeState({
|
|
127
129
|
orientation
|
|
128
130
|
});
|
|
@@ -130,7 +132,8 @@ function BlockPatternList({
|
|
|
130
132
|
...composite,
|
|
131
133
|
role: "listbox",
|
|
132
134
|
className: "block-editor-block-patterns-list",
|
|
133
|
-
"aria-label": label
|
|
135
|
+
"aria-label": label,
|
|
136
|
+
ref: ref
|
|
134
137
|
}, blockPatterns.map(pattern => {
|
|
135
138
|
const isShown = shownPatterns.includes(pattern);
|
|
136
139
|
return isShown ? createElement(BlockPattern, {
|
|
@@ -144,7 +147,9 @@ function BlockPatternList({
|
|
|
144
147
|
}) : createElement(BlockPatternPlaceholder, {
|
|
145
148
|
key: pattern.name
|
|
146
149
|
});
|
|
150
|
+
}), pagingProps && pagingProps.numPages > 1 && createElement(BlockPatternsPaging, {
|
|
151
|
+
...pagingProps
|
|
147
152
|
}));
|
|
148
153
|
}
|
|
149
|
-
export default BlockPatternList;
|
|
154
|
+
export default forwardRef(BlockPatternList);
|
|
150
155
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","useState","VisuallyHidden","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","Tooltip","__experimentalHStack","HStack","useInstanceId","__","Icon","symbol","BlockPreview","InserterDraggableBlocks","WithToolTip","showTooltip","title","children","createElement","text","Fragment","BlockPattern","isDraggable","pattern","onClick","onHover","composite","isDragging","setIsDragging","blocks","viewportWidth","instanceId","descriptionId","isEnabled","isPattern","draggable","onDragStart","onDragEnd","className","event","id","role","as","syncStatus","onMouseEnter","onMouseLeave","description","undefined","icon","BlockPatternPlaceholder","BlockPatternList","blockPatterns","shownPatterns","onClickPattern","orientation","label","showTitlesAsTooltip","map","isShown","includes","key","name"],"sources":["@wordpress/block-editor/src/components/block-patterns-list/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport {\n\tVisuallyHidden,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n\tTooltip,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, symbol } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockPreview from '../block-preview';\nimport InserterDraggableBlocks from '../inserter-draggable-blocks';\n\nconst WithToolTip = ( { showTooltip, title, children } ) => {\n\tif ( showTooltip ) {\n\t\treturn <Tooltip text={ title }>{ children }</Tooltip>;\n\t}\n\treturn <>{ children }</>;\n};\n\nfunction BlockPattern( {\n\tisDraggable,\n\tpattern,\n\tonClick,\n\tonHover,\n\tcomposite,\n\tshowTooltip,\n} ) {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst { blocks, viewportWidth } = pattern;\n\tconst instanceId = useInstanceId( BlockPattern );\n\tconst descriptionId = `block-editor-block-patterns-list__item-description-${ instanceId }`;\n\n\treturn (\n\t\t<InserterDraggableBlocks\n\t\t\tisEnabled={ isDraggable }\n\t\t\tblocks={ blocks }\n\t\t\tisPattern={ !! pattern }\n\t\t>\n\t\t\t{ ( { draggable, onDragStart, onDragEnd } ) => (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"block-editor-block-patterns-list__list-item\"\n\t\t\t\t\tdraggable={ draggable }\n\t\t\t\t\tonDragStart={ ( event ) => {\n\t\t\t\t\t\tsetIsDragging( true );\n\t\t\t\t\t\tif ( onDragStart ) {\n\t\t\t\t\t\t\tonHover?.( null );\n\t\t\t\t\t\t\tonDragStart( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonDragEnd={ ( event ) => {\n\t\t\t\t\t\tsetIsDragging( false );\n\t\t\t\t\t\tif ( onDragEnd ) {\n\t\t\t\t\t\t\tonDragEnd( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<WithToolTip\n\t\t\t\t\t\tshowTooltip={ showTooltip && ! pattern.id }\n\t\t\t\t\t\ttitle={ pattern.title }\n\t\t\t\t\t>\n\t\t\t\t\t\t<CompositeItem\n\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\tas=\"div\"\n\t\t\t\t\t\t\t{ ...composite }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-block-patterns-list__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'block-editor-block-patterns-list__list-item-synced':\n\t\t\t\t\t\t\t\t\t\tpattern.id && ! pattern.syncStatus,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClick( pattern, blocks );\n\t\t\t\t\t\t\t\tonHover?.( null );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonMouseEnter={ () => {\n\t\t\t\t\t\t\t\tif ( isDragging ) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonHover?.( pattern );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonMouseLeave={ () => onHover?.( null ) }\n\t\t\t\t\t\t\taria-label={ pattern.title }\n\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\tpattern.description ? descriptionId : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<BlockPreview\n\t\t\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\t\t\tviewportWidth={ viewportWidth }\n\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t<HStack className=\"block-editor-patterns__pattern-details\">\n\t\t\t\t\t\t\t\t{ pattern.id && ! pattern.syncStatus && (\n\t\t\t\t\t\t\t\t\t<div className=\"block-editor-patterns__pattern-icon-wrapper\">\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-patterns__pattern-icon\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ symbol }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ ( ! showTooltip || pattern.id ) && (\n\t\t\t\t\t\t\t\t\t<div className=\"block-editor-block-patterns-list__item-title\">\n\t\t\t\t\t\t\t\t\t\t{ pattern.title }\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</HStack>\n\n\t\t\t\t\t\t\t{ !! pattern.description && (\n\t\t\t\t\t\t\t\t<VisuallyHidden id={ descriptionId }>\n\t\t\t\t\t\t\t\t\t{ pattern.description }\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</CompositeItem>\n\t\t\t\t\t</WithToolTip>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</InserterDraggableBlocks>\n\t);\n}\n\nfunction BlockPatternPlaceholder() {\n\treturn (\n\t\t<div className=\"block-editor-block-patterns-list__item is-placeholder\" />\n\t);\n}\n\nfunction BlockPatternList( {\n\tisDraggable,\n\tblockPatterns,\n\tshownPatterns,\n\tonHover,\n\tonClickPattern,\n\torientation,\n\tlabel = __( 'Block Patterns' ),\n\tshowTitlesAsTooltip,\n} ) {\n\tconst composite = useCompositeState( { orientation } );\n\treturn (\n\t\t<Composite\n\t\t\t{ ...composite }\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-editor-block-patterns-list\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ blockPatterns.map( ( pattern ) => {\n\t\t\t\tconst isShown = shownPatterns.includes( pattern );\n\t\t\t\treturn isShown ? (\n\t\t\t\t\t<BlockPattern\n\t\t\t\t\t\tkey={ pattern.name }\n\t\t\t\t\t\tpattern={ pattern }\n\t\t\t\t\t\tonClick={ onClickPattern }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\tisDraggable={ isDraggable }\n\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\tshowTooltip={ showTitlesAsTooltip }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockPatternPlaceholder key={ pattern.name } />\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Composite>\n\t);\n}\n\nexport default BlockPatternList;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YA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gB;MAC1B5B,OAAO,EAAGA,OAAS;MACnBH,WAAW,EAAGA,WAAa;MAC3BI,SAAS,EAAGA,SAAW;MACvBX,WAAW,EAAGyC;IAAqB,CACnC,CAAC,GAEFtC,aAAA,CAAC+B,uBAAuB;MAACW,GAAG,EAAGrC,OAAO,CAACsC;IAAM,CAAE,CAC/C;EACF,CAAE,CACQ,CAAC;AAEd;AAEA,eAAeX,gBAAgB"}
|
|
1
|
+
{"version":3,"names":["classnames","useState","forwardRef","VisuallyHidden","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","Tooltip","__experimentalHStack","HStack","useInstanceId","__","Icon","symbol","BlockPreview","InserterDraggableBlocks","BlockPatternsPaging","WithToolTip","showTooltip","title","children","createElement","text","Fragment","BlockPattern","isDraggable","pattern","onClick","onHover","composite","isDragging","setIsDragging","blocks","viewportWidth","instanceId","descriptionId","isEnabled","isPattern","draggable","onDragStart","onDragEnd","className","event","id","role","as","syncStatus","onMouseEnter","onMouseLeave","description","undefined","icon","BlockPatternPlaceholder","BlockPatternList","blockPatterns","shownPatterns","onClickPattern","orientation","label","showTitlesAsTooltip","pagingProps","ref","map","isShown","includes","key","name","numPages"],"sources":["@wordpress/block-editor/src/components/block-patterns-list/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, forwardRef } from '@wordpress/element';\nimport {\n\tVisuallyHidden,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n\tTooltip,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, symbol } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockPreview from '../block-preview';\nimport InserterDraggableBlocks from '../inserter-draggable-blocks';\nimport BlockPatternsPaging from '../block-patterns-paging';\n\nconst WithToolTip = ( { showTooltip, title, children } ) => {\n\tif ( showTooltip ) {\n\t\treturn <Tooltip text={ title }>{ children }</Tooltip>;\n\t}\n\treturn <>{ children }</>;\n};\n\nfunction BlockPattern( {\n\tisDraggable,\n\tpattern,\n\tonClick,\n\tonHover,\n\tcomposite,\n\tshowTooltip,\n} ) {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst { blocks, viewportWidth } = pattern;\n\tconst instanceId = useInstanceId( BlockPattern );\n\tconst descriptionId = `block-editor-block-patterns-list__item-description-${ instanceId }`;\n\n\treturn (\n\t\t<InserterDraggableBlocks\n\t\t\tisEnabled={ isDraggable }\n\t\t\tblocks={ blocks }\n\t\t\tisPattern={ !! pattern }\n\t\t>\n\t\t\t{ ( { draggable, onDragStart, onDragEnd } ) => (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"block-editor-block-patterns-list__list-item\"\n\t\t\t\t\tdraggable={ draggable }\n\t\t\t\t\tonDragStart={ ( event ) => {\n\t\t\t\t\t\tsetIsDragging( true );\n\t\t\t\t\t\tif ( onDragStart ) {\n\t\t\t\t\t\t\tonHover?.( null );\n\t\t\t\t\t\t\tonDragStart( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonDragEnd={ ( event ) => {\n\t\t\t\t\t\tsetIsDragging( false );\n\t\t\t\t\t\tif ( onDragEnd ) {\n\t\t\t\t\t\t\tonDragEnd( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<WithToolTip\n\t\t\t\t\t\tshowTooltip={ showTooltip && ! pattern.id }\n\t\t\t\t\t\ttitle={ pattern.title }\n\t\t\t\t\t>\n\t\t\t\t\t\t<CompositeItem\n\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\tas=\"div\"\n\t\t\t\t\t\t\t{ ...composite }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-block-patterns-list__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'block-editor-block-patterns-list__list-item-synced':\n\t\t\t\t\t\t\t\t\t\tpattern.id && ! pattern.syncStatus,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClick( pattern, blocks );\n\t\t\t\t\t\t\t\tonHover?.( null );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonMouseEnter={ () => {\n\t\t\t\t\t\t\t\tif ( isDragging ) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonHover?.( pattern );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonMouseLeave={ () => onHover?.( null ) }\n\t\t\t\t\t\t\taria-label={ pattern.title }\n\t\t\t\t\t\t\taria-describedby={\n\t\t\t\t\t\t\t\tpattern.description ? descriptionId : undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<BlockPreview\n\t\t\t\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\t\t\t\tviewportWidth={ viewportWidth }\n\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t<HStack className=\"block-editor-patterns__pattern-details\">\n\t\t\t\t\t\t\t\t{ pattern.id && ! pattern.syncStatus && (\n\t\t\t\t\t\t\t\t\t<div className=\"block-editor-patterns__pattern-icon-wrapper\">\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"block-editor-patterns__pattern-icon\"\n\t\t\t\t\t\t\t\t\t\t\ticon={ symbol }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ ( ! showTooltip || pattern.id ) && (\n\t\t\t\t\t\t\t\t\t<div className=\"block-editor-block-patterns-list__item-title\">\n\t\t\t\t\t\t\t\t\t\t{ pattern.title }\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</HStack>\n\n\t\t\t\t\t\t\t{ !! pattern.description && (\n\t\t\t\t\t\t\t\t<VisuallyHidden id={ descriptionId }>\n\t\t\t\t\t\t\t\t\t{ pattern.description }\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</CompositeItem>\n\t\t\t\t\t</WithToolTip>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</InserterDraggableBlocks>\n\t);\n}\n\nfunction BlockPatternPlaceholder() {\n\treturn (\n\t\t<div className=\"block-editor-block-patterns-list__item is-placeholder\" />\n\t);\n}\n\nfunction BlockPatternList(\n\t{\n\t\tisDraggable,\n\t\tblockPatterns,\n\t\tshownPatterns,\n\t\tonHover,\n\t\tonClickPattern,\n\t\torientation,\n\t\tlabel = __( 'Block Patterns' ),\n\t\tshowTitlesAsTooltip,\n\t\tpagingProps,\n\t},\n\tref\n) {\n\tconst composite = useCompositeState( { orientation } );\n\treturn (\n\t\t<Composite\n\t\t\t{ ...composite }\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-editor-block-patterns-list\"\n\t\t\taria-label={ label }\n\t\t\tref={ ref }\n\t\t>\n\t\t\t{ blockPatterns.map( ( pattern ) => {\n\t\t\t\tconst isShown = shownPatterns.includes( pattern );\n\t\t\t\treturn isShown ? (\n\t\t\t\t\t<BlockPattern\n\t\t\t\t\t\tkey={ pattern.name }\n\t\t\t\t\t\tpattern={ pattern }\n\t\t\t\t\t\tonClick={ onClickPattern }\n\t\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\t\tisDraggable={ isDraggable }\n\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\tshowTooltip={ showTitlesAsTooltip }\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockPatternPlaceholder key={ pattern.name } />\n\t\t\t\t);\n\t\t\t} ) }\n\t\t\t{ pagingProps && pagingProps.numPages > 1 && (\n\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t) }\n\t\t</Composite>\n\t);\n}\n\nexport default forwardRef( BlockPatternList );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,QAAQ,EAAEC,UAAU,QAAQ,oBAAoB;AACzD,SACCC,cAAc,EACdC,mBAAmB,IAAIC,SAAS,EAChCC,2BAA2B,IAAIC,iBAAiB,EAChDC,uBAAuB,IAAIC,aAAa,EACxCC,OAAO,EACPC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,IAAI,EAAEC,MAAM,QAAQ,kBAAkB;;AAE/C;AACA;AACA;AACA,OAAOC,YAAY,MAAM,kBAAkB;AAC3C,OAAOC,uBAAuB,MAAM,8BAA8B;AAClE,OAAOC,mBAAmB,MAAM,0BAA0B;AAE1D,MAAMC,WAAW,GAAGA,CAAE;EAAEC,WAAW;EAAEC,KAAK;EAAEC;AAAS,CAAC,KAAM;EAC3D,IAAKF,WAAW,EAAG;IAClB,OAAOG,aAAA,CAACd,OAAO;MAACe,IAAI,EAAGH;IAAO,GAAGC,QAAmB,CAAC;EACtD;EACA,OAAOC,aAAA,CAAAE,QAAA,QAAIH,QAAY,CAAC;AACzB,CAAC;AAED,SAASI,YAAYA,CAAE;EACtBC,WAAW;EACXC,OAAO;EACPC,OAAO;EACPC,OAAO;EACPC,SAAS;EACTX;AACD,CAAC,EAAG;EACH,MAAM,CAAEY,UAAU,EAAEC,aAAa,CAAE,GAAGjC,QAAQ,CAAE,KAAM,CAAC;EACvD,MAAM;IAAEkC,MAAM;IAAEC;EAAc,CAAC,GAAGP,OAAO;EACzC,MAAMQ,UAAU,GAAGxB,aAAa,CAAEc,YAAa,CAAC;EAChD,MAAMW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AAaiB,KAAO;IACpBG,GAAG,EAAGA;EAAK,GAETP,aAAa,CAACQ,GAAG,CAAIpC,OAAO,IAAM;IACnC,MAAMqC,OAAO,GAAGR,aAAa,CAACS,QAAQ,CAAEtC,OAAQ,CAAC;IACjD,OAAOqC,OAAO,GACb1C,aAAA,CAACG,YAAY;MACZyC,GAAG,EAAGvC,OAAO,CAACwC,IAAM;MACpBxC,OAAO,EAAGA,OAAS;MACnBC,OAAO,EAAG6B,cAAgB;MAC1B5B,OAAO,EAAGA,OAAS;MACnBH,WAAW,EAAGA,WAAa;MAC3BI,SAAS,EAAGA,SAAW;MACvBX,WAAW,EAAGyC;IAAqB,CACnC,CAAC,GAEFtC,aAAA,CAAC+B,uBAAuB;MAACa,GAAG,EAAGvC,OAAO,CAACwC;IAAM,CAAE,CAC/C;EACF,CAAE,CAAC,EACDN,WAAW,IAAIA,WAAW,CAACO,QAAQ,GAAG,CAAC,IACxC9C,aAAA,CAACL,mBAAmB;IAAA,GAAM4C;EAAW,CAAI,CAEhC,CAAC;AAEd;AAEA,eAAe7D,UAAU,CAAEsD,gBAAiB,CAAC"}
|
|
@@ -10,7 +10,9 @@ export default function Pagination({
|
|
|
10
10
|
changePage,
|
|
11
11
|
totalItems
|
|
12
12
|
}) {
|
|
13
|
-
return createElement(VStack,
|
|
13
|
+
return createElement(VStack, {
|
|
14
|
+
className: "block-editor-patterns__grid-pagination-wrapper"
|
|
15
|
+
}, createElement(Text, {
|
|
14
16
|
variant: "muted"
|
|
15
17
|
},
|
|
16
18
|
// translators: %s: Total number of patterns.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__experimentalVStack","VStack","__experimentalHStack","HStack","__experimentalText","Text","Button","__","_x","_n","sprintf","Pagination","currentPage","numPages","changePage","totalItems","createElement","variant","expanded","spacing","justify","
|
|
1
|
+
{"version":3,"names":["__experimentalVStack","VStack","__experimentalHStack","HStack","__experimentalText","Text","Button","__","_x","_n","sprintf","Pagination","currentPage","numPages","changePage","totalItems","createElement","className","variant","expanded","spacing","justify","onClick","disabled","size"],"sources":["@wordpress/block-editor/src/components/block-patterns-paging/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\t__experimentalText as Text,\n\tButton,\n} from '@wordpress/components';\nimport { __, _x, _n, sprintf } from '@wordpress/i18n';\n\nexport default function Pagination( {\n\tcurrentPage,\n\tnumPages,\n\tchangePage,\n\ttotalItems,\n} ) {\n\treturn (\n\t\t<VStack className=\"block-editor-patterns__grid-pagination-wrapper\">\n\t\t\t<Text variant=\"muted\">\n\t\t\t\t{\n\t\t\t\t\t// translators: %s: Total number of patterns.\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Total number of patterns.\n\t\t\t\t\t\t_n( '%s item', '%s items', totalItems ),\n\t\t\t\t\t\ttotalItems\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t</Text>\n\t\t\t<HStack\n\t\t\t\texpanded={ false }\n\t\t\t\tspacing={ 3 }\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"block-editor-patterns__grid-pagination\"\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\tclassName=\"block-editor-patterns__grid-pagination-previous\"\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => changePage( 1 ) }\n\t\t\t\t\t\tdisabled={ currentPage === 1 }\n\t\t\t\t\t\taria-label={ __( 'First page' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>«</span>\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => changePage( currentPage - 1 ) }\n\t\t\t\t\t\tdisabled={ currentPage === 1 }\n\t\t\t\t\t\taria-label={ __( 'Previous page' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>‹</span>\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t\t<Text variant=\"muted\">\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t// translators: %1$s: Current page number, %2$s: Total number of pages.\n\t\t\t\t\t\t_x( '%1$s of %2$s', 'paging' ),\n\t\t\t\t\t\tcurrentPage,\n\t\t\t\t\t\tnumPages\n\t\t\t\t\t) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\tclassName=\"block-editor-patterns__grid-pagination-next\"\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => changePage( currentPage + 1 ) }\n\t\t\t\t\t\tdisabled={ currentPage === numPages }\n\t\t\t\t\t\taria-label={ __( 'Next page' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>›</span>\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => changePage( numPages ) }\n\t\t\t\t\t\tdisabled={ currentPage === numPages }\n\t\t\t\t\t\taria-label={ __( 'Last page' ) }\n\t\t\t\t\t\tsize=\"default\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span>»</span>\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</HStack>\n\t\t</VStack>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,kBAAkB,IAAIC,IAAI,EAC1BC,MAAM,QACA,uBAAuB;AAC9B,SAASC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAErD,eAAe,SAASC,UAAUA,CAAE;EACnCC,WAAW;EACXC,QAAQ;EAC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AClBI,OAAO,EAAGA,CAAA,KAAMR,UAAU,CAAEF,WAAW,GAAG,CAAE,CAAG;IAC/CW,QAAQ,EAAGX,WAAW,KAAKC,QAAU;IACrC,cAAaN,EAAE,CAAE,WAAY;EAAG,GAEhCS,aAAA,eAAM,QAAO,CACN,CAAC,EACTA,aAAA,CAACV,MAAM;IACNY,OAAO,EAAC,UAAU;IAClBI,OAAO,EAAGA,CAAA,KAAMR,UAAU,CAAED,QAAS,CAAG;IACxCU,QAAQ,EAAGX,WAAW,KAAKC,QAAU;IACrC,cAAaN,EAAE,CAAE,WAAY,CAAG;IAChCiB,IAAI,EAAC;EAAS,GAEdR,aAAA,eAAM,MAAO,CACN,CACD,CACD,CACD,CAAC;AAEX"}
|
|
@@ -18,39 +18,26 @@ import InserterListbox from '../../inserter-listbox';
|
|
|
18
18
|
import { searchItems } from '../search-items';
|
|
19
19
|
import BlockPatternsPaging from '../../block-patterns-paging';
|
|
20
20
|
import usePatternsPaging from '../hooks/use-patterns-paging';
|
|
21
|
-
import { allPatternsCategory,
|
|
22
|
-
import { BlockPatternsSyncFilter } from '../block-patterns-sync-filter';
|
|
23
|
-
import { PATTERN_TYPES, PATTERN_SOURCE_FILTERS } from '../block-patterns-source-filter';
|
|
21
|
+
import { allPatternsCategory, myPatternsCategory } from '../block-patterns-tab';
|
|
24
22
|
function PatternsListHeader({
|
|
25
23
|
filterValue,
|
|
26
|
-
filteredBlockPatternsLength
|
|
27
|
-
selectedCategory,
|
|
28
|
-
patternCategories
|
|
24
|
+
filteredBlockPatternsLength
|
|
29
25
|
}) {
|
|
30
26
|
if (!filterValue) {
|
|
31
27
|
return null;
|
|
32
28
|
}
|
|
33
|
-
let filter = filterValue;
|
|
34
|
-
if (selectedCategory !== allPatternsCategory.name) {
|
|
35
|
-
const category = patternCategories.find(patternCategory => patternCategory.name === selectedCategory);
|
|
36
|
-
if (category) {
|
|
37
|
-
filter = `${filter} - ${category?.label}`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
29
|
return createElement(Heading, {
|
|
41
30
|
level: 2,
|
|
42
31
|
lineHeight: '48px',
|
|
43
32
|
className: "block-editor-block-patterns-explorer__search-results-count"
|
|
44
|
-
}, sprintf( /* translators: %d: number of patterns.
|
|
45
|
-
_n('%
|
|
33
|
+
}, sprintf( /* translators: %d: number of patterns. */
|
|
34
|
+
_n('%d pattern found', '%d patterns found', filteredBlockPatternsLength), filteredBlockPatternsLength));
|
|
46
35
|
}
|
|
47
36
|
function PatternList({
|
|
48
37
|
searchValue,
|
|
49
|
-
patternSourceFilter,
|
|
50
38
|
selectedCategory,
|
|
51
39
|
patternCategories
|
|
52
40
|
}) {
|
|
53
|
-
const [patternSyncFilter, setPatternSyncFilter] = useState('all');
|
|
54
41
|
const container = useRef();
|
|
55
42
|
const debouncedSpeak = useDebounce(speak, 500);
|
|
56
43
|
const [destinationRootClientId, onInsertBlocks] = useInsertionPoint({
|
|
@@ -60,12 +47,12 @@ function PatternList({
|
|
|
60
47
|
const registeredPatternCategories = useMemo(() => patternCategories.map(patternCategory => patternCategory.name), [patternCategories]);
|
|
61
48
|
const filteredBlockPatterns = useMemo(() => {
|
|
62
49
|
const filteredPatterns = patterns.filter(pattern => {
|
|
63
|
-
if (isPatternFiltered(pattern, patternSourceFilter, patternSyncFilter)) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
50
|
if (selectedCategory === allPatternsCategory.name) {
|
|
67
51
|
return true;
|
|
68
52
|
}
|
|
53
|
+
if (selectedCategory === myPatternsCategory.name && pattern.id) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
69
56
|
if (selectedCategory === 'uncategorized') {
|
|
70
57
|
const hasKnownCategory = pattern.categories.some(category => registeredPatternCategories.includes(category));
|
|
71
58
|
return !pattern.categories?.length || !hasKnownCategory;
|
|
@@ -75,8 +62,8 @@ function PatternList({
|
|
|
75
62
|
if (!searchValue) {
|
|
76
63
|
return filteredPatterns;
|
|
77
64
|
}
|
|
78
|
-
return searchItems(filteredPatterns, searchValue
|
|
79
|
-
}, [searchValue,
|
|
65
|
+
return searchItems(filteredPatterns, searchValue);
|
|
66
|
+
}, [searchValue, patterns, selectedCategory, registeredPatternCategories]);
|
|
80
67
|
|
|
81
68
|
// Announce search results on change.
|
|
82
69
|
useEffect(() => {
|
|
@@ -88,20 +75,22 @@ function PatternList({
|
|
|
88
75
|
_n('%d result found.', '%d results found.', count), count);
|
|
89
76
|
debouncedSpeak(resultsFoundMessage);
|
|
90
77
|
}, [searchValue, debouncedSpeak, filteredBlockPatterns.length]);
|
|
91
|
-
const pagingProps = usePatternsPaging(filteredBlockPatterns, selectedCategory, container
|
|
78
|
+
const pagingProps = usePatternsPaging(filteredBlockPatterns, selectedCategory, container);
|
|
79
|
+
|
|
80
|
+
// Reset page when search value changes.
|
|
81
|
+
const [previousSearchValue, setPreviousSearchValue] = useState(searchValue);
|
|
82
|
+
if (searchValue !== previousSearchValue) {
|
|
83
|
+
setPreviousSearchValue(searchValue);
|
|
84
|
+
pagingProps.changePage(1);
|
|
85
|
+
}
|
|
92
86
|
const hasItems = !!filteredBlockPatterns?.length;
|
|
93
87
|
return createElement("div", {
|
|
94
88
|
className: "block-editor-block-patterns-explorer__list",
|
|
95
89
|
ref: container
|
|
96
90
|
}, createElement(PatternsListHeader, {
|
|
97
|
-
filterValue: searchValue
|
|
98
|
-
filteredBlockPatternsLength: filteredBlockPatterns.length
|
|
99
|
-
|
|
100
|
-
patternCategories: patternCategories
|
|
101
|
-
}), createElement(InserterListbox, null, patternSourceFilter === PATTERN_TYPES.user && !searchValue && createElement(BlockPatternsSyncFilter, {
|
|
102
|
-
patternSyncFilter: patternSyncFilter,
|
|
103
|
-
setPatternSyncFilter: setPatternSyncFilter
|
|
104
|
-
}), hasItems && createElement(BlockPatternsList, {
|
|
91
|
+
filterValue: searchValue,
|
|
92
|
+
filteredBlockPatternsLength: filteredBlockPatterns.length
|
|
93
|
+
}), createElement(InserterListbox, null, hasItems && createElement(BlockPatternsList, {
|
|
105
94
|
shownPatterns: pagingProps.categoryPatternsAsyncList,
|
|
106
95
|
blockPatterns: pagingProps.categoryPatterns,
|
|
107
96
|
onClickPattern: onClickPattern,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","allPatternsCategory","isPatternFiltered","BlockPatternsSyncFilter","PATTERN_TYPES","PATTERN_SOURCE_FILTERS","PatternsListHeader","filterValue","filteredBlockPatternsLength","selectedCategory","patternCategories","filter","name","category","find","patternCategory","label","createElement","level","lineHeight","className","PatternList","searchValue","patternSourceFilter","patternSyncFilter","setPatternSyncFilter","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","filteredBlockPatterns","filteredPatterns","pattern","hasKnownCategory","categories","some","includes","length","count","resultsFoundMessage","pagingProps","hasItems","ref","user","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","isDraggable","numPages"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport { allPatternsCategory, isPatternFiltered } from '../block-patterns-tab';\nimport { BlockPatternsSyncFilter } from '../block-patterns-sync-filter';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_SOURCE_FILTERS,\n} from '../block-patterns-source-filter';\n\nfunction PatternsListHeader( {\n\tfilterValue,\n\tfilteredBlockPatternsLength,\n\tselectedCategory,\n\tpatternCategories,\n} ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\tlet filter = filterValue;\n\tif ( selectedCategory !== allPatternsCategory.name ) {\n\t\tconst category = patternCategories.find(\n\t\t\t( patternCategory ) => patternCategory.name === selectedCategory\n\t\t);\n\t\tif ( category ) {\n\t\t\tfilter = `${ filter } - ${ category?.label }`;\n\t\t}\n\t}\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight={ '48px' }\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. %s: block pattern search query */\n\t\t\t\t_n(\n\t\t\t\t\t'%1$d pattern found for \"%2$s\"',\n\t\t\t\t\t'%1$d patterns found for \"%2$s\"',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength,\n\t\t\t\tfilter\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( {\n\tsearchValue,\n\tpatternSourceFilter,\n\tselectedCategory,\n\tpatternCategories,\n} ) {\n\tconst [ patternSyncFilter, setPatternSyncFilter ] = useState( 'all' );\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif (\n\t\t\t\tisPatternFiltered(\n\t\t\t\t\tpattern,\n\t\t\t\t\tpatternSourceFilter,\n\t\t\t\t\tpatternSyncFilter\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory = pattern.categories.some(\n\t\t\t\t\t( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t);\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems(\n\t\t\tfilteredPatterns,\n\t\t\tsearchValue,\n\t\t\tpatternSourceFilter\n\t\t);\n\t}, [\n\t\tsearchValue,\n\t\tpatternSourceFilter,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t\tpatternSyncFilter,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer,\n\t\tpatternSourceFilter\n\t);\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={\n\t\t\t\t\tsearchValue || PATTERN_SOURCE_FILTERS[ patternSourceFilter ]\n\t\t\t\t}\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\tpatternCategories={ patternCategories }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ patternSourceFilter === PATTERN_TYPES.user &&\n\t\t\t\t\t! searchValue && (\n\t\t\t\t\t\t<BlockPatternsSyncFilter\n\t\t\t\t\t\t\tpatternSyncFilter={ patternSyncFilter }\n\t\t\t\t\t\t\tsetPatternSyncFilter={ setPatternSyncFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\tshownPatterns={ pagingProps.categoryPatternsAsyncList }\n\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ pagingProps.numPages > 1 && (\n\t\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t\t) }\n\t\t\t</InserterListbox>\n\t\t</div>\n\t);\n}\n\nexport default PatternList;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AACzE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,qBAAqB,IAAIC,OAAO,QAAQ,uBAAuB;AACxE,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,2BAA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,CAACO,gBAAkB;IAC9CpB,cAAc,EAAGA,cAAgB;IACjCqB,WAAW,EAAG;EAAO,CACrB,CACD,EACCR,WAAW,CAACS,QAAQ,GAAG,CAAC,IACzBrC,aAAA,CAAClB,mBAAmB;IAAA,GAAM8C;EAAW,CAAI,CAE1B,CACb,CAAC;AAER;AAEA,eAAexB,WAAW"}
|
|
1
|
+
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","allPatternsCategory","myPatternsCategory","PatternsListHeader","filterValue","filteredBlockPatternsLength","createElement","level","lineHeight","className","PatternList","searchValue","selectedCategory","patternCategories","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","id","hasKnownCategory","categories","some","category","includes","length","count","resultsFoundMessage","pagingProps","previousSearchValue","setPreviousSearchValue","changePage","hasItems","ref","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","isDraggable","numPages"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport { allPatternsCategory, myPatternsCategory } from '../block-patterns-tab';\n\nfunction PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight={ '48px' }\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. */\n\t\t\t\t_n(\n\t\t\t\t\t'%d pattern found',\n\t\t\t\t\t'%d patterns found',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( { searchValue, selectedCategory, patternCategories } ) {\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === myPatternsCategory.name && pattern.id ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory = pattern.categories.some(\n\t\t\t\t\t( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t);\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems( filteredPatterns, searchValue );\n\t}, [\n\t\tsearchValue,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer\n\t);\n\n\t// Reset page when search value changes.\n\tconst [ previousSearchValue, setPreviousSearchValue ] =\n\t\tuseState( searchValue );\n\tif ( searchValue !== previousSearchValue ) {\n\t\tsetPreviousSearchValue( searchValue );\n\t\tpagingProps.changePage( 1 );\n\t}\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={ searchValue }\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\tshownPatterns={ pagingProps.categoryPatternsAsyncList }\n\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ pagingProps.numPages > 1 && (\n\t\t\t\t\t<BlockPatterns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-4,12 +4,6 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
*/
|
|
5
5
|
import { Button, SearchControl } from '@wordpress/components';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { default as BlockPatternsSourceFilter } from '../block-patterns-source-filter';
|
|
12
|
-
import { allPatternsCategory } from '../block-patterns-tab';
|
|
13
7
|
function PatternCategoriesList({
|
|
14
8
|
selectedCategory,
|
|
15
9
|
patternCategories,
|
|
@@ -52,8 +46,6 @@ function PatternExplorerSidebar({
|
|
|
52
46
|
selectedCategory,
|
|
53
47
|
patternCategories,
|
|
54
48
|
onClickCategory,
|
|
55
|
-
patternSourceFilter,
|
|
56
|
-
setPatternSourceFilter,
|
|
57
49
|
searchValue,
|
|
58
50
|
setSearchValue
|
|
59
51
|
}) {
|
|
@@ -63,12 +55,6 @@ function PatternExplorerSidebar({
|
|
|
63
55
|
}, createElement(PatternsExplorerSearch, {
|
|
64
56
|
searchValue: searchValue,
|
|
65
57
|
setSearchValue: setSearchValue
|
|
66
|
-
}), createElement(BlockPatternsSourceFilter, {
|
|
67
|
-
value: patternSourceFilter,
|
|
68
|
-
onChange: value => {
|
|
69
|
-
setPatternSourceFilter(value);
|
|
70
|
-
onClickCategory(allPatternsCategory.name);
|
|
71
|
-
}
|
|
72
58
|
}), !searchValue && createElement(PatternCategoriesList, {
|
|
73
59
|
selectedCategory: selectedCategory,
|
|
74
60
|
patternCategories: patternCategories,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Button","SearchControl","__","
|
|
1
|
+
{"version":3,"names":["Button","SearchControl","__","PatternCategoriesList","selectedCategory","patternCategories","onClickCategory","baseClassName","createElement","className","map","name","label","key","isPressed","onClick","PatternsExplorerSearch","searchValue","setSearchValue","__nextHasNoMarginBottom","onChange","value","placeholder","PatternExplorerSidebar"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/sidebar.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button, SearchControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nfunction PatternCategoriesList( {\n\tselectedCategory,\n\tpatternCategories,\n\tonClickCategory,\n} ) {\n\tconst baseClassName = 'block-editor-block-patterns-explorer__sidebar';\n\treturn (\n\t\t<div className={ `${ baseClassName }__categories-list` }>\n\t\t\t{ patternCategories.map( ( { name, label } ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={ name }\n\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\tclassName={ `${ baseClassName }__categories-list__item` }\n\t\t\t\t\t\tisPressed={ selectedCategory === name }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tonClickCategory( name );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n\nfunction PatternsExplorerSearch( { searchValue, setSearchValue } ) {\n\tconst baseClassName = 'block-editor-block-patterns-explorer__search';\n\treturn (\n\t\t<div className={ baseClassName }>\n\t\t\t<SearchControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tonChange={ setSearchValue }\n\t\t\t\tvalue={ searchValue }\n\t\t\t\tlabel={ __( 'Search for patterns' ) }\n\t\t\t\tplaceholder={ __( 'Search' ) }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction PatternExplorerSidebar( {\n\tselectedCategory,\n\tpatternCategories,\n\tonClickCategory,\n\tsearchValue,\n\tsetSearchValue,\n} ) {\n\tconst baseClassName = 'block-editor-block-patterns-explorer__sidebar';\n\treturn (\n\t\t<div className={ baseClassName }>\n\t\t\t<PatternsExplorerSearch\n\t\t\t\tsearchValue={ searchValue }\n\t\t\t\tsetSearchValue={ setSearchValue }\n\t\t\t/>\n\t\t\t{ ! searchValue && (\n\t\t\t\t<PatternCategoriesList\n\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\tpatternCategories={ patternCategories }\n\t\t\t\t\tonClickCategory={ onClickCategory }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default PatternExplorerSidebar;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,aAAa,QAAQ,uBAAuB;AAC7D,SAASC,EAAE,QAAQ,iBAAiB;AAEpC,SAASC,qBAAqBA,CAAE;EAC/BC,gBAAgB;EAChBC,iBAAiB;EACjBC;AACD,CAAC,EAAG;EACH,MAAMC,aAAa,GAAG,+CAA+C;EACrE,OACCC,aAAA;IAAKC,SAAS,EAAI,GAAGF,aAAe;EAAoB,GACrDF,iBAAiB,CAACK,GAAG,CAAE,CAAE;IAAEC,IAAI;IAAEC;EAAM,CAAC,KAAM;IAC/C,OACCJ,aAAA,CAACR,MAAM;MACNa,GAAG,EAAGF,IAAM;MACZC,KAAK,EAAGA,KAAO;MACfH,SAAS,EAAI,GAAGF,aAAe,yBAA0B;MACzDO,SAAS,EAAGV,gBAAgB,KAAKO,IAAM;MACvCI,OAAO,EAAGA,CAAA,KAAM;QACfT,eAAe,CAAEK,IAAK,CAAC;MACxB;IAAG,GAEDC,KACK,CAAC;EAEX,CAAE,CACE,CAAC;AAER;AAEA,SAASI,sBAAsBA,CAAE;EAAEC,WAAW;EAAEC;AAAe,CAAC,EAAG;EAClE,MAAMX,aAAa,GAAG,8CAA8C;EACpE,OACCC,aAAA;IAAKC,SAAS,EAAGF;EAAe,GAC/BC,aAAA,CAACP,aAAa;IACbkB,uBAAuB;IACvBC,QAAQ,EAAGF,cAAgB;IAC3BG,KAAK,EAAGJ,WAAa;IACrBL,KAAK,EAAGV,EAAE,CAAE,qBAAsB,CAAG;IACrCoB,WAAW,EAAGpB,EAAE,CAAE,QAAS;EAAG,CAC9B,CACG,CAAC;AAER;AAEA,SAASqB,sBAAsBA,CAAE;EAChCnB,gBAAgB;EAChBC,iBAAiB;EACjBC,eAAe;EACfW,WAAW;EACXC;AACD,CAAC,EAAG;EACH,MAAMX,aAAa,GAAG,+CAA+C;EACrE,OACCC,aAAA;IAAKC,SAAS,EAAGF;EAAe,GAC/BC,aAAA,CAACQ,sBAAsB;IACtBC,WAAW,EAAGA,WAAa;IAC3BC,cAAc,EAAGA;EAAgB,CACjC,CAAC,EACA,CAAED,WAAW,IACdT,aAAA,CAACL,qBAAqB;IACrBC,gBAAgB,EAAGA,gBAAkB;IACrCC,iBAAiB,EAAGA,iBAAmB;IACvCC,eAAe,EAAGA;EAAiB,CACnC,CAEE,CAAC;AAER;AAEA,eAAeiB,sBAAsB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { SVG, Path, DropdownMenu, MenuGroup, MenuItemsChoice } from '@wordpress/components';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { Icon } from '@wordpress/icons';
|
|
8
|
+
import { useMemo } from '@wordpress/element';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { myPatternsCategory } from './block-patterns-tab';
|
|
14
|
+
export const PATTERN_TYPES = {
|
|
15
|
+
all: 'all',
|
|
16
|
+
synced: 'synced',
|
|
17
|
+
unsynced: 'unsynced',
|
|
18
|
+
user: 'user',
|
|
19
|
+
theme: 'theme',
|
|
20
|
+
directory: 'directory'
|
|
21
|
+
};
|
|
22
|
+
export const SYNC_TYPES = {
|
|
23
|
+
all: 'all',
|
|
24
|
+
full: 'fully',
|
|
25
|
+
unsynced: 'unsynced'
|
|
26
|
+
};
|
|
27
|
+
const getShouldDisableSyncFilter = sourceFilter => sourceFilter !== PATTERN_TYPES.all && sourceFilter !== PATTERN_TYPES.user;
|
|
28
|
+
const getShouldDisableNonUserSources = category => {
|
|
29
|
+
return category.name === myPatternsCategory.name;
|
|
30
|
+
};
|
|
31
|
+
export function BlockPatternsSyncFilter({
|
|
32
|
+
setPatternSyncFilter,
|
|
33
|
+
setPatternSourceFilter,
|
|
34
|
+
patternSyncFilter,
|
|
35
|
+
patternSourceFilter,
|
|
36
|
+
scrollContainerRef,
|
|
37
|
+
category
|
|
38
|
+
}) {
|
|
39
|
+
// If the category is `myPatterns` then we need to set the source filter to `user`, but
|
|
40
|
+
// we do this by deriving from props rather than calling setPatternSourceFilter otherwise
|
|
41
|
+
// the user may be confused when switching to another category if the haven't explicity set
|
|
42
|
+
// this filter themselves.
|
|
43
|
+
const currentPatternSourceFilter = category.name === myPatternsCategory.name ? PATTERN_TYPES.user : patternSourceFilter;
|
|
44
|
+
|
|
45
|
+
// We need to disable the sync filter option if the source filter is not 'all' or 'user'
|
|
46
|
+
// otherwise applying them will just result in no patterns being shown.
|
|
47
|
+
const shouldDisableSyncFilter = getShouldDisableSyncFilter(currentPatternSourceFilter);
|
|
48
|
+
|
|
49
|
+
// We also need to disable the directory and theme source filter options if the category
|
|
50
|
+
// is `myPatterns` otherwise applying them will also just result in no patterns being shown.
|
|
51
|
+
const shouldDisableNonUserSources = getShouldDisableNonUserSources(category);
|
|
52
|
+
const patternSyncMenuOptions = useMemo(() => [{
|
|
53
|
+
value: SYNC_TYPES.all,
|
|
54
|
+
label: __('All')
|
|
55
|
+
}, {
|
|
56
|
+
value: SYNC_TYPES.full,
|
|
57
|
+
label: __('Synced'),
|
|
58
|
+
info: __('Updated everywhere'),
|
|
59
|
+
disabled: shouldDisableSyncFilter
|
|
60
|
+
}, {
|
|
61
|
+
value: SYNC_TYPES.unsynced,
|
|
62
|
+
label: __('Standard'),
|
|
63
|
+
info: __('Edit freely'),
|
|
64
|
+
disabled: shouldDisableSyncFilter
|
|
65
|
+
}], [shouldDisableSyncFilter]);
|
|
66
|
+
const patternSourceMenuOptions = useMemo(() => [{
|
|
67
|
+
value: PATTERN_TYPES.all,
|
|
68
|
+
label: __('All'),
|
|
69
|
+
disabled: shouldDisableNonUserSources
|
|
70
|
+
}, {
|
|
71
|
+
value: PATTERN_TYPES.directory,
|
|
72
|
+
label: __('Directory'),
|
|
73
|
+
info: __('Pattern directory & core'),
|
|
74
|
+
disabled: shouldDisableNonUserSources
|
|
75
|
+
}, {
|
|
76
|
+
value: PATTERN_TYPES.theme,
|
|
77
|
+
label: __('Theme'),
|
|
78
|
+
info: __('Bundled with the theme'),
|
|
79
|
+
disabled: shouldDisableNonUserSources
|
|
80
|
+
}, {
|
|
81
|
+
value: PATTERN_TYPES.user,
|
|
82
|
+
label: __('User'),
|
|
83
|
+
info: __('Custom created')
|
|
84
|
+
}], [shouldDisableNonUserSources]);
|
|
85
|
+
function handleSetSourceFilterChange(newSourceFilter) {
|
|
86
|
+
setPatternSourceFilter(newSourceFilter);
|
|
87
|
+
if (getShouldDisableSyncFilter(newSourceFilter)) {
|
|
88
|
+
setPatternSyncFilter(SYNC_TYPES.all);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return createElement(Fragment, null, createElement(DropdownMenu, {
|
|
92
|
+
popoverProps: {
|
|
93
|
+
placement: 'right-end'
|
|
94
|
+
},
|
|
95
|
+
label: "Filter patterns",
|
|
96
|
+
icon: createElement(Icon, {
|
|
97
|
+
icon: createElement(SVG, {
|
|
98
|
+
width: "24",
|
|
99
|
+
height: "24",
|
|
100
|
+
viewBox: "0 0 24 24",
|
|
101
|
+
fill: "none",
|
|
102
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
103
|
+
}, createElement(Path, {
|
|
104
|
+
d: "M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z",
|
|
105
|
+
fill: "#1E1E1E"
|
|
106
|
+
}))
|
|
107
|
+
})
|
|
108
|
+
}, () => createElement(Fragment, null, createElement(MenuGroup, {
|
|
109
|
+
label: __('Author')
|
|
110
|
+
}, createElement(MenuItemsChoice, {
|
|
111
|
+
choices: patternSourceMenuOptions,
|
|
112
|
+
onSelect: value => {
|
|
113
|
+
handleSetSourceFilterChange(value);
|
|
114
|
+
scrollContainerRef.current?.scrollTo(0, 0);
|
|
115
|
+
},
|
|
116
|
+
value: currentPatternSourceFilter
|
|
117
|
+
})), createElement(MenuGroup, {
|
|
118
|
+
label: __('Type')
|
|
119
|
+
}, createElement(MenuItemsChoice, {
|
|
120
|
+
choices: patternSyncMenuOptions,
|
|
121
|
+
onSelect: value => {
|
|
122
|
+
setPatternSyncFilter(value);
|
|
123
|
+
scrollContainerRef.current?.scrollTo(0, 0);
|
|
124
|
+
},
|
|
125
|
+
value: patternSyncFilter
|
|
126
|
+
})))));
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=block-patterns-filter.js.map
|