@secretstache/wordpress-gutenberg 0.5.12 → 0.5.15

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.
@@ -0,0 +1,40 @@
1
+ import { createHigherOrderComponent } from '@wordpress/compose';
2
+ import { dispatch, select, useSelect } from '@wordpress/data';
3
+ import { useEffect } from '@wordpress/element';
4
+ import { addFilter } from '@wordpress/hooks';
5
+
6
+ export const addInnerBlocksCleanupFilter = (blockName) => {
7
+ // eslint-disable-next-line
8
+ const withInnerBlocksCleanup = createHigherOrderComponent((BlockEdit) => (props) => {
9
+ const { clientId, attributes, name } = props;
10
+
11
+ if (name !== blockName) {
12
+ return <BlockEdit {...props} />;
13
+ }
14
+
15
+ const innerBlocks = useSelect(
16
+ (select) => select('core/block-editor').getBlock(clientId)?.innerBlocks || [],
17
+ []
18
+ );
19
+
20
+ useEffect(() => {
21
+ if (
22
+ attributes.dataSource !== 'none' &&
23
+ innerBlocks.length > 0
24
+ ) {
25
+ dispatch('core/block-editor').updateBlock(clientId, {
26
+ ...select('core/block-editor').getBlock(clientId),
27
+ innerBlocks: [],
28
+ });
29
+ }
30
+ }, [ attributes.dataSource, clientId, innerBlocks.length ]);
31
+
32
+ return <BlockEdit {...props} />;
33
+ }, 'withInnerBlocksCleanup');
34
+
35
+ addFilter(
36
+ 'editor.BlockEdit',
37
+ 'ssm/with-inner-blocks-cleanup',
38
+ withInnerBlocksCleanup
39
+ );
40
+ };
@@ -11,18 +11,33 @@ import { getBlockType, registerBlockType, unregisterBlockType } from '@wordpress
11
11
  * @param {string} inputValue - Search term to filter posts
12
12
  * @param {string} postType - WordPress post type to query
13
13
  * @param {Function|null} [mapper=null] - Optional function to transform API response items
14
+ * @param {Object} [extraParams={}] - Additional query parameters
14
15
  * @returns {Promise<Array<{value: number, label: string}>>} Array of select options
15
16
  */
16
- export const loadSelectOptions = async (inputValue, postType, mapper = null) => {
17
+ export const loadSelectOptions = async (inputValue, postType, mapper = null, extraParams = {}) => {
18
+ const defaultParams = {
19
+ per_page: -1,
20
+ status: 'publish',
21
+ orderby: 'title',
22
+ order: 'asc'
23
+ };
24
+
25
+ const queryParams = { ...defaultParams, ...extraParams };
26
+
27
+ if (inputValue && inputValue.trim()) {
28
+ queryParams.search = inputValue;
29
+ }
30
+
31
+ const queryString = new URLSearchParams(queryParams).toString();
32
+
17
33
  const response = await apiFetch({
18
- path: `/wp/v2/${postType}?search=${encodeURIComponent(inputValue)}`,
34
+ path: `/wp/v2/${postType}?${queryString}`,
19
35
  });
20
36
 
21
37
  if (mapper) {
22
38
  return response?.map(mapper);
23
39
  } else {
24
40
  return response?.map((post) => {
25
- // Create a temporary DOM element to decode HTML entities
26
41
  const tempElement = document.createElement('div');
27
42
  tempElement.innerHTML = post?.title?.rendered;
28
43
 
@@ -4,3 +4,4 @@ export * from './rootContainer/index.js';
4
4
  export * from './attributes.js';
5
5
  export * from './constants.js';
6
6
  export * from './helpers.js';
7
+ export * from './filters.js';