@wordpress/patterns 2.32.0 → 2.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/api/index.js +35 -29
- package/build/api/index.js.map +7 -1
- package/build/components/allow-overrides-modal.js +149 -112
- package/build/components/allow-overrides-modal.js.map +7 -1
- package/build/components/category-selector.js +59 -38
- package/build/components/category-selector.js.map +7 -1
- package/build/components/create-pattern-modal.js +162 -111
- package/build/components/create-pattern-modal.js.map +7 -1
- package/build/components/duplicate-pattern-modal.js +85 -66
- package/build/components/duplicate-pattern-modal.js.map +7 -1
- package/build/components/index.js +50 -33
- package/build/components/index.js.map +7 -1
- package/build/components/overrides-panel.js +44 -39
- package/build/components/overrides-panel.js.map +7 -1
- package/build/components/pattern-convert-button.js +144 -133
- package/build/components/pattern-convert-button.js.map +7 -1
- package/build/components/pattern-overrides-block-controls.js +109 -109
- package/build/components/pattern-overrides-block-controls.js.map +7 -1
- package/build/components/pattern-overrides-controls.js +86 -69
- package/build/components/pattern-overrides-controls.js.map +7 -1
- package/build/components/patterns-manage-button.js +96 -97
- package/build/components/patterns-manage-button.js.map +7 -1
- package/build/components/rename-pattern-category-modal.js +122 -111
- package/build/components/rename-pattern-category-modal.js.map +7 -1
- package/build/components/rename-pattern-modal.js +95 -73
- package/build/components/rename-pattern-modal.js.map +7 -1
- package/build/components/reset-overrides-control.js +61 -57
- package/build/components/reset-overrides-control.js.map +7 -1
- package/build/constants.js +57 -23
- package/build/constants.js.map +7 -1
- package/build/index.js +27 -24
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +71 -48
- package/build/private-apis.js.map +7 -1
- package/build/private-hooks.js +57 -69
- package/build/private-hooks.js.map +7 -1
- package/build/store/actions.js +72 -85
- package/build/store/actions.js.map +7 -1
- package/build/store/constants.js +27 -10
- package/build/store/constants.js.map +7 -1
- package/build/store/index.js +50 -44
- package/build/store/index.js.map +7 -1
- package/build/store/reducer.js +30 -14
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +26 -13
- package/build/store/selectors.js.map +7 -1
- package/build-module/api/index.js +14 -25
- package/build-module/api/index.js.map +7 -1
- package/build-module/components/allow-overrides-modal.js +131 -103
- package/build-module/components/allow-overrides-modal.js.map +7 -1
- package/build-module/components/category-selector.js +35 -29
- package/build-module/components/category-selector.js.map +7 -1
- package/build-module/components/create-pattern-modal.js +137 -99
- package/build-module/components/create-pattern-modal.js.map +7 -1
- package/build-module/components/duplicate-pattern-modal.js +53 -58
- package/build-module/components/duplicate-pattern-modal.js.map +7 -1
- package/build-module/components/index.js +22 -26
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/overrides-panel.js +30 -34
- package/build-module/components/overrides-panel.js.map +7 -1
- package/build-module/components/pattern-convert-button.js +120 -125
- package/build-module/components/pattern-convert-button.js.map +7 -1
- package/build-module/components/pattern-overrides-block-controls.js +100 -103
- package/build-module/components/pattern-overrides-block-controls.js.map +7 -1
- package/build-module/components/pattern-overrides-controls.js +69 -58
- package/build-module/components/pattern-overrides-controls.js.map +7 -1
- package/build-module/components/patterns-manage-button.js +78 -91
- package/build-module/components/patterns-manage-button.js.map +7 -1
- package/build-module/components/rename-pattern-category-modal.js +106 -101
- package/build-module/components/rename-pattern-category-modal.js.map +7 -1
- package/build-module/components/rename-pattern-modal.js +80 -64
- package/build-module/components/rename-pattern-modal.js.map +7 -1
- package/build-module/components/reset-overrides-control.js +46 -51
- package/build-module/components/reset-overrides-control.js.map +7 -1
- package/build-module/constants.js +29 -18
- package/build-module/constants.js.map +7 -1
- package/build-module/index.js +6 -6
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/private-apis.js +31 -18
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-hooks.js +35 -64
- package/build-module/private-hooks.js.map +7 -1
- package/build-module/store/actions.js +44 -74
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/constants.js +5 -5
- package/build-module/store/constants.js.map +7 -1
- package/build-module/store/index.js +13 -32
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/reducer.js +9 -8
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +5 -9
- package/build-module/store/selectors.js.map +7 -1
- package/build-style/style-rtl.css +3 -138
- package/build-style/style.css +3 -138
- package/package.json +24 -17
- package/src/components/style.scss +5 -0
- package/src/style.scss +2 -1
- package/build/index.native.js +0 -18
- package/build/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -11
- package/build-module/index.native.js.map +0 -1
|
@@ -1,56 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* This hook also provides a function to find or create a pattern category.
|
|
18
|
-
*
|
|
19
|
-
* @return {Object} The merged categories map and the callback function to find or create a category.
|
|
20
|
-
*/
|
|
21
|
-
export function useAddPatternCategory() {
|
|
22
|
-
const {
|
|
23
|
-
saveEntityRecord,
|
|
24
|
-
invalidateResolution
|
|
25
|
-
} = useDispatch(coreStore);
|
|
26
|
-
const {
|
|
27
|
-
corePatternCategories,
|
|
28
|
-
userPatternCategories
|
|
29
|
-
} = useSelect(select => {
|
|
30
|
-
const {
|
|
31
|
-
getUserPatternCategories,
|
|
32
|
-
getBlockPatternCategories
|
|
33
|
-
} = select(coreStore);
|
|
34
|
-
return {
|
|
35
|
-
corePatternCategories: getBlockPatternCategories(),
|
|
36
|
-
userPatternCategories: getUserPatternCategories()
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
1
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
2
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
3
|
+
import { useMemo } from "@wordpress/element";
|
|
4
|
+
import { CATEGORY_SLUG } from "./components/category-selector";
|
|
5
|
+
function useAddPatternCategory() {
|
|
6
|
+
const { saveEntityRecord, invalidateResolution } = useDispatch(coreStore);
|
|
7
|
+
const { corePatternCategories, userPatternCategories } = useSelect(
|
|
8
|
+
(select) => {
|
|
9
|
+
const { getUserPatternCategories, getBlockPatternCategories } = select(coreStore);
|
|
10
|
+
return {
|
|
11
|
+
corePatternCategories: getBlockPatternCategories(),
|
|
12
|
+
userPatternCategories: getUserPatternCategories()
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
[]
|
|
16
|
+
);
|
|
39
17
|
const categoryMap = useMemo(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
userPatternCategories.forEach(category => {
|
|
18
|
+
const uniqueCategories = /* @__PURE__ */ new Map();
|
|
19
|
+
userPatternCategories.forEach((category) => {
|
|
43
20
|
uniqueCategories.set(category.label.toLowerCase(), {
|
|
44
21
|
label: category.label,
|
|
45
22
|
name: category.name,
|
|
46
23
|
id: category.id
|
|
47
24
|
});
|
|
48
25
|
});
|
|
49
|
-
corePatternCategories.forEach(category => {
|
|
50
|
-
if (!uniqueCategories.has(category.label.toLowerCase()) &&
|
|
51
|
-
// There are two core categories with `Post` label so explicitly remove the one with
|
|
26
|
+
corePatternCategories.forEach((category) => {
|
|
27
|
+
if (!uniqueCategories.has(category.label.toLowerCase()) && // There are two core categories with `Post` label so explicitly remove the one with
|
|
52
28
|
// the `query` slug to avoid any confusion.
|
|
53
|
-
category.name !==
|
|
29
|
+
category.name !== "query") {
|
|
54
30
|
uniqueCategories.set(category.label.toLowerCase(), {
|
|
55
31
|
label: category.label,
|
|
56
32
|
name: category.name
|
|
@@ -65,30 +41,25 @@ export function useAddPatternCategory() {
|
|
|
65
41
|
if (existingTerm?.id) {
|
|
66
42
|
return existingTerm.id;
|
|
67
43
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
const newTerm = await saveEntityRecord('taxonomy', CATEGORY_SLUG, termData, {
|
|
78
|
-
throwOnError: true
|
|
79
|
-
});
|
|
80
|
-
invalidateResolution('getUserPatternCategories');
|
|
44
|
+
const termData = existingTerm ? { name: existingTerm.label, slug: existingTerm.name } : { name: term };
|
|
45
|
+
const newTerm = await saveEntityRecord(
|
|
46
|
+
"taxonomy",
|
|
47
|
+
CATEGORY_SLUG,
|
|
48
|
+
termData,
|
|
49
|
+
{ throwOnError: true }
|
|
50
|
+
);
|
|
51
|
+
invalidateResolution("getUserPatternCategories");
|
|
81
52
|
return newTerm.id;
|
|
82
53
|
} catch (error) {
|
|
83
|
-
if (error.code !==
|
|
54
|
+
if (error.code !== "term_exists") {
|
|
84
55
|
throw error;
|
|
85
56
|
}
|
|
86
57
|
return error.data.term_id;
|
|
87
58
|
}
|
|
88
59
|
}
|
|
89
|
-
return {
|
|
90
|
-
categoryMap,
|
|
91
|
-
findOrCreateTerm
|
|
92
|
-
};
|
|
60
|
+
return { categoryMap, findOrCreateTerm };
|
|
93
61
|
}
|
|
94
|
-
|
|
62
|
+
export {
|
|
63
|
+
useAddPatternCategory
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=private-hooks.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/private-hooks.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './components/category-selector';\n\n/**\n * Helper hook that creates a Map with the core and user patterns categories\n * and removes any duplicates. It's used when we need to create new user\n * categories when creating or importing patterns.\n * This hook also provides a function to find or create a pattern category.\n *\n * @return {Object} The merged categories map and the callback function to find or create a category.\n */\nexport function useAddPatternCategory() {\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\tuserPatternCategories.forEach( ( category ) => {\n\t\t\tuniqueCategories.set( category.label.toLowerCase(), {\n\t\t\t\tlabel: category.label,\n\t\t\t\tname: category.name,\n\t\t\t\tid: category.id,\n\t\t\t} );\n\t\t} );\n\n\t\tcorePatternCategories.forEach( ( category ) => {\n\t\t\tif (\n\t\t\t\t! uniqueCategories.has( category.label.toLowerCase() ) &&\n\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\tcategory.name !== 'query'\n\t\t\t) {\n\t\t\t\tuniqueCategories.set( category.label.toLowerCase(), {\n\t\t\t\t\tlabel: category.label,\n\t\t\t\t\tname: category.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst existingTerm = categoryMap.get( term.toLowerCase() );\n\t\t\tif ( existingTerm?.id ) {\n\t\t\t\treturn existingTerm.id;\n\t\t\t}\n\t\t\t// If we have an existing core category we need to match the new user category to the\n\t\t\t// correct slug rather than autogenerating it to prevent duplicates, eg. the core `Headers`\n\t\t\t// category uses the singular `header` as the slug.\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn { categoryMap, findOrCreateTerm };\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,iBAAiB;AACnC,SAAS,eAAe;AAKxB,SAAS,qBAAqB;AAUvB,SAAS,wBAAwB;AACvC,QAAM,EAAE,kBAAkB,qBAAqB,IAAI,YAAa,SAAU;AAC1E,QAAM,EAAE,uBAAuB,sBAAsB,IAAI;AAAA,IACxD,CAAE,WAAY;AACb,YAAM,EAAE,0BAA0B,0BAA0B,IAC3D,OAAQ,SAAU;AAEnB,aAAO;AAAA,QACN,uBAAuB,0BAA0B;AAAA,QACjD,uBAAuB,yBAAyB;AAAA,MACjD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AACA,QAAM,cAAc,QAAS,MAAM;AAElC,UAAM,mBAAmB,oBAAI,IAAI;AACjC,0BAAsB,QAAS,CAAE,aAAc;AAC9C,uBAAiB,IAAK,SAAS,MAAM,YAAY,GAAG;AAAA,QACnD,OAAO,SAAS;AAAA,QAChB,MAAM,SAAS;AAAA,QACf,IAAI,SAAS;AAAA,MACd,CAAE;AAAA,IACH,CAAE;AAEF,0BAAsB,QAAS,CAAE,aAAc;AAC9C,UACC,CAAE,iBAAiB,IAAK,SAAS,MAAM,YAAY,CAAE;AAAA;AAAA,MAGrD,SAAS,SAAS,SACjB;AACD,yBAAiB,IAAK,SAAS,MAAM,YAAY,GAAG;AAAA,UACnD,OAAO,SAAS;AAAA,UAChB,MAAM,SAAS;AAAA,QAChB,CAAE;AAAA,MACH;AAAA,IACD,CAAE;AACF,WAAO;AAAA,EACR,GAAG,CAAE,uBAAuB,qBAAsB,CAAE;AAEpD,iBAAe,iBAAkB,MAAO;AACvC,QAAI;AACH,YAAM,eAAe,YAAY,IAAK,KAAK,YAAY,CAAE;AACzD,UAAK,cAAc,IAAK;AACvB,eAAO,aAAa;AAAA,MACrB;AAIA,YAAM,WAAW,eACd,EAAE,MAAM,aAAa,OAAO,MAAM,aAAa,KAAK,IACpD,EAAE,MAAM,KAAK;AAChB,YAAM,UAAU,MAAM;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,QACA,EAAE,cAAc,KAAK;AAAA,MACtB;AACA,2BAAsB,0BAA2B;AACjD,aAAO,QAAQ;AAAA,IAChB,SAAU,OAAQ;AACjB,UAAK,MAAM,SAAS,eAAgB;AACnC,cAAM;AAAA,MACP;AACA,aAAO,MAAM,KAAK;AAAA,IACnB;AAAA,EACD;AAEA,SAAO,EAAE,aAAa,iBAAiB;AACxC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,117 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
-
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
import { PATTERN_SYNC_TYPES } from '../constants';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern.
|
|
16
|
-
*
|
|
17
|
-
* @param {string} title Pattern title.
|
|
18
|
-
* @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'.
|
|
19
|
-
* @param {string|undefined} [content] Optional serialized content of blocks to convert to pattern.
|
|
20
|
-
* @param {number[]|undefined} [categories] Ids of any selected categories.
|
|
21
|
-
*/
|
|
22
|
-
export const createPattern = (title, syncType, content, categories) => async ({
|
|
23
|
-
registry
|
|
24
|
-
}) => {
|
|
1
|
+
import { getBlockType, cloneBlock } from "@wordpress/blocks";
|
|
2
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
3
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
4
|
+
import { PATTERN_SYNC_TYPES } from "../constants";
|
|
5
|
+
const createPattern = (title, syncType, content, categories) => async ({ registry }) => {
|
|
25
6
|
const meta = syncType === PATTERN_SYNC_TYPES.unsynced ? {
|
|
26
7
|
wp_pattern_sync_status: syncType
|
|
27
|
-
} :
|
|
8
|
+
} : void 0;
|
|
28
9
|
const reusableBlock = {
|
|
29
10
|
title,
|
|
30
11
|
content,
|
|
31
|
-
status:
|
|
12
|
+
status: "publish",
|
|
32
13
|
meta,
|
|
33
14
|
wp_pattern_category: categories
|
|
34
15
|
};
|
|
35
|
-
const updatedRecord = await registry.dispatch(coreStore).saveEntityRecord(
|
|
16
|
+
const updatedRecord = await registry.dispatch(coreStore).saveEntityRecord("postType", "wp_block", reusableBlock);
|
|
36
17
|
return updatedRecord;
|
|
37
18
|
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Create a pattern from a JSON file.
|
|
41
|
-
* @param {File} file The JSON file instance of the pattern.
|
|
42
|
-
* @param {number[]|undefined} [categories] Ids of any selected categories.
|
|
43
|
-
*/
|
|
44
|
-
export const createPatternFromFile = (file, categories) => async ({
|
|
45
|
-
dispatch
|
|
46
|
-
}) => {
|
|
19
|
+
const createPatternFromFile = (file, categories) => async ({ dispatch }) => {
|
|
47
20
|
const fileContent = await file.text();
|
|
48
|
-
/** @type {import('./types').PatternJSON} */
|
|
49
21
|
let parsedContent;
|
|
50
22
|
try {
|
|
51
23
|
parsedContent = JSON.parse(fileContent);
|
|
52
24
|
} catch (e) {
|
|
53
|
-
throw new Error(
|
|
25
|
+
throw new Error("Invalid JSON file");
|
|
54
26
|
}
|
|
55
|
-
if (parsedContent.__file !==
|
|
56
|
-
throw new Error(
|
|
27
|
+
if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") {
|
|
28
|
+
throw new Error("Invalid pattern JSON file");
|
|
57
29
|
}
|
|
58
|
-
const pattern = await dispatch.createPattern(
|
|
30
|
+
const pattern = await dispatch.createPattern(
|
|
31
|
+
parsedContent.title,
|
|
32
|
+
parsedContent.syncStatus,
|
|
33
|
+
parsedContent.content,
|
|
34
|
+
categories
|
|
35
|
+
);
|
|
59
36
|
return pattern;
|
|
60
37
|
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Returns a generator converting a synced pattern block into a static block.
|
|
64
|
-
*
|
|
65
|
-
* @param {string} clientId The client ID of the block to attach.
|
|
66
|
-
*/
|
|
67
|
-
export const convertSyncedPatternToStatic = clientId => ({
|
|
68
|
-
registry
|
|
69
|
-
}) => {
|
|
38
|
+
const convertSyncedPatternToStatic = (clientId) => ({ registry }) => {
|
|
70
39
|
const patternBlock = registry.select(blockEditorStore).getBlock(clientId);
|
|
71
40
|
const existingOverrides = patternBlock.attributes?.content;
|
|
72
41
|
function cloneBlocksAndRemoveBindings(blocks) {
|
|
73
|
-
return blocks.map(block => {
|
|
42
|
+
return blocks.map((block) => {
|
|
74
43
|
let metadata = block.attributes.metadata;
|
|
75
44
|
if (metadata) {
|
|
76
|
-
metadata = {
|
|
77
|
-
...metadata
|
|
78
|
-
};
|
|
45
|
+
metadata = { ...metadata };
|
|
79
46
|
delete metadata.id;
|
|
80
47
|
delete metadata.bindings;
|
|
81
|
-
// Use overridden values of the pattern block if they exist.
|
|
82
48
|
if (existingOverrides?.[metadata.name]) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
for (const [attributeName, value] of Object.entries(
|
|
50
|
+
existingOverrides[metadata.name]
|
|
51
|
+
)) {
|
|
86
52
|
if (!getBlockType(block.name)?.attributes[attributeName]) {
|
|
87
53
|
continue;
|
|
88
54
|
}
|
|
89
|
-
// Update the block attribute with the override value.
|
|
90
55
|
block.attributes[attributeName] = value;
|
|
91
56
|
}
|
|
92
57
|
}
|
|
93
58
|
}
|
|
94
|
-
return cloneBlock(
|
|
95
|
-
|
|
96
|
-
|
|
59
|
+
return cloneBlock(
|
|
60
|
+
block,
|
|
61
|
+
{
|
|
62
|
+
metadata: metadata && Object.keys(metadata).length > 0 ? metadata : void 0
|
|
63
|
+
},
|
|
64
|
+
cloneBlocksAndRemoveBindings(block.innerBlocks)
|
|
65
|
+
);
|
|
97
66
|
});
|
|
98
67
|
}
|
|
99
68
|
const patternInnerBlocks = registry.select(blockEditorStore).getBlocks(patternBlock.clientId);
|
|
100
|
-
registry.dispatch(blockEditorStore).replaceBlocks(
|
|
69
|
+
registry.dispatch(blockEditorStore).replaceBlocks(
|
|
70
|
+
patternBlock.clientId,
|
|
71
|
+
cloneBlocksAndRemoveBindings(patternInnerBlocks)
|
|
72
|
+
);
|
|
101
73
|
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Returns an action descriptor for SET_EDITING_PATTERN action.
|
|
105
|
-
*
|
|
106
|
-
* @param {string} clientId The clientID of the pattern to target.
|
|
107
|
-
* @param {boolean} isEditing Whether the block should be in editing state.
|
|
108
|
-
* @return {Object} Action descriptor.
|
|
109
|
-
*/
|
|
110
|
-
export function setEditingPattern(clientId, isEditing) {
|
|
74
|
+
function setEditingPattern(clientId, isEditing) {
|
|
111
75
|
return {
|
|
112
|
-
type:
|
|
76
|
+
type: "SET_EDITING_PATTERN",
|
|
113
77
|
clientId,
|
|
114
78
|
isEditing
|
|
115
79
|
};
|
|
116
80
|
}
|
|
117
|
-
|
|
81
|
+
export {
|
|
82
|
+
convertSyncedPatternToStatic,
|
|
83
|
+
createPattern,
|
|
84
|
+
createPatternFromFile,
|
|
85
|
+
setEditingPattern
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/actions.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\n\nimport { getBlockType, cloneBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern.\n *\n * @param {string} title Pattern title.\n * @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'.\n * @param {string|undefined} [content] Optional serialized content of blocks to convert to pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPattern =\n\t( title, syncType, content, categories ) =>\n\tasync ( { registry } ) => {\n\t\tconst meta =\n\t\t\tsyncType === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? {\n\t\t\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t\t }\n\t\t\t\t: undefined;\n\n\t\tconst reusableBlock = {\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tstatus: 'publish',\n\t\t\tmeta,\n\t\t\twp_pattern_category: categories,\n\t\t};\n\n\t\tconst updatedRecord = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEntityRecord( 'postType', 'wp_block', reusableBlock );\n\n\t\treturn updatedRecord;\n\t};\n\n/**\n * Create a pattern from a JSON file.\n * @param {File} file The JSON file instance of the pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPatternFromFile =\n\t( file, categories ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst fileContent = await file.text();\n\t\t/** @type {import('./types').PatternJSON} */\n\t\tlet parsedContent;\n\t\ttry {\n\t\t\tparsedContent = JSON.parse( fileContent );\n\t\t} catch ( e ) {\n\t\t\tthrow new Error( 'Invalid JSON file' );\n\t\t}\n\t\tif (\n\t\t\tparsedContent.__file !== 'wp_block' ||\n\t\t\t! parsedContent.title ||\n\t\t\t! parsedContent.content ||\n\t\t\ttypeof parsedContent.title !== 'string' ||\n\t\t\ttypeof parsedContent.content !== 'string' ||\n\t\t\t( parsedContent.syncStatus &&\n\t\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t\t) {\n\t\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t\t}\n\n\t\tconst pattern = await dispatch.createPattern(\n\t\t\tparsedContent.title,\n\t\t\tparsedContent.syncStatus,\n\t\t\tparsedContent.content,\n\t\t\tcategories\n\t\t);\n\n\t\treturn pattern;\n\t};\n\n/**\n * Returns a generator converting a synced pattern block into a static block.\n *\n * @param {string} clientId The client ID of the block to attach.\n */\nexport const convertSyncedPatternToStatic =\n\t( clientId ) =>\n\t( { registry } ) => {\n\t\tconst patternBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst existingOverrides = patternBlock.attributes?.content;\n\n\t\tfunction cloneBlocksAndRemoveBindings( blocks ) {\n\t\t\treturn blocks.map( ( block ) => {\n\t\t\t\tlet metadata = block.attributes.metadata;\n\t\t\t\tif ( metadata ) {\n\t\t\t\t\tmetadata = { ...metadata };\n\t\t\t\t\tdelete metadata.id;\n\t\t\t\t\tdelete metadata.bindings;\n\t\t\t\t\t// Use overridden values of the pattern block if they exist.\n\t\t\t\t\tif ( existingOverrides?.[ metadata.name ] ) {\n\t\t\t\t\t\t// Iterate over each overridden attribute.\n\t\t\t\t\t\tfor ( const [ attributeName, value ] of Object.entries(\n\t\t\t\t\t\t\texistingOverrides[ metadata.name ]\n\t\t\t\t\t\t) ) {\n\t\t\t\t\t\t\t// Skip if the attribute does not exist in the block type.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t! getBlockType( block.name )?.attributes[\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Update the block attribute with the override value.\n\t\t\t\t\t\t\tblock.attributes[ attributeName ] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn cloneBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t{\n\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\tmetadata && Object.keys( metadata ).length > 0\n\t\t\t\t\t\t\t\t? metadata\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t\tcloneBlocksAndRemoveBindings( block.innerBlocks )\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\tconst patternInnerBlocks = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlocks( patternBlock.clientId );\n\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks(\n\t\t\t\tpatternBlock.clientId,\n\t\t\t\tcloneBlocksAndRemoveBindings( patternInnerBlocks )\n\t\t\t);\n\t};\n\n/**\n * Returns an action descriptor for SET_EDITING_PATTERN action.\n *\n * @param {string} clientId The clientID of the pattern to target.\n * @param {boolean} isEditing Whether the block should be in editing state.\n * @return {Object} Action descriptor.\n */\nexport function setEditingPattern( clientId, isEditing ) {\n\treturn {\n\t\ttype: 'SET_EDITING_PATTERN',\n\t\tclientId,\n\t\tisEditing,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,cAAc,kBAAkB;AACzC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,wBAAwB;AAK1C,SAAS,0BAA0B;AAU5B,MAAM,gBACZ,CAAE,OAAO,UAAU,SAAS,eAC5B,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,OACL,aAAa,mBAAmB,WAC7B;AAAA,IACA,wBAAwB;AAAA,EACxB,IACA;AAEJ,QAAM,gBAAgB;AAAA,IACrB;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,qBAAqB;AAAA,EACtB;AAEA,QAAM,gBAAgB,MAAM,SAC1B,SAAU,SAAU,EACpB,iBAAkB,YAAY,YAAY,aAAc;AAE1D,SAAO;AACR;AAOM,MAAM,wBACZ,CAAE,MAAM,eACR,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,cAAc,MAAM,KAAK,KAAK;AAEpC,MAAI;AACJ,MAAI;AACH,oBAAgB,KAAK,MAAO,WAAY;AAAA,EACzC,SAAU,GAAI;AACb,UAAM,IAAI,MAAO,mBAAoB;AAAA,EACtC;AACA,MACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UACpC;AACD,UAAM,IAAI,MAAO,2BAA4B;AAAA,EAC9C;AAEA,QAAM,UAAU,MAAM,SAAS;AAAA,IAC9B,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,IACd;AAAA,EACD;AAEA,SAAO;AACR;AAOM,MAAM,+BACZ,CAAE,aACF,CAAE,EAAE,SAAS,MAAO;AACnB,QAAM,eAAe,SACnB,OAAQ,gBAAiB,EACzB,SAAU,QAAS;AACrB,QAAM,oBAAoB,aAAa,YAAY;AAEnD,WAAS,6BAA8B,QAAS;AAC/C,WAAO,OAAO,IAAK,CAAE,UAAW;AAC/B,UAAI,WAAW,MAAM,WAAW;AAChC,UAAK,UAAW;AACf,mBAAW,EAAE,GAAG,SAAS;AACzB,eAAO,SAAS;AAChB,eAAO,SAAS;AAEhB,YAAK,oBAAqB,SAAS,IAAK,GAAI;AAE3C,qBAAY,CAAE,eAAe,KAAM,KAAK,OAAO;AAAA,YAC9C,kBAAmB,SAAS,IAAK;AAAA,UAClC,GAAI;AAEH,gBACC,CAAE,aAAc,MAAM,IAAK,GAAG,WAC7B,aACD,GACC;AACD;AAAA,YACD;AAEA,kBAAM,WAAY,aAAc,IAAI;AAAA,UACrC;AAAA,QACD;AAAA,MACD;AACA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,UACC,UACC,YAAY,OAAO,KAAM,QAAS,EAAE,SAAS,IAC1C,WACA;AAAA,QACL;AAAA,QACA,6BAA8B,MAAM,WAAY;AAAA,MACjD;AAAA,IACD,CAAE;AAAA,EACH;AAEA,QAAM,qBAAqB,SACzB,OAAQ,gBAAiB,EACzB,UAAW,aAAa,QAAS;AAEnC,WACE,SAAU,gBAAiB,EAC3B;AAAA,IACA,aAAa;AAAA,IACb,6BAA8B,kBAAmB;AAAA,EAClD;AACF;AASM,SAAS,kBAAmB,UAAU,WAAY;AACxD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
const STORE_NAME = "core/patterns";
|
|
2
|
+
export {
|
|
3
|
+
STORE_NAME
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/constants.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Module Constants\n */\nexport const STORE_NAME = 'core/patterns';\n"],
|
|
5
|
+
"mappings": "AAGO,MAAM,aAAa;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
import reducer from './reducer';
|
|
10
|
-
import * as actions from './actions';
|
|
11
|
-
import { STORE_NAME } from './constants';
|
|
12
|
-
import * as selectors from './selectors';
|
|
13
|
-
import { unlock } from '../lock-unlock';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Post editor data store configuration.
|
|
17
|
-
*
|
|
18
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
|
|
19
|
-
*
|
|
20
|
-
* @type {Object}
|
|
21
|
-
*/
|
|
22
|
-
export const storeConfig = {
|
|
1
|
+
import { createReduxStore, register } from "@wordpress/data";
|
|
2
|
+
import reducer from "./reducer";
|
|
3
|
+
import * as actions from "./actions";
|
|
4
|
+
import { STORE_NAME } from "./constants";
|
|
5
|
+
import * as selectors from "./selectors";
|
|
6
|
+
import { unlock } from "../lock-unlock";
|
|
7
|
+
const storeConfig = {
|
|
23
8
|
reducer
|
|
24
9
|
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Store definition for the editor namespace.
|
|
28
|
-
*
|
|
29
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
30
|
-
*
|
|
31
|
-
* @type {Object}
|
|
32
|
-
*/
|
|
33
|
-
export const store = createReduxStore(STORE_NAME, {
|
|
10
|
+
const store = createReduxStore(STORE_NAME, {
|
|
34
11
|
...storeConfig
|
|
35
12
|
});
|
|
36
13
|
register(store);
|
|
37
14
|
unlock(store).registerPrivateActions(actions);
|
|
38
15
|
unlock(store).registerPrivateSelectors(selectors);
|
|
39
|
-
|
|
16
|
+
export {
|
|
17
|
+
store,
|
|
18
|
+
storeConfig
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport { STORE_NAME } from './constants';\nimport * as selectors from './selectors';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Post editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore\n *\n * @type {Object}\n */\nexport const storeConfig = {\n\treducer,\n};\n\n/**\n * Store definition for the editor namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\t...storeConfig,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( actions );\nunlock( store ).registerPrivateSelectors( selectors );\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,aAAa;AACzB,SAAS,kBAAkB;AAC3B,YAAY,eAAe;AAC3B,SAAS,cAAc;AAShB,MAAM,cAAc;AAAA,EAC1B;AACD;AASO,MAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD,GAAG;AACJ,CAAE;AAEF,SAAU,KAAM;AAChB,OAAQ,KAAM,EAAE,uBAAwB,OAAQ;AAChD,OAAQ,KAAM,EAAE,yBAA0B,SAAU;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { combineReducers } from '@wordpress/data';
|
|
5
|
-
export function isEditingPattern(state = {}, action) {
|
|
6
|
-
if (action?.type === 'SET_EDITING_PATTERN') {
|
|
1
|
+
import { combineReducers } from "@wordpress/data";
|
|
2
|
+
function isEditingPattern(state = {}, action) {
|
|
3
|
+
if (action?.type === "SET_EDITING_PATTERN") {
|
|
7
4
|
return {
|
|
8
5
|
...state,
|
|
9
6
|
[action.clientId]: action.isEditing
|
|
@@ -11,7 +8,11 @@ export function isEditingPattern(state = {}, action) {
|
|
|
11
8
|
}
|
|
12
9
|
return state;
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
var reducer_default = combineReducers({
|
|
15
12
|
isEditingPattern
|
|
16
13
|
});
|
|
17
|
-
|
|
14
|
+
export {
|
|
15
|
+
reducer_default as default,
|
|
16
|
+
isEditingPattern
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/reducer.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\nexport function isEditingPattern( state = {}, action ) {\n\tif ( action?.type === 'SET_EDITING_PATTERN' ) {\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ action.clientId ]: action.isEditing,\n\t\t};\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tisEditingPattern,\n} );\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAEzB,SAAS,iBAAkB,QAAQ,CAAC,GAAG,QAAS;AACtD,MAAK,QAAQ,SAAS,uBAAwB;AAC7C,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,OAAO,QAAS,GAAG,OAAO;AAAA,IAC7B;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,kBAAQ,gBAAiB;AAAA,EAC/B;AACD,CAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* Returns true if pattern is in the editing state.
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} state Global application state.
|
|
5
|
-
* @param {number} clientId the clientID of the block.
|
|
6
|
-
* @return {boolean} Whether the pattern is in the editing state.
|
|
7
|
-
*/
|
|
8
|
-
export function isEditingPattern(state, clientId) {
|
|
1
|
+
function isEditingPattern(state, clientId) {
|
|
9
2
|
return state.isEditingPattern[clientId];
|
|
10
3
|
}
|
|
11
|
-
|
|
4
|
+
export {
|
|
5
|
+
isEditingPattern
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/selectors.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Returns true if pattern is in the editing state.\n *\n * @param {Object} state Global application state.\n * @param {number} clientId the clientID of the block.\n * @return {boolean} Whether the pattern is in the editing state.\n */\nexport function isEditingPattern( state, clientId ) {\n\treturn state.isEditingPattern[ clientId ];\n}\n"],
|
|
5
|
+
"mappings": "AAOO,SAAS,iBAAkB,OAAO,UAAW;AACnD,SAAO,MAAM,iBAAkB,QAAS;AACzC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|