@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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
export const { lock, unlock } =
|
|
6
|
+
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
7
|
+
'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',
|
|
8
|
+
'@wordpress/patterns'
|
|
9
|
+
);
|
|
@@ -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
|
+
|
|
8
|
+
export const privateApis = {};
|
|
9
|
+
lock( privateApis, {
|
|
10
|
+
CreatePatternModal,
|
|
11
|
+
PatternsMenuItems,
|
|
12
|
+
} );
|
|
@@ -0,0 +1,99 @@
|
|
|
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 =
|
|
17
|
+
( title, syncType, clientIds ) =>
|
|
18
|
+
async ( { registry, dispatch } ) => {
|
|
19
|
+
const meta =
|
|
20
|
+
syncType === 'unsynced'
|
|
21
|
+
? {
|
|
22
|
+
wp_pattern_sync_status: syncType,
|
|
23
|
+
}
|
|
24
|
+
: undefined;
|
|
25
|
+
|
|
26
|
+
const reusableBlock = {
|
|
27
|
+
title,
|
|
28
|
+
content: clientIds
|
|
29
|
+
? serialize(
|
|
30
|
+
registry
|
|
31
|
+
.select( blockEditorStore )
|
|
32
|
+
.getBlocksByClientId( clientIds )
|
|
33
|
+
)
|
|
34
|
+
: undefined,
|
|
35
|
+
status: 'publish',
|
|
36
|
+
meta,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const updatedRecord = await registry
|
|
40
|
+
.dispatch( coreStore )
|
|
41
|
+
.saveEntityRecord( 'postType', 'wp_block', reusableBlock );
|
|
42
|
+
|
|
43
|
+
if ( syncType === 'unsynced' || ! clientIds ) {
|
|
44
|
+
return updatedRecord;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const newBlock = createBlock( 'core/block', {
|
|
48
|
+
ref: updatedRecord.id,
|
|
49
|
+
} );
|
|
50
|
+
registry
|
|
51
|
+
.dispatch( blockEditorStore )
|
|
52
|
+
.replaceBlocks( clientIds, newBlock );
|
|
53
|
+
dispatch.__experimentalSetEditingPattern( newBlock.clientId, true );
|
|
54
|
+
return updatedRecord;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns a generator converting a synced pattern block into a static block.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} clientId The client ID of the block to attach.
|
|
61
|
+
*/
|
|
62
|
+
export const __experimentalConvertSyncedPatternToStatic =
|
|
63
|
+
( clientId ) =>
|
|
64
|
+
( { registry } ) => {
|
|
65
|
+
const oldBlock = registry
|
|
66
|
+
.select( blockEditorStore )
|
|
67
|
+
.getBlock( clientId );
|
|
68
|
+
const pattern = registry
|
|
69
|
+
.select( 'core' )
|
|
70
|
+
.getEditedEntityRecord(
|
|
71
|
+
'postType',
|
|
72
|
+
'wp_block',
|
|
73
|
+
oldBlock.attributes.ref
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const newBlocks = parse(
|
|
77
|
+
typeof pattern.content === 'function'
|
|
78
|
+
? pattern.content( pattern )
|
|
79
|
+
: pattern.content
|
|
80
|
+
);
|
|
81
|
+
registry
|
|
82
|
+
.dispatch( blockEditorStore )
|
|
83
|
+
.replaceBlocks( oldBlock.clientId, newBlocks );
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns an action descriptor for SET_EDITING_PATTERN action.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} clientId The clientID of the pattern to target.
|
|
90
|
+
* @param {boolean} isEditing Whether the block should be in editing state.
|
|
91
|
+
* @return {Object} Action descriptor.
|
|
92
|
+
*/
|
|
93
|
+
export function __experimentalSetEditingPattern( clientId, isEditing ) {
|
|
94
|
+
return {
|
|
95
|
+
type: 'SET_EDITING_PATTERN',
|
|
96
|
+
clientId,
|
|
97
|
+
isEditing,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -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
|
+
|
|
38
|
+
register( store );
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { combineReducers } from '@wordpress/data';
|
|
5
|
+
|
|
6
|
+
export function isEditingPattern( state = {}, action ) {
|
|
7
|
+
if ( action?.type === 'SET_EDITING_PATTERN' ) {
|
|
8
|
+
return {
|
|
9
|
+
...state,
|
|
10
|
+
[ action.clientId ]: action.isEditing,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return state;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default combineReducers( {
|
|
18
|
+
isEditingPattern,
|
|
19
|
+
} );
|
|
@@ -0,0 +1,10 @@
|
|
|
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 __experimentalIsEditingPattern( state, clientId ) {
|
|
9
|
+
return state.isEditingPattern[ clientId ];
|
|
10
|
+
}
|
package/src/style.scss
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "./components/style.scss";
|