@marvalt/wadapter 2.3.19 → 2.3.21

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