@marvalt/wadapter 2.3.19 → 2.3.20

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
@@ -259,8 +259,8 @@ class WordPressClient {
259
259
  return this.makeRequest(`/wp-custom/v1/pages/${pageId}/blocks`);
260
260
  }
261
261
  /**
262
- * Fetch WordPress Reading Settings from custom endpoint
263
- * @returns Settings including front page information
262
+ * Fetch WordPress Settings from custom endpoint
263
+ * @returns Settings including front page information and site branding
264
264
  */
265
265
  async getSettings() {
266
266
  return this.makeRequest('/wp-custom/v1/settings');
@@ -696,6 +696,287 @@ function useGravityFormsConfig(formId, config) {
696
696
  };
697
697
  }
698
698
 
699
+ /**
700
+ * @license GPL-3.0-or-later
701
+ *
702
+ * This file is part of the MarVAlt Open SDK.
703
+ * Copyright (c) 2025 Vibune Pty Ltd.
704
+ *
705
+ * This program is free software: you can redistribute it and/or modify
706
+ * it under the terms of the GNU General Public License as published by
707
+ * the Free Software Foundation, either version 3 of the License, or
708
+ * (at your option) any later version.
709
+ *
710
+ * This program is distributed in the hope that it will be useful,
711
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
712
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
713
+ * See the GNU General Public License for more details.
714
+ */
715
+ let wordpressStaticData = null;
716
+ async function loadWordPressData(path = '/wordpress-data.json') {
717
+ try {
718
+ const res = await fetch(path);
719
+ if (!res.ok)
720
+ return null;
721
+ wordpressStaticData = (await res.json());
722
+ return wordpressStaticData;
723
+ }
724
+ catch {
725
+ return null;
726
+ }
727
+ }
728
+ function hasWordPressStatic() {
729
+ return !!wordpressStaticData && Array.isArray(wordpressStaticData.posts);
730
+ }
731
+ function getWordPressPosts() {
732
+ return wordpressStaticData?.posts ?? [];
733
+ }
734
+ function getWordPressPages() {
735
+ return wordpressStaticData?.pages ?? [];
736
+ }
737
+ function getWordPressMedia() {
738
+ return wordpressStaticData?.media ?? [];
739
+ }
740
+ function getWordPressCategories() {
741
+ return wordpressStaticData?.categories ?? [];
742
+ }
743
+ function getWordPressTags() {
744
+ return wordpressStaticData?.tags ?? [];
745
+ }
746
+ /**
747
+ * Get frontpage metadata from static data
748
+ * This is set by the generator based on WordPress Reading Settings or slug 'frontpage'
749
+ */
750
+ function getFrontpageMetadata() {
751
+ return wordpressStaticData?.front_page;
752
+ }
753
+ /**
754
+ * Get site settings (logo, site icon, site name, description) from static data
755
+ * This is set by the generator from WordPress theme mods and options
756
+ */
757
+ function getSiteSettings() {
758
+ return wordpressStaticData?.site_settings;
759
+ }
760
+
761
+ /**
762
+ * @license GPL-3.0-or-later
763
+ *
764
+ * This file is part of the MarVAlt Open SDK.
765
+ * Copyright (c) 2025 Vibune Pty Ltd.
766
+ *
767
+ * This program is free software: you can redistribute it and/or modify
768
+ * it under the terms of the GNU General Public License as published by
769
+ * the Free Software Foundation, either version 3 of the License, or
770
+ * (at your option) any later version.
771
+ *
772
+ * This program is distributed in the hope that it will be useful,
773
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
774
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
775
+ * See the GNU General Public License for more details.
776
+ */
777
+ /**
778
+ * Get root pages (pages with parent = 0)
779
+ * Sorted by menu_order
780
+ */
781
+ function getRootPages(pages) {
782
+ return pages
783
+ .filter(page => page.parent === 0)
784
+ .sort((a, b) => a.menu_order - b.menu_order);
785
+ }
786
+ /**
787
+ * Get child pages of a specific parent
788
+ * Sorted by menu_order
789
+ */
790
+ function getChildPages(pages, parentId) {
791
+ return pages
792
+ .filter(page => page.parent === parentId)
793
+ .sort((a, b) => a.menu_order - b.menu_order);
794
+ }
795
+ function buildPageHierarchy(pages) {
796
+ const pageMap = new Map();
797
+ const rootPages = [];
798
+ // Create map of all pages with children array
799
+ pages.forEach(page => {
800
+ pageMap.set(page.id, { ...page, children: [] });
801
+ });
802
+ // Build hierarchy
803
+ pages.forEach(page => {
804
+ const hierarchicalPage = pageMap.get(page.id);
805
+ if (page.parent === 0) {
806
+ rootPages.push(hierarchicalPage);
807
+ }
808
+ else {
809
+ const parent = pageMap.get(page.parent);
810
+ if (parent) {
811
+ if (!parent.children) {
812
+ parent.children = [];
813
+ }
814
+ parent.children.push(hierarchicalPage);
815
+ }
816
+ }
817
+ });
818
+ // Sort root pages and recursively sort children
819
+ const sortByMenuOrder = (pages) => {
820
+ return pages
821
+ .sort((a, b) => a.menu_order - b.menu_order)
822
+ .map(page => ({
823
+ ...page,
824
+ children: page.children ? sortByMenuOrder(page.children) : undefined,
825
+ }));
826
+ };
827
+ return sortByMenuOrder(rootPages);
828
+ }
829
+ /**
830
+ * Build menu structure from WordPress pages
831
+ * Converts WordPress pages to a generic menu structure
832
+ *
833
+ * @param pages - Array of WordPress pages
834
+ * @param baseUrl - Base URL for building page URLs (default: '/')
835
+ * @param filterPublished - Only include published pages (default: true)
836
+ * @returns Array of menu items with nested children
837
+ */
838
+ function buildMenuStructure(pages, baseUrl = '/', filterPublished = true) {
839
+ // Filter published pages if requested
840
+ const filteredPages = filterPublished
841
+ ? pages.filter(page => page.status === 'publish')
842
+ : pages;
843
+ // Build hierarchy
844
+ const hierarchicalPages = buildPageHierarchy(filteredPages);
845
+ // Convert to menu items
846
+ const convertToMenuItem = (page) => {
847
+ const url = baseUrl === '/'
848
+ ? `/${page.slug}`
849
+ : `${baseUrl.replace(/\/$/, '')}/${page.slug}`;
850
+ const menuItem = {
851
+ id: page.id,
852
+ title: page.title?.rendered || page.slug,
853
+ slug: page.slug,
854
+ url,
855
+ menuOrder: page.menu_order,
856
+ };
857
+ // Add children if they exist
858
+ if (page.children && page.children.length > 0) {
859
+ menuItem.children = page.children.map(convertToMenuItem);
860
+ }
861
+ return menuItem;
862
+ };
863
+ return hierarchicalPages.map(convertToMenuItem);
864
+ }
865
+ /**
866
+ * Find a page by slug
867
+ */
868
+ function findPageBySlug(pages, slug) {
869
+ return pages.find(page => page.slug === slug);
870
+ }
871
+ /**
872
+ * Find a page by ID
873
+ */
874
+ function findPageById(pages, id) {
875
+ return pages.find(page => page.id === id);
876
+ }
877
+ /**
878
+ * Get frontpage (page with slug 'frontpage' or 'home')
879
+ * Useful for determining homepage content
880
+ */
881
+ function getFrontpage(pages) {
882
+ return pages.find(page => page.slug === 'frontpage' ||
883
+ page.slug === 'home' ||
884
+ page.slug === '');
885
+ }
886
+ /**
887
+ * Get frontpage slug using standardized approach
888
+ *
889
+ * Priority:
890
+ * 1. front_page metadata from generator (WordPress Reading Settings or slug 'frontpage')
891
+ * 2. Fallback to getFrontpage() utility (slug check: 'frontpage', 'home', '')
892
+ *
893
+ * @param pages - Array of WordPress pages (optional, used for fallback)
894
+ * @param frontPageMetadata - Frontpage metadata from static data (optional)
895
+ * @returns Frontpage slug string, or undefined if not found
896
+ */
897
+ function getFrontpageSlug(pages, frontPageMetadata) {
898
+ // First priority: Use metadata from generator (WordPress Reading Settings or slug 'frontpage')
899
+ if (frontPageMetadata?.slug) {
900
+ return frontPageMetadata.slug;
901
+ }
902
+ // Fallback: Check pages for slug 'frontpage', 'home', or ''
903
+ if (pages) {
904
+ const frontpage = getFrontpage(pages);
905
+ return frontpage?.slug;
906
+ }
907
+ return undefined;
908
+ }
909
+
910
+ /**
911
+ * @license GPL-3.0-or-later
912
+ *
913
+ * This file is part of the MarVAlt Open SDK.
914
+ * Copyright (c) 2025 Vibune Pty Ltd.
915
+ *
916
+ * This program is free software: you can redistribute it and/or modify
917
+ * it under the terms of the GNU General Public License as published by
918
+ * the Free Software Foundation, either version 3 of the License, or
919
+ * (at your option) any later version.
920
+ *
921
+ * This program is distributed in the hope that it will be useful,
922
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
923
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
924
+ * See the GNU General Public License for more details.
925
+ */
926
+ // React Hook for Frontpage Slug
927
+ // Standardized approach for determining frontpage slug from WordPress static data
928
+ /**
929
+ * Hook to get the frontpage slug using standardized approach
930
+ *
931
+ * Priority:
932
+ * 1. front_page metadata from generator (WordPress Reading Settings or slug 'frontpage')
933
+ * 2. Fallback to getFrontpage() utility (slug check: 'frontpage', 'home', '')
934
+ *
935
+ * @param overrideSlug - Optional override slug (if provided, this takes precedence)
936
+ * @param dataPath - Path to WordPress static data JSON file (default: '/wordpress-data.json')
937
+ * @returns Object with slug, loading state, and error
938
+ */
939
+ function useFrontpageSlug(overrideSlug, dataPath = '/wordpress-data.json') {
940
+ const [slug, setSlug] = require$$0.useState(overrideSlug);
941
+ const [loading, setLoading] = require$$0.useState(true);
942
+ const [error, setError] = require$$0.useState(null);
943
+ require$$0.useEffect(() => {
944
+ // If override slug is provided, use it immediately
945
+ if (overrideSlug) {
946
+ setSlug(overrideSlug);
947
+ setLoading(false);
948
+ return;
949
+ }
950
+ const fetchFrontpageSlug = async () => {
951
+ try {
952
+ setLoading(true);
953
+ setError(null);
954
+ // Load WordPress static data
955
+ await loadWordPressData(dataPath);
956
+ // Get frontpage metadata and pages
957
+ const frontPageMetadata = getFrontpageMetadata();
958
+ const pages = getWordPressPages();
959
+ // Use standardized utility to get frontpage slug
960
+ const frontpageSlug = getFrontpageSlug(pages, frontPageMetadata);
961
+ setSlug(frontpageSlug);
962
+ }
963
+ catch (err) {
964
+ setError(err instanceof Error ? err : new Error('Failed to load frontpage slug'));
965
+ setSlug(undefined);
966
+ }
967
+ finally {
968
+ setLoading(false);
969
+ }
970
+ };
971
+ fetchFrontpageSlug();
972
+ }, [overrideSlug, dataPath]);
973
+ return {
974
+ slug,
975
+ loading,
976
+ error,
977
+ };
978
+ }
979
+
699
980
  var jsxRuntime = {exports: {}};
