@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SVG","Path","DropdownMenu","MenuGroup","MenuItemsChoice","__","Icon","useMemo","myPatternsCategory","PATTERN_TYPES","all","synced","unsynced","user","theme","directory","SYNC_TYPES","full","getShouldDisableSyncFilter","sourceFilter","getShouldDisableNonUserSources","category","name","BlockPatternsSyncFilter","setPatternSyncFilter","setPatternSourceFilter","patternSyncFilter","patternSourceFilter","scrollContainerRef","currentPatternSourceFilter","shouldDisableSyncFilter","shouldDisableNonUserSources","patternSyncMenuOptions","value","label","info","disabled","patternSourceMenuOptions","handleSetSourceFilterChange","newSourceFilter","createElement","Fragment","popoverProps","placement","icon","width","height","viewBox","fill","xmlns","d","choices","onSelect","current","scrollTo"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-filter.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tSVG,\n\tPath,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItemsChoice,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { Icon } from '@wordpress/icons';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { myPatternsCategory } from './block-patterns-tab';\n\nexport const PATTERN_TYPES = {\n\tall: 'all',\n\tsynced: 'synced',\n\tunsynced: 'unsynced',\n\tuser: 'user',\n\ttheme: 'theme',\n\tdirectory: 'directory',\n};\n\nexport const SYNC_TYPES = {\n\tall: 'all',\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\nconst getShouldDisableSyncFilter = ( sourceFilter ) =>\n\tsourceFilter !== PATTERN_TYPES.all && sourceFilter !== PATTERN_TYPES.user;\n\nconst getShouldDisableNonUserSources = ( category ) => {\n\treturn category.name === myPatternsCategory.name;\n};\n\nexport function BlockPatternsSyncFilter( {\n\tsetPatternSyncFilter,\n\tsetPatternSourceFilter,\n\tpatternSyncFilter,\n\tpatternSourceFilter,\n\tscrollContainerRef,\n\tcategory,\n} ) {\n\t// If the category is `myPatterns` then we need to set the source filter to `user`, but\n\t// we do this by deriving from props rather than calling setPatternSourceFilter otherwise\n\t// the user may be confused when switching to another category if the haven't explicity set\n\t// this filter themselves.\n\tconst currentPatternSourceFilter =\n\t\tcategory.name === myPatternsCategory.name\n\t\t\t? PATTERN_TYPES.user\n\t\t\t: patternSourceFilter;\n\n\t// We need to disable the sync filter option if the source filter is not 'all' or 'user'\n\t// otherwise applying them will just result in no patterns being shown.\n\tconst shouldDisableSyncFilter = getShouldDisableSyncFilter(\n\t\tcurrentPatternSourceFilter\n\t);\n\n\t// We also need to disable the directory and theme source filter options if the category\n\t// is `myPatterns` otherwise applying them will also just result in no patterns being shown.\n\tconst shouldDisableNonUserSources =\n\t\tgetShouldDisableNonUserSources( category );\n\n\tconst patternSyncMenuOptions = useMemo(\n\t\t() => [\n\t\t\t{ value: SYNC_TYPES.all, label: __( 'All' ) },\n\t\t\t{\n\t\t\t\tvalue: SYNC_TYPES.full,\n\t\t\t\tlabel: __( 'Synced' ),\n\t\t\t\tinfo: __( 'Updated everywhere' ),\n\t\t\t\tdisabled: shouldDisableSyncFilter,\n\t\t\t},\n\t\t\t{\n\t\t\t\tvalue: SYNC_TYPES.unsynced,\n\t\t\t\tlabel: __( 'Standard' ),\n\t\t\t\tinfo: __( 'Edit freely' ),\n\t\t\t\tdisabled: shouldDisableSyncFilter,\n\t\t\t},\n\t\t],\n\t\t[ shouldDisableSyncFilter ]\n\t);\n\n\tconst patternSourceMenuOptions = useMemo(\n\t\t() => [\n\t\t\t{\n\t\t\t\tvalue: PATTERN_TYPES.all,\n\t\t\t\tlabel: __( 'All' ),\n\t\t\t\tdisabled: shouldDisableNonUserSources,\n\t\t\t},\n\t\t\t{\n\t\t\t\tvalue: PATTERN_TYPES.directory,\n\t\t\t\tlabel: __( 'Directory' ),\n\t\t\t\tinfo: __( 'Pattern directory & core' ),\n\t\t\t\tdisabled: shouldDisableNonUserSources,\n\t\t\t},\n\t\t\t{\n\t\t\t\tvalue: PATTERN_TYPES.theme,\n\t\t\t\tlabel: __( 'Theme' ),\n\t\t\t\tinfo: __( 'Bundled with the theme' ),\n\t\t\t\tdisabled: shouldDisableNonUserSources,\n\t\t\t},\n\t\t\t{\n\t\t\t\tvalue: PATTERN_TYPES.user,\n\t\t\t\tlabel: __( 'User' ),\n\t\t\t\tinfo: __( 'Custom created' ),\n\t\t\t},\n\t\t],\n\t\t[ shouldDisableNonUserSources ]\n\t);\n\n\tfunction handleSetSourceFilterChange( newSourceFilter ) {\n\t\tsetPatternSourceFilter( newSourceFilter );\n\t\tif ( getShouldDisableSyncFilter( newSourceFilter ) ) {\n\t\t\tsetPatternSyncFilter( SYNC_TYPES.all );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tplacement: 'right-end',\n\t\t\t\t} }\n\t\t\t\tlabel=\"Filter patterns\"\n\t\t\t\ticon={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t<SVG\n\t\t\t\t\t\t\t\twidth=\"24\"\n\t\t\t\t\t\t\t\theight=\"24\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Path\n\t\t\t\t\t\t\t\t\td=\"M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z\"\n\t\t\t\t\t\t\t\t\tfill=\"#1E1E1E\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</SVG>\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\t\t{ () => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<MenuGroup label={ __( 'Author' ) }>\n\t\t\t\t\t\t\t<MenuItemsChoice\n\t\t\t\t\t\t\t\tchoices={ patternSourceMenuOptions }\n\t\t\t\t\t\t\t\tonSelect={ ( value ) => {\n\t\t\t\t\t\t\t\t\thandleSetSourceFilterChange( value );\n\t\t\t\t\t\t\t\t\tscrollContainerRef.current?.scrollTo(\n\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t0\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\tvalue={ currentPatternSourceFilter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup label={ __( 'Type' ) }>\n\t\t\t\t\t\t\t<MenuItemsChoice\n\t\t\t\t\t\t\t\tchoices={ patternSyncMenuOptions }\n\t\t\t\t\t\t\t\tonSelect={ ( value ) => {\n\t\t\t\t\t\t\t\t\tsetPatternSyncFilter( value );\n\t\t\t\t\t\t\t\t\tscrollContainerRef.current?.scrollTo(\n\t\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t\t0\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\tvalue={ patternSyncFilter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,GAAG,EACHC,IAAI,EACJC,YAAY,EACZC,SAAS,EACTC,eAAe,QACT,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,IAAI,QAAQ,kBAAkB;AACvC,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,sBAAsB;AAEzD,OAAO,MAAMC,aAAa,GAAG;EAC5BC,GAAG,EAAE,KAAK;EACVC,MAAM,EAAE,Q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,EACHJ,aAAA,CAACxC,GAAG;QACH6C,KAAK,EAAC,IAAI;QACVC,MAAM,EAAC,IAAI;QACXC,OAAO,EAAC,WAAW;QACnBC,IAAI,EAAC,MAAM;QACXC,KAAK,EAAC;MAA4B,GAElCT,aAAA,CAACvC,IAAI;QACJiD,CAAC,EAAC,8DAA8D;QAChEF,IAAI,EAAC;MAAS,CACd,CACG;IACL,CACD;EACD,GAEC,MACDR,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACrC,SAAS;IAAC+B,KAAK,EAAG7B,EAAE,CAAE,QAAS;EAAG,GAClCmC,aAAA,CAACpC,eAAe;IACf+C,OAAO,EAAGd,wBAA0B;IACpCe,QAAQ,EAAKnB,KAAK,IAAM;MACvBK,2BAA2B,CAAEL,KAAM,CAAC;MACpCL,kBAAkB,CAACyB,OAAO,EAAEC,QAAQ,CACnC,CAAC,EACD,CACD,CAAC;IACF,CAAG;IACHrB,KAAK,EAAGJ;EAA4B,CACpC,CACS,CAAC,EACZW,aAAA,CAACrC,SAAS;IAAC+B,KAAK,EAAG7B,EAAE,CAAE,MAAO;EAAG,GAChCmC,aAAA,CAACpC,eAAe;IACf+C,OAAO,EAAGnB,sBAAwB;IAClCoB,QAAQ,EAAKnB,KAAK,IAAM;MACvBT,oBAAoB,CAAES,KAAM,CAAC;MAC7BL,kBAAkB,CAACyB,OAAO,EAAEC,QAAQ,CACnC,CAAC,EACD,CACD,CAAC;IACF,CAAG;IACHrB,KAAK,EAAGP;EAAmB,CAC3B,CACS,CACV,CAEU,CACb,CAAC;AAEL"}
|
|
@@ -5,7 +5,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
5
5
|
import { useMemo, useState, useCallback, useRef, useEffect } from '@wordpress/element';
|
|
6
6
|
import { _x, __, _n, isRTL, sprintf } from '@wordpress/i18n';
|
|
7
7
|
import { useViewportMatch } from '@wordpress/compose';
|
|
8
|
-
import { __experimentalItemGroup as ItemGroup, __experimentalItem as Item, __experimentalHStack as HStack, FlexBlock, Button } from '@wordpress/components';
|
|
8
|
+
import { __experimentalItemGroup as ItemGroup, __experimentalItem as Item, __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalHeading as Heading, __experimentalText as Text, FlexBlock, Button } from '@wordpress/components';
|
|
9
9
|
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons';
|
|
10
10
|
import { focus } from '@wordpress/dom';
|
|
11
11
|
import { speak } from '@wordpress/a11y';
|
|
@@ -17,26 +17,44 @@ import usePatternsState from './hooks/use-patterns-state';
|
|
|
17
17
|
import BlockPatternList from '../block-patterns-list';
|
|
18
18
|
import PatternsExplorerModal from './block-patterns-explorer/explorer';
|
|
19
19
|
import MobileTabNavigation from './mobile-tab-navigation';
|
|
20
|
-
import BlockPatternsPaging from '../block-patterns-paging';
|
|
21
20
|
import usePatternsPaging from './hooks/use-patterns-paging';
|
|
22
|
-
import {
|
|
23
|
-
import { BlockPatternsSyncFilter, SYNC_TYPES } from './block-patterns-sync-filter';
|
|
21
|
+
import { BlockPatternsSyncFilter, SYNC_TYPES, PATTERN_TYPES } from './block-patterns-filter';
|
|
24
22
|
const noop = () => {};
|
|
25
23
|
export const allPatternsCategory = {
|
|
26
24
|
name: 'allPatterns',
|
|
27
|
-
label: __('All
|
|
25
|
+
label: __('All Patterns')
|
|
26
|
+
};
|
|
27
|
+
export const myPatternsCategory = {
|
|
28
|
+
name: 'myPatterns',
|
|
29
|
+
label: __('My patterns')
|
|
28
30
|
};
|
|
29
31
|
export function isPatternFiltered(pattern, sourceFilter, syncFilter) {
|
|
30
|
-
|
|
32
|
+
const isUserPattern = pattern.name.startsWith('core/block');
|
|
33
|
+
const isDirectoryPattern = pattern.source === 'core' || pattern.source?.startsWith('pattern-directory');
|
|
34
|
+
|
|
35
|
+
// If theme source selected, filter out user created patterns and those from
|
|
36
|
+
// the core patterns directory.
|
|
37
|
+
if (sourceFilter === PATTERN_TYPES.theme && (isUserPattern || isDirectoryPattern)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If the directory source is selected, filter out user created patterns
|
|
42
|
+
// and those bundled with the theme.
|
|
43
|
+
if (sourceFilter === PATTERN_TYPES.directory && (isUserPattern || !isDirectoryPattern)) {
|
|
31
44
|
return true;
|
|
32
45
|
}
|
|
46
|
+
|
|
47
|
+
// If user source selected, filter out theme patterns. Any pattern without
|
|
48
|
+
// an id wasn't created by a user.
|
|
33
49
|
if (sourceFilter === PATTERN_TYPES.user && !pattern.id) {
|
|
34
50
|
return true;
|
|
35
51
|
}
|
|
36
|
-
|
|
52
|
+
|
|
53
|
+
// Filter by sync status.
|
|
54
|
+
if (syncFilter === SYNC_TYPES.full && pattern.syncStatus !== '') {
|
|
37
55
|
return true;
|
|
38
56
|
}
|
|
39
|
-
if (
|
|
57
|
+
if (syncFilter === SYNC_TYPES.unsynced && pattern.syncStatus !== 'unsynced' && isUserPattern) {
|
|
40
58
|
return true;
|
|
41
59
|
}
|
|
42
60
|
return false;
|
|
@@ -60,6 +78,9 @@ export function usePatternsCategories(rootClientId, sourceFilter = 'all') {
|
|
|
60
78
|
label: _x('Uncategorized')
|
|
61
79
|
});
|
|
62
80
|
}
|
|
81
|
+
if (filteredPatterns.some(pattern => pattern.id)) {
|
|
82
|
+
categories.unshift(myPatternsCategory);
|
|
83
|
+
}
|
|
63
84
|
if (filteredPatterns.length > 0) {
|
|
64
85
|
categories.unshift({
|
|
65
86
|
name: allPatternsCategory.name,
|
|
@@ -92,6 +113,7 @@ export function BlockPatternsCategoryDialog({
|
|
|
92
113
|
ref: container,
|
|
93
114
|
className: "block-editor-inserter__patterns-category-dialog"
|
|
94
115
|
}, createElement(BlockPatternsCategoryPanel, {
|
|
116
|
+
key: category.name,
|
|
95
117
|
rootClientId: rootClientId,
|
|
96
118
|
onInsert: onInsert,
|
|
97
119
|
onHover: onHover,
|
|
@@ -105,21 +127,24 @@ export function BlockPatternsCategoryPanel({
|
|
|
105
127
|
onInsert,
|
|
106
128
|
onHover = noop,
|
|
107
129
|
category,
|
|
108
|
-
showTitlesAsTooltip
|
|
109
|
-
patternFilter
|
|
130
|
+
showTitlesAsTooltip
|
|
110
131
|
}) {
|
|
111
132
|
const [allPatterns,, onClickPattern] = usePatternsState(onInsert, rootClientId);
|
|
112
133
|
const [patternSyncFilter, setPatternSyncFilter] = useState('all');
|
|
113
|
-
const
|
|
114
|
-
const
|
|
134
|
+
const [patternSourceFilter, setPatternSourceFilter] = useState('all');
|
|
135
|
+
const availableCategories = usePatternsCategories(rootClientId, patternSourceFilter);
|
|
136
|
+
const scrollContainerRef = useRef();
|
|
115
137
|
const currentCategoryPatterns = useMemo(() => allPatterns.filter(pattern => {
|
|
116
138
|
var _pattern$categories$f;
|
|
117
|
-
if (isPatternFiltered(pattern,
|
|
139
|
+
if (isPatternFiltered(pattern, patternSourceFilter, patternSyncFilter)) {
|
|
118
140
|
return false;
|
|
119
141
|
}
|
|
120
142
|
if (category.name === allPatternsCategory.name) {
|
|
121
143
|
return true;
|
|
122
144
|
}
|
|
145
|
+
if (category.name === myPatternsCategory.name && pattern.id) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
123
148
|
if (category.name !== 'uncategorized') {
|
|
124
149
|
return pattern.categories?.includes(category.name);
|
|
125
150
|
}
|
|
@@ -128,21 +153,43 @@ export function BlockPatternsCategoryPanel({
|
|
|
128
153
|
// or with no available category.
|
|
129
154
|
const availablePatternCategories = (_pattern$categories$f = pattern.categories?.filter(cat => availableCategories.find(availableCategory => availableCategory.name === cat))) !== null && _pattern$categories$f !== void 0 ? _pattern$categories$f : [];
|
|
130
155
|
return availablePatternCategories.length === 0;
|
|
131
|
-
}), [allPatterns, availableCategories, category.name,
|
|
132
|
-
const pagingProps = usePatternsPaging(currentCategoryPatterns, category,
|
|
156
|
+
}), [allPatterns, availableCategories, category.name, patternSourceFilter, patternSyncFilter]);
|
|
157
|
+
const pagingProps = usePatternsPaging(currentCategoryPatterns, category, scrollContainerRef);
|
|
158
|
+
const {
|
|
159
|
+
changePage
|
|
160
|
+
} = pagingProps;
|
|
133
161
|
|
|
134
162
|
// Hide block pattern preview on unmount.
|
|
135
163
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
164
|
useEffect(() => () => onHover(null), []);
|
|
165
|
+
const onSetPatternSyncFilter = useCallback(value => {
|
|
166
|
+
setPatternSyncFilter(value);
|
|
167
|
+
changePage(1);
|
|
168
|
+
}, [setPatternSyncFilter, changePage]);
|
|
169
|
+
const onSetPatternSourceFilter = useCallback(value => {
|
|
170
|
+
setPatternSourceFilter(value);
|
|
171
|
+
changePage(1);
|
|
172
|
+
}, [setPatternSourceFilter, changePage]);
|
|
137
173
|
return createElement("div", {
|
|
138
|
-
className: "block-editor-inserter__patterns-category-panel"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
className: "block-editor-inserter__patterns-category-panel-
|
|
142
|
-
},
|
|
174
|
+
className: "block-editor-inserter__patterns-category-panel"
|
|
175
|
+
}, createElement(VStack, {
|
|
176
|
+
spacing: 2,
|
|
177
|
+
className: "block-editor-inserter__patterns-category-panel-header"
|
|
178
|
+
}, createElement(HStack, null, createElement(FlexBlock, null, createElement(Heading, {
|
|
179
|
+
level: 4,
|
|
180
|
+
as: "div"
|
|
181
|
+
}, category.label)), createElement(BlockPatternsSyncFilter, {
|
|
143
182
|
patternSyncFilter: patternSyncFilter,
|
|
144
|
-
|
|
145
|
-
|
|
183
|
+
patternSourceFilter: patternSourceFilter,
|
|
184
|
+
setPatternSyncFilter: onSetPatternSyncFilter,
|
|
185
|
+
setPatternSourceFilter: onSetPatternSourceFilter,
|
|
186
|
+
scrollContainerRef: scrollContainerRef,
|
|
187
|
+
category: category
|
|
188
|
+
})), category.description && createElement(Text, null, category.description), !currentCategoryPatterns.length && createElement(Text, {
|
|
189
|
+
variant: "muted",
|
|
190
|
+
className: "block-editor-inserter__patterns-category-no-results"
|
|
191
|
+
}, __('No results found'))), currentCategoryPatterns.length > 0 && createElement(BlockPatternList, {
|
|
192
|
+
ref: scrollContainerRef,
|
|
146
193
|
shownPatterns: pagingProps.categoryPatternsAsyncList,
|
|
147
194
|
blockPatterns: pagingProps.categoryPatterns,
|
|
148
195
|
onClickPattern: onClickPattern,
|
|
@@ -152,9 +199,8 @@ export function BlockPatternsCategoryPanel({
|
|
|
152
199
|
category: category.name,
|
|
153
200
|
isDraggable: true,
|
|
154
201
|
showTitlesAsTooltip: showTitlesAsTooltip,
|
|
155
|
-
patternFilter:
|
|
156
|
-
|
|
157
|
-
...pagingProps
|
|
202
|
+
patternFilter: patternSourceFilter,
|
|
203
|
+
pagingProps: pagingProps
|
|
158
204
|
}));
|
|
159
205
|
}
|
|
160
206
|
function BlockPatternsTabs({
|
|
@@ -164,8 +210,7 @@ function BlockPatternsTabs({
|
|
|
164
210
|
rootClientId
|
|
165
211
|
}) {
|
|
166
212
|
const [showPatternsExplorer, setShowPatternsExplorer] = useState(false);
|
|
167
|
-
const
|
|
168
|
-
const categories = usePatternsCategories(rootClientId, patternSourceFilter);
|
|
213
|
+
const categories = usePatternsCategories(rootClientId);
|
|
169
214
|
const initialCategory = selectedCategory || categories[0];
|
|
170
215
|
const isMobile = useViewportMatch('medium', '<');
|
|
171
216
|
return createElement(Fragment, null, !isMobile && createElement("div", {
|
|
@@ -173,18 +218,12 @@ function BlockPatternsTabs({
|
|
|
173
218
|
}, createElement("nav", {
|
|
174
219
|
"aria-label": __('Block pattern categories'),
|
|
175
220
|
className: "block-editor-inserter__block-patterns-tabs"
|
|
176
|
-
}, createElement(
|
|
177
|
-
value: patternSourceFilter,
|
|
178
|
-
onChange: value => {
|
|
179
|
-
setPatternSourceFilter(value);
|
|
180
|
-
onSelectCategory(allPatternsCategory, value);
|
|
181
|
-
}
|
|
182
|
-
}), createElement(ItemGroup, {
|
|
221
|
+
}, createElement(ItemGroup, {
|
|
183
222
|
role: "list"
|
|
184
223
|
}, categories.map(category => createElement(Item, {
|
|
185
224
|
role: "listitem",
|
|
186
225
|
key: category.name,
|
|
187
|
-
onClick: () => onSelectCategory(category
|
|
226
|
+
onClick: () => onSelectCategory(category),
|
|
188
227
|
className: category === selectedCategory ? 'block-editor-inserter__patterns-category block-editor-inserter__patterns-selected-category' : 'block-editor-inserter__patterns-category',
|
|
189
228
|
"aria-label": category.label,
|
|
190
229
|
"aria-current": category === selectedCategory ? 'true' : undefined
|
|
@@ -199,6 +238,7 @@ function BlockPatternsTabs({
|
|
|
199
238
|
}, __('Explore all patterns')))))), isMobile && createElement(MobileTabNavigation, {
|
|
200
239
|
categories: categories
|
|
201
240
|
}, category => createElement(BlockPatternsCategoryPanel, {
|
|
241
|
+
key: category.name,
|
|
202
242
|
onInsert: onInsert,
|
|
203
243
|
rootClientId: rootClientId,
|
|
204
244
|
category: category,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useState","useCallback","useRef","useEffect","_x","__","_n","isRTL","sprintf","useViewportMatch","__experimentalItemGroup","ItemGroup","__experimentalItem","Item","__experimentalHStack","HStack","FlexBlock","Button","Icon","chevronRight","chevronLeft","focus","speak","usePatternsState","BlockPatternList","PatternsExplorerModal","MobileTabNavigation","BlockPatternsPaging","usePatternsPaging","PATTERN_TYPES","default","BlockPatternsSourceFilter","BlockPatternsSyncFilter","SYNC_TYPES","noop","allPatternsCategory","name","label","isPatternFiltered","pattern","sourceFilter","syncFilter","theme","startsWith","user","id","full","syncStatus","unsynced","usePatternsCategories","rootClientId","patterns","allCategories","undefined","filteredPatterns","filter","hasRegisteredCategory","categories","length","some","cat","category","populatedCategories","includes","sort","a","b","localeCompare","find","push","unshift","BlockPatternsCategoryDialog","onInsert","onHover","showTitlesAsTooltip","patternFilter","container","timeout","setTimeout","firstTabbable","tabbable","current","clearTimeout","createElement","ref","className","BlockPatternsCategoryPanel","allPatterns","onClickPattern","patternSyncFilter","setPatternSyncFilter","availableCategories","currentCategoryPatterns","_pattern$categories$f","availablePatternCategories","availableCategory","pagingProps","description","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","orientation","isDraggable","numPages","BlockPatternsTabs","onSelectCategory","selectedCategory","showPatternsExplorer","setShowPatternsExplorer","patternSourceFilter","setPatternSourceFilter","initialCategory","isMobile","Fragment","value","onChange","role","map","key","onClick","icon","variant","patternCategories","onModalClose"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseState,\n\tuseCallback,\n\tuseRef,\n\tuseEffect,\n} from '@wordpress/element';\nimport { _x, __, _n, isRTL, sprintf } from '@wordpress/i18n';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalHStack as HStack,\n\tFlexBlock,\n\tButton,\n} from '@wordpress/components';\nimport { Icon, chevronRight, chevronLeft } from '@wordpress/icons';\nimport { focus } from '@wordpress/dom';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport usePatternsState from './hooks/use-patterns-state';\nimport BlockPatternList from '../block-patterns-list';\nimport PatternsExplorerModal from './block-patterns-explorer/explorer';\nimport MobileTabNavigation from './mobile-tab-navigation';\nimport BlockPatternsPaging from '../block-patterns-paging';\nimport usePatternsPaging from './hooks/use-patterns-paging';\nimport {\n\tPATTERN_TYPES,\n\tdefault as BlockPatternsSourceFilter,\n} from './block-patterns-source-filter';\nimport {\n\tBlockPatternsSyncFilter,\n\tSYNC_TYPES,\n} from './block-patterns-sync-filter';\n\nconst noop = () => {};\n\nexport const allPatternsCategory = {\n\tname: 'allPatterns',\n\tlabel: __( 'All categories' ),\n};\n\nexport function isPatternFiltered( pattern, sourceFilter, syncFilter ) {\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.theme &&\n\t\tpattern.name.startsWith( 'core/block' )\n\t) {\n\t\treturn true;\n\t}\n\tif ( sourceFilter === PATTERN_TYPES.user && ! pattern.id ) {\n\t\treturn true;\n\t}\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.user &&\n\t\tsyncFilter === SYNC_TYPES.full &&\n\t\tpattern.syncStatus !== ''\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.user &&\n\t\tsyncFilter === SYNC_TYPES.unsynced &&\n\t\tpattern.syncStatus !== 'unsynced'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function usePatternsCategories( rootClientId, sourceFilter = 'all' ) {\n\tconst [ patterns, allCategories ] = usePatternsState(\n\t\tundefined,\n\t\trootClientId\n\t);\n\n\tconst filteredPatterns = useMemo(\n\t\t() =>\n\t\t\tsourceFilter === 'all'\n\t\t\t\t? patterns\n\t\t\t\t: patterns.filter(\n\t\t\t\t\t\t( pattern ) =>\n\t\t\t\t\t\t\t! isPatternFiltered( pattern, sourceFilter )\n\t\t\t\t ),\n\t\t[ sourceFilter, patterns ]\n\t);\n\n\tconst hasRegisteredCategory = useCallback(\n\t\t( pattern ) => {\n\t\t\tif ( ! pattern.categories || ! pattern.categories.length ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn pattern.categories.some( ( cat ) =>\n\t\t\t\tallCategories.some( ( category ) => category.name === cat )\n\t\t\t);\n\t\t},\n\t\t[ allCategories ]\n\t);\n\n\t// Remove any empty categories.\n\tconst populatedCategories = useMemo( () => {\n\t\tconst categories = allCategories\n\t\t\t.filter( ( category ) =>\n\t\t\t\tfilteredPatterns.some( ( pattern ) =>\n\t\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.sort( ( a, b ) => a.label.localeCompare( b.label ) );\n\n\t\tif (\n\t\t\tfilteredPatterns.some(\n\t\t\t\t( pattern ) => ! hasRegisteredCategory( pattern )\n\t\t\t) &&\n\t\t\t! categories.find(\n\t\t\t\t( category ) => category.name === 'uncategorized'\n\t\t\t)\n\t\t) {\n\t\t\tcategories.push( {\n\t\t\t\tname: 'uncategorized',\n\t\t\t\tlabel: _x( 'Uncategorized' ),\n\t\t\t} );\n\t\t}\n\t\tif ( filteredPatterns.length > 0 ) {\n\t\t\tcategories.unshift( {\n\t\t\t\tname: allPatternsCategory.name,\n\t\t\t\tlabel: allPatternsCategory.label,\n\t\t\t} );\n\t\t}\n\t\tspeak(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %d: number of categories . */\n\t\t\t\t_n(\n\t\t\t\t\t'%d category button displayed.',\n\t\t\t\t\t'%d category buttons displayed.',\n\t\t\t\t\tcategories.length\n\t\t\t\t),\n\t\t\t\tcategories.length\n\t\t\t)\n\t\t);\n\t\treturn categories;\n\t}, [ allCategories, filteredPatterns, hasRegisteredCategory ] );\n\n\treturn populatedCategories;\n}\n\nexport function BlockPatternsCategoryDialog( {\n\trootClientId,\n\tonInsert,\n\tonHover,\n\tcategory,\n\tshowTitlesAsTooltip,\n\tpatternFilter,\n} ) {\n\tconst container = useRef();\n\n\tuseEffect( () => {\n\t\tconst timeout = setTimeout( () => {\n\t\t\tconst [ firstTabbable ] = focus.tabbable.find( container.current );\n\t\t\tfirstTabbable?.focus();\n\t\t} );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ category ] );\n\n\treturn (\n\t\t<div\n\t\t\tref={ container }\n\t\t\tclassName=\"block-editor-inserter__patterns-category-dialog\"\n\t\t>\n\t\t\t<BlockPatternsCategoryPanel\n\t\t\t\trootClientId={ rootClientId }\n\t\t\t\tonInsert={ onInsert }\n\t\t\t\tonHover={ onHover }\n\t\t\t\tcategory={ category }\n\t\t\t\tshowTitlesAsTooltip={ showTitlesAsTooltip }\n\t\t\t\tpatternFilter={ patternFilter }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nexport function BlockPatternsCategoryPanel( {\n\trootClientId,\n\tonInsert,\n\tonHover = noop,\n\tcategory,\n\tshowTitlesAsTooltip,\n\tpatternFilter,\n} ) {\n\tconst [ allPatterns, , onClickPattern ] = usePatternsState(\n\t\tonInsert,\n\t\trootClientId\n\t);\n\tconst [ patternSyncFilter, setPatternSyncFilter ] = useState( 'all' );\n\n\tconst availableCategories = usePatternsCategories(\n\t\trootClientId,\n\t\tpatternFilter\n\t);\n\tconst container = useRef();\n\tconst currentCategoryPatterns = useMemo(\n\t\t() =>\n\t\t\tallPatterns.filter( ( pattern ) => {\n\t\t\t\tif (\n\t\t\t\t\tisPatternFiltered(\n\t\t\t\t\t\tpattern,\n\t\t\t\t\t\tpatternFilter,\n\t\t\t\t\t\tpatternSyncFilter\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif ( category.name === allPatternsCategory.name ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif ( category.name !== 'uncategorized' ) {\n\t\t\t\t\treturn pattern.categories?.includes( category.name );\n\t\t\t\t}\n\n\t\t\t\t// The uncategorized category should show all the patterns without any category\n\t\t\t\t// or with no available category.\n\t\t\t\tconst availablePatternCategories =\n\t\t\t\t\tpattern.categories?.filter( ( cat ) =>\n\t\t\t\t\t\tavailableCategories.find(\n\t\t\t\t\t\t\t( availableCategory ) =>\n\t\t\t\t\t\t\t\tavailableCategory.name === cat\n\t\t\t\t\t\t)\n\t\t\t\t\t) ?? [];\n\n\t\t\t\treturn availablePatternCategories.length === 0;\n\t\t\t} ),\n\t\t[\n\t\t\tallPatterns,\n\t\t\tavailableCategories,\n\t\t\tcategory.name,\n\t\t\tpatternFilter,\n\t\t\tpatternSyncFilter,\n\t\t]\n\t);\n\n\tconst pagingProps = usePatternsPaging(\n\t\tcurrentCategoryPatterns,\n\t\tcategory,\n\t\tcontainer\n\t);\n\n\t// Hide block pattern preview on unmount.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tuseEffect( () => () => onHover( null ), [] );\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-inserter__patterns-category-panel\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<div className=\"block-editor-inserter__patterns-category-panel-title\">\n\t\t\t\t{ category.label }\n\t\t\t</div>\n\t\t\t<p>{ category.description }</p>\n\t\t\t{ patternFilter === PATTERN_TYPES.user && (\n\t\t\t\t<BlockPatternsSyncFilter\n\t\t\t\t\tpatternSyncFilter={ patternSyncFilter }\n\t\t\t\t\tsetPatternSyncFilter={ setPatternSyncFilter }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! currentCategoryPatterns.length && (\n\t\t\t\t<div>{ __( 'No results found' ) }</div>\n\t\t\t) }\n\t\t\t{ currentCategoryPatterns.length > 0 && (\n\t\t\t\t<BlockPatternList\n\t\t\t\t\tshownPatterns={ pagingProps.categoryPatternsAsyncList }\n\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\tlabel={ category.label }\n\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\tcategory={ category.name }\n\t\t\t\t\tisDraggable\n\t\t\t\t\tshowTitlesAsTooltip={ showTitlesAsTooltip }\n\t\t\t\t\tpatternFilter={ patternFilter }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ pagingProps.numPages > 1 && (\n\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction BlockPatternsTabs( {\n\tonSelectCategory,\n\tselectedCategory,\n\tonInsert,\n\trootClientId,\n} ) {\n\tconst [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );\n\tconst [ patternSourceFilter, setPatternSourceFilter ] = useState( 'all' );\n\n\tconst categories = usePatternsCategories(\n\t\trootClientId,\n\t\tpatternSourceFilter\n\t);\n\n\tconst initialCategory = selectedCategory || categories[ 0 ];\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className=\"block-editor-inserter__block-patterns-tabs-container\">\n\t\t\t\t\t<nav\n\t\t\t\t\t\taria-label={ __( 'Block pattern categories' ) }\n\t\t\t\t\t\tclassName=\"block-editor-inserter__block-patterns-tabs\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockPatternsSourceFilter\n\t\t\t\t\t\t\tvalue={ patternSourceFilter }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetPatternSourceFilter( value );\n\t\t\t\t\t\t\t\tonSelectCategory( allPatternsCategory, value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ItemGroup role=\"list\">\n\t\t\t\t\t\t\t{ categories.map( ( category ) => (\n\t\t\t\t\t\t\t\t<Item\n\t\t\t\t\t\t\t\t\trole=\"listitem\"\n\t\t\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tonSelectCategory(\n\t\t\t\t\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t\t\t\t\t\tpatternSourceFilter\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\tcategory === selectedCategory\n\t\t\t\t\t\t\t\t\t\t\t? 'block-editor-inserter__patterns-category block-editor-inserter__patterns-selected-category'\n\t\t\t\t\t\t\t\t\t\t\t: 'block-editor-inserter__patterns-category'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-label={ category.label }\n\t\t\t\t\t\t\t\t\taria-current={\n\t\t\t\t\t\t\t\t\t\tcategory === selectedCategory\n\t\t\t\t\t\t\t\t\t\t\t? 'true'\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<HStack>\n\t\t\t\t\t\t\t\t\t\t<FlexBlock>\n\t\t\t\t\t\t\t\t\t\t\t{ category.label }\n\t\t\t\t\t\t\t\t\t\t</FlexBlock>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\tisRTL()\n\t\t\t\t\t\t\t\t\t\t\t\t\t? chevronLeft\n\t\t\t\t\t\t\t\t\t\t\t\t\t: chevronRight\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t</Item>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t<div role=\"listitem\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-explore-button\"\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tsetShowPatternsExplorer( true )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Explore all patterns' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t</nav>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<BlockPatternsCategoryPanel\n\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\tshowTitlesAsTooltip={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t\t{ showPatternsExplorer && (\n\t\t\t\t<PatternsExplorerModal\n\t\t\t\t\tinitialCategory={ initialCategory }\n\t\t\t\t\tpatternCategories={ categories }\n\t\t\t\t\tonModalClose={ () => setShowPatternsExplorer( false ) }\n\t\t\t\t\trootClientId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Y,GACzCI,QAAQ,IACXsB,aAAA,CAACG,0BAA0B;IAC1Bd,QAAQ,EAAGA,QAAU;IACrBtB,YAAY,EAAGA,YAAc;IAC7BW,QAAQ,EAAGA,QAAU;IACrBa,mBAAmB,EAAG;EAAO,CAC7B,CAEkB,CACrB,EACCkC,oBAAoB,IACrBzB,aAAA,CAAC1D,qBAAqB;IACrBuF,eAAe,EAAGA,eAAiB;IACnCW,iBAAiB,EAAGlE,UAAY;IAChCmE,YAAY,EAAGA,CAAA,KAAMf,uBAAuB,CAAE,KAAM,CAAG;IACvD3D,YAAY,EAAGA;EAAc,CAC7B,CAED,CAAC;AAEL;AAEA,eAAeuD,iBAAiB"}
|
|
1
|
+
{"version":3,"names":["useMemo","useState","useCallback","useRef","useEffect","_x","__","_n","isRTL","sprintf","useViewportMatch","__experimentalItemGroup","ItemGroup","__experimentalItem","Item","__experimentalHStack","HStack","__experimentalVStack","VStack","__experimentalHeading","Heading","__experimentalText","Text","FlexBlock","Button","Icon","chevronRight","chevronLeft","focus","speak","usePatternsState","BlockPatternList","PatternsExplorerModal","MobileTabNavigation","usePatternsPaging","BlockPatternsSyncFilter","SYNC_TYPES","PATTERN_TYPES","noop","allPatternsCategory","name","label","myPatternsCategory","isPatternFiltered","pattern","sourceFilter","syncFilter","isUserPattern","startsWith","isDirectoryPattern","source","theme","directory","user","id","full","syncStatus","unsynced","usePatternsCategories","rootClientId","patterns","allCategories","undefined","filteredPatterns","filter","hasRegisteredCategory","categories","length","some","cat","category","populatedCategories","includes","sort","a","b","localeCompare","find","push","unshift","BlockPatternsCategoryDialog","onInsert","onHover","showTitlesAsTooltip","patternFilter","container","timeout","setTimeout","firstTabbable","tabbable","current","clearTimeout","createElement","ref","className","BlockPatternsCategoryPanel","key","allPatterns","onClickPattern","patternSyncFilter","setPatternSyncFilter","patternSourceFilter","setPatternSourceFilter","availableCategories","scrollContainerRef","currentCategoryPatterns","_pattern$categories$f","availablePatternCategories","availableCategory","pagingProps","changePage","onSetPatternSyncFilter","value","onSetPatternSourceFilter","spacing","level","as","description","variant","shownPatterns","categoryPatternsAsyncList","blockPatterns","categoryPatterns","orientation","isDraggable","BlockPatternsTabs","onSelectCategory","selectedCategory","showPatternsExplorer","setShowPatternsExplorer","initialCategory","isMobile","Fragment","role","map","onClick","icon","patternCategories","onModalClose"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseState,\n\tuseCallback,\n\tuseRef,\n\tuseEffect,\n} from '@wordpress/element';\nimport { _x, __, _n, isRTL, sprintf } from '@wordpress/i18n';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\t__experimentalHeading as Heading,\n\t__experimentalText as Text,\n\tFlexBlock,\n\tButton,\n} from '@wordpress/components';\nimport { Icon, chevronRight, chevronLeft } from '@wordpress/icons';\nimport { focus } from '@wordpress/dom';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport usePatternsState from './hooks/use-patterns-state';\nimport BlockPatternList from '../block-patterns-list';\nimport PatternsExplorerModal from './block-patterns-explorer/explorer';\nimport MobileTabNavigation from './mobile-tab-navigation';\nimport usePatternsPaging from './hooks/use-patterns-paging';\nimport {\n\tBlockPatternsSyncFilter,\n\tSYNC_TYPES,\n\tPATTERN_TYPES,\n} from './block-patterns-filter';\n\nconst noop = () => {};\n\nexport const allPatternsCategory = {\n\tname: 'allPatterns',\n\tlabel: __( 'All Patterns' ),\n};\n\nexport const myPatternsCategory = {\n\tname: 'myPatterns',\n\tlabel: __( 'My patterns' ),\n};\n\nexport function isPatternFiltered( pattern, sourceFilter, syncFilter ) {\n\tconst isUserPattern = pattern.name.startsWith( 'core/block' );\n\tconst isDirectoryPattern =\n\t\tpattern.source === 'core' ||\n\t\tpattern.source?.startsWith( 'pattern-directory' );\n\n\t// If theme source selected, filter out user created patterns and those from\n\t// the core patterns directory.\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.theme &&\n\t\t( isUserPattern || isDirectoryPattern )\n\t) {\n\t\treturn true;\n\t}\n\n\t// If the directory source is selected, filter out user created patterns\n\t// and those bundled with the theme.\n\tif (\n\t\tsourceFilter === PATTERN_TYPES.directory &&\n\t\t( isUserPattern || ! isDirectoryPattern )\n\t) {\n\t\treturn true;\n\t}\n\n\t// If user source selected, filter out theme patterns. Any pattern without\n\t// an id wasn't created by a user.\n\tif ( sourceFilter === PATTERN_TYPES.user && ! pattern.id ) {\n\t\treturn true;\n\t}\n\n\t// Filter by sync status.\n\tif ( syncFilter === SYNC_TYPES.full && pattern.syncStatus !== '' ) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\tsyncFilter === SYNC_TYPES.unsynced &&\n\t\tpattern.syncStatus !== 'unsynced' &&\n\t\tisUserPattern\n\t) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nexport function usePatternsCategories( rootClientId, sourceFilter = 'all' ) {\n\tconst [ patterns, allCategories ] = usePatternsState(\n\t\tundefined,\n\t\trootClientId\n\t);\n\n\tconst filteredPatterns = useMemo(\n\t\t() =>\n\t\t\tsourceFilter === 'all'\n\t\t\t\t? patterns\n\t\t\t\t: patterns.filter(\n\t\t\t\t\t\t( pattern ) =>\n\t\t\t\t\t\t\t! isPatternFiltered( pattern, sourceFilter )\n\t\t\t\t ),\n\t\t[ sourceFilter, patterns ]\n\t);\n\n\tconst hasRegisteredCategory = useCallback(\n\t\t( pattern ) => {\n\t\t\tif ( ! pattern.categories || ! pattern.categories.length ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn pattern.categories.some( ( cat ) =>\n\t\t\t\tallCategories.some( ( category ) => category.name === cat )\n\t\t\t);\n\t\t},\n\t\t[ allCategories ]\n\t);\n\n\t// Remove any empty categories.\n\tconst populatedCategories = useMemo( () => {\n\t\tconst categories = allCategories\n\t\t\t.filter( ( category ) =>\n\t\t\t\tfilteredPatterns.some( ( pattern ) =>\n\t\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.sort( ( a, b ) => a.label.localeCompare( b.label ) );\n\n\t\tif (\n\t\t\tfilteredPatterns.some(\n\t\t\t\t( pattern ) => ! hasRegisteredCategory( pattern )\n\t\t\t) &&\n\t\t\t! categories.find(\n\t\t\t\t( category ) => category.name === 'uncategorized'\n\t\t\t)\n\t\t) {\n\t\t\tcategories.push( {\n\t\t\t\tname: 'uncategorized',\n\t\t\t\tlabel: _x( 'Uncategorized' ),\n\t\t\t} );\n\t\t}\n\t\tif ( filteredPatterns.some( ( pattern ) => pattern.id ) ) {\n\t\t\tcategories.unshift( myPatternsCategory );\n\t\t}\n\t\tif ( filteredPatterns.length > 0 ) {\n\t\t\tcategories.unshift( {\n\t\t\t\tname: allPatternsCategory.name,\n\t\t\t\tlabel: allPatternsCategory.label,\n\t\t\t} );\n\t\t}\n\t\tspeak(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %d: number of categories . */\n\t\t\t\t_n(\n\t\t\t\t\t'%d category button displayed.',\n\t\t\t\t\t'%d category buttons displayed.',\n\t\t\t\t\tcategories.length\n\t\t\t\t),\n\t\t\t\tcategories.length\n\t\t\t)\n\t\t);\n\t\treturn categories;\n\t}, [ allCategories, filteredPatterns, hasRegisteredCategory ] );\n\n\treturn populatedCategories;\n}\n\nexport function BlockPatternsCategoryDialog( {\n\trootClientId,\n\tonInsert,\n\tonHover,\n\tcategory,\n\tshowTitlesAsTooltip,\n\tpatternFilter,\n} ) {\n\tconst container = useRef();\n\n\tuseEffect( () => {\n\t\tconst timeout = setTimeout( () => {\n\t\t\tconst [ firstTabbable ] = focus.tabbable.find( container.current );\n\t\t\tfirstTabbable?.focus();\n\t\t} );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ category ] );\n\n\treturn (\n\t\t<div\n\t\t\tref={ container }\n\t\t\tclassName=\"block-editor-inserter__patterns-category-dialog\"\n\t\t>\n\t\t\t<BlockPatternsCategoryPanel\n\t\t\t\tkey={ category.name }\n\t\t\t\trootClientId={ rootClientId }\n\t\t\t\tonInsert={ onInsert }\n\t\t\t\tonHover={ onHover }\n\t\t\t\tcategory={ category }\n\t\t\t\tshowTitlesAsTooltip={ showTitlesAsTooltip }\n\t\t\t\tpatternFilter={ patternFilter }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nexport function BlockPatternsCategoryPanel( {\n\trootClientId,\n\tonInsert,\n\tonHover = noop,\n\tcategory,\n\tshowTitlesAsTooltip,\n} ) {\n\tconst [ allPatterns, , onClickPattern ] = usePatternsState(\n\t\tonInsert,\n\t\trootClientId\n\t);\n\tconst [ patternSyncFilter, setPatternSyncFilter ] = useState( 'all' );\n\tconst [ patternSourceFilter, setPatternSourceFilter ] = useState( 'all' );\n\n\tconst availableCategories = usePatternsCategories(\n\t\trootClientId,\n\t\tpatternSourceFilter\n\t);\n\tconst scrollContainerRef = useRef();\n\tconst currentCategoryPatterns = useMemo(\n\t\t() =>\n\t\t\tallPatterns.filter( ( pattern ) => {\n\t\t\t\tif (\n\t\t\t\t\tisPatternFiltered(\n\t\t\t\t\t\tpattern,\n\t\t\t\t\t\tpatternSourceFilter,\n\t\t\t\t\t\tpatternSyncFilter\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tif ( category.name === allPatternsCategory.name ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif ( category.name === myPatternsCategory.name && pattern.id ) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tif ( category.name !== 'uncategorized' ) {\n\t\t\t\t\treturn pattern.categories?.includes( category.name );\n\t\t\t\t}\n\n\t\t\t\t// The uncategorized category should show all the patterns without any category\n\t\t\t\t// or with no available category.\n\t\t\t\tconst availablePatternCategories =\n\t\t\t\t\tpattern.categories?.filter( ( cat ) =>\n\t\t\t\t\t\tavailableCategories.find(\n\t\t\t\t\t\t\t( availableCategory ) =>\n\t\t\t\t\t\t\t\tavailableCategory.name === cat\n\t\t\t\t\t\t)\n\t\t\t\t\t) ?? [];\n\n\t\t\t\treturn availablePatternCategories.length === 0;\n\t\t\t} ),\n\t\t[\n\t\t\tallPatterns,\n\t\t\tavailableCategories,\n\t\t\tcategory.name,\n\t\t\tpatternSourceFilter,\n\t\t\tpatternSyncFilter,\n\t\t]\n\t);\n\n\tconst pagingProps = usePatternsPaging(\n\t\tcurrentCategoryPatterns,\n\t\tcategory,\n\t\tscrollContainerRef\n\t);\n\tconst { changePage } = pagingProps;\n\n\t// Hide block pattern preview on unmount.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tuseEffect( () => () => onHover( null ), [] );\n\n\tconst onSetPatternSyncFilter = useCallback(\n\t\t( value ) => {\n\t\t\tsetPatternSyncFilter( value );\n\t\t\tchangePage( 1 );\n\t\t},\n\t\t[ setPatternSyncFilter, changePage ]\n\t);\n\tconst onSetPatternSourceFilter = useCallback(\n\t\t( value ) => {\n\t\t\tsetPatternSourceFilter( value );\n\t\t\tchangePage( 1 );\n\t\t},\n\t\t[ setPatternSourceFilter, changePage ]\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-inserter__patterns-category-panel\">\n\t\t\t<VStack\n\t\t\t\tspacing={ 2 }\n\t\t\t\tclassName=\"block-editor-inserter__patterns-category-panel-header\"\n\t\t\t>\n\t\t\t\t<HStack>\n\t\t\t\t\t<FlexBlock>\n\t\t\t\t\t\t<Heading level={ 4 } as=\"div\">\n\t\t\t\t\t\t\t{ category.label }\n\t\t\t\t\t\t</Heading>\n\t\t\t\t\t</FlexBlock>\n\t\t\t\t\t<BlockPatternsSyncFilter\n\t\t\t\t\t\tpatternSyncFilter={ patternSyncFilter }\n\t\t\t\t\t\tpatternSourceFilter={ patternSourceFilter }\n\t\t\t\t\t\tsetPatternSyncFilter={ onSetPatternSyncFilter }\n\t\t\t\t\t\tsetPatternSourceFilter={ onSetPatternSourceFilter }\n\t\t\t\t\t\tscrollContainerRef={ scrollContainerRef }\n\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t{ category.description && (\n\t\t\t\t\t<Text>{ category.description }</Text>\n\t\t\t\t) }\n\t\t\t\t{ ! currentCategoryPatterns.length && (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tvariant=\"muted\"\n\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-category-no-results\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'No results found' ) }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t</VStack>\n\n\t\t\t{ currentCategoryPatterns.length > 0 && (\n\t\t\t\t<BlockPatternList\n\t\t\t\t\tref={ scrollContainerRef }\n\t\t\t\t\tshownPatterns={ pagingProps.categoryPatternsAsyncList }\n\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\tonClickPattern={ onClickPattern }\n\t\t\t\t\tonHover={ onHover }\n\t\t\t\t\tlabel={ category.label }\n\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\tcategory={ category.name }\n\t\t\t\t\tisDraggable\n\t\t\t\t\tshowTitlesAsTooltip={ showTitlesAsTooltip }\n\t\t\t\t\tpatternFilter={ patternSourceFilter }\n\t\t\t\t\tpagingProps={ pagingProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction BlockPatternsTabs( {\n\tonSelectCategory,\n\tselectedCategory,\n\tonInsert,\n\trootClientId,\n} ) {\n\tconst [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );\n\n\tconst categories = usePatternsCategories( rootClientId );\n\n\tconst initialCategory = selectedCategory || categories[ 0 ];\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className=\"block-editor-inserter__block-patterns-tabs-container\">\n\t\t\t\t\t<nav\n\t\t\t\t\t\taria-label={ __( 'Block pattern categories' ) }\n\t\t\t\t\t\tclassName=\"block-editor-inserter__block-patterns-tabs\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<ItemGroup role=\"list\">\n\t\t\t\t\t\t\t{ categories.map( ( category ) => (\n\t\t\t\t\t\t\t\t<Item\n\t\t\t\t\t\t\t\t\trole=\"listitem\"\n\t\t\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tonSelectCategory( category )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tclassName={\n\t\t\t\t\t\t\t\t\t\tcategory === selectedCategory\n\t\t\t\t\t\t\t\t\t\t\t? 'block-editor-inserter__patterns-category block-editor-inserter__patterns-selected-category'\n\t\t\t\t\t\t\t\t\t\t\t: 'block-editor-inserter__patterns-category'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\taria-label={ category.label }\n\t\t\t\t\t\t\t\t\taria-current={\n\t\t\t\t\t\t\t\t\t\tcategory === selectedCategory\n\t\t\t\t\t\t\t\t\t\t\t? 'true'\n\t\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<HStack>\n\t\t\t\t\t\t\t\t\t\t<FlexBlock>\n\t\t\t\t\t\t\t\t\t\t\t{ category.label }\n\t\t\t\t\t\t\t\t\t\t</FlexBlock>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\tisRTL()\n\t\t\t\t\t\t\t\t\t\t\t\t\t? chevronLeft\n\t\t\t\t\t\t\t\t\t\t\t\t\t: chevronRight\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t</Item>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t<div role=\"listitem\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-explore-button\"\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tsetShowPatternsExplorer( true )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Explore all patterns' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t</nav>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<BlockPatternsCategoryPanel\n\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\tshowTitlesAsTooltip={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t\t{ showPatternsExplorer && (\n\t\t\t\t<PatternsExplorerModal\n\t\t\t\t\tinitialCategory={ initialCategory }\n\t\t\t\t\tpatternCategories={ categories }\n\t\t\t\t\tonModalClose={ () => setShowPatternsExplorer( false ) }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default BlockPatternsTabs;\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,OAAO,EACPC,QAAQ,EACRC,WAAW,EACXC,MAAM,EACNC,SAAS,QACH,oBAAoB;AAC3B,SAASC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,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,EAAGA,eAAiB;IACnCO,iBAAiB,EAAGvE,UAAY;IAChCwE,YAAY,EAAGA,CAAA,KAAMT,uBAAuB,CAAE,KAAM,CAAG;IACvDtE,YAAY,EAAGA;EAAc,CAC7B,CAED,CAAC;AAEL;AAEA,eAAekE,iBAAiB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { useMemo, useState } from '@wordpress/element';
|
|
4
|
+
import { useMemo, useState, useEffect } from '@wordpress/element';
|
|
5
5
|
import { useAsyncList, usePrevious } from '@wordpress/compose';
|
|
6
6
|
import { getScrollContainer } from '@wordpress/dom';
|
|
7
7
|
const PAGE_SIZE = 20;
|
|
@@ -38,6 +38,10 @@ export default function usePatternsPaging(currentCategoryPatterns, currentCatego
|
|
|
38
38
|
scrollContainer?.scrollTo(0, 0);
|
|
39
39
|
setCurrentPage(page);
|
|
40
40
|
};
|
|
41
|
+
useEffect(function scrollToTopOnCategoryChange() {
|
|
42
|
+
const scrollContainer = getScrollContainer(scrollContainerRef?.current);
|
|
43
|
+
scrollContainer?.scrollTo(0, 0);
|
|
44
|
+
}, [currentCategory, scrollContainerRef]);
|
|
41
45
|
return {
|
|
42
46
|
totalItems,
|
|
43
47
|
categoryPatterns,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useState","useAsyncList","usePrevious","getScrollContainer","PAGE_SIZE","INITIAL_INSERTER_RESULTS","usePatternsPaging","currentCategoryPatterns","currentCategory","scrollContainerRef","currentFilter","currentPage","setCurrentPage","previousCategory","previousFilter","totalItems","length","pageIndex","categoryPatterns","slice","categoryPatternsAsyncList","step","numPages","Math","ceil","changePage","page","scrollContainer","current","scrollTo"],"sources":["@wordpress/block-editor/src/components/inserter/hooks/use-patterns-paging.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState } from '@wordpress/element';\nimport { useAsyncList, usePrevious } from '@wordpress/compose';\nimport { getScrollContainer } from '@wordpress/dom';\n\nconst PAGE_SIZE = 20;\nconst INITIAL_INSERTER_RESULTS = 5;\n\n/**\n * Supplies values needed to page the patterns list client side.\n *\n * @param {Array} currentCategoryPatterns An array of the current patterns to display.\n * @param {string} currentCategory The currently selected category.\n * @param {Object} scrollContainerRef Ref of container to to find scroll container for when moving between pages.\n * @param {string} currentFilter The currently search filter.\n *\n * @return {Object} Returns the relevant paging values. (totalItems, categoryPatternsList, numPages, changePage, currentPage)\n */\nexport default function usePatternsPaging(\n\tcurrentCategoryPatterns,\n\tcurrentCategory,\n\tscrollContainerRef,\n\tcurrentFilter = ''\n) {\n\tconst [ currentPage, setCurrentPage ] = useState( 1 );\n\tconst previousCategory = usePrevious( currentCategory );\n\tconst previousFilter = usePrevious( currentFilter );\n\tif (\n\t\t( previousCategory !== currentCategory ||\n\t\t\tpreviousFilter !== currentFilter ) &&\n\t\tcurrentPage !== 1\n\t) {\n\t\tsetCurrentPage( 1 );\n\t}\n\tconst totalItems = currentCategoryPatterns.length;\n\tconst pageIndex = currentPage - 1;\n\tconst categoryPatterns = useMemo( () => {\n\t\treturn currentCategoryPatterns.slice(\n\t\t\tpageIndex * PAGE_SIZE,\n\t\t\tpageIndex * PAGE_SIZE + PAGE_SIZE\n\t\t);\n\t}, [ pageIndex, currentCategoryPatterns ] );\n\tconst categoryPatternsAsyncList = useAsyncList( categoryPatterns, {\n\t\tstep: INITIAL_INSERTER_RESULTS,\n\t} );\n\tconst numPages = Math.ceil( currentCategoryPatterns.length / PAGE_SIZE );\n\tconst changePage = ( page ) => {\n\t\tconst scrollContainer = getScrollContainer(\n\t\t\tscrollContainerRef?.current\n\t\t);\n\t\tscrollContainer?.scrollTo( 0, 0 );\n\n\t\tsetCurrentPage( page );\n\t};\n\treturn {\n\t\ttotalItems,\n\t\tcategoryPatterns,\n\t\tcategoryPatternsAsyncList,\n\t\tnumPages,\n\t\tchangePage,\n\t\tcurrentPage,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;
|
|
1
|
+
{"version":3,"names":["useMemo","useState","useEffect","useAsyncList","usePrevious","getScrollContainer","PAGE_SIZE","INITIAL_INSERTER_RESULTS","usePatternsPaging","currentCategoryPatterns","currentCategory","scrollContainerRef","currentFilter","currentPage","setCurrentPage","previousCategory","previousFilter","totalItems","length","pageIndex","categoryPatterns","slice","categoryPatternsAsyncList","step","numPages","Math","ceil","changePage","page","scrollContainer","current","scrollTo","scrollToTopOnCategoryChange"],"sources":["@wordpress/block-editor/src/components/inserter/hooks/use-patterns-paging.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useState, useEffect } from '@wordpress/element';\nimport { useAsyncList, usePrevious } from '@wordpress/compose';\nimport { getScrollContainer } from '@wordpress/dom';\n\nconst PAGE_SIZE = 20;\nconst INITIAL_INSERTER_RESULTS = 5;\n\n/**\n * Supplies values needed to page the patterns list client side.\n *\n * @param {Array} currentCategoryPatterns An array of the current patterns to display.\n * @param {string} currentCategory The currently selected category.\n * @param {Object} scrollContainerRef Ref of container to to find scroll container for when moving between pages.\n * @param {string} currentFilter The currently search filter.\n *\n * @return {Object} Returns the relevant paging values. (totalItems, categoryPatternsList, numPages, changePage, currentPage)\n */\nexport default function usePatternsPaging(\n\tcurrentCategoryPatterns,\n\tcurrentCategory,\n\tscrollContainerRef,\n\tcurrentFilter = ''\n) {\n\tconst [ currentPage, setCurrentPage ] = useState( 1 );\n\tconst previousCategory = usePrevious( currentCategory );\n\tconst previousFilter = usePrevious( currentFilter );\n\tif (\n\t\t( previousCategory !== currentCategory ||\n\t\t\tpreviousFilter !== currentFilter ) &&\n\t\tcurrentPage !== 1\n\t) {\n\t\tsetCurrentPage( 1 );\n\t}\n\tconst totalItems = currentCategoryPatterns.length;\n\tconst pageIndex = currentPage - 1;\n\tconst categoryPatterns = useMemo( () => {\n\t\treturn currentCategoryPatterns.slice(\n\t\t\tpageIndex * PAGE_SIZE,\n\t\t\tpageIndex * PAGE_SIZE + PAGE_SIZE\n\t\t);\n\t}, [ pageIndex, currentCategoryPatterns ] );\n\tconst categoryPatternsAsyncList = useAsyncList( categoryPatterns, {\n\t\tstep: INITIAL_INSERTER_RESULTS,\n\t} );\n\tconst numPages = Math.ceil( currentCategoryPatterns.length / PAGE_SIZE );\n\tconst changePage = ( page ) => {\n\t\tconst scrollContainer = getScrollContainer(\n\t\t\tscrollContainerRef?.current\n\t\t);\n\t\tscrollContainer?.scrollTo( 0, 0 );\n\n\t\tsetCurrentPage( page );\n\t};\n\n\tuseEffect(\n\t\tfunction scrollToTopOnCategoryChange() {\n\t\t\tconst scrollContainer = getScrollContainer(\n\t\t\t\tscrollContainerRef?.current\n\t\t\t);\n\t\t\tscrollContainer?.scrollTo( 0, 0 );\n\t\t},\n\t\t[ currentCategory, scrollContainerRef ]\n\t);\n\n\treturn {\n\t\ttotalItems,\n\t\tcategoryPatterns,\n\t\tcategoryPatternsAsyncList,\n\t\tnumPages,\n\t\tchangePage,\n\t\tcurrentPage,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACjE,SAASC,YAAY,EAAEC,WAAW,QAAQ,oBAAoB;AAC9D,SAASC,kBAAkB,QAAQ,gBAAgB;AAEnD,MAAMC,SAAS,GAAG,EAAE;AACpB,MAAMC,wBAAwB,GAAG,CAAC;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,iBAAiBA,CACxCC,uBAAuB,EACvBC,eAAe,EACfC,kBAAkB,EAClBC,aAAa,GAAG,EAAE,EACjB;EACD,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAGb,QAAQ,CAAE,CAAE,CAAC;EACrD,MAAMc,gBAAgB,GAAGX,WAAW,CAAEM,eAAgB,CAAC;EACvD,MAAMM,cAAc,GAAGZ,WAAW,CAAEQ,aA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
|
|
29
29
|
className: "color-block-support-panel__inner-wrapper"
|
|
30
30
|
}), createElement(InspectorControls.Slot, {
|
|
31
31
|
group: "background",
|
|
32
|
-
label: __('Background
|
|
32
|
+
label: __('Background')
|
|
33
33
|
}), createElement(InspectorControls.Slot, {
|
|
34
34
|
group: "filter"
|
|
35
35
|
}), createElement(InspectorControls.Slot, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","PanelBody","__","BlockStyles","DefaultStylePicker","InspectorControls","StylesTab","blockName","clientId","hasBlockStyles","createElement","Fragment","title","Slot","group","label","className"],"sources":["@wordpress/block-editor/src/components/inspector-controls-tabs/styles-tab.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { PanelBody } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockStyles from '../block-styles';\nimport DefaultStylePicker from '../default-style-picker';\nimport InspectorControls from '../inspector-controls';\n\nconst StylesTab = ( { blockName, clientId, hasBlockStyles } ) => {\n\treturn (\n\t\t<>\n\t\t\t{ hasBlockStyles && (\n\t\t\t\t<div>\n\t\t\t\t\t<PanelBody title={ __( 'Styles' ) }>\n\t\t\t\t\t\t<BlockStyles clientId={ clientId } />\n\t\t\t\t\t\t{ hasBlockSupport(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\t'defaultStylePicker',\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t) && <DefaultStylePicker blockName={ blockName } /> }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"color\"\n\t\t\t\tlabel={ __( 'Color' ) }\n\t\t\t\tclassName=\"color-block-support-panel__inner-wrapper\"\n\t\t\t/>\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"background\"\n\t\t\t\tlabel={ __( 'Background
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","PanelBody","__","BlockStyles","DefaultStylePicker","InspectorControls","StylesTab","blockName","clientId","hasBlockStyles","createElement","Fragment","title","Slot","group","label","className"],"sources":["@wordpress/block-editor/src/components/inspector-controls-tabs/styles-tab.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { PanelBody } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockStyles from '../block-styles';\nimport DefaultStylePicker from '../default-style-picker';\nimport InspectorControls from '../inspector-controls';\n\nconst StylesTab = ( { blockName, clientId, hasBlockStyles } ) => {\n\treturn (\n\t\t<>\n\t\t\t{ hasBlockStyles && (\n\t\t\t\t<div>\n\t\t\t\t\t<PanelBody title={ __( 'Styles' ) }>\n\t\t\t\t\t\t<BlockStyles clientId={ clientId } />\n\t\t\t\t\t\t{ hasBlockSupport(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\t'defaultStylePicker',\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t) && <DefaultStylePicker blockName={ blockName } /> }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"color\"\n\t\t\t\tlabel={ __( 'Color' ) }\n\t\t\t\tclassName=\"color-block-support-panel__inner-wrapper\"\n\t\t\t/>\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"background\"\n\t\t\t\tlabel={ __( 'Background' ) }\n\t\t\t/>\n\t\t\t<InspectorControls.Slot group=\"filter\" />\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"typography\"\n\t\t\t\tlabel={ __( 'Typography' ) }\n\t\t\t/>\n\t\t\t<InspectorControls.Slot\n\t\t\t\tgroup=\"dimensions\"\n\t\t\t\tlabel={ __( 'Dimensions' ) }\n\t\t\t/>\n\t\t\t<InspectorControls.Slot group=\"border\" label={ __( 'Border' ) } />\n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AI;IACtBC,KAAK,EAAC,YAAY;IAClBC,KAAK,EAAGb,EAAE,CAAE,YAAa;EAAG,CAC5B,CAAC,EACFQ,aAAA,CAACL,iBAAiB,CAACQ,IAAI;IAACC,KAAK,EAAC,QAAQ;IAACC,KAAK,EAAGb,EAAE,CAAE,QAAS;EAAG,CAAE,CAAC,EAClEQ,aAAA,CAACL,iBAAiB,CAACQ,IAAI;IAACC,KAAK,EAAC;EAAQ,CAAE,CACvC,CAAC;AAEL,CAAC;AAED,eAAeR,SAAS"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
|
|
2
7
|
/**
|
|
3
8
|
* WordPress dependencies
|
|
4
9
|
*/
|
|
5
10
|
import { isBlobURL } from '@wordpress/blob';
|
|
6
11
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
7
|
-
import { __experimentalToolsPanelItem as ToolsPanelItem,
|
|
12
|
+
import { __experimentalToolsPanelItem as ToolsPanelItem, DropZone, FlexItem, MenuItem, VisuallyHidden, __experimentalItemGroup as ItemGroup, __experimentalHStack as HStack, __experimentalTruncate as Truncate } from '@wordpress/components';
|
|
8
13
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
9
14
|
import { Platform, useCallback } from '@wordpress/element';
|
|
10
|
-
import { __ } from '@wordpress/i18n';
|
|
15
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
11
16
|
import { store as noticesStore } from '@wordpress/notices';
|
|
12
17
|
import { getFilename } from '@wordpress/url';
|
|
13
18
|
|
|
@@ -16,8 +21,6 @@ import { getFilename } from '@wordpress/url';
|
|
|
16
21
|
*/
|
|
17
22
|
import InspectorControls from '../components/inspector-controls';
|
|
18
23
|
import MediaReplaceFlow from '../components/media-replace-flow';
|
|
19
|
-
import MediaUpload from '../components/media-upload';
|
|
20
|
-
import MediaUploadCheck from '../components/media-upload/check';
|
|
21
24
|
import useSetting from '../components/use-setting';
|
|
22
25
|
import { cleanEmptyObject } from './utils';
|
|
23
26
|
import { store as blockEditorStore } from '../store';
|
|
@@ -85,6 +88,7 @@ export function resetBackgroundImage({
|
|
|
85
88
|
}
|
|
86
89
|
function InspectorImagePreview({
|
|
87
90
|
label,
|
|
91
|
+
filename,
|
|
88
92
|
url: imgUrl
|
|
89
93
|
}) {
|
|
90
94
|
const imgLabel = label || getFilename(imgUrl);
|
|
@@ -93,15 +97,25 @@ function InspectorImagePreview({
|
|
|
93
97
|
}, createElement(HStack, {
|
|
94
98
|
justify: "flex-start",
|
|
95
99
|
as: "span"
|
|
96
|
-
}, createElement("
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
}, createElement("span", {
|
|
101
|
+
className: classnames('block-editor-hooks__background__inspector-image-indicator-wrapper', {
|
|
102
|
+
'has-image': imgUrl
|
|
103
|
+
}),
|
|
104
|
+
"aria-hidden": true
|
|
105
|
+
}, imgUrl && createElement("span", {
|
|
106
|
+
className: "block-editor-hooks__background__inspector-image-indicator",
|
|
107
|
+
style: {
|
|
108
|
+
backgroundImage: `url(${imgUrl})`
|
|
109
|
+
}
|
|
110
|
+
})), createElement(FlexItem, {
|
|
100
111
|
as: "span"
|
|
101
112
|
}, createElement(Truncate, {
|
|
102
113
|
numberOfLines: 1,
|
|
103
114
|
className: "block-editor-hooks__background__inspector-media-replace-title"
|
|
104
|
-
}, imgLabel)
|
|
115
|
+
}, imgLabel), createElement(VisuallyHidden, {
|
|
116
|
+
as: "span"
|
|
117
|
+
}, filename ? sprintf( /* translators: %s: file name */
|
|
118
|
+
__('Selected image: %s'), filename) : __('No image selected')))));
|
|
105
119
|
}
|
|
106
120
|
function BackgroundImagePanelItem(props) {
|
|
107
121
|
const {
|
|
@@ -202,33 +216,24 @@ function BackgroundImagePanelItem(props) {
|
|
|
202
216
|
panelId: clientId
|
|
203
217
|
}, createElement("div", {
|
|
204
218
|
className: "block-editor-hooks__background__inspector-media-replace-container"
|
|
205
|
-
},
|
|
219
|
+
}, createElement(MediaReplaceFlow, {
|
|
206
220
|
mediaId: id,
|
|
207
221
|
mediaURL: url,
|
|
208
222
|
allowedTypes: [IMAGE_BACKGROUND_TYPE],
|
|
209
223
|
accept: "image/*",
|
|
210
224
|
onSelect: onSelectMedia,
|
|
211
225
|
name: createElement(InspectorImagePreview, {
|
|
212
|
-
label:
|
|
226
|
+
label: __('Background image'),
|
|
227
|
+
filename: title,
|
|
213
228
|
url: url
|
|
214
229
|
}),
|
|
215
230
|
variant: "secondary"
|
|
216
231
|
}, createElement(MenuItem, {
|
|
217
232
|
onClick: () => resetBackgroundImage(props)
|
|
218
|
-
}, __('Reset '))),
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
open
|
|
223
|
-
}) => createElement("div", {
|
|
224
|
-
className: "block-editor-hooks__background__inspector-upload-container"
|
|
225
|
-
}, createElement(Button, {
|
|
226
|
-
onClick: open,
|
|
227
|
-
variant: "secondary"
|
|
228
|
-
}, __('Add background image')), createElement(DropZone, {
|
|
229
|
-
onFilesDrop: onFilesDrop
|
|
230
|
-
}))
|
|
231
|
-
}))));
|
|
233
|
+
}, __('Reset '))), createElement(DropZone, {
|
|
234
|
+
onFilesDrop: onFilesDrop,
|
|
235
|
+
label: __('Drop to upload')
|
|
236
|
+
})));
|
|
232
237
|
}
|
|
233
238
|
export function BackgroundImagePanel(props) {
|
|
234
239
|
const isBackgroundImageSupported = useSetting('background.backgroundImage') && hasBackgroundSupport(props.name, 'backgroundImage');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isBlobURL","getBlockSupport","__experimentalToolsPanelItem","ToolsPanelItem","Button","DropZone","FlexItem","MenuItem","__experimentalItemGroup","ItemGroup","__experimentalHStack","HStack","__experimentalTruncate","Truncate","useDispatch","useSelect","Platform","useCallback","__","store","noticesStore","getFilename","InspectorControls","MediaReplaceFlow","MediaUpload","MediaUploadCheck","useSetting","cleanEmptyObject","blockEditorStore","BACKGROUND_SUPPORT_KEY","IMAGE_BACKGROUND_TYPE","hasBackgroundImageValue","props","hasValue","attributes","style","background","backgroundImage","id","url","hasBackgroundSupport","blockName","feature","OS","support","resetBackgroundImage","setAttributes","undefined","InspectorImagePreview","label","imgUrl","imgLabel","createElement","as","justify","src","alt","numberOfLines","className","BackgroundImagePanelItem","clientId","title","mediaUpload","select","getSettings","createErrorNotice","onUploadError","message","type","onSelectMedia","media","newStyle","newAttributes","media_type","source","onFilesDrop","filesList","allowedTypes","onFileChange","image","onError","resetAllFilter","previousValue","onDeselect","isShownByDefault","panelId","mediaId","mediaURL","accept","onSelect","name","variant","onClick","render","open","BackgroundImagePanel","isBackgroundImageSupported","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tButton,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Platform, useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getFilename } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport MediaReplaceFlow from '../components/media-replace-flow';\nimport MediaUpload from '../components/media-upload';\nimport MediaUploadCheck from '../components/media-upload/check';\nimport useSetting from '../components/use-setting';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nexport const BACKGROUND_SUPPORT_KEY = 'background';\nexport const IMAGE_BACKGROUND_TYPE = 'image';\n\n/**\n * Checks if there is a current value in the background image block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a background image value set.\n */\nexport function hasBackgroundImageValue( props ) {\n\tconst hasValue =\n\t\t!! props.attributes.style?.background?.backgroundImage?.id ||\n\t\t!! props.attributes.style?.background?.backgroundImage?.url;\n\n\treturn hasValue;\n}\n\n/**\n * Determine whether there is block support for background.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBackgroundSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! support?.backgroundImage;\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Resets the background image block support attributes. This can be used when disabling\n * the background image controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBackgroundImage( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tbackground: {\n\t\t\t\t...style?.background,\n\t\t\t\tbackgroundImage: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction InspectorImagePreview( { label, url: imgUrl } ) {\n\tconst imgLabel = label || getFilename( imgUrl );\n\treturn (\n\t\t<ItemGroup as=\"span\">\n\t\t\t<HStack justify=\"flex-start\" as=\"span\">\n\t\t\t\t<img src={ imgUrl } alt=\"\" />\n\t\t\t\t<FlexItem as=\"span\">\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ imgLabel }\n\t\t\t\t\t</Truncate>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</ItemGroup>\n\t);\n}\n\nfunction BackgroundImagePanelItem( props ) {\n\tconst { attributes, clientId, setAttributes } = props;\n\n\tconst { id, title, url } =\n\t\tattributes.style?.background?.backgroundImage || {};\n\n\tconst { mediaUpload } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tmediaUpload: select( blockEditorStore ).getSettings().mediaUpload,\n\t\t};\n\t} );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onUploadError = ( message ) => {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t};\n\n\tconst onSelectMedia = ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tconst newStyle = {\n\t\t\t\t...attributes.style,\n\t\t\t\tbackground: {\n\t\t\t\t\t...attributes.style?.background,\n\t\t\t\t\tbackgroundImage: undefined,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst newAttributes = {\n\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t};\n\n\t\t\tsetAttributes( newAttributes );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For media selections originated from a file upload.\n\t\tif (\n\t\t\t( media.media_type &&\n\t\t\t\tmedia.media_type !== IMAGE_BACKGROUND_TYPE ) ||\n\t\t\t( ! media.media_type &&\n\t\t\t\tmedia.type &&\n\t\t\t\tmedia.type !== IMAGE_BACKGROUND_TYPE )\n\t\t) {\n\t\t\tonUploadError(\n\t\t\t\t__( 'Only images can be used as a background image.' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStyle = {\n\t\t\t...attributes.style,\n\t\t\tbackground: {\n\t\t\t\t...attributes.style?.background,\n\t\t\t\tbackgroundImage: {\n\t\t\t\t\turl: media.url,\n\t\t\t\t\tid: media.id,\n\t\t\t\t\tsource: 'file',\n\t\t\t\t\ttitle: media.title || undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tconst newAttributes = {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t};\n\n\t\tsetAttributes( newAttributes );\n\t};\n\n\tconst onFilesDrop = ( filesList ) => {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonSelectMedia( image );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tstyle: {\n\t\t\t\t...previousValue.style,\n\t\t\t\tbackground: undefined,\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tclassName=\"single-column\"\n\t\t\thasValue={ () => hasBackgroundImageValue( props ) }\n\t\t\tlabel={ __( 'Background image' ) }\n\t\t\tonDeselect={ () => resetBackgroundImage( props ) }\n\t\t\tisShownByDefault={ true }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<div className=\"block-editor-hooks__background__inspector-media-replace-container\">\n\t\t\t\t{ !! url && (\n\t\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\t\tmediaId={ id }\n\t\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\tname={\n\t\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => resetBackgroundImage( props ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset ' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MediaReplaceFlow>\n\t\t\t\t) }\n\t\t\t\t{ ! url && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<div className=\"block-editor-hooks__background__inspector-upload-container\">\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Add background image' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onFilesDrop } />\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst isBackgroundImageSupported =\n\t\tuseSetting( 'background.backgroundImage' ) &&\n\t\thasBackgroundSupport( props.name, 'backgroundImage' );\n\n\tif ( ! isBackgroundImageSupported ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t{ isBackgroundImageSupported && (\n\t\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t\t) }\n\t\t</InspectorControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SACCC,4BAA4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oBAAoB,CAAER,KAAK,CAAC0D,IAAI,EAAE,iBAAkB,CAAC;EAEtD,IAAK,CAAEM,0BAA0B,EAAG;IACnC,OAAO,IAAI;EACZ;EAEA,OACC5C,aAAA,CAAC9B,iBAAiB;IAAC2E,KAAK,EAAC;EAAY,GAClCD,0BAA0B,IAC3B5C,aAAA,CAACO,wBAAwB;IAAA,GAAM3B;EAAK,CAAI,CAEvB,CAAC;AAEtB"}
|
|
1
|
+
{"version":3,"names":["classnames","isBlobURL","getBlockSupport","__experimentalToolsPanelItem","ToolsPanelItem","DropZone","FlexItem","MenuItem","VisuallyHidden","__experimentalItemGroup","ItemGroup","__experimentalHStack","HStack","__experimentalTruncate","Truncate","useDispatch","useSelect","Platform","useCallback","__","sprintf","store","noticesStore","getFilename","InspectorControls","MediaReplaceFlow","useSetting","cleanEmptyObject","blockEditorStore","BACKGROUND_SUPPORT_KEY","IMAGE_BACKGROUND_TYPE","hasBackgroundImageValue","props","hasValue","attributes","style","background","backgroundImage","id","url","hasBackgroundSupport","blockName","feature","OS","support","resetBackgroundImage","setAttributes","undefined","InspectorImagePreview","label","filename","imgUrl","imgLabel","createElement","as","justify","className","numberOfLines","BackgroundImagePanelItem","clientId","title","mediaUpload","select","getSettings","createErrorNotice","onUploadError","message","type","onSelectMedia","media","newStyle","newAttributes","media_type","source","onFilesDrop","filesList","allowedTypes","onFileChange","image","onError","resetAllFilter","previousValue","onDeselect","isShownByDefault","panelId","mediaId","mediaURL","accept","onSelect","name","variant","onClick","BackgroundImagePanel","isBackgroundImageSupported","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\n\tVisuallyHidden,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Platform, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getFilename } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport MediaReplaceFlow from '../components/media-replace-flow';\nimport useSetting from '../components/use-setting';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nexport const BACKGROUND_SUPPORT_KEY = 'background';\nexport const IMAGE_BACKGROUND_TYPE = 'image';\n\n/**\n * Checks if there is a current value in the background image block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a background image value set.\n */\nexport function hasBackgroundImageValue( props ) {\n\tconst hasValue =\n\t\t!! props.attributes.style?.background?.backgroundImage?.id ||\n\t\t!! props.attributes.style?.background?.backgroundImage?.url;\n\n\treturn hasValue;\n}\n\n/**\n * Determine whether there is block support for background.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBackgroundSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! support?.backgroundImage;\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Resets the background image block support attributes. This can be used when disabling\n * the background image controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBackgroundImage( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tbackground: {\n\t\t\t\t...style?.background,\n\t\t\t\tbackgroundImage: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction InspectorImagePreview( { label, filename, url: imgUrl } ) {\n\tconst imgLabel = label || getFilename( imgUrl );\n\treturn (\n\t\t<ItemGroup as=\"span\">\n\t\t\t<HStack justify=\"flex-start\" as=\"span\">\n\t\t\t\t<span\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'block-editor-hooks__background__inspector-image-indicator-wrapper',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'has-image': imgUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-hidden\n\t\t\t\t>\n\t\t\t\t\t{ imgUrl && (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-image-indicator\"\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tbackgroundImage: `url(${ imgUrl })`,\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</span>\n\t\t\t\t<FlexItem as=\"span\">\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ imgLabel }\n\t\t\t\t\t</Truncate>\n\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t{ filename\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: file name */\n\t\t\t\t\t\t\t\t\t__( 'Selected image: %s' ),\n\t\t\t\t\t\t\t\t\tfilename\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __( 'No image selected' ) }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</ItemGroup>\n\t);\n}\n\nfunction BackgroundImagePanelItem( props ) {\n\tconst { attributes, clientId, setAttributes } = props;\n\n\tconst { id, title, url } =\n\t\tattributes.style?.background?.backgroundImage || {};\n\n\tconst { mediaUpload } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tmediaUpload: select( blockEditorStore ).getSettings().mediaUpload,\n\t\t};\n\t} );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onUploadError = ( message ) => {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t};\n\n\tconst onSelectMedia = ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tconst newStyle = {\n\t\t\t\t...attributes.style,\n\t\t\t\tbackground: {\n\t\t\t\t\t...attributes.style?.background,\n\t\t\t\t\tbackgroundImage: undefined,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst newAttributes = {\n\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t};\n\n\t\t\tsetAttributes( newAttributes );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For media selections originated from a file upload.\n\t\tif (\n\t\t\t( media.media_type &&\n\t\t\t\tmedia.media_type !== IMAGE_BACKGROUND_TYPE ) ||\n\t\t\t( ! media.media_type &&\n\t\t\t\tmedia.type &&\n\t\t\t\tmedia.type !== IMAGE_BACKGROUND_TYPE )\n\t\t) {\n\t\t\tonUploadError(\n\t\t\t\t__( 'Only images can be used as a background image.' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStyle = {\n\t\t\t...attributes.style,\n\t\t\tbackground: {\n\t\t\t\t...attributes.style?.background,\n\t\t\t\tbackgroundImage: {\n\t\t\t\t\turl: media.url,\n\t\t\t\t\tid: media.id,\n\t\t\t\t\tsource: 'file',\n\t\t\t\t\ttitle: media.title || undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tconst newAttributes = {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t};\n\n\t\tsetAttributes( newAttributes );\n\t};\n\n\tconst onFilesDrop = ( filesList ) => {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonSelectMedia( image );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tstyle: {\n\t\t\t\t...previousValue.style,\n\t\t\t\tbackground: undefined,\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tclassName=\"single-column\"\n\t\t\thasValue={ () => hasBackgroundImageValue( props ) }\n\t\t\tlabel={ __( 'Background image' ) }\n\t\t\tonDeselect={ () => resetBackgroundImage( props ) }\n\t\t\tisShownByDefault={ true }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<div className=\"block-editor-hooks__background__inspector-media-replace-container\">\n\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\tmediaId={ id }\n\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\tname={\n\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\tlabel={ __( 'Background image' ) }\n\t\t\t\t\t\t\tfilename={ title }\n\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t>\n\t\t\t\t\t<MenuItem onClick={ () => resetBackgroundImage( props ) }>\n\t\t\t\t\t\t{ __( 'Reset ' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MediaReplaceFlow>\n\t\t\t\t<DropZone\n\t\t\t\t\tonFilesDrop={ onFilesDrop }\n\t\t\t\t\tlabel={ __( 'Drop to upload' ) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst isBackgroundImageSupported =\n\t\tuseSetting( 'background.backgroundImage' ) &&\n\t\thasBackgroundSupport( props.name, 'backgroundImage' );\n\n\tif ( ! isBackgroundImageSupported ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t{ isBackgroundImageSupported && (\n\t\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t\t) }\n\t\t</InspectorControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SACCC,4BAA4B,IAAIC,cAAc,EAC9CC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,uBAAuB,IAAIC,SAAS,EACpCC,oBAAoB,IAAIC,MAAM,EAC9BC,sBAAsB,IAAIC,QAAQ,QAC5B,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,WAAW,QAAQ,gBAAgB;;AAE5C;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,kCAAkC;AAChE,OAAOC,gBAAgB,MAAM,kCAAkC;AAC/D,OAAOC,UAAU,MAAM,2BAA2B;AAClD,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASN,KAAK,IAAIO,gBAA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