@dotcms/client 0.0.1-alpha.57 → 0.0.1-alpha.58

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 CHANGED
@@ -1525,131 +1525,6 @@ 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
-
1653
1528
  /**
1654
1529
  * Updates the navigation in the editor.
1655
1530
  *
@@ -1745,9 +1620,6 @@ function isInsideEditor() {
1745
1620
  if (typeof window === 'undefined') {
1746
1621
  return false;
1747
1622
  }
1748
- if (isPreviewMode()) {
1749
- return false;
1750
- }
1751
1623
  return window.parent !== window;
1752
1624
  }
1753
1625
  function initDotUVE() {
@@ -2056,6 +1928,119 @@ class DotCmsClient {
2056
1928
  }
2057
1929
  _DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
2058
1930
 
1931
+ exports.UVE_MODE = void 0;
1932
+ (function (UVE_MODE) {
1933
+ UVE_MODE["EDIT"] = "edit";
1934
+ UVE_MODE["PREVIEW"] = "preview";
1935
+ })(exports.UVE_MODE || (exports.UVE_MODE = {}));
1936
+
1937
+ /**
1938
+ * Transforms a GraphQL Page response to a Page Entity.
1939
+ *
1940
+ * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
1941
+ * @returns {object|null} The transformed Page Entity or null if the page is not present.
1942
+ *
1943
+ * @example
1944
+ * ```ts
1945
+ * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
1946
+ * ```
1947
+ */
1948
+ const graphqlToPageEntity = (graphQLPageResponse) => {
1949
+ const { page } = graphQLPageResponse;
1950
+ // If there is no page, return null
1951
+ if (!page) {
1952
+ return null;
1953
+ }
1954
+ const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
1955
+ const data = (_map || {});
1956
+ return {
1957
+ layout,
1958
+ template,
1959
+ viewAs,
1960
+ urlContentMap,
1961
+ site,
1962
+ page: {
1963
+ ...data,
1964
+ ...pageAsset
1965
+ },
1966
+ containers: parseContainers(containers)
1967
+ };
1968
+ };
1969
+ /**
1970
+ * Parses the containers from the GraphQL response.
1971
+ *
1972
+ * @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
1973
+ * @returns {Record<string, unknown>} The parsed containers.
1974
+ */
1975
+ const parseContainers = (containers = []) => {
1976
+ return containers.reduce((acc, container) => {
1977
+ const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
1978
+ const key = (path || identifier);
1979
+ acc[key] = {
1980
+ containerStructures,
1981
+ container: {
1982
+ path,
1983
+ identifier,
1984
+ ...rest
1985
+ },
1986
+ contentlets: parseContentletsToUuidMap(containerContentlets)
1987
+ };
1988
+ return acc;
1989
+ }, {});
1990
+ };
1991
+ /**
1992
+ * Parses the contentlets from the GraphQL response.
1993
+ *
1994
+ * @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
1995
+ * @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
1996
+ */
1997
+ const parseContentletsToUuidMap = (containerContentlets = []) => {
1998
+ return containerContentlets.reduce((acc, containerContentlet) => {
1999
+ const { uuid, contentlets } = containerContentlet;
2000
+ // TODO: This is a temporary solution, we need to find a better way to handle this.
2001
+ acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
2002
+ return {
2003
+ ..._map,
2004
+ ...rest
2005
+ };
2006
+ });
2007
+ return acc;
2008
+ }, {});
2009
+ };
2010
+
2011
+ /**
2012
+ * Generates the page request parameters to be used in the API call.
2013
+ *
2014
+ * @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
2015
+ * @returns {PageApiOptions} The options for the page API.
2016
+ * @example
2017
+ * ```ts
2018
+ * const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
2019
+ * ```
2020
+ */
2021
+ const getPageRequestParams = ({ path = '', params = {} }) => {
2022
+ const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
2023
+ const finalParams = {};
2024
+ const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
2025
+ finalParams['mode'] = copiedParams['mode'] || 'LIVE';
2026
+ if (copiedParams['language_id']) {
2027
+ finalParams['language_id'] = copiedParams['language_id'];
2028
+ }
2029
+ if (copiedParams['variantName']) {
2030
+ finalParams['variantName'] = copiedParams['variantName'];
2031
+ }
2032
+ if (copiedParams['personaId'] || dotMarketingPersonaId) {
2033
+ finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
2034
+ }
2035
+ if (copiedParams['publishDate']) {
2036
+ finalParams['publishDate'] = copiedParams['publishDate'];
2037
+ }
2038
+ return {
2039
+ path,
2040
+ ...finalParams
2041
+ };
2042
+ };
2043
+
2059
2044
  exports.DotCmsClient = DotCmsClient;
2060
2045
  exports.destroyEditor = destroyEditor;
2061
2046
  exports.editContentlet = editContentlet;