700
981
 
701
982
  var reactJsxRuntime_production_min = {};
@@ -2229,54 +2510,6 @@ function useGravityFormsContext() {
2229
2510
  return context;
2230
2511
  }
2231
2512
 
2232
- /**
2233
- * @license GPL-3.0-or-later
2234
- *
2235
- * This file is part of the MarVAlt Open SDK.
2236
- * Copyright (c) 2025 Vibune Pty Ltd.
2237
- *
2238
- * This program is free software: you can redistribute it and/or modify
2239
- * it under the terms of the GNU General Public License as published by
2240
- * the Free Software Foundation, either version 3 of the License, or
2241
- * (at your option) any later version.
2242
- *
2243
- * This program is distributed in the hope that it will be useful,
2244
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2245
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2246
- * See the GNU General Public License for more details.
2247
- */
2248
- let wordpressStaticData = null;
2249
- async function loadWordPressData(path = '/wordpress-data.json') {
2250
- try {
2251
- const res = await fetch(path);
2252
- if (!res.ok)
2253
- return null;
2254
- wordpressStaticData = (await res.json());
2255
- return wordpressStaticData;
2256
- }
2257
- catch {
2258
- return null;
2259
- }
2260
- }
2261
- function hasWordPressStatic() {
2262
- return !!wordpressStaticData && Array.isArray(wordpressStaticData.posts);
2263
- }
2264
- function getWordPressPosts() {
2265
- return wordpressStaticData?.posts ?? [];
2266
- }
2267
- function getWordPressPages() {
2268
- return wordpressStaticData?.pages ?? [];
2269
- }
2270
- function getWordPressMedia() {
2271
- return wordpressStaticData?.media ?? [];
2272
- }
2273
- function getWordPressCategories() {
2274
- return wordpressStaticData?.categories ?? [];
2275
- }
2276
- function getWordPressTags() {
2277
- return wordpressStaticData?.tags ?? [];
2278
- }
2279
-
2280
2513
  /**
2281
2514
  * @license GPL-3.0-or-later
2282
2515
  *
@@ -2504,12 +2737,22 @@ exports.GravityFormsProvider = GravityFormsProvider;
2504
2737
  exports.WordPressClient = WordPressClient;
2505
2738
  exports.WordPressContent = WordPressContent;
2506
2739
  exports.WordPressProvider = WordPressProvider;
2740
+ exports.buildMenuStructure = buildMenuStructure;
2741
+ exports.buildPageHierarchy = buildPageHierarchy;
2507
2742
  exports.createFormProtectionConfig = createFormProtectionConfig;
2508
2743
  exports.createGravityFormsConfig = createGravityFormsConfig;
2509
2744
  exports.createWordPressConfig = createWordPressConfig;
2745
+ exports.findPageById = findPageById;
2746
+ exports.findPageBySlug = findPageBySlug;
2510
2747
  exports.getActiveForms = getActiveForms;
2748
+ exports.getChildPages = getChildPages;
2511
2749
  exports.getFormById = getFormById;
2750
+ exports.getFrontpage = getFrontpage;
2751
+ exports.getFrontpageMetadata = getFrontpageMetadata;
2752
+ exports.getFrontpageSlug = getFrontpageSlug;
2512
2753
  exports.getPublishedForms = getPublishedForms;
2754
+ exports.getRootPages = getRootPages;
2755
+ exports.getSiteSettings = getSiteSettings;
2513
2756
  exports.getWordPressCategories = getWordPressCategories;
2514
2757
  exports.getWordPressMedia = getWordPressMedia;
2515
2758
  exports.getWordPressPages = getWordPressPages;
@@ -2526,6 +2769,7 @@ exports.transformWordPressPage = transformWordPressPage;
2526
2769
  exports.transformWordPressPages = transformWordPressPages;
2527
2770
  exports.transformWordPressPost = transformWordPressPost;
2528
2771
  exports.transformWordPressPosts = transformWordPressPosts;
2772
+ exports.useFrontpageSlug = useFrontpageSlug;
2529
2773
  exports.useGravityForms = useGravityForms;
2530
2774
  exports.useGravityFormsConfig = useGravityFormsConfig;
2531
2775
  exports.useGravityFormsContext = useGravityFormsContext;