@secretstache/wordpress-gutenberg 0.5.13 → 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.
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/styles.css +25 -10
- package/package.json +1 -1
- package/src/components/DataQueryControls.js +355 -43
- package/src/components/EmptyBlockAppender.js +2 -1
- package/src/hooks/useAccordionItem.js +8 -8
- package/src/styles/_empty-block-appender.scss +26 -9
- package/src/utils/filters.js +40 -0
- package/src/utils/helpers.js +18 -3
- package/src/utils/index.js +1 -0
package/src/utils/helpers.js
CHANGED
@@ -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}
|
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
|
|
package/src/utils/index.js
CHANGED