@wordpress/reusable-blocks 5.32.0 → 5.32.1-next.47f435fc9.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/components/index.js +36 -12
- package/build/components/index.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/index.js +51 -34
- package/build/components/reusable-blocks-menu-items/index.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js +189 -150
- package/build/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +7 -1
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +65 -72
- package/build/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +7 -1
- package/build/index.js +27 -24
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +30 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/store/actions.js +74 -81
- package/build/store/actions.js.map +7 -1
- package/build/store/index.js +44 -33
- 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/components/index.js +5 -2
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/index.js +23 -27
- package/build-module/components/reusable-blocks-menu-items/index.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js +178 -145
- package/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js.map +7 -1
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +47 -66
- package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map +7 -1
- package/build-module/index.js +6 -3
- 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/store/actions.js +50 -68
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/index.js +10 -22
- 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 +21 -14
- package/src/components/reusable-blocks-menu-items/style.scss +2 -0
- package/src/style.scss +2 -1
- package/build/components/reusable-blocks-menu-items/index.native.js +0 -9
- package/build/components/reusable-blocks-menu-items/index.native.js.map +0 -1
- package/build/index.native.js +0 -29
- package/build/index.native.js.map +0 -1
- package/build-module/components/reusable-blocks-menu-items/index.native.js +0 -2
- package/build-module/components/reusable-blocks-menu-items/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -7
- package/build-module/index.native.js.map +0 -1
|
@@ -1,70 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { store as
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}),
|
|
40
|
-
// The site editor and templates both check whether the user
|
|
41
|
-
// has edit_theme_options capabilities. We can leverage that here
|
|
42
|
-
// and omit the manage patterns link if the user can't access it.
|
|
43
|
-
managePatternsUrl: canUser('create', {
|
|
44
|
-
kind: 'postType',
|
|
45
|
-
name: 'wp_template'
|
|
46
|
-
}) ? addQueryArgs('site-editor.php', {
|
|
47
|
-
p: '/pattern'
|
|
48
|
-
}) : addQueryArgs('edit.php', {
|
|
49
|
-
post_type: 'wp_block'
|
|
50
|
-
})
|
|
51
|
-
};
|
|
52
|
-
}, [clientId]);
|
|
53
|
-
const {
|
|
54
|
-
__experimentalConvertBlockToStatic: convertBlockToStatic
|
|
55
|
-
} = useDispatch(reusableBlocksStore);
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MenuItem } from "@wordpress/components";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import { isReusableBlock } from "@wordpress/blocks";
|
|
5
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
6
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
7
|
+
import { addQueryArgs } from "@wordpress/url";
|
|
8
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
9
|
+
import { store as reusableBlocksStore } from "../../store";
|
|
10
|
+
function ReusableBlocksManageButton({ clientId }) {
|
|
11
|
+
const { canRemove, isVisible, managePatternsUrl } = useSelect(
|
|
12
|
+
(select) => {
|
|
13
|
+
const { getBlock, canRemoveBlock } = select(blockEditorStore);
|
|
14
|
+
const { canUser } = select(coreStore);
|
|
15
|
+
const reusableBlock = getBlock(clientId);
|
|
16
|
+
return {
|
|
17
|
+
canRemove: canRemoveBlock(clientId),
|
|
18
|
+
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser("update", {
|
|
19
|
+
kind: "postType",
|
|
20
|
+
name: "wp_block",
|
|
21
|
+
id: reusableBlock.attributes.ref
|
|
22
|
+
}),
|
|
23
|
+
// The site editor and templates both check whether the user
|
|
24
|
+
// has edit_theme_options capabilities. We can leverage that here
|
|
25
|
+
// and omit the manage patterns link if the user can't access it.
|
|
26
|
+
managePatternsUrl: canUser("create", {
|
|
27
|
+
kind: "postType",
|
|
28
|
+
name: "wp_template"
|
|
29
|
+
}) ? addQueryArgs("site-editor.php", {
|
|
30
|
+
p: "/pattern"
|
|
31
|
+
}) : addQueryArgs("edit.php", {
|
|
32
|
+
post_type: "wp_block"
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
[clientId]
|
|
37
|
+
);
|
|
38
|
+
const { __experimentalConvertBlockToStatic: convertBlockToStatic } = useDispatch(reusableBlocksStore);
|
|
56
39
|
if (!isVisible) {
|
|
57
40
|
return null;
|
|
58
41
|
}
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}), canRemove && /*#__PURE__*/_jsx(MenuItem, {
|
|
64
|
-
onClick: () => convertBlockToStatic(clientId),
|
|
65
|
-
children: __('Detach')
|
|
66
|
-
})]
|
|
67
|
-
});
|
|
42
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
43
|
+
/* @__PURE__ */ jsx(MenuItem, { href: managePatternsUrl, children: __("Manage patterns") }),
|
|
44
|
+
canRemove && /* @__PURE__ */ jsx(MenuItem, { onClick: () => convertBlockToStatic(clientId), children: __("Detach") })
|
|
45
|
+
] });
|
|
68
46
|
}
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
var reusable_blocks_manage_button_default = ReusableBlocksManageButton;
|
|
48
|
+
export {
|
|
49
|
+
reusable_blocks_manage_button_default as default
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=reusable-blocks-manage-button.js.map
|
package/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as reusableBlocksStore } from '../../store';\n\nfunction ReusableBlocksManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock } = select( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\t\tid: reusableBlock.attributes.ref,\n\t\t\t\t\t} ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tp: '/pattern',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { __experimentalConvertBlockToStatic: convertBlockToStatic } =\n\t\tuseDispatch( reusableBlocksStore );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem onClick={ () => convertBlockToStatic( clientId ) }>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default ReusableBlocksManageButton;\n"],
|
|
5
|
+
"mappings": "AA2DE,mBACC,KADD;AAxDF,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAChC,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,oBAAoB;AAC7B,SAAS,SAAS,iBAAiB;AAKnC,SAAS,SAAS,2BAA2B;AAE7C,SAAS,2BAA4B,EAAE,SAAS,GAAI;AACnD,QAAM,EAAE,WAAW,WAAW,kBAAkB,IAAI;AAAA,IACnD,CAAE,WAAY;AACb,YAAM,EAAE,UAAU,eAAe,IAAI,OAAQ,gBAAiB;AAC9D,YAAM,EAAE,QAAQ,IAAI,OAAQ,SAAU;AACtC,YAAM,gBAAgB,SAAU,QAAS;AAEzC,aAAO;AAAA,QACN,WAAW,eAAgB,QAAS;AAAA,QACpC,WACC,CAAC,CAAE,iBACH,gBAAiB,aAAc,KAC/B,CAAC,CAAE,QAAS,UAAU;AAAA,UACrB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,IAAI,cAAc,WAAW;AAAA,QAC9B,CAAE;AAAA;AAAA;AAAA;AAAA,QAIH,mBAAmB,QAAS,UAAU;AAAA,UACrC,MAAM;AAAA,UACN,MAAM;AAAA,QACP,CAAE,IACC,aAAc,mBAAmB;AAAA,UACjC,GAAG;AAAA,QACH,CAAE,IACF,aAAc,YAAY;AAAA,UAC1B,WAAW;AAAA,QACX,CAAE;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,QAAM,EAAE,oCAAoC,qBAAqB,IAChE,YAAa,mBAAoB;AAElC,MAAK,CAAE,WAAY;AAClB,WAAO;AAAA,EACR;AAEA,SACC,iCACC;AAAA,wBAAC,YAAS,MAAO,mBACd,aAAI,iBAAkB,GACzB;AAAA,IACE,aACD,oBAAC,YAAS,SAAU,MAAM,qBAAsB,QAAS,GACtD,aAAI,QAAS,GAChB;AAAA,KAEF;AAEF;AAEA,IAAO,wCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["export { store } from './store';\nexport * from './components';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
2
|
+
const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
3
|
+
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
4
|
+
"@wordpress/reusable-blocks"
|
|
5
|
+
);
|
|
6
|
+
export {
|
|
6
7
|
unlock
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=lock-unlock.js.map
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t'@wordpress/reusable-blocks'\n);\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wDAAwD;AAE1D,MAAM,EAAE,OAAO,IAAI;AAAA,EACzB;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,94 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param {string} clientId The client ID of the block to attach.
|
|
12
|
-
*/
|
|
13
|
-
export const __experimentalConvertBlockToStatic = clientId => ({
|
|
14
|
-
registry
|
|
15
|
-
}) => {
|
|
1
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
2
|
+
import {
|
|
3
|
+
createBlock,
|
|
4
|
+
isReusableBlock,
|
|
5
|
+
parse,
|
|
6
|
+
serialize
|
|
7
|
+
} from "@wordpress/blocks";
|
|
8
|
+
import { __ } from "@wordpress/i18n";
|
|
9
|
+
const __experimentalConvertBlockToStatic = (clientId) => ({ registry }) => {
|
|
16
10
|
const oldBlock = registry.select(blockEditorStore).getBlock(clientId);
|
|
17
|
-
const reusableBlock = registry.select(
|
|
18
|
-
|
|
11
|
+
const reusableBlock = registry.select("core").getEditedEntityRecord(
|
|
12
|
+
"postType",
|
|
13
|
+
"wp_block",
|
|
14
|
+
oldBlock.attributes.ref
|
|
15
|
+
);
|
|
16
|
+
const newBlocks = parse(
|
|
17
|
+
typeof reusableBlock.content === "function" ? reusableBlock.content(reusableBlock) : reusableBlock.content
|
|
18
|
+
);
|
|
19
19
|
registry.dispatch(blockEditorStore).replaceBlocks(oldBlock.clientId, newBlocks);
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Returns a generator converting one or more static blocks into a pattern.
|
|
24
|
-
*
|
|
25
|
-
* @param {string[]} clientIds The client IDs of the block to detach.
|
|
26
|
-
* @param {string} title Pattern title.
|
|
27
|
-
* @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'.
|
|
28
|
-
*/
|
|
29
|
-
export const __experimentalConvertBlocksToReusable = (clientIds, title, syncType) => async ({
|
|
30
|
-
registry,
|
|
31
|
-
dispatch
|
|
32
|
-
}) => {
|
|
33
|
-
const meta = syncType === 'unsynced' ? {
|
|
21
|
+
const __experimentalConvertBlocksToReusable = (clientIds, title, syncType) => async ({ registry, dispatch }) => {
|
|
22
|
+
const meta = syncType === "unsynced" ? {
|
|
34
23
|
wp_pattern_sync_status: syncType
|
|
35
|
-
} :
|
|
24
|
+
} : void 0;
|
|
36
25
|
const reusableBlock = {
|
|
37
|
-
title: title || __(
|
|
38
|
-
content: serialize(
|
|
39
|
-
|
|
26
|
+
title: title || __("Untitled pattern block"),
|
|
27
|
+
content: serialize(
|
|
28
|
+
registry.select(blockEditorStore).getBlocksByClientId(clientIds)
|
|
29
|
+
),
|
|
30
|
+
status: "publish",
|
|
40
31
|
meta
|
|
41
32
|
};
|
|
42
|
-
const updatedRecord = await registry.dispatch(
|
|
43
|
-
if (syncType ===
|
|
33
|
+
const updatedRecord = await registry.dispatch("core").saveEntityRecord("postType", "wp_block", reusableBlock);
|
|
34
|
+
if (syncType === "unsynced") {
|
|
44
35
|
return;
|
|
45
36
|
}
|
|
46
|
-
const newBlock = createBlock(
|
|
37
|
+
const newBlock = createBlock("core/block", {
|
|
47
38
|
ref: updatedRecord.id
|
|
48
39
|
});
|
|
49
40
|
registry.dispatch(blockEditorStore).replaceBlocks(clientIds, newBlock);
|
|
50
|
-
dispatch.__experimentalSetEditingReusableBlock(
|
|
41
|
+
dispatch.__experimentalSetEditingReusableBlock(
|
|
42
|
+
newBlock.clientId,
|
|
43
|
+
true
|
|
44
|
+
);
|
|
51
45
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* Returns a generator deleting a reusable block.
|
|
55
|
-
*
|
|
56
|
-
* @param {string} id The ID of the reusable block to delete.
|
|
57
|
-
*/
|
|
58
|
-
export const __experimentalDeleteReusableBlock = id => async ({
|
|
59
|
-
registry
|
|
60
|
-
}) => {
|
|
61
|
-
const reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', id);
|
|
62
|
-
|
|
63
|
-
// Don't allow a reusable block with a temporary ID to be deleted.
|
|
46
|
+
const __experimentalDeleteReusableBlock = (id) => async ({ registry }) => {
|
|
47
|
+
const reusableBlock = registry.select("core").getEditedEntityRecord("postType", "wp_block", id);
|
|
64
48
|
if (!reusableBlock) {
|
|
65
49
|
return;
|
|
66
50
|
}
|
|
67
|
-
|
|
68
|
-
// Remove any other blocks that reference this reusable block.
|
|
69
51
|
const allBlocks = registry.select(blockEditorStore).getBlocks();
|
|
70
|
-
const associatedBlocks = allBlocks.filter(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
const associatedBlocks = allBlocks.filter(
|
|
53
|
+
(block) => isReusableBlock(block) && block.attributes.ref === id
|
|
54
|
+
);
|
|
55
|
+
const associatedBlockClientIds = associatedBlocks.map(
|
|
56
|
+
(block) => block.clientId
|
|
57
|
+
);
|
|
74
58
|
if (associatedBlockClientIds.length) {
|
|
75
59
|
registry.dispatch(blockEditorStore).removeBlocks(associatedBlockClientIds);
|
|
76
60
|
}
|
|
77
|
-
await registry.dispatch(
|
|
61
|
+
await registry.dispatch("core").deleteEntityRecord("postType", "wp_block", id);
|
|
78
62
|
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns an action descriptor for SET_EDITING_REUSABLE_BLOCK action.
|
|
82
|
-
*
|
|
83
|
-
* @param {string} clientId The clientID of the reusable block to target.
|
|
84
|
-
* @param {boolean} isEditing Whether the block should be in editing state.
|
|
85
|
-
* @return {Object} Action descriptor.
|
|
86
|
-
*/
|
|
87
|
-
export function __experimentalSetEditingReusableBlock(clientId, isEditing) {
|
|
63
|
+
function __experimentalSetEditingReusableBlock(clientId, isEditing) {
|
|
88
64
|
return {
|
|
89
|
-
type:
|
|
65
|
+
type: "SET_EDITING_REUSABLE_BLOCK",
|
|
90
66
|
clientId,
|
|
91
67
|
isEditing
|
|
92
68
|
};
|
|
93
69
|
}
|
|
94
|
-
|
|
70
|
+
export {
|
|
71
|
+
__experimentalConvertBlockToStatic,
|
|
72
|
+
__experimentalConvertBlocksToReusable,
|
|
73
|
+
__experimentalDeleteReusableBlock,
|
|
74
|
+
__experimentalSetEditingReusableBlock
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/actions.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tcreateBlock,\n\tisReusableBlock,\n\tparse,\n\tserialize,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Returns a generator converting a reusable block into a static block.\n *\n * @param {string} clientId The client ID of the block to attach.\n */\nexport const __experimentalConvertBlockToStatic =\n\t( clientId ) =>\n\t( { registry } ) => {\n\t\tconst oldBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst reusableBlock = registry\n\t\t\t.select( 'core' )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\toldBlock.attributes.ref\n\t\t\t);\n\n\t\tconst newBlocks = parse(\n\t\t\ttypeof reusableBlock.content === 'function'\n\t\t\t\t? reusableBlock.content( reusableBlock )\n\t\t\t\t: reusableBlock.content\n\t\t);\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks( oldBlock.clientId, newBlocks );\n\t};\n\n/**\n * Returns a generator converting one or more static blocks into a pattern.\n *\n * @param {string[]} clientIds The client IDs of the block to detach.\n * @param {string} title Pattern title.\n * @param {undefined|'unsynced'} syncType They way block is synced, current undefined (synced) and 'unsynced'.\n */\nexport const __experimentalConvertBlocksToReusable =\n\t( clientIds, title, syncType ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst meta =\n\t\t\tsyncType === '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: title || __( 'Untitled pattern block' ),\n\t\t\tcontent: serialize(\n\t\t\t\tregistry\n\t\t\t\t\t.select( blockEditorStore )\n\t\t\t\t\t.getBlocksByClientId( clientIds )\n\t\t\t),\n\t\t\tstatus: 'publish',\n\t\t\tmeta,\n\t\t};\n\n\t\tconst updatedRecord = await registry\n\t\t\t.dispatch( 'core' )\n\t\t\t.saveEntityRecord( 'postType', 'wp_block', reusableBlock );\n\n\t\tif ( syncType === 'unsynced' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\tref: updatedRecord.id,\n\t\t} );\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks( clientIds, newBlock );\n\t\tdispatch.__experimentalSetEditingReusableBlock(\n\t\t\tnewBlock.clientId,\n\t\t\ttrue\n\t\t);\n\t};\n\n/**\n * Returns a generator deleting a reusable block.\n *\n * @param {string} id The ID of the reusable block to delete.\n */\nexport const __experimentalDeleteReusableBlock =\n\t( id ) =>\n\tasync ( { registry } ) => {\n\t\tconst reusableBlock = registry\n\t\t\t.select( 'core' )\n\t\t\t.getEditedEntityRecord( 'postType', 'wp_block', id );\n\n\t\t// Don't allow a reusable block with a temporary ID to be deleted.\n\t\tif ( ! reusableBlock ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove any other blocks that reference this reusable block.\n\t\tconst allBlocks = registry.select( blockEditorStore ).getBlocks();\n\t\tconst associatedBlocks = allBlocks.filter(\n\t\t\t( block ) => isReusableBlock( block ) && block.attributes.ref === id\n\t\t);\n\t\tconst associatedBlockClientIds = associatedBlocks.map(\n\t\t\t( block ) => block.clientId\n\t\t);\n\n\t\t// Remove the parsed block.\n\t\tif ( associatedBlockClientIds.length ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( blockEditorStore )\n\t\t\t\t.removeBlocks( associatedBlockClientIds );\n\t\t}\n\n\t\tawait registry\n\t\t\t.dispatch( 'core' )\n\t\t\t.deleteEntityRecord( 'postType', 'wp_block', id );\n\t};\n\n/**\n * Returns an action descriptor for SET_EDITING_REUSABLE_BLOCK action.\n *\n * @param {string} clientId The clientID of the reusable block to target.\n * @param {boolean} isEditing Whether the block should be in editing state.\n * @return {Object} Action descriptor.\n */\nexport function __experimentalSetEditingReusableBlock( clientId, isEditing ) {\n\treturn {\n\t\ttype: 'SET_EDITING_REUSABLE_BLOCK',\n\t\tclientId,\n\t\tisEditing,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,SAAS,wBAAwB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAOZ,MAAM,qCACZ,CAAE,aACF,CAAE,EAAE,SAAS,MAAO;AACnB,QAAM,WAAW,SACf,OAAQ,gBAAiB,EACzB,SAAU,QAAS;AACrB,QAAM,gBAAgB,SACpB,OAAQ,MAAO,EACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,WAAW;AAAA,EACrB;AAED,QAAM,YAAY;AAAA,IACjB,OAAO,cAAc,YAAY,aAC9B,cAAc,QAAS,aAAc,IACrC,cAAc;AAAA,EAClB;AACA,WACE,SAAU,gBAAiB,EAC3B,cAAe,SAAS,UAAU,SAAU;AAC/C;AASM,MAAM,wCACZ,CAAE,WAAW,OAAO,aACpB,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,QAAM,OACL,aAAa,aACV;AAAA,IACA,wBAAwB;AAAA,EACxB,IACA;AAEJ,QAAM,gBAAgB;AAAA,IACrB,OAAO,SAAS,GAAI,wBAAyB;AAAA,IAC7C,SAAS;AAAA,MACR,SACE,OAAQ,gBAAiB,EACzB,oBAAqB,SAAU;AAAA,IAClC;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EACD;AAEA,QAAM,gBAAgB,MAAM,SAC1B,SAAU,MAAO,EACjB,iBAAkB,YAAY,YAAY,aAAc;AAE1D,MAAK,aAAa,YAAa;AAC9B;AAAA,EACD;AAEA,QAAM,WAAW,YAAa,cAAc;AAAA,IAC3C,KAAK,cAAc;AAAA,EACpB,CAAE;AACF,WACE,SAAU,gBAAiB,EAC3B,cAAe,WAAW,QAAS;AACrC,WAAS;AAAA,IACR,SAAS;AAAA,IACT;AAAA,EACD;AACD;AAOM,MAAM,oCACZ,CAAE,OACF,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,gBAAgB,SACpB,OAAQ,MAAO,EACf,sBAAuB,YAAY,YAAY,EAAG;AAGpD,MAAK,CAAE,eAAgB;AACtB;AAAA,EACD;AAGA,QAAM,YAAY,SAAS,OAAQ,gBAAiB,EAAE,UAAU;AAChE,QAAM,mBAAmB,UAAU;AAAA,IAClC,CAAE,UAAW,gBAAiB,KAAM,KAAK,MAAM,WAAW,QAAQ;AAAA,EACnE;AACA,QAAM,2BAA2B,iBAAiB;AAAA,IACjD,CAAE,UAAW,MAAM;AAAA,EACpB;AAGA,MAAK,yBAAyB,QAAS;AACtC,aACE,SAAU,gBAAiB,EAC3B,aAAc,wBAAyB;AAAA,EAC1C;AAEA,QAAM,SACJ,SAAU,MAAO,EACjB,mBAAoB,YAAY,YAAY,EAAG;AAClD;AASM,SAAS,sCAAuC,UAAU,WAAY;AAC5E,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import * as actions from './actions';
|
|
10
|
-
import reducer from './reducer';
|
|
11
|
-
import * as selectors from './selectors';
|
|
12
|
-
const STORE_NAME = 'core/reusable-blocks';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Store definition for the reusable blocks namespace.
|
|
16
|
-
*
|
|
17
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
18
|
-
*
|
|
19
|
-
* @type {Object}
|
|
20
|
-
*/
|
|
21
|
-
export const store = createReduxStore(STORE_NAME, {
|
|
1
|
+
import { createReduxStore, register } from "@wordpress/data";
|
|
2
|
+
import * as actions from "./actions";
|
|
3
|
+
import reducer from "./reducer";
|
|
4
|
+
import * as selectors from "./selectors";
|
|
5
|
+
const STORE_NAME = "core/reusable-blocks";
|
|
6
|
+
const store = createReduxStore(STORE_NAME, {
|
|
22
7
|
actions,
|
|
23
8
|
reducer,
|
|
24
9
|
selectors
|
|
25
10
|
});
|
|
26
11
|
register(store);
|
|
27
|
-
|
|
12
|
+
export {
|
|
13
|
+
store
|
|
14
|
+
};
|
|
15
|
+
//# 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 * as actions from './actions';\nimport reducer from './reducer';\nimport * as selectors from './selectors';\n\nconst STORE_NAME = 'core/reusable-blocks';\n\n/**\n * Store definition for the reusable blocks 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\tactions,\n\treducer,\n\tselectors,\n} );\n\nregister( store );\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,YAAY,aAAa;AACzB,OAAO,aAAa;AACpB,YAAY,eAAe;AAE3B,MAAM,aAAa;AASZ,MAAM,QAAQ,iBAAkB,YAAY;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,SAAU,KAAM;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { combineReducers } from '@wordpress/data';
|
|
5
|
-
export function isEditingReusableBlock(state = {}, action) {
|
|
6
|
-
if (action?.type === 'SET_EDITING_REUSABLE_BLOCK') {
|
|
1
|
+
import { combineReducers } from "@wordpress/data";
|
|
2
|
+
function isEditingReusableBlock(state = {}, action) {
|
|
3
|
+
if (action?.type === "SET_EDITING_REUSABLE_BLOCK") {
|
|
7
4
|
return {
|
|
8
5
|
...state,
|
|
9
6
|
[action.clientId]: action.isEditing
|
|
@@ -11,7 +8,11 @@ export function isEditingReusableBlock(state = {}, action) {
|
|
|
11
8
|
}
|
|
12
9
|
return state;
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
var reducer_default = combineReducers({
|
|
15
12
|
isEditingReusableBlock
|
|
16
13
|
});
|
|
17
|
-
|
|
14
|
+
export {
|
|
15
|
+
reducer_default as default,
|
|
16
|
+
isEditingReusableBlock
|
|
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 isEditingReusableBlock( state = {}, action ) {\n\tif ( action?.type === 'SET_EDITING_REUSABLE_BLOCK' ) {\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\tisEditingReusableBlock,\n} );\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAEzB,SAAS,uBAAwB,QAAQ,CAAC,GAAG,QAAS;AAC5D,MAAK,QAAQ,SAAS,8BAA+B;AACpD,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 reusable block 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 reusable block is in the editing state.
|
|
7
|
-
*/
|
|
8
|
-
export function __experimentalIsEditingReusableBlock(state, clientId) {
|
|
1
|
+
function __experimentalIsEditingReusableBlock(state, clientId) {
|
|
9
2
|
return state.isEditingReusableBlock[clientId];
|
|
10
3
|
}
|
|
11
|
-
|
|
4
|
+
export {
|
|
5
|
+
__experimentalIsEditingReusableBlock
|
|
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 reusable block 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 reusable block is in the editing state.\n */\nexport function __experimentalIsEditingReusableBlock( state, clientId ) {\n\treturn state.isEditingReusableBlock[ clientId ];\n}\n"],
|
|
5
|
+
"mappings": "AAOO,SAAS,qCAAsC,OAAO,UAAW;AACvE,SAAO,MAAM,uBAAwB,QAAS;AAC/C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|