@secretstache/wordpress-gutenberg 0.6.2 → 0.6.4

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.2",
3
+ "version": "0.6.4",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -190,26 +190,36 @@ export const decodeHtmlEntities = (text) => {
190
190
  * @param {Object} spacing - The spacing object containing margin and padding values.
191
191
  * @param desktopPrefix - Prefix for desktop classes
192
192
  * @param mobilePrefix - Prefix for mobile classes
193
+ * @param valuePrefix - Prefix for value
193
194
  * @returns {string} - A string of class names for the specified spacing.
194
195
  */
195
196
  export const getSpacingClasses = (
196
197
  spacing,
197
- desktopPrefix = 'md:',
198
- mobilePrefix = '',
198
+ {
199
+ desktopPrefix = 'md:',
200
+ mobilePrefix = '',
201
+ valuePrefix = '',
202
+ } = {}
199
203
  ) => {
200
- return classNames({
201
- [`${desktopPrefix}mt-${spacing?.desktop?.margin?.top}`]: spacing?.desktop?.margin?.top !== -1,
202
- [`${desktopPrefix}mb-${spacing?.desktop?.margin?.bottom}`]: spacing?.desktop?.margin?.bottom !== -1,
204
+ const SKIP = -1;
203
205
 
204
- [`${desktopPrefix}pt-${spacing?.desktop?.padding?.top}`]: spacing?.desktop?.padding?.top !== -1,
205
- [`${desktopPrefix}pb-${spacing?.desktop?.padding?.bottom}`]: spacing?.desktop?.padding?.bottom !== -1,
206
+ const buildClass = (prefix, property, valuePrefix, value) => {
207
+ if (value === SKIP) return null;
206
208
 
207
- [`${mobilePrefix}mt-${spacing?.mobile?.margin?.top}`]: spacing?.mobile?.margin?.top !== -1,
208
- [`${mobilePrefix}mb-${spacing?.mobile?.margin?.bottom}`]: spacing?.mobile?.margin?.bottom !== -1,
209
+ return `${prefix}${property}-${valuePrefix}${value}`;
210
+ };
209
211
 
210
- [`${mobilePrefix}pt-${spacing?.mobile?.padding?.top}`]: spacing?.mobile?.padding?.top !== -1,
211
- [`${mobilePrefix}pb-${spacing?.mobile?.padding?.bottom}`]: spacing?.mobile?.padding?.bottom !== -1,
212
- });
212
+ return classNames(
213
+ buildClass(desktopPrefix, 'mt', valuePrefix, spacing?.desktop?.margin?.top),
214
+ buildClass(desktopPrefix, 'mb', valuePrefix, spacing?.desktop?.margin?.bottom),
215
+ buildClass(desktopPrefix, 'pt', valuePrefix, spacing?.desktop?.padding?.top),
216
+ buildClass(desktopPrefix, 'pb', valuePrefix, spacing?.desktop?.padding?.bottom),
217
+
218
+ buildClass(mobilePrefix, 'mt', valuePrefix, spacing?.mobile?.margin?.top),
219
+ buildClass(mobilePrefix, 'mb', valuePrefix, spacing?.mobile?.margin?.bottom),
220
+ buildClass(mobilePrefix, 'pt', valuePrefix, spacing?.mobile?.padding?.top),
221
+ buildClass(mobilePrefix, 'pb', valuePrefix, spacing?.mobile?.padding?.bottom),
222
+ );
213
223
  };
214
224
 
215
225
  /**
@@ -234,7 +244,25 @@ export const getFiltersByNamespace = (namespace) => {
234
244
  };
235
245
 
236
246
  /**
237
- * Unregisters a block type for a specific post type when editor loads.
247
+ * Allow a block for a specific post type
248
+ * @param {string} blockName - Name of the block to unregister
249
+ * @param {string} postType - Post type to check against
250
+ */
251
+ export const setBlockForPostType = (blockName, postType) => {
252
+ const unsubscribe = subscribe(
253
+ () => {
254
+ const currentPostType = select('core/editor').getCurrentPostType();
255
+ if (currentPostType && currentPostType !== postType && getBlockType(blockName)) {
256
+ unregisterBlockType(blockName);
257
+ unsubscribe();
258
+ }
259
+ },
260
+ 'core/editor',
261
+ );
262
+ };
263
+
264
+ /**
265
+ * Disallow a block for a specific post type
238
266
  * @param {string} blockName - Name of the block to unregister
239
267
  * @param {string} postType - Post type to check against
240
268
  */
@@ -242,7 +270,7 @@ export const unsetBlockForPostType = (blockName, postType) => {
242
270
  const unsubscribe = subscribe(
243
271
  () => {
244
272
  const currentPostType = select('core/editor').getCurrentPostType();
245
- if (currentPostType === postType && getBlockType(blockName)) {
273
+ if (currentPostType && currentPostType === postType && getBlockType(blockName)) {
246
274
  unregisterBlockType(blockName);
247
275
  unsubscribe();
248
276
  }