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