@wordpress/patterns 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +788 -0
- package/README.md +26 -0
- package/build/components/create-pattern-modal.js +100 -0
- package/build/components/create-pattern-modal.js.map +1 -0
- package/build/components/index.js +32 -0
- package/build/components/index.js.map +1 -0
- package/build/components/pattern-convert-button.js +102 -0
- package/build/components/pattern-convert-button.js.map +1 -0
- package/build/components/patterns-manage-button.js +72 -0
- package/build/components/patterns-manage-button.js.map +1 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/index.native.js +19 -0
- package/build/index.native.js.map +1 -0
- package/build/lock-unlock.js +18 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/private-apis.js +21 -0
- package/build/private-apis.js.map +1 -0
- package/build/store/actions.js +77 -0
- package/build/store/actions.js.map +1 -0
- package/build/store/constants.js +12 -0
- package/build/store/constants.js.map +1 -0
- package/build/store/index.js +49 -0
- package/build/store/index.js.map +1 -0
- package/build/store/reducer.js +26 -0
- package/build/store/reducer.js.map +1 -0
- package/build/store/selectors.js +17 -0
- package/build/store/selectors.js.map +1 -0
- package/build-module/components/create-pattern-modal.js +91 -0
- package/build-module/components/create-pattern-modal.js.map +1 -0
- package/build-module/components/index.js +24 -0
- package/build-module/components/index.js.map +1 -0
- package/build-module/components/pattern-convert-button.js +95 -0
- package/build-module/components/pattern-convert-button.js.map +1 -0
- package/build-module/components/patterns-manage-button.js +64 -0
- package/build-module/components/patterns-manage-button.js.map +1 -0
- package/build-module/index.js +6 -0
- package/build-module/index.js.map +1 -0
- package/build-module/index.native.js +11 -0
- package/build-module/index.native.js.map +1 -0
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/private-apis.js +12 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/store/actions.js +69 -0
- package/build-module/store/actions.js.map +1 -0
- package/build-module/store/constants.js +5 -0
- package/build-module/store/constants.js.map +1 -0
- package/build-module/store/index.js +38 -0
- package/build-module/store/index.js.map +1 -0
- package/build-module/store/reducer.js +17 -0
- package/build-module/store/reducer.js.map +1 -0
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -0
- package/build-style/style-rtl.css +108 -0
- package/build-style/style.css +108 -0
- package/package.json +55 -0
- package/src/components/create-pattern-modal.js +121 -0
- package/src/components/index.js +30 -0
- package/src/components/pattern-convert-button.js +123 -0
- package/src/components/patterns-manage-button.js +77 -0
- package/src/components/style.scss +3 -0
- package/src/index.js +6 -0
- package/src/index.native.js +11 -0
- package/src/lock-unlock.js +9 -0
- package/src/private-apis.js +12 -0
- package/src/store/actions.js +99 -0
- package/src/store/constants.js +4 -0
- package/src/store/index.js +38 -0
- package/src/store/reducer.js +19 -0
- package/src/store/selectors.js +10 -0
- package/src/style.scss +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.storeConfig = exports.store = void 0;
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
10
|
+
var actions = _interopRequireWildcard(require("./actions"));
|
|
11
|
+
var _constants = require("./constants");
|
|
12
|
+
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Post editor data store configuration.
|
|
25
|
+
*
|
|
26
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
|
|
27
|
+
*
|
|
28
|
+
* @type {Object}
|
|
29
|
+
*/
|
|
30
|
+
const storeConfig = {
|
|
31
|
+
reducer: _reducer.default,
|
|
32
|
+
selectors,
|
|
33
|
+
actions
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Store definition for the editor namespace.
|
|
38
|
+
*
|
|
39
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
40
|
+
*
|
|
41
|
+
* @type {Object}
|
|
42
|
+
*/
|
|
43
|
+
exports.storeConfig = storeConfig;
|
|
44
|
+
const store = (0, _data.createReduxStore)(_constants.STORE_NAME, {
|
|
45
|
+
...storeConfig
|
|
46
|
+
});
|
|
47
|
+
exports.store = store;
|
|
48
|
+
(0, _data.register)(store);
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_reducer","_interopRequireDefault","actions","_interopRequireWildcard","_constants","selectors","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","storeConfig","reducer","exports","store","createReduxStore","STORE_NAME","register"],"sources":["@wordpress/patterns/src/store/index.js"],"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';\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\tselectors,\n\tactions,\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 );\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAF,uBAAA,CAAAJ,OAAA;AAAyC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBA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
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.isEditingPattern = isEditingPattern;
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function isEditingPattern(state = {}, action) {
|
|
14
|
+
if (action?.type === 'SET_EDITING_PATTERN') {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
[action.clientId]: action.isEditing
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return state;
|
|
21
|
+
}
|
|
22
|
+
var _default = (0, _data.combineReducers)({
|
|
23
|
+
isEditingPattern
|
|
24
|
+
});
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","isEditingPattern","state","action","type","clientId","isEditing","_default","combineReducers","exports","default"],"sources":["@wordpress/patterns/src/store/reducer.js"],"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"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,SAASC,gBAAgBA,CAAEC,KAAK,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAG;EACtD,IAAKA,MAAM,EAAEC,IAAI,KAAK,qBAAqB,EAAG;IAC7C,OAAO;MACN,GAAGF,KAAK;MACR,CAAEC,MAAM,CAACE,QAAQ,GAAIF,MAAM,CAACG;IAC7B,CAAC;EACF;EAEA,OAAOJ,KAAK;AACb;AAAC,IAAAK,QAAA,GAEc,IAAAC,qBAAe,EAAE;EAC/BP;AACD,CAAE,CAAC;AAAAQ,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.__experimentalIsEditingPattern = __experimentalIsEditingPattern;
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if pattern is in the editing state.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} state Global application state.
|
|
11
|
+
* @param {number} clientId the clientID of the block.
|
|
12
|
+
* @return {boolean} Whether the pattern is in the editing state.
|
|
13
|
+
*/
|
|
14
|
+
function __experimentalIsEditingPattern(state, clientId) {
|
|
15
|
+
return state.isEditingPattern[clientId];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__experimentalIsEditingPattern","state","clientId","isEditingPattern"],"sources":["@wordpress/patterns/src/store/selectors.js"],"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 __experimentalIsEditingPattern( state, clientId ) {\n\treturn state.isEditingPattern[ clientId ];\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,8BAA8BA,CAAEC,KAAK,EAAEC,QAAQ,EAAG;EACjE,OAAOD,KAAK,CAACE,gBAAgB,CAAED,QAAQ,CAAE;AAC1C"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { Modal, Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, ToggleControl } from '@wordpress/components';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useState, useCallback } from '@wordpress/element';
|
|
8
|
+
import { useDispatch } from '@wordpress/data';
|
|
9
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
10
|
+
export const USER_PATTERN_CATEGORY = 'my-patterns';
|
|
11
|
+
export const SYNC_TYPES = {
|
|
12
|
+
full: undefined,
|
|
13
|
+
unsynced: 'unsynced'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import { store } from '../store';
|
|
20
|
+
export default function CreatePatternModal({
|
|
21
|
+
onSuccess,
|
|
22
|
+
onError,
|
|
23
|
+
clientIds,
|
|
24
|
+
onClose,
|
|
25
|
+
className = 'patterns-menu-items__convert-modal'
|
|
26
|
+
}) {
|
|
27
|
+
const [syncType, setSyncType] = useState(SYNC_TYPES.full);
|
|
28
|
+
const [title, setTitle] = useState('');
|
|
29
|
+
const {
|
|
30
|
+
__experimentalCreatePattern: createPattern
|
|
31
|
+
} = useDispatch(store);
|
|
32
|
+
const {
|
|
33
|
+
createErrorNotice
|
|
34
|
+
} = useDispatch(noticesStore);
|
|
35
|
+
const onCreate = useCallback(async function (patternTitle, sync) {
|
|
36
|
+
try {
|
|
37
|
+
const newPattern = await createPattern(patternTitle, sync, clientIds);
|
|
38
|
+
onSuccess({
|
|
39
|
+
pattern: newPattern,
|
|
40
|
+
categoryId: USER_PATTERN_CATEGORY
|
|
41
|
+
});
|
|
42
|
+
} catch (error) {
|
|
43
|
+
createErrorNotice(error.message, {
|
|
44
|
+
type: 'snackbar',
|
|
45
|
+
id: 'convert-to-pattern-error'
|
|
46
|
+
});
|
|
47
|
+
onError();
|
|
48
|
+
}
|
|
49
|
+
}, [createPattern, clientIds, onSuccess, createErrorNotice, onError]);
|
|
50
|
+
return createElement(Modal, {
|
|
51
|
+
title: __('Create pattern'),
|
|
52
|
+
onRequestClose: () => {
|
|
53
|
+
onClose();
|
|
54
|
+
setTitle('');
|
|
55
|
+
},
|
|
56
|
+
overlayClassName: className
|
|
57
|
+
}, createElement("form", {
|
|
58
|
+
onSubmit: event => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
onCreate(title, syncType);
|
|
61
|
+
setTitle('');
|
|
62
|
+
}
|
|
63
|
+
}, createElement(VStack, {
|
|
64
|
+
spacing: "5"
|
|
65
|
+
}, createElement(TextControl, {
|
|
66
|
+
__nextHasNoMarginBottom: true,
|
|
67
|
+
label: __('Name'),
|
|
68
|
+
value: title,
|
|
69
|
+
onChange: setTitle,
|
|
70
|
+
placeholder: __('My pattern')
|
|
71
|
+
}), createElement(ToggleControl, {
|
|
72
|
+
label: __('Synced'),
|
|
73
|
+
help: __('Editing the pattern will update it anywhere it is used.'),
|
|
74
|
+
checked: !syncType,
|
|
75
|
+
onChange: () => {
|
|
76
|
+
setSyncType(syncType === SYNC_TYPES.full ? SYNC_TYPES.unsynced : SYNC_TYPES.full);
|
|
77
|
+
}
|
|
78
|
+
}), createElement(HStack, {
|
|
79
|
+
justify: "right"
|
|
80
|
+
}, createElement(Button, {
|
|
81
|
+
variant: "tertiary",
|
|
82
|
+
onClick: () => {
|
|
83
|
+
onClose();
|
|
84
|
+
setTitle('');
|
|
85
|
+
}
|
|
86
|
+
}, __('Cancel')), createElement(Button, {
|
|
87
|
+
variant: "primary",
|
|
88
|
+
type: "submit"
|
|
89
|
+
}, __('Create'))))));
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=create-pattern-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","useState","useCallback","useDispatch","store","noticesStore","USER_PATTERN_CATEGORY","SYNC_TYPES","full","undefined","unsynced","CreatePatternModal","onSuccess","onError","clientIds","onClose","className","syncType","setSyncType","title","setTitle","__experimentalCreatePattern","createPattern","createErrorNotice","onCreate","patternTitle","sync","newPattern","pattern","categoryId","error","message","type","id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","help","checked","justify","variant","onClick"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport const USER_PATTERN_CATEGORY = 'my-patterns';\n\nexport const SYNC_TYPES = {\n\tfull: undefined,\n\tunsynced: 'unsynced',\n};\n\n/**\n * Internal dependencies\n */\nimport { store } from '../store';\n\nexport default function CreatePatternModal( {\n\tonSuccess,\n\tonError,\n\tclientIds,\n\tonClose,\n\tclassName = 'patterns-menu-items__convert-modal',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( SYNC_TYPES.full );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { __experimentalCreatePattern: createPattern } = useDispatch( store );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onCreate = useCallback(\n\t\tasync function ( patternTitle, sync ) {\n\t\t\ttry {\n\t\t\t\tconst newPattern = await createPattern(\n\t\t\t\t\tpatternTitle,\n\t\t\t\t\tsync,\n\t\t\t\t\tclientIds\n\t\t\t\t);\n\t\t\t\tonSuccess( {\n\t\t\t\t\tpattern: newPattern,\n\t\t\t\t\tcategoryId: USER_PATTERN_CATEGORY,\n\t\t\t\t} );\n\t\t\t} catch ( error ) {\n\t\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'convert-to-pattern-error',\n\t\t\t\t} );\n\t\t\t\tonError();\n\t\t\t}\n\t\t},\n\t\t[ createPattern, clientIds, onSuccess, createErrorNotice, onError ]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t\tsetTitle( '' );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t/>\n\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ ! syncType }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: SYNC_TYPES.full\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\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</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,KAAM;MAChB1B,WAAW,CACVD,QAAQ,KAAKV,UAAU,CAACC,IAAI,GACzBD,UAAU,CAACG,QAAQ,GACnBH,UAAU,CAACC,IACf,CAAC;IACF;EAAG,CACH,CAAC,EACF0B,aAAA,CAACtC,MAAM;IAACoD,OAAO,EAAC;EAAO,GACtBd,aAAA,CAACzC,MAAM;IACNwD,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfnC,OAAO,CAAC,CAAC;MACTK,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAEDpB,EAAE,CAAE,QAAS,CACR,CAAC,EAETkC,aAAA,CAACzC,MAAM;IAACwD,OAAO,EAAC,SAAS;IAACjB,IAAI,EAAC;EAAQ,GACpChC,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { BlockSettingsMenuControls } from '@wordpress/block-editor';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import PatternConvertButton from './pattern-convert-button';
|
|
11
|
+
import PatternsManageButton from './patterns-manage-button';
|
|
12
|
+
export default function PatternsMenuItems({
|
|
13
|
+
rootClientId
|
|
14
|
+
}) {
|
|
15
|
+
return createElement(BlockSettingsMenuControls, null, ({
|
|
16
|
+
selectedClientIds
|
|
17
|
+
}) => createElement(Fragment, null, createElement(PatternConvertButton, {
|
|
18
|
+
clientIds: selectedClientIds,
|
|
19
|
+
rootClientId: rootClientId
|
|
20
|
+
}), selectedClientIds.length === 1 && createElement(PatternsManageButton, {
|
|
21
|
+
clientId: selectedClientIds[0]
|
|
22
|
+
})));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BlockSettingsMenuControls","PatternConvertButton","PatternsManageButton","PatternsMenuItems","rootClientId","createElement","selectedClientIds","Fragment","clientIds","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\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</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,OAAOC,oBAAoB,MAAM,0BAA0B;AAE3D,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACCC,aAAA,CAACL,yBAAyB,QACvB,CAAE;IAAEM;EAAkB,CAAC,KACxBD,aAAA,CAAAE,QAAA,QACCF,aAAA,CAACJ,oBAAoB;IACpBO,SAAS,EAAGF,iBAAmB;IAC/BF,YAAY,EAAGA;EAAc,CAC7B,CAAC,EACAE,iBAAiB,CAACG,MAAM,KAAK,CAAC,IAC/BJ,aAAA,CAACH,oBAAoB;IACpBQ,QAAQ,EAAGJ,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
import { MenuItem } from '@wordpress/components';
|
|
9
|
+
import { symbol } from '@wordpress/icons';
|
|
10
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
13
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import CreatePatternModal from './create-pattern-modal';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Menu control to convert block(s) to a pattern block.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} props Component props.
|
|
23
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
24
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
25
|
+
* @return {import('@wordpress/element').WPComponent} The menu control or null.
|
|
26
|
+
*/
|
|
27
|
+
export default function PatternConvertButton({
|
|
28
|
+
clientIds,
|
|
29
|
+
rootClientId
|
|
30
|
+
}) {
|
|
31
|
+
const {
|
|
32
|
+
createSuccessNotice
|
|
33
|
+
} = useDispatch(noticesStore);
|
|
34
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
35
|
+
const canConvert = useSelect(select => {
|
|
36
|
+
var _getBlocksByClientId;
|
|
37
|
+
const {
|
|
38
|
+
canUser
|
|
39
|
+
} = select(coreStore);
|
|
40
|
+
const {
|
|
41
|
+
getBlocksByClientId,
|
|
42
|
+
canInsertBlockType,
|
|
43
|
+
getBlockRootClientId
|
|
44
|
+
} = select(blockEditorStore);
|
|
45
|
+
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined);
|
|
46
|
+
const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
|
|
47
|
+
const isReusable = blocks.length === 1 && blocks[0] && isReusableBlock(blocks[0]) && !!select(coreStore).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
|
|
48
|
+
const _canConvert =
|
|
49
|
+
// Hide when this is already a synced pattern.
|
|
50
|
+
!isReusable &&
|
|
51
|
+
// Hide when patterns are disabled.
|
|
52
|
+
canInsertBlockType('core/block', rootId) && blocks.every(block =>
|
|
53
|
+
// Guard against the case where a regular block has *just* been converted.
|
|
54
|
+
!!block &&
|
|
55
|
+
// Hide on invalid blocks.
|
|
56
|
+
block.isValid &&
|
|
57
|
+
// Hide when block doesn't support being made into a pattern.
|
|
58
|
+
hasBlockSupport(block.name, 'reusable', true)) &&
|
|
59
|
+
// Hide when current doesn't have permission to do that.
|
|
60
|
+
!!canUser('create', 'blocks');
|
|
61
|
+
return _canConvert;
|
|
62
|
+
}, [clientIds, rootClientId]);
|
|
63
|
+
if (!canConvert) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const handleSuccess = ({
|
|
67
|
+
pattern
|
|
68
|
+
}) => {
|
|
69
|
+
createSuccessNotice(pattern.wp_pattern_sync_status === 'unsynced' ? sprintf(
|
|
70
|
+
// translators: %s: the name the user has given to the pattern.
|
|
71
|
+
__('Unsynced Pattern created: %s'), pattern.title.raw) : sprintf(
|
|
72
|
+
// translators: %s: the name the user has given to the pattern.
|
|
73
|
+
__('Synced Pattern created: %s'), pattern.title.raw), {
|
|
74
|
+
type: 'snackbar',
|
|
75
|
+
id: 'convert-to-pattern-success'
|
|
76
|
+
});
|
|
77
|
+
setIsModalOpen(false);
|
|
78
|
+
};
|
|
79
|
+
return createElement(Fragment, null, createElement(MenuItem, {
|
|
80
|
+
icon: symbol,
|
|
81
|
+
onClick: () => setIsModalOpen(true)
|
|
82
|
+
}, __('Create pattern')), isModalOpen && createElement(CreatePatternModal, {
|
|
83
|
+
clientIds: clientIds,
|
|
84
|
+
onSuccess: pattern => {
|
|
85
|
+
handleSuccess(pattern);
|
|
86
|
+
},
|
|
87
|
+
onError: () => {
|
|
88
|
+
setIsModalOpen(false);
|
|
89
|
+
},
|
|
90
|
+
onClose: () => {
|
|
91
|
+
setIsModalOpen(false);
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=pattern-convert-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","store","blockEditorStore","useState","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","CreatePatternModal","PatternConvertButton","clientIds","rootClientId","createSuccessNotice","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","handleSuccess","pattern","wp_pattern_sync_status","title","raw","type","id","createElement","Fragment","icon","onClick","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { hasBlockSupport, isReusableBlock } from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @return {import('@wordpress/element').WPComponent} The menu control or null.\n */\nexport default function PatternConvertButton( { clientIds, rootClientId } ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === 'unsynced'\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced Pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced Pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem icon={ symbol } onClick={ () => setIsModalOpen( true ) }>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SA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IACvBoC,SAAS,EAAKV,OAAO,IAAM;MAC1BD,aAAa,CAAEC,OAAQ,CAAC;IACzB,CAAG;IACHW,OAAO,EAAGA,CAAA,KAAM;MACfjC,cAAc,CAAE,KAAM,CAAC;IACxB,CAAG;IACHkC,OAAO,EAAGA,CAAA,KAAM;MACflC,cAAc,CAAE,KAAM,CAAC;IACxB;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { MenuItem } from '@wordpress/components';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { isReusableBlock } from '@wordpress/blocks';
|
|
8
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
9
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
10
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
11
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as editorStore } from '../store';
|
|
17
|
+
function PatternsManageButton({
|
|
18
|
+
clientId
|
|
19
|
+
}) {
|
|
20
|
+
const {
|
|
21
|
+
canRemove,
|
|
22
|
+
isVisible,
|
|
23
|
+
innerBlockCount,
|
|
24
|
+
managePatternsUrl
|
|
25
|
+
} = useSelect(select => {
|
|
26
|
+
const {
|
|
27
|
+
getBlock,
|
|
28
|
+
canRemoveBlock,
|
|
29
|
+
getBlockCount,
|
|
30
|
+
getSettings
|
|
31
|
+
} = select(blockEditorStore);
|
|
32
|
+
const {
|
|
33
|
+
canUser
|
|
34
|
+
} = select(coreStore);
|
|
35
|
+
const reusableBlock = getBlock(clientId);
|
|
36
|
+
const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
|
|
37
|
+
return {
|
|
38
|
+
canRemove: canRemoveBlock(clientId),
|
|
39
|
+
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref),
|
|
40
|
+
innerBlockCount: getBlockCount(clientId),
|
|
41
|
+
// The site editor and templates both check whether the user
|
|
42
|
+
// has edit_theme_options capabilities. We can leverage that here
|
|
43
|
+
// and omit the manage patterns link if the user can't access it.
|
|
44
|
+
managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? addQueryArgs('site-editor.php', {
|
|
45
|
+
path: '/patterns'
|
|
46
|
+
}) : addQueryArgs('edit.php', {
|
|
47
|
+
post_type: 'wp_block'
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
}, [clientId]);
|
|
51
|
+
const {
|
|
52
|
+
__experimentalConvertSyncedPatternToStatic: convertBlockToStatic
|
|
53
|
+
} = useDispatch(editorStore);
|
|
54
|
+
if (!isVisible) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return createElement(Fragment, null, createElement(MenuItem, {
|
|
58
|
+
href: managePatternsUrl
|
|
59
|
+
}, __('Manage patterns')), canRemove && createElement(MenuItem, {
|
|
60
|
+
onClick: () => convertBlockToStatic(clientId)
|
|
61
|
+
}, innerBlockCount > 1 ? __('Detach patterns') : __('Detach pattern')));
|
|
62
|
+
}
|
|
63
|
+
export default PatternsManageButton;
|
|
64
|
+
//# sourceMappingURL=patterns-manage-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","editorStore","PatternsManageButton","clientId","canRemove","isVisible","innerBlockCount","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","getSettings","canUser","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","attributes","ref","path","post_type","__experimentalConvertSyncedPatternToStatic","convertBlockToStatic","createElement","Fragment","href","onClick"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"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 editorStore } from '../store';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, innerBlockCount, managePatternsUrl } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\t\tselect( blockEditorStore );\n\t\t\t\tconst { canUser } = select( coreStore );\n\t\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\t\treturn {\n\t\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\t\tisVisible:\n\t\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t\t'update',\n\t\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t\t),\n\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t\t } )\n\t\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t\t } ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ clientId ]\n\t\t);\n\n\tconst { __experimentalConvertSyncedPatternToStatic: convertBlockToStatic } =\n\t\tuseDispatch( editorStore );\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{ innerBlockCount > 1\n\t\t\t\t\t\t? __( 'Detach patterns' )\n\t\t\t\t\t\t: __( 'Detach pattern' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,WAAW,QAAQ,UAAU;AAE/C,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GACjEZ,SAAS,CACNa,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC,aAAa;MAAEC;IAAY,CAAC,GAC7DJ,MAAM,CAAEV,gBAAiB,CAAC;IAC3B,MAAM;MAAEe;IAAQ,CAAC,GAAGL,MAAM,CAAER,SAAU,CAAC;IACvC,MAAMc,aAAa,GAAGL,QAA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encies\n */\nimport './store';\n\nexport * from './private-apis';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,SAAS;AAEhB,cAAc,gBAAgB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import './store';
|
|
5
|
+
import { lock } from './lock-unlock';
|
|
6
|
+
export const privateApis = {};
|
|
7
|
+
lock(privateApis, {
|
|
8
|
+
CreatePatternModal: () => null,
|
|
9
|
+
PatternsMenuItems: () => null
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lock","privateApis","CreatePatternModal","PatternsMenuItems"],"sources":["@wordpress/patterns/src/index.native.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport './store';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal: () => null,\n\tPatternsMenuItems: () => null,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,SAAS;AAChB,SAASA,IAAI,QAAQ,eAAe;AAEpC,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BD,IAAI,CAAEC,WAAW,EAAE;EAClBC,kBAAkB,EAAEA,CAAA,KAAM,IAAI;EAC9BC,iBAAiB,EAAEA,CAAA,KAAM;AAC1B,CAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
export const {
|
|
6
|
+
lock,
|
|
7
|
+
unlock
|
|
8
|
+
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/patterns');
|
|
9
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/patterns/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/patterns'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAC1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,8GAA8G,EAC9G,qBACD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { lock } from './lock-unlock';
|
|
5
|
+
import CreatePatternModal from './components/create-pattern-modal';
|
|
6
|
+
import PatternsMenuItems from './components';
|
|
7
|
+
export const privateApis = {};
|
|
8
|
+
lock(privateApis, {
|
|
9
|
+
CreatePatternModal,
|
|
10
|
+
PatternsMenuItems
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lock","CreatePatternModal","PatternsMenuItems","privateApis"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport CreatePatternModal from './components/create-pattern-modal';\nimport PatternsMenuItems from './components';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal,\n\tPatternsMenuItems,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,eAAe;AACpC,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAE5C,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BH,IAAI,CAAEG,WAAW,EAAE;EAClBF,kBAAkB;EAClBC;AACD,CAAE,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { parse, serialize, createBlock } from '@wordpress/blocks';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} title Pattern title.
|
|
13
|
+
* @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'.
|
|
14
|
+
* @param {string[]|undefined} clientIds Optional client IDs of blocks to convert to pattern.
|
|
15
|
+
*/
|
|
16
|
+
export const __experimentalCreatePattern = (title, syncType, clientIds) => async ({
|
|
17
|
+
registry,
|
|
18
|
+
dispatch
|
|
19
|
+
}) => {
|
|
20
|
+
const meta = syncType === 'unsynced' ? {
|
|
21
|
+
wp_pattern_sync_status: syncType
|
|
22
|
+
} : undefined;
|
|
23
|
+
const reusableBlock = {
|
|
24
|
+
title,
|
|
25
|
+
content: clientIds ? serialize(registry.select(blockEditorStore).getBlocksByClientId(clientIds)) : undefined,
|
|
26
|
+
status: 'publish',
|
|
27
|
+
meta
|
|
28
|
+
};
|
|
29
|
+
const updatedRecord = await registry.dispatch(coreStore).saveEntityRecord('postType', 'wp_block', reusableBlock);
|
|
30
|
+
if (syncType === 'unsynced' || !clientIds) {
|
|
31
|
+
return updatedRecord;
|
|
32
|
+
}
|
|
33
|
+
const newBlock = createBlock('core/block', {
|
|
34
|
+
ref: updatedRecord.id
|
|
35
|
+
});
|
|
36
|
+
registry.dispatch(blockEditorStore).replaceBlocks(clientIds, newBlock);
|
|
37
|
+
dispatch.__experimentalSetEditingPattern(newBlock.clientId, true);
|
|
38
|
+
return updatedRecord;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns a generator converting a synced pattern block into a static block.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} clientId The client ID of the block to attach.
|
|
45
|
+
*/
|
|
46
|
+
export const __experimentalConvertSyncedPatternToStatic = clientId => ({
|
|
47
|
+
registry
|
|
48
|
+
}) => {
|
|
49
|
+
const oldBlock = registry.select(blockEditorStore).getBlock(clientId);
|
|
50
|
+
const pattern = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
|
|
51
|
+
const newBlocks = parse(typeof pattern.content === 'function' ? pattern.content(pattern) : pattern.content);
|
|
52
|
+
registry.dispatch(blockEditorStore).replaceBlocks(oldBlock.clientId, newBlocks);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns an action descriptor for SET_EDITING_PATTERN action.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} clientId The clientID of the pattern to target.
|
|
59
|
+
* @param {boolean} isEditing Whether the block should be in editing state.
|
|
60
|
+
* @return {Object} Action descriptor.
|
|
61
|
+
*/
|
|
62
|
+
export function __experimentalSetEditingPattern(clientId, isEditing) {
|
|
63
|
+
return {
|
|
64
|
+
type: 'SET_EDITING_PATTERN',
|
|
65
|
+
clientId,
|
|
66
|
+
isEditing
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parse","serialize","createBlock","store","coreStore","blockEditorStore","__experimentalCreatePattern","title","syncType","clientIds","registry","dispatch","meta","wp_pattern_sync_status","undefined","reusableBlock","content","select","getBlocksByClientId","status","updatedRecord","saveEntityRecord","newBlock","ref","id","replaceBlocks","__experimentalSetEditingPattern","clientId","__experimentalConvertSyncedPatternToStatic","oldBlock","getBlock","pattern","getEditedEntityRecord","attributes","newBlocks","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { parse, serialize, createBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\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} clientIds Optional client IDs of blocks to convert to pattern.\n */\nexport const __experimentalCreatePattern =\n\t( title, syncType, clientIds ) =>\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,\n\t\t\tcontent: clientIds\n\t\t\t\t? serialize(\n\t\t\t\t\t\tregistry\n\t\t\t\t\t\t\t.select( blockEditorStore )\n\t\t\t\t\t\t\t.getBlocksByClientId( clientIds )\n\t\t\t\t )\n\t\t\t\t: undefined,\n\t\t\tstatus: 'publish',\n\t\t\tmeta,\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\tif ( syncType === 'unsynced' || ! clientIds ) {\n\t\t\treturn updatedRecord;\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.__experimentalSetEditingPattern( newBlock.clientId, true );\n\t\treturn updatedRecord;\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 __experimentalConvertSyncedPatternToStatic =\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 pattern = 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 pattern.content === 'function'\n\t\t\t\t? pattern.content( pattern )\n\t\t\t\t: pattern.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 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 __experimentalSetEditingPattern( clientId, isEditing ) {\n\treturn {\n\t\ttype: 'SET_EDITING_PATTERN',\n\t\tclientId,\n\t\tisEditing,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,KAAK,EAAEC,SAAS,EAAEC,WAAW,QAAQ,mBAAmB;AACjE,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,2BAA2B,GACvCA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,KAC5B,OAAQ;EAAEC,QAAQ;EAAEC;AAAS,CAAC,KAAM;EACnC,MAAMC,IAAI,GACTJ,QAAQ,KAAK,UAAU,GACpB;IACAK,sBAAsB,EAAEL;EACxB,CAAC,GACDM,SAAS;EAEb,MAAMC,aAAa,GAAG;IACrBR,KAAK;IACLS,OAAO,EAAEP,SAAS,GACfR,SAAS,CACTS,QAAQ,CACNO,MAAM,CAAEZ,gBAAiB,CAAC,CAC1Ba,mBA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AU,CAAC;AAChD,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASR,+BAA+BA,CAAEC,QAAQ,EAAEQ,SAAS,EAAG;EACtE,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3BT,QAAQ;IACRQ;EACD,CAAC;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["STORE_NAME"],"sources":["@wordpress/patterns/src/store/constants.js"],"sourcesContent":["/**\n * Module Constants\n */\nexport const STORE_NAME = 'core/patterns';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,MAAMA,UAAU,GAAG,eAAe"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
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
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Post editor data store configuration.
|
|
16
|
+
*
|
|
17
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
|
|
18
|
+
*
|
|
19
|
+
* @type {Object}
|
|
20
|
+
*/
|
|
21
|
+
export const storeConfig = {
|
|
22
|
+
reducer,
|
|
23
|
+
selectors,
|
|
24
|
+
actions
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Store definition for the editor namespace.
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
31
|
+
*
|
|
32
|
+
* @type {Object}
|
|
33
|
+
*/
|
|
34
|
+
export const store = createReduxStore(STORE_NAME, {
|
|
35
|
+
...storeConfig
|
|
36
|
+
});
|
|
37
|
+
register(store);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|