@dotcms/client 0.0.1-alpha.54 → 0.0.1-alpha.56
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 +138 -110
- package/index.esm.js +139 -111
- package/package.json +1 -1
- package/src/index.d.ts +2 -2
- package/src/lib/editor/models/editor.model.d.ts +4 -0
- package/src/lib/editor/sdk-editor.d.ts +10 -4
- package/src/lib/utils/page/common-utils.d.ts +6 -0
package/index.cjs.js
CHANGED
|
@@ -1525,6 +1525,131 @@ 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
|
+
exports.UVE_MODE = void 0;
|
|
1603
|
+
(function (UVE_MODE) {
|
|
1604
|
+
UVE_MODE["EDIT"] = "edit";
|
|
1605
|
+
UVE_MODE["PREVIEW"] = "preview";
|
|
1606
|
+
})(exports.UVE_MODE || (exports.UVE_MODE = {}));
|
|
1607
|
+
|
|
1608
|
+
/**
|
|
1609
|
+
* Generates the page request parameters to be used in the API call.
|
|
1610
|
+
*
|
|
1611
|
+
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
1612
|
+
* @returns {PageApiOptions} The options for the page API.
|
|
1613
|
+
* @example
|
|
1614
|
+
* ```ts
|
|
1615
|
+
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
1616
|
+
* ```
|
|
1617
|
+
*/
|
|
1618
|
+
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
1619
|
+
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
1620
|
+
const finalParams = {};
|
|
1621
|
+
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
1622
|
+
if (copiedParams['mode']) {
|
|
1623
|
+
finalParams['mode'] = copiedParams['mode'];
|
|
1624
|
+
}
|
|
1625
|
+
if (copiedParams['language_id']) {
|
|
1626
|
+
finalParams['language_id'] = copiedParams['language_id'];
|
|
1627
|
+
}
|
|
1628
|
+
if (copiedParams['variantName']) {
|
|
1629
|
+
finalParams['variantName'] = copiedParams['variantName'];
|
|
1630
|
+
}
|
|
1631
|
+
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
1632
|
+
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
1633
|
+
}
|
|
1634
|
+
if (copiedParams['publishDate']) {
|
|
1635
|
+
finalParams['publishDate'] = copiedParams['publishDate'];
|
|
1636
|
+
}
|
|
1637
|
+
return {
|
|
1638
|
+
path,
|
|
1639
|
+
...finalParams
|
|
1640
|
+
};
|
|
1641
|
+
};
|
|
1642
|
+
/**
|
|
1643
|
+
* Checks if the code is running inside an editor.
|
|
1644
|
+
*
|
|
1645
|
+
* @return {*} {boolean}
|
|
1646
|
+
*/
|
|
1647
|
+
const isPreviewMode = () => {
|
|
1648
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
1649
|
+
const editorMode = queryParams.get('editorMode');
|
|
1650
|
+
return editorMode === exports.UVE_MODE.PREVIEW;
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1528
1653
|
/**
|
|
1529
1654
|
* Updates the navigation in the editor.
|
|
1530
1655
|
*
|
|
@@ -1598,15 +1723,21 @@ function reorderMenu(config) {
|
|
|
1598
1723
|
});
|
|
1599
1724
|
}
|
|
1600
1725
|
/**
|
|
1601
|
-
* Checks if the code is running inside
|
|
1726
|
+
* Checks if the code is running inside the DotCMS Universal Visual Editor (UVE).
|
|
1602
1727
|
*
|
|
1603
|
-
*
|
|
1728
|
+
* The function checks three conditions:
|
|
1729
|
+
* 1. If window is defined (for SSR environments)
|
|
1730
|
+
* 2. If the page is not in preview mode
|
|
1731
|
+
* 3. If the current window is embedded in a parent frame
|
|
1732
|
+
*
|
|
1733
|
+
* @returns {boolean} Returns true if running inside the UVE editor, false if running standalone or in preview mode
|
|
1604
1734
|
* @example
|
|
1605
1735
|
* ```ts
|
|
1736
|
+
* // Check if code is running in editor before initializing editor-specific features
|
|
1606
1737
|
* if (isInsideEditor()) {
|
|
1607
|
-
*
|
|
1738
|
+
* initEditor(config);
|
|
1608
1739
|
* } else {
|
|
1609
|
-
*
|
|
1740
|
+
* initStandaloneMode();
|
|
1610
1741
|
* }
|
|
1611
1742
|
* ```
|
|
1612
1743
|
*/
|
|
@@ -1614,6 +1745,9 @@ function isInsideEditor() {
|
|
|
1614
1745
|
if (typeof window === 'undefined') {
|
|
1615
1746
|
return false;
|
|
1616
1747
|
}
|
|
1748
|
+
if (isPreviewMode()) {
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1617
1751
|
return window.parent !== window;
|
|
1618
1752
|
}
|
|
1619
1753
|
function initDotUVE() {
|
|
@@ -1922,112 +2056,6 @@ class DotCmsClient {
|
|
|
1922
2056
|
}
|
|
1923
2057
|
_DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
|
|
1924
2058
|
|
|
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
2059
|
exports.DotCmsClient = DotCmsClient;
|
|
2032
2060
|
exports.destroyEditor = destroyEditor;
|
|
2033
2061
|
exports.editContentlet = editContentlet;
|
package/index.esm.js
CHANGED
|
@@ -1523,6 +1523,131 @@ 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
|
+
var UVE_MODE;
|
|
1601
|
+
(function (UVE_MODE) {
|
|
1602
|
+
UVE_MODE["EDIT"] = "edit";
|
|
1603
|
+
UVE_MODE["PREVIEW"] = "preview";
|
|
1604
|
+
})(UVE_MODE || (UVE_MODE = {}));
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
* Generates the page request parameters to be used in the API call.
|
|
1608
|
+
*
|
|
1609
|
+
* @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
|
|
1610
|
+
* @returns {PageApiOptions} The options for the page API.
|
|
1611
|
+
* @example
|
|
1612
|
+
* ```ts
|
|
1613
|
+
* const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
|
|
1614
|
+
* ```
|
|
1615
|
+
*/
|
|
1616
|
+
const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
1617
|
+
const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
|
|
1618
|
+
const finalParams = {};
|
|
1619
|
+
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
|
|
1620
|
+
if (copiedParams['mode']) {
|
|
1621
|
+
finalParams['mode'] = copiedParams['mode'];
|
|
1622
|
+
}
|
|
1623
|
+
if (copiedParams['language_id']) {
|
|
1624
|
+
finalParams['language_id'] = copiedParams['language_id'];
|
|
1625
|
+
}
|
|
1626
|
+
if (copiedParams['variantName']) {
|
|
1627
|
+
finalParams['variantName'] = copiedParams['variantName'];
|
|
1628
|
+
}
|
|
1629
|
+
if (copiedParams['personaId'] || dotMarketingPersonaId) {
|
|
1630
|
+
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
|
|
1631
|
+
}
|
|
1632
|
+
if (copiedParams['publishDate']) {
|
|
1633
|
+
finalParams['publishDate'] = copiedParams['publishDate'];
|
|
1634
|
+
}
|
|
1635
|
+
return {
|
|
1636
|
+
path,
|
|
1637
|
+
...finalParams
|
|
1638
|
+
};
|
|
1639
|
+
};
|
|
1640
|
+
/**
|
|
1641
|
+
* Checks if the code is running inside an editor.
|
|
1642
|
+
*
|
|
1643
|
+
* @return {*} {boolean}
|
|
1644
|
+
*/
|
|
1645
|
+
const isPreviewMode = () => {
|
|
1646
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
1647
|
+
const editorMode = queryParams.get('editorMode');
|
|
1648
|
+
return editorMode === UVE_MODE.PREVIEW;
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1526
1651
|
/**
|
|
1527
1652
|
* Updates the navigation in the editor.
|
|
1528
1653
|
*
|
|
@@ -1596,15 +1721,21 @@ function reorderMenu(config) {
|
|
|
1596
1721
|
});
|
|
1597
1722
|
}
|
|
1598
1723
|
/**
|
|
1599
|
-
* Checks if the code is running inside
|
|
1724
|
+
* Checks if the code is running inside the DotCMS Universal Visual Editor (UVE).
|
|
1600
1725
|
*
|
|
1601
|
-
*
|
|
1726
|
+
* The function checks three conditions:
|
|
1727
|
+
* 1. If window is defined (for SSR environments)
|
|
1728
|
+
* 2. If the page is not in preview mode
|
|
1729
|
+
* 3. If the current window is embedded in a parent frame
|
|
1730
|
+
*
|
|
1731
|
+
* @returns {boolean} Returns true if running inside the UVE editor, false if running standalone or in preview mode
|
|
1602
1732
|
* @example
|
|
1603
1733
|
* ```ts
|
|
1734
|
+
* // Check if code is running in editor before initializing editor-specific features
|
|
1604
1735
|
* if (isInsideEditor()) {
|
|
1605
|
-
*
|
|
1736
|
+
* initEditor(config);
|
|
1606
1737
|
* } else {
|
|
1607
|
-
*
|
|
1738
|
+
* initStandaloneMode();
|
|
1608
1739
|
* }
|
|
1609
1740
|
* ```
|
|
1610
1741
|
*/
|
|
@@ -1612,6 +1743,9 @@ function isInsideEditor() {
|
|
|
1612
1743
|
if (typeof window === 'undefined') {
|
|
1613
1744
|
return false;
|
|
1614
1745
|
}
|
|
1746
|
+
if (isPreviewMode()) {
|
|
1747
|
+
return false;
|
|
1748
|
+
}
|
|
1615
1749
|
return window.parent !== window;
|
|
1616
1750
|
}
|
|
1617
1751
|
function initDotUVE() {
|
|
@@ -1920,110 +2054,4 @@ class DotCmsClient {
|
|
|
1920
2054
|
}
|
|
1921
2055
|
_DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
|
|
1922
2056
|
|
|
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
|
-
export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, destroyEditor, editContentlet, getPageRequestParams, graphqlToPageEntity, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };
|
|
2057
|
+
export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, UVE_MODE, destroyEditor, editContentlet, getPageRequestParams, graphqlToPageEntity, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ClientConfig, DotCmsClient } from './lib/client/sdk-js-client';
|
|
2
2
|
import { CLIENT_ACTIONS, postMessageToEditor } from './lib/editor/models/client.model';
|
|
3
|
-
import { CustomClientParams, DotCMSPageEditorConfig, EditorConfig } from './lib/editor/models/editor.model';
|
|
3
|
+
import { CustomClientParams, DotCMSPageEditorConfig, EditorConfig, UVE_MODE } from './lib/editor/models/editor.model';
|
|
4
4
|
import { InlineEditorData, INLINE_EDITING_EVENT_KEY, InlineEditEventData } from './lib/editor/models/inline-event.model';
|
|
5
5
|
import { NOTIFY_CLIENT } from './lib/editor/models/listeners.model';
|
|
6
6
|
import { destroyEditor, editContentlet, reorderMenu, initEditor, isInsideEditor, updateNavigation, initInlineEditing } from './lib/editor/sdk-editor';
|
|
7
7
|
import { getPageRequestParams, graphqlToPageEntity } from './lib/utils';
|
|
8
|
-
export { graphqlToPageEntity, getPageRequestParams, isInsideEditor, editContentlet, reorderMenu, DotCmsClient, DotCMSPageEditorConfig, CLIENT_ACTIONS, NOTIFY_CLIENT, CustomClientParams, postMessageToEditor, EditorConfig, initEditor, updateNavigation, destroyEditor, ClientConfig, initInlineEditing, InlineEditEventData, InlineEditorData, INLINE_EDITING_EVENT_KEY };
|
|
8
|
+
export { graphqlToPageEntity, getPageRequestParams, isInsideEditor, editContentlet, reorderMenu, DotCmsClient, DotCMSPageEditorConfig, CLIENT_ACTIONS, NOTIFY_CLIENT, CustomClientParams, postMessageToEditor, EditorConfig, initEditor, updateNavigation, destroyEditor, ClientConfig, initInlineEditing, InlineEditEventData, InlineEditorData, INLINE_EDITING_EVENT_KEY, UVE_MODE };
|
|
@@ -38,15 +38,21 @@ export declare function editContentlet<T>(contentlet: Contentlet<T>): void;
|
|
|
38
38
|
export declare function initInlineEditing(type: INLINE_EDITING_EVENT_KEY, data?: InlineEditEventData): void;
|
|
39
39
|
export declare function reorderMenu(config?: ReorderMenuConfig): void;
|
|
40
40
|
/**
|
|
41
|
-
* Checks if the code is running inside
|
|
41
|
+
* Checks if the code is running inside the DotCMS Universal Visual Editor (UVE).
|
|
42
42
|
*
|
|
43
|
-
*
|
|
43
|
+
* The function checks three conditions:
|
|
44
|
+
* 1. If window is defined (for SSR environments)
|
|
45
|
+
* 2. If the page is not in preview mode
|
|
46
|
+
* 3. If the current window is embedded in a parent frame
|
|
47
|
+
*
|
|
48
|
+
* @returns {boolean} Returns true if running inside the UVE editor, false if running standalone or in preview mode
|
|
44
49
|
* @example
|
|
45
50
|
* ```ts
|
|
51
|
+
* // Check if code is running in editor before initializing editor-specific features
|
|
46
52
|
* if (isInsideEditor()) {
|
|
47
|
-
*
|
|
53
|
+
* initEditor(config);
|
|
48
54
|
* } else {
|
|
49
|
-
*
|
|
55
|
+
* initStandaloneMode();
|
|
50
56
|
* }
|
|
51
57
|
* ```
|
|
52
58
|
*/
|
|
@@ -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;
|