@secretstache/wordpress-gutenberg 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
package/build/styles.css CHANGED
@@ -128,7 +128,7 @@
128
128
  .block-editor__container .bc-spacing-range-control .components-range-control__root .components-range-control__wrapper .components-range-control__marks .components-range-control__mark-label {
129
129
  left: 8px !important;
130
130
  margin-top: 7px !important; }
131
- .block-editor__container .bc-spacing-range-control .components-range-control__root .components-base-control__help {
131
+ .block-editor__container .bc-spacing-range-control .components-base-control__help {
132
132
  margin-left: -11px; }
133
133
 
134
134
  .block-editor__container .bc-add-new-child-btn {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretstache/wordpress-gutenberg",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "",
5
5
  "author": "Secret Stache",
6
6
  "license": "GPL-2.0-or-later",
@@ -2,22 +2,27 @@ import { useState } from '@wordpress/element';
2
2
  import { SelectControl } from '@wordpress/components';
3
3
 
4
4
  import { MediaControl } from './MediaControl.js';
5
- import { MEDIA_TYPE_LABELS } from '../utils/index.js';
5
+ import { MEDIA_TYPE_LABELS, MEDIA_TYPES } from '../utils/index.js';
6
6
 
7
7
  export const MediaTypeControl = (props) => {
8
8
  const {
9
- mediaTypes = [],
9
+ types = [ MEDIA_TYPES.IMAGE, MEDIA_TYPES.VIDEO ],
10
+
11
+ selectedType = MEDIA_TYPES.IMAGE,
12
+ typeOnSelect,
13
+
10
14
  mediaId,
11
15
  mediaUrl,
12
16
  mediaFileName = '',
17
+
13
18
  mediaOnSelect,
14
19
  mediaOnRemove,
20
+
15
21
  label = 'Media Type',
16
22
  } = props;
17
23
 
18
- const [selectedMediaType, setSelectedMediaType] = useState(mediaTypes?.[0]);
19
24
 
20
- const mediaTypesOptions = mediaTypes
25
+ const typesOptions = types
21
26
  ?.filter((type) => MEDIA_TYPE_LABELS[type]) // Ensure it's an allowed type
22
27
  ?.map((type) => ({
23
28
  label: MEDIA_TYPE_LABELS[type],
@@ -27,23 +32,23 @@ export const MediaTypeControl = (props) => {
27
32
  return (
28
33
  <>
29
34
  {
30
- mediaTypes && (
35
+ types && (
31
36
  <SelectControl
32
37
  label={label}
33
- value={selectedMediaType}
34
- onChange={(mediaType) => setSelectedMediaType(mediaType)}
35
- options={mediaTypesOptions}
38
+ value={selectedType}
39
+ onChange={(type) => typeOnSelect(type)}
40
+ options={typesOptions}
36
41
  />
37
42
  )
38
43
  }
39
44
 
40
45
  {
41
- selectedMediaType && (
46
+ selectedType && (
42
47
  <MediaControl
43
48
  mediaId={mediaId}
44
49
  mediaUrl={mediaUrl}
45
50
  mediaFileName={mediaFileName}
46
- type={selectedMediaType}
51
+ type={selectedType}
47
52
  onSelect={mediaOnSelect}
48
53
  onRemove={mediaOnRemove}
49
54
  />
@@ -9,3 +9,4 @@ export { useAccordionItem } from './useAccordionItem.js';
9
9
  export { useBlockTabsData } from './useBlockTabsData.js';
10
10
  export { useAllowedBlocks } from './useAllowedBlocks.js';
11
11
  export { useChildBlockPosition } from './useChildBlockPosition.js';
12
+ export { useFilterBlocks } from './useFilterBlocks.js';
@@ -0,0 +1,15 @@
1
+ import { useSelect } from '@wordpress/data';
2
+ import { useMemo } from '@wordpress/element';
3
+
4
+ export const useFilterBlocks = (filter) => {
5
+ const allBlocks = useSelect(
6
+ (select) => select('core/blocks').getBlockTypes(),
7
+ [],
8
+ );
9
+
10
+ return useMemo(() => allBlocks
11
+ ?.filter((block) => filter(block))
12
+ ?.map((block) => block.name),
13
+ [ allBlocks, filter ],
14
+ );
15
+ };
@@ -26,9 +26,9 @@
26
26
  }
27
27
  }
28
28
  }
29
+ }
29
30
 
30
- .components-base-control__help {
31
- margin-left: -11px;
32
- }
31
+ .components-base-control__help {
32
+ margin-left: -11px;
33
33
  }
34
34
  }
@@ -152,7 +152,7 @@ export const getBaseBackgroundAttributes = (
152
152
  },
153
153
  backgroundMediaType: {
154
154
  type: 'string',
155
- default: '',
155
+ default: defaultBackgroundMediaType,
156
156
  },
157
157
  backgroundColor: {
158
158
  type: 'object',
@@ -122,54 +122,26 @@ export const decodeHtmlEntities = (text) => {
122
122
  * Generates a string of class names for spacing based on the provided spacing object.
123
123
  *
124
124
  * @param {Object} spacing - The spacing object containing margin and padding values.
125
- * @param {Object} [desktopPrefixes] - Optional prefixes for desktop spacing classes.
126
- * @param {string} [desktopPrefixes.marginTop='mt-'] - Prefix for desktop margin-top class.
127
- * @param {string} [desktopPrefixes.marginBottom='mb-'] - Prefix for desktop margin-bottom class.
128
- * @param {string} [desktopPrefixes.paddingTop='pt-'] - Prefix for desktop padding-top class.
129
- * @param {string} [desktopPrefixes.paddingBottom='pb-'] - Prefix for desktop padding-bottom class.
130
- * @param {Object} [mobilePrefixes] - Optional prefixes for mobile spacing classes.
131
- * @param {string} [mobilePrefixes.marginTop='sm:mt-'] - Prefix for mobile margin-top class.
132
- * @param {string} [mobilePrefixes.marginBottom='sm:mb-'] - Prefix for mobile margin-bottom class.
133
- * @param {string} [mobilePrefixes.paddingTop='sm:pt-'] - Prefix for mobile padding-top class.
134
- * @param {string} [mobilePrefixes.paddingBottom='sm:pb-'] - Prefix for mobile padding-bottom class.
125
+ * @param desktopPrefix - Prefix for desktop classes
126
+ * @param mobilePrefix - Prefix for mobile classes
135
127
  * @returns {string} - A string of class names for the specified spacing.
136
128
  */
137
129
  export const getSpacingClasses = (
138
130
  spacing,
139
- desktopPrefixes = {
140
- marginTop: 'mt-',
141
- marginBottom: 'mb-',
142
- paddingTop: 'pt-',
143
- paddingBottom: 'pb-',
144
- },
145
- mobilePrefixes = {
146
- marginTop: 'sm:mt-',
147
- marginBottom: 'sm:mb-',
148
- paddingTop: 'sm:pt-',
149
- paddingBottom: 'sm:pb-',
150
- }
131
+ desktopPrefix = 'md:',
132
+ mobilePrefix = '',
151
133
  ) => {
152
- if (spacing?.desktop || spacing?.mobile) {
153
- return classNames({
154
- [`${desktopPrefixes.marginTop}${spacing.desktop.margin.top}`]: spacing.desktop.margin.top !== -1,
155
- [`${desktopPrefixes.marginBottom}${spacing.desktop.margin.bottom}`]: spacing.desktop.margin.bottom !== -1,
156
-
157
- [`${desktopPrefixes.paddingTop}${spacing.desktop.padding.top}`]: spacing.desktop.padding.top !== -1,
158
- [`${desktopPrefixes.paddingBottom}${spacing.desktop.padding.bottom}`]: spacing.desktop.padding.bottom !== -1,
134
+ return classNames({
135
+ [`${desktopPrefix}mt-${spacing?.desktop?.margin?.top}`]: spacing?.desktop?.margin?.top !== -1,
136
+ [`${desktopPrefix}mb-${spacing?.desktop?.margin?.bottom}`]: spacing?.desktop?.margin?.bottom !== -1,
159
137
 
160
- [`${mobilePrefixes.marginTop}${spacing.mobile.margin.top}`]: spacing.mobile.margin.top !== -1,
161
- [`${mobilePrefixes.marginBottom}${spacing.mobile.margin.bottom}`]: spacing.mobile.margin.bottom !== -1,
138
+ [`${desktopPrefix}pt-${spacing?.desktop?.padding?.top}`]: spacing?.desktop?.padding?.top !== -1,
139
+ [`${desktopPrefix}pb-${spacing?.desktop?.padding?.bottom}`]: spacing?.desktop?.padding?.bottom !== -1,
162
140
 
163
- [`${mobilePrefixes.paddingTop}${spacing.mobile.padding.top}`]: spacing.mobile.padding.top !== -1,
164
- [`${mobilePrefixes.paddingBottom}${spacing.mobile.padding.bottom}`]: spacing.mobile.padding.bottom !== -1,
165
- });
166
- } else {
167
- return classNames({
168
- [`${desktopPrefixes.marginTop}${spacing.margin.top}`]: spacing.margin.top !== -1,
169
- [`${desktopPrefixes.marginBottom}${spacing.margin.bottom}`]: spacing.margin.bottom !== -1,
141
+ [`${mobilePrefix}mt-${spacing?.mobile?.margin?.top}`]: spacing?.mobile?.margin?.top !== -1,
142
+ [`${mobilePrefix}mb-${spacing?.mobile?.margin?.bottom}`]: spacing?.mobile?.margin?.bottom !== -1,
170
143
 
171
- [`${desktopPrefixes.paddingTop}${spacing.padding.top}`]: spacing.padding.top !== -1,
172
- [`${desktopPrefixes.paddingBottom}${spacing.padding.bottom}`]: spacing.padding.bottom !== -1,
173
- });
174
- }
144
+ [`${mobilePrefix}pt-${spacing?.mobile?.padding?.top}`]: spacing?.mobile?.padding?.top !== -1,
145
+ [`${mobilePrefix}pb-${spacing?.mobile?.padding?.bottom}`]: spacing?.mobile?.padding?.bottom !== -1,
146
+ });
175
147
  };