@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/build/index.js +753 -736
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/helpers.js +42 -14
package/package.json
CHANGED
package/src/utils/helpers.js
CHANGED
@@ -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
|
-
|
198
|
-
|
198
|
+
{
|
199
|
+
desktopPrefix = 'md:',
|
200
|
+
mobilePrefix = '',
|
201
|
+
valuePrefix = '',
|
202
|
+
} = {}
|
199
203
|
) => {
|
200
|
-
|
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
|
-
|
205
|
-
|
206
|
+
const buildClass = (prefix, property, valuePrefix, value) => {
|
207
|
+
if (value === SKIP) return null;
|
206
208
|
|
207
|
-
|
208
|
-
|
209
|
+
return `${prefix}${property}-${valuePrefix}${value}`;
|
210
|
+
};
|
209
211
|
|
210
|
-
|
211
|
-
|
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
|
-
*
|
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
|
}
|