package/index.esm.js CHANGED
@@ -1523,131 +1523,6 @@ 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
-
1651
1526
  /**
1652
1527
  * Updates the navigation in the editor.
1653
1528
  *
@@ -1743,9 +1618,6 @@ function isInsideEditor() {
1743
1618
  if (typeof window === 'undefined') {
1744
1619
  return false;
1745
1620
  }
1746
- if (isPreviewMode()) {
1747
- return false;
1748
- }
1749
1621
  return window.parent !== window;
1750
1622
  }
1751
1623
  function initDotUVE() {
@@ -2054,4 +1926,117 @@ class DotCmsClient {
2054
1926
  }
2055
1927
  _DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
2056
1928
 
1929
+ var UVE_MODE;
1930
+ (function (UVE_MODE) {
1931
+ UVE_MODE["EDIT"] = "edit";
1932
+ UVE_MODE["PREVIEW"] = "preview";
1933
+ })(UVE_MODE || (UVE_MODE = {}));
1934
+
1935
+ /**
1936
+ * Transforms a GraphQL Page response to a Page Entity.
1937
+ *
1938
+ * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
1939
+ * @returns {object|null} The transformed Page Entity or null if the page is not present.
1940
+ *
1941
+ * @example
1942
+ * ```ts
1943
+ * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
1944
+ * ```
1945
+ */
1946
+ const graphqlToPageEntity = (graphQLPageResponse) => {
1947
+ const { page } = graphQLPageResponse;
1948
+ // If there is no page, return null
1949
+ if (!page) {
1950
+ return null;
1951
+ }
1952
+ const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
1953
+ const data = (_map || {});
1954
+ return {
1955
+ layout,
1956
+ template,
1957
+ viewAs,
1958
+ urlContentMap,
1959
+ site,
1960
+ page: {
1961
+ ...data,
1962
+ ...pageAsset
1963
+ },
1964
+ containers: parseContainers(containers)
1965
+ };
1966
+ };
1967
+ /**
1968
+ * Parses the containers from the GraphQL response.
1969
+ *
1970
+ * @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
1971
+ * @returns {Record<string, unknown>} The parsed containers.
1972
+ */
1973
+ const parseContainers = (containers = []) => {
1974
+ return containers.reduce((acc, container) => {
1975
+ const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
1976
+ const key = (path || identifier);
1977
+ acc[key] = {
1978
+ containerStructures,
1979
+ container: {
1980
+ path,
1981
+ identifier,
1982
+ ...rest
1983
+ },
1984
+ contentlets: parseContentletsToUuidMap(containerContentlets)
1985
+ };
1986
+ return acc;
1987
+ }, {});
1988
+ };
1989
+ /**
1990
+ * Parses the contentlets from the GraphQL response.
1991
+ *
1992
+ * @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
1993
+ * @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
1994
+ */
1995
+ const parseContentletsToUuidMap = (containerContentlets = []) => {
1996
+ return containerContentlets.reduce((acc, containerContentlet) => {
1997
+ const { uuid, contentlets } = containerContentlet;
1998
+ // TODO: This is a temporary solution, we need to find a better way to handle this.
1999
+ acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
2000
+ return {
2001
+ ..._map,
2002
+ ...rest
2003
+ };
2004
+ });
2005
+ return acc;
2006
+ }, {});
2007
+ };
2008
+
2009
+ /**
2010
+ * Generates the page request parameters to be used in the API call.
2011
+ *
2012
+ * @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
2013
+ * @returns {PageApiOptions} The options for the page API.
2014
+ * @example
2015
+ * ```ts
2016
+ * const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
2017
+ * ```
2018
+ */
2019
+ const getPageRequestParams = ({ path = '', params = {} }) => {
2020
+ const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
2021
+ const finalParams = {};
2022
+ const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';
2023
+ finalParams['mode'] = copiedParams['mode'] || 'LIVE';
2024
+ if (copiedParams['language_id']) {
2025
+ finalParams['language_id'] = copiedParams['language_id'];
2026
+ }
2027
+ if (copiedParams['variantName']) {
2028
+ finalParams['variantName'] = copiedParams['variantName'];
2029
+ }
2030
+ if (copiedParams['personaId'] || dotMarketingPersonaId) {
2031
+ finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
2032
+ }
2033
+ if (copiedParams['publishDate']) {
2034
+ finalParams['publishDate'] = copiedParams['publishDate'];
2035
+ }
2036
+ return {
2037
+ path,
2038
+ ...finalParams
2039
+ };
2040
+ };
2041
+
2057
2042
  export { CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, UVE_MODE, destroyEditor, editContentlet, getPageRequestParams, graphqlToPageEntity, initEditor, initInlineEditing, isInsideEditor, postMessageToEditor, reorderMenu, updateNavigation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "0.0.1-alpha.57",
3
+ "version": "0.0.1-alpha.58",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,9 +31,3 @@ 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;