@marvalt/wadapter 2.3.37 → 2.3.38

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/dist/index.js CHANGED
@@ -271,6 +271,30 @@ class WordPressClient {
271
271
  * Fetch WordPress Settings from custom endpoint
272
272
  * @returns Settings including front page information and site branding
273
273
  */
274
+ /**
275
+ * Fetch header template part blocks from custom endpoint
276
+ * @param slug Template part slug (default: 'header')
277
+ * @param area Template part area (default: 'header')
278
+ * @returns Header blocks data
279
+ */
280
+ async getHeader(slug = 'header', area = 'header') {
281
+ return this.makeRequest(`/wp-custom/v1/header`, { slug, area });
282
+ }
283
+ /**
284
+ * Fetch all navigation menus
285
+ * @returns Array of menu objects
286
+ */
287
+ async getMenus() {
288
+ return this.makeRequest('/wp-custom/v1/menus');
289
+ }
290
+ /**
291
+ * Fetch a specific navigation menu with its items
292
+ * @param menuId Menu ID
293
+ * @returns Menu data with hierarchical items
294
+ */
295
+ async getMenu(menuId) {
296
+ return this.makeRequest(`/wp-custom/v1/menus/${menuId}`);
297
+ }
274
298
  async getFooter(slug = 'footer', area = 'footer') {
275
299
  return this.makeRequest(`/wp-custom/v1/footer`, { slug, area });
276
300
  }
@@ -907,6 +931,46 @@ function buildMenuStructure(pages, baseUrl = '/', filterPublished = true) {
907
931
  };
908
932
  return hierarchicalPages.map(convertToMenuItem);
909
933
  }
934
+ /**
935
+ * Convert WordPress menu items to MenuItem format
936
+ *
937
+ * @param menuItems WordPress menu items (hierarchical structure from API)
938
+ * @param baseUrl Base URL for building relative URLs (default: '/')
939
+ * @returns Array of MenuItem objects
940
+ */
941
+ function convertMenuItemsToMenuStructure(menuItems, baseUrl = '/') {
942
+ return menuItems.map(item => {
943
+ // Convert URL to relative path if it's absolute
944
+ let url = item.url;
945
+ if (url.startsWith('http://') || url.startsWith('https://')) {
946
+ try {
947
+ const urlObj = new URL(url);
948
+ url = urlObj.pathname + urlObj.search + urlObj.hash;
949
+ }
950
+ catch (e) {
951
+ // Invalid URL, keep as is
952
+ }
953
+ }
954
+ // Ensure URL starts with /
955
+ if (!url.startsWith('/')) {
956
+ url = `/${url}`;
957
+ }
958
+ // Extract slug from URL (remove leading/trailing slashes)
959
+ const slug = url.replace(/^\/+|\/+$/g, '') || 'home';
960
+ const menuItem = {
961
+ id: item.id,
962
+ title: item.title,
963
+ slug,
964
+ url,
965
+ menuOrder: item.menu_order,
966
+ };
967
+ // Add children if they exist
968
+ if (item.children && item.children.length > 0) {
969
+ menuItem.children = convertMenuItemsToMenuStructure(item.children, baseUrl);
970
+ }
971
+ return menuItem;
972
+ });
973
+ }
910
974
  /**
911
975
  * Find a page by slug
912
976
  */
@@ -2784,6 +2848,7 @@ exports.WordPressContent = WordPressContent;
2784
2848
  exports.WordPressProvider = WordPressProvider;
2785
2849
  exports.buildMenuStructure = buildMenuStructure;
2786
2850
  exports.buildPageHierarchy = buildPageHierarchy;
2851
+ exports.convertMenuItemsToMenuStructure = convertMenuItemsToMenuStructure;
2787
2852
  exports.createFormProtectionConfig = createFormProtectionConfig;
2788
2853
  exports.createGravityFormsConfig = createGravityFormsConfig;
2789
2854
  exports.createWordPressConfig = createWordPressConfig;