@secretstache/wordpress-gutenberg 0.6.1 → 0.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -217,7 +217,7 @@ export const getSpacingClasses = (
217
217
  * @param {string} namespace - Filter namespace to search for
218
218
  * @returns {Array<{filterName: string, namespace: string}>} Array of matching filters
219
219
  */
220
- const getFiltersByNamespace = (namespace) => {
220
+ export const getFiltersByNamespace = (namespace) => {
221
221
  const list = [];
222
222
 
223
223
  Object.entries(filters).forEach(([filterName, filterData]) => {
@@ -234,15 +234,33 @@ const getFiltersByNamespace = (namespace) => {
234
234
  };
235
235
 
236
236
  /**
237
- * Unregisters a block type for a specific post type when editor loads.
237
+ * Allow a block for a specific post type
238
238
  * @param {string} blockName - Name of the block to unregister
239
239
  * @param {string} postType - Post type to check against
240
240
  */
241
- const unsetBlockForPostType = (blockName, postType) => {
241
+ export const setBlockForPostType = (blockName, postType) => {
242
242
  const unsubscribe = subscribe(
243
243
  () => {
244
244
  const currentPostType = select('core/editor').getCurrentPostType();
245
- if (currentPostType === postType && getBlockType(blockName)) {
245
+ if (currentPostType && currentPostType !== postType && getBlockType(blockName)) {
246
+ unregisterBlockType(blockName);
247
+ unsubscribe();
248
+ }
249
+ },
250
+ 'core/editor',
251
+ );
252
+ };
253
+
254
+ /**
255
+ * Disallow a block for a specific post type
256
+ * @param {string} blockName - Name of the block to unregister
257
+ * @param {string} postType - Post type to check against
258
+ */
259
+ export const unsetBlockForPostType = (blockName, postType) => {
260
+ const unsubscribe = subscribe(
261
+ () => {
262
+ const currentPostType = select('core/editor').getCurrentPostType();
263
+ if (currentPostType && currentPostType === postType && getBlockType(blockName)) {
246
264
  unregisterBlockType(blockName);
247
265
  unsubscribe();
248
266
  }