@dotcms/client 0.0.1-alpha.54 → 0.0.1-alpha.55
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/index.cjs.js +120 -106
- package/index.esm.js +120 -106
- package/package.json +1 -1
- package/src/lib/utils/page/common-utils.d.ts +6 -0
package/index.cjs.js
CHANGED
|
@@ -1525,6 +1525,122 @@ function fetchPageDataFromInsideUVE(pathname) {
|
|
|
1525
1525
|
});
|
|
1526
1526
|
}
|
|
1527
1527
|
|
|
1528
|
+
/**
|
|
1529
|
+
* Transforms a GraphQL Page response to a Page Entity.
|
|
1530
|
+
*
|
|
1531
|
+
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
1532
|
+
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
1533
|
+
*
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```ts
|
|
1536
|
+
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
1537
|
+
* ```
|
|
1538
|
+
*/
|
|
1539
|
+
const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
1540
|
+
const { page } = graphQLPageResponse;
|
|
1541
|
+
// If there is no page, return null
|
|
1542
|
+
if (!page) {
|
|
1543
|
+
return null;
|
|
1544
|
+
}
|
|
1545
|
+
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1546
|
+
const data = (_map || {});
|
|
1547
|
+
return {
|
|
1548
|
+
layout,
|
|
1549
|
+
template,
|
|
1550
|
+
viewAs,
|
|
1551
|
+
urlContentMap,
|
|
1552
|
+
site,
|
|
1553
|
+
page: {
|
|
1554
|
+
...data,
|
|
1555
|
+
...pageAsset
|
|
1556
|
+
},
|
|
1557
|
+
containers: parseContainers(containers)
|
|
1558
|
+
};
|
|
1559
|
+
};
|
|
1560
|
+
/**
|
|
1561
|
+
* Parses the containers from the GraphQL response.
|
|
1562
|
+
*
|
|
1563
|
+
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
1564
|
+
* @returns {Record<string, unknown>} The parsed containers.
|
|
1565
|
+
*/
|
|
1566
|
+
const parseContainers = (containers = []) => {
|
|
1567
|
+
return containers.reduce((acc, container) => {
|
|
1568
|
+
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
1569
|
+
const key = (path || identifier);
|
|
1570
|
+
acc[key] = {
|
|
1571
|
+
containerStructures,
|
|
1572
|
+
container: {
|
|
1573
|
+
path,
|
|
1574
|
+
identifier,
|
|
1575
|
+
...rest
|
|
1576
|
+
},
|
|
1577
|
+
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
1578
|
+
};
|
|
1579
|
+
return acc;
|
|
1580
|
+
}, {});
|
|
1581
|
+
};
|
|
1582
|
+
/**
|
|
1583
|
+
* Parses the contentlets from the GraphQL response.
|
|
1584
|
+
*
|
|
1585
|
+
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
1586
|
+
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
1587
|
+
*/
|
|
1588
|
+
const parseContentletsToUuidMap = (containerContentlets = []) => {
|
|
1589
|
+
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
1590
|
+
const { uuid, contentlets } = containerContentlet;
|
|
1591
|
+
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
1592
|
+
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
1593
|
+
return {
|
|
1594
|
+
..._map,
|
|
1595
|
+
...rest
|
|
1596
|
+
};
|
|
1597
|
+
});
|
|
1598
|
+
return acc;
|
|
1599
|
+
}, {});
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Generates the page request parameters to be used in the API call.
|
|
1604
|
+
*
|
|
1605
|
+
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
1606
|
+
* @returns {PageApiOptions} The options for the page API.
|
|
1607
|
+
* @example
|
|
1608
|
+
* ```ts
|
|
1609
|
+
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
1610
|
+
* ```
|
|
1611
|
+
*/
|
|
1612
|
+
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
1613
|
+
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
1614
|
+
const finalParams = {};
|
|
1615
|
+
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
1616
|
+
if (copiedParams['mode']) {
|
|
1617
|
+
finalParams['mode'] = copiedParams['mode'];
|
|
1618
|
+
}
|
|
1619
|
+
if (copiedParams['language_id']) {
|
|
1620
|
+
finalParams['language_id'] = copiedParams['language_id'];
|
|
1621
|
+
}
|
|
1622
|
+
if (copiedParams['variantName']) {
|
|
1623
|
+
finalParams['variantName'] = copiedParams['variantName'];
|
|
1624
|
+
}
|
|
1625
|
+
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
1626
|
+
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
1627
|
+
}
|
|
1628
|
+
return {
|
|
1629
|
+
path,
|
|
1630
|
+
...finalParams
|
|
1631
|
+
};
|
|
1632
|
+
};
|
|
1633
|
+
/**
|
|
1634
|
+
* Checks if the code is running inside an editor.
|
|
1635
|
+
*
|
|
1636
|
+
* @return {*} {boolean}
|
|
1637
|
+
*/
|
|
1638
|
+
const isPreviewMode = () => {
|
|
1639
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
1640
|
+
const isPreviewMode = queryParams.get('preview');
|
|
1641
|
+
return isPreviewMode === 'true';
|
|
1642
|
+
};
|
|
1643
|
+
|
|
1528
1644
|
/**
|
|
1529
1645
|
* Updates the navigation in the editor.
|
|
1530
1646
|
*
|
|
@@ -1614,6 +1730,10 @@ function isInsideEditor() {
|
|
|
1614
1730
|
if (typeof window === 'undefined') {
|
|
1615
1731
|
return false;
|
|
1616
1732
|
}
|
|
1733
|
+
const preview = isPreviewMode();
|
|
1734
|
+
if (preview) {
|
|
1735
|
+
return false;
|
|
1736
|
+
}
|
|
1617
1737
|
return window.parent !== window;
|
|
1618
1738
|
}
|
|
1619
1739
|
function initDotUVE() {
|
|
@@ -1922,112 +2042,6 @@ class DotCmsClient {
|
|
|
1922
2042
|
}
|
|
1923
2043
|
_DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
|
|
1924
2044
|
|
|
1925
|
-
/**
|
|
1926
|
-
* Transforms a GraphQL Page response to a Page Entity.
|
|
1927
|
-
*
|
|
1928
|
-
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
1929
|
-
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
1930
|
-
*
|
|
1931
|
-
* @example
|
|
1932
|
-
* ```ts
|
|
1933
|
-
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
1934
|
-
* ```
|
|
1935
|
-
*/
|
|
1936
|
-
const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
1937
|
-
const { page } = graphQLPageResponse;
|
|
1938
|
-
// If there is no page, return null
|
|
1939
|
-
if (!page) {
|
|
1940
|
-
return null;
|
|
1941
|
-
}
|
|
1942
|
-
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1943
|
-
const data = (_map || {});
|
|
1944
|
-
return {
|
|
1945
|
-
layout,
|
|
1946
|
-
template,
|
|
1947
|
-
viewAs,
|
|
1948
|
-
urlContentMap,
|
|
1949
|
-
site,
|
|
1950
|
-
page: {
|
|
1951
|
-
...data,
|
|
1952
|
-
...pageAsset
|
|
1953
|
-
},
|
|
1954
|
-
containers: parseContainers(containers)
|
|
1955
|
-
};
|
|
1956
|
-
};
|
|
1957
|
-
/**
|
|
1958
|
-
* Parses the containers from the GraphQL response.
|
|
1959
|
-
*
|
|
1960
|
-
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
1961
|
-
* @returns {Record<string, unknown>} The parsed containers.
|
|
1962
|
-
*/
|
|
1963
|
-
const parseContainers = (containers = []) => {
|
|
1964
|
-
return containers.reduce((acc, container) => {
|
|
1965
|
-
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
1966
|
-
const key = (path || identifier);
|
|
1967
|
-
acc[key] = {
|
|
1968
|
-
containerStructures,
|
|
1969
|
-
container: {
|
|
1970
|
-
path,
|
|
1971
|
-
identifier,
|
|
1972
|
-
...rest
|
|
1973
|
-
},
|
|
1974
|
-
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
1975
|
-
};
|
|
1976
|
-
return acc;
|
|
1977
|
-
}, {});
|
|
1978
|
-
};
|
|
1979
|
-
/**
|
|
1980
|
-
* Parses the contentlets from the GraphQL response.
|
|
1981
|
-
*
|
|
1982
|
-
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
1983
|
-
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
1984
|
-
*/
|
|
1985
|
-
const parseContentletsToUuidMap = (containerContentlets = []) => {
|
|
1986
|
-
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
1987
|
-
const { uuid, contentlets } = containerContentlet;
|
|
1988
|
-
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
1989
|
-
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
1990
|
-
return {
|
|
1991
|
-
..._map,
|
|
1992
|
-
...rest
|
|
1993
|
-
};
|
|
1994
|
-
});
|
|
1995
|
-
return acc;
|
|
1996
|
-
}, {});
|
|
1997
|
-
};
|
|
1998
|
-
|
|
1999
|
-
/**
|
|
2000
|
-
* Generates the page request parameters to be used in the API call.
|
|
2001
|
-
*
|
|
2002
|
-
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
2003
|
-
* @returns {PageApiOptions} The options for the page API.
|
|
2004
|
-
* @example
|
|
2005
|
-
* ```ts
|
|
2006
|
-
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
2007
|
-
* ```
|
|
2008
|
-
*/
|
|
2009
|
-
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
2010
|
-
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
2011
|
-
const finalParams = {};
|
|
2012
|
-
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
2013
|
-
if (copiedParams['mode']) {
|
|
2014
|
-
finalParams['mode'] = copiedParams['mode'];
|
|
2015
|
-
}
|
|
2016
|
-
if (copiedParams['language_id']) {
|
|
2017
|
-
finalParams['language_id'] = copiedParams['language_id'];
|
|
2018
|
-
}
|
|
2019
|
-
if (copiedParams['variantName']) {
|
|
2020
|
-
finalParams['variantName'] = copiedParams['variantName'];
|
|
2021
|
-
}
|
|
2022
|
-
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
2023
|
-
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
2024
|
-
}
|
|
2025
|
-
return {
|
|
2026
|
-
path,
|
|
2027
|
-
...finalParams
|
|
2028
|
-
};
|
|
2029
|
-
};
|
|
2030
|
-
|
|
2031
2045
|
exports.DotCmsClient = DotCmsClient;
|
|
2032
2046
|
exports.destroyEditor = destroyEditor;
|
|
2033
2047
|
exports.editContentlet = editContentlet;
|
package/index.esm.js
CHANGED
|
@@ -1523,6 +1523,122 @@ function fetchPageDataFromInsideUVE(pathname) {
|
|
|
1523
1523
|
});
|
|
1524
1524
|
}
|
|
1525
1525
|
|
|
1526
|
+
/**
|
|
1527
|
+
* Transforms a GraphQL Page response to a Page Entity.
|
|
1528
|
+
*
|
|
1529
|
+
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
1530
|
+
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
1531
|
+
*
|
|
1532
|
+
* @example
|
|
1533
|
+
* ```ts
|
|
1534
|
+
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
1535
|
+
* ```
|
|
1536
|
+
*/
|
|
1537
|
+
const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
1538
|
+
const { page } = graphQLPageResponse;
|
|
1539
|
+
// If there is no page, return null
|
|
1540
|
+
if (!page) {
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1544
|
+
const data = (_map || {});
|
|
1545
|
+
return {
|
|
1546
|
+
layout,
|
|
1547
|
+
template,
|
|
1548
|
+
viewAs,
|
|
1549
|
+
urlContentMap,
|
|
1550
|
+
site,
|
|
1551
|
+
page: {
|
|
1552
|
+
...data,
|
|
1553
|
+
...pageAsset
|
|
1554
|
+
},
|
|
1555
|
+
containers: parseContainers(containers)
|
|
1556
|
+
};
|
|
1557
|
+
};
|
|
1558
|
+
/**
|
|
1559
|
+
* Parses the containers from the GraphQL response.
|
|
1560
|
+
*
|
|
1561
|
+
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
1562
|
+
* @returns {Record<string, unknown>} The parsed containers.
|
|
1563
|
+
*/
|
|
1564
|
+
const parseContainers = (containers = []) => {
|
|
1565
|
+
return containers.reduce((acc, container) => {
|
|
1566
|
+
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
1567
|
+
const key = (path || identifier);
|
|
1568
|
+
acc[key] = {
|
|
1569
|
+
containerStructures,
|
|
1570
|
+
container: {
|
|
1571
|
+
path,
|
|
1572
|
+
identifier,
|
|
1573
|
+
...rest
|
|
1574
|
+
},
|
|
1575
|
+
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
1576
|
+
};
|
|
1577
|
+
return acc;
|
|
1578
|
+
}, {});
|
|
1579
|
+
};
|
|
1580
|
+
/**
|
|
1581
|
+
* Parses the contentlets from the GraphQL response.
|
|
1582
|
+
*
|
|
1583
|
+
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
1584
|
+
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
1585
|
+
*/
|
|
1586
|
+
const parseContentletsToUuidMap = (containerContentlets = []) => {
|
|
1587
|
+
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
1588
|
+
const { uuid, contentlets } = containerContentlet;
|
|
1589
|
+
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
1590
|
+
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
1591
|
+
return {
|
|
1592
|
+
..._map,
|
|
1593
|
+
...rest
|
|
1594
|
+
};
|
|
1595
|
+
});
|
|
1596
|
+
return acc;
|
|
1597
|
+
}, {});
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* Generates the page request parameters to be used in the API call.
|
|
1602
|
+
*
|
|
1603
|
+
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
1604
|
+
* @returns {PageApiOptions} The options for the page API.
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
1608
|
+
* ```
|
|
1609
|
+
*/
|
|
1610
|
+
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
1611
|
+
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
1612
|
+
const finalParams = {};
|
|
1613
|
+
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
1614
|
+
if (copiedParams['mode']) {
|
|
1615
|
+
finalParams['mode'] = copiedParams['mode'];
|
|
1616
|
+
}
|
|
1617
|
+
if (copiedParams['language_id']) {
|
|
1618
|
+
finalParams['language_id'] = copiedParams['language_id'];
|
|
1619
|
+
}
|
|
1620
|
+
if (copiedParams['variantName']) {
|
|
1621
|
+
finalParams['variantName'] = copiedParams['variantName'];
|
|
1622
|
+
}
|
|
1623
|
+
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
1624
|
+
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
1625
|
+
}
|
|
1626
|
+
return {
|
|
1627
|
+
path,
|
|
1628
|
+
...finalParams
|
|
1629
|
+
};
|
|
1630
|
+
};
|
|
1631
|
+
/**
|
|
1632
|
+
* Checks if the code is running inside an editor.
|
|
1633
|
+
*
|
|
1634
|
+
* @return {*} {boolean}
|
|
1635
|
+
*/
|
|
1636
|
+
const isPreviewMode = () => {
|
|
1637
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
1638
|
+
const isPreviewMode = queryParams.get('preview');
|
|
1639
|
+
return isPreviewMode === 'true';
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1526
1642
|
/**
|
|
1527
1643
|
* Updates the navigation in the editor.
|
|
1528
1644
|
*
|
|
@@ -1612,6 +1728,10 @@ function isInsideEditor() {
|
|
|
1612
1728
|
if (typeof window === 'undefined') {
|
|
1613
1729
|
return false;
|
|
1614
1730
|
}
|
|
1731
|
+
const preview = isPreviewMode();
|
|
1732
|
+
if (preview) {
|
|
1733
|
+
return false;
|
|
1734
|
+
}
|
|
1615
1735
|
return window.parent !== window;
|
|
1616
1736
|
}
|
|
1617
1737
|
function initDotUVE() {
|
|
@@ -1920,110 +2040,4 @@ class DotCmsClient {
|
|
|
1920
2040
|
}
|
|
1921
2041
|
_DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
|
|
1922
2042
|
|
|
1923
|
-
/**
|
|
1924
|
-
* Transforms a GraphQL Page response to a Page Entity.
|
|
1925
|
-
*
|
|
1926
|
-
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
1927
|
-
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
1928
|
-
*
|
|
1929
|
-
* @example
|
|
1930
|
-
* ```ts
|
|
1931
|
-
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
1932
|
-
* ```
|
|
1933
|
-
*/
|
|
1934
|
-
const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
1935
|
-
const { page } = graphQLPageResponse;
|
|
1936
|
-
// If there is no page, return null
|
|
1937
|
-
if (!page) {
|
|
1938
|
-
return null;
|
|
1939
|
-
}
|
|
1940
|
-
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1941
|
-
const data = (_map || {});
|
|
1942
|
-
return {
|
|
1943
|
-
layout,
|
|
1944
|
-
template,
|
|
1945
|
-
viewAs,
|
|
1946
|
-
urlContentMap,
|
|
1947
|
-
site,
|
|
1948
|
-
page: {
|
|
1949
|
-
...data,
|
|
1950
|
-
...pageAsset
|
|
1951
|
-
},
|
|
1952
|
-
containers: parseContainers(containers)
|
|
1953
|
-
};
|
|
1954
|
-
};
|
|
1955
|
-
/**
|
|
1956
|
-
* Parses the containers from the GraphQL response.
|
|
1957
|
-
*
|
|
1958
|
-
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
1959
|
-
* @returns {Record<string, unknown>} The parsed containers.
|
|
1960
|
-
*/
|
|
1961
|
-
const parseContainers = (containers = []) => {
|
|
1962
|
-
return containers.reduce((acc, container) => {
|
|
1963
|
-
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
1964
|
-
const key = (path || identifier);
|
|
1965
|
-
acc[key] = {
|
|
1966
|
-
containerStructures,
|
|
1967
|
-
container: {
|
|
1968
|
-
path,
|
|
1969
|
-
identifier,
|
|
1970
|
-
...rest
|
|
1971
|
-
},
|
|
1972
|
-
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
1973
|
-
};
|
|
1974
|
-
return acc;
|
|
1975
|
-
}, {});
|
|
1976
|
-
};
|
|
1977
|
-
/**
|
|
1978
|
-
* Parses the contentlets from the GraphQL response.
|
|
1979
|
-
*
|
|
1980
|
-
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
1981
|
-
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
1982
|
-
*/
|
|
1983
|
-
const parseContentletsToUuidMap = (containerContentlets = []) => {
|
|
1984
|
-
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
1985
|
-
const { uuid, contentlets } = containerContentlet;
|
|
1986
|
-
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
1987
|
-
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
1988
|
-
return {
|
|
1989
|
-
..._map,
|
|
1990
|
-
...rest
|
|
1991
|
-
};
|
|
1992
|
-
});
|
|
1993
|
-
return acc;
|
|
1994
|
-
}, {});
|
|
1995
|
-
};
|
|
1996
|
-
|
|
1997
|
-
/**
|
|
1998
|
-
* Generates the page request parameters to be used in the API call.
|
|
1999
|
-
*
|
|
2000
|
-
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
2001
|
-
* @returns {PageApiOptions} The options for the page API.
|
|
2002
|
-
* @example
|
|
2003
|
-
* ```ts
|
|
2004
|
-
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
2005
|
-
* ```
|
|
2006
|
-
*/
|
|
2007
|
-
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
2008
|
-
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
2009
|
-
const finalParams = {};
|
|
2010
|
-
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
2011
|
-
if (copiedParams['mode']) {
|
|
2012
|
-
finalParams['mode'] = copiedParams['mode'];
|
|
2013
|
-
}
|
|
2014
|
-
if (copiedParams['language_id']) {
|
|
2015
|
-
finalParams['language_id'] = copiedParams['language_id'];
|
|
2016
|
-
}
|
|
2017
|
-
if (copiedParams['variantName']) {
|
|
2018
|
-
finalParams['variantName'] = copiedParams['variantName'];
|
|
2019
|
-
}
|
|
2020
|
-
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
2021
|
-
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
2022
|
-
}
|
|
2023
|
-
return {
|
|
2024
|
-
path,
|
|
2025
|
-
...finalParams
|
|
2026
|
-
};
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
2043
|
export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, destroyEditor, editContentlet, getPageRequestParams, graphqlToPageEntity, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };
|
package/package.json
CHANGED
|
@@ -31,3 +31,9 @@ export interface PageRequestParamsProps {
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export declare const getPageRequestParams: ({ path, params }: PageRequestParamsProps) => PageApiOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the code is running inside an editor.
|
|
36
|
+
*
|
|
37
|
+
* @return {*} {boolean}
|
|
38
|
+
*/
|
|
39
|
+
export declare const isPreviewMode: () => boolean;
|