@remkoj/optimizely-cms-react 2.0.0-pre4 → 2.0.0

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.
Files changed (43) hide show
  1. package/dist/components/cms-styles.d.ts +53 -0
  2. package/dist/components/cms-styles.js +23 -0
  3. package/dist/components/cms-styles.js.map +1 -0
  4. package/dist/components/index.d.ts +2 -1
  5. package/dist/components/index.js +2 -1
  6. package/dist/components/index.js.map +1 -1
  7. package/dist/components/rich-text.d.ts +75 -0
  8. package/dist/components/rich-text.js +136 -0
  9. package/dist/components/rich-text.js.map +1 -0
  10. package/dist/factory.d.ts +10 -2
  11. package/dist/factory.js +26 -3
  12. package/dist/factory.js.map +1 -1
  13. package/dist/server/components/cms-content-area.d.ts +0 -1
  14. package/dist/server/components/cms-content.d.ts +0 -1
  15. package/dist/server/components/cms-content.js +16 -19
  16. package/dist/server/components/cms-content.js.map +1 -1
  17. package/dist/server/components/cms-editable.d.ts +22 -0
  18. package/dist/server/components/cms-editable.js +18 -0
  19. package/dist/server/components/cms-editable.js.map +1 -0
  20. package/dist/server/components/get-content-type.js +9 -14
  21. package/dist/server/components/get-content-type.js.map +1 -1
  22. package/dist/server/components/index.d.ts +1 -0
  23. package/dist/server/components/index.js +1 -0
  24. package/dist/server/components/index.js.map +1 -1
  25. package/dist/server/components/queries.js +12 -12
  26. package/dist/server/components/visual-builder/Composition.d.ts +6 -1
  27. package/dist/server/components/visual-builder/Composition.js +24 -66
  28. package/dist/server/components/visual-builder/Composition.js.map +1 -1
  29. package/dist/server/components/visual-builder/functions.d.ts +6 -1
  30. package/dist/server/components/visual-builder/functions.js +46 -0
  31. package/dist/server/components/visual-builder/functions.js.map +1 -1
  32. package/dist/server/components/visual-builder/types.d.ts +12 -2
  33. package/dist/server/type-utils.d.ts +0 -1
  34. package/dist/types.d.ts +44 -13
  35. package/dist/utilities.d.ts +22 -1
  36. package/dist/utilities.js +33 -3
  37. package/dist/utilities.js.map +1 -1
  38. package/package.json +9 -8
  39. package/dist/components/rich-text/index.d.ts +0 -32
  40. package/dist/components/rich-text/index.js +0 -43
  41. package/dist/components/rich-text/index.js.map +0 -1
  42. package/dist/server/components/utils.d.ts +0 -10
  43. package/dist/server/components/utils.js +0 -28
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@remkoj/optimizely-cms-react",
3
3
  "license": "Apache-2.0",
4
- "version": "2.0.0-pre4",
4
+ "version": "2.0.0",
5
5
  "packageManager": "yarn@4.1.1",
6
6
  "repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
7
7
  "author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
@@ -40,25 +40,27 @@
40
40
  }
41
41
  },
42
42
  "devDependencies": {
43
- "@remkoj/optimizely-graph-client": "2.0.0-pre4",
43
+ "@remkoj/optimizely-graph-client": "2.0.0",
44
44
  "@types/crypto-js": "^4.2.2",
45
- "@types/node": "^20.12.12",
45
+ "@types/node": "^20.14.7",
46
46
  "@types/react": "^18.3.3",
47
47
  "@types/react-dom": "18.3.0",
48
- "graphql": "^16.8.1",
48
+ "entities": "^4.5.0",
49
+ "graphql": "^16.8.2",
49
50
  "graphql-request": "^6.1.0",
50
51
  "prop-types": "^15.8.1",
51
52
  "react": "^18.3.1",
52
53
  "react-dom": "^18.3.1",
53
54
  "scheduler": "^0.23.2",
54
- "typescript": "^5.4.5"
55
+ "typescript": "^5.5.2"
55
56
  },
56
57
  "dependencies": {
57
58
  "@graphql-typed-document-node/core": "^3.2.0",
58
59
  "crypto-js": "^4.2.0"
59
60
  },
60
61
  "peerDependencies": {
61
- "@remkoj/optimizely-graph-client": "2.0.0-pre4",
62
+ "@remkoj/optimizely-graph-client": "2.0.0",
63
+ "entities": "*",
62
64
  "graphql": "^16.8.1",
63
65
  "graphql-request": "^6.1.0",
64
66
  "react": "*",
@@ -69,6 +71,5 @@
69
71
  "prepare": "yarn tsc --build",
70
72
  "watch": "tsc --watch",
71
73
  "recompile": "tsc --build --clean && tsc --build --force"
72
- },
73
- "stableVersion": "1.0.4"
74
+ }
74
75
  }
@@ -1,32 +0,0 @@
1
- /// <reference types="react" />
2
- import { type ComponentFactory } from "../../types.js";
3
- export type RichTextProps = {
4
- /**
5
- * The component factory used for this rich text content
6
- */
7
- factory: ComponentFactory;
8
- /**
9
- * The rich text to render, provided as either a HTML string or JSON encoded
10
- * structured data.
11
- */
12
- text: string | null | undefined;
13
- /**
14
- * The value for the "data-epi-edit" marker on the top level element
15
- */
16
- editId?: string | null;
17
- /**
18
- * The CSS Class to apply to the text container
19
- */
20
- className?: string;
21
- };
22
- export type RichTextTextNode = {
23
- text: string;
24
- };
25
- export type RichTextData = {
26
- type: string;
27
- children?: Array<RichTextData | RichTextTextNode>;
28
- };
29
- export declare function isRichTextData(toTest: any): toTest is RichTextData;
30
- export declare function isRichTextText(toTest: any): toTest is RichTextTextNode;
31
- export declare const RichText: (props: RichTextProps) => JSX.Element;
32
- export default RichText;
@@ -1,43 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- export function isRichTextData(toTest) {
3
- if (typeof (toTest) != 'object' || toTest == null)
4
- return false;
5
- return typeof toTest.type == 'string' && toTest.type.length > 0;
6
- }
7
- export function isRichTextText(toTest) {
8
- if (typeof (toTest) != 'object' || toTest == null)
9
- return false;
10
- return typeof toTest.text == 'string' && toTest.text.length > 0;
11
- }
12
- export const RichText = ({ factory, text, editId, className }) => {
13
- const debug = process.env.NODE_ENV != 'production';
14
- let data = undefined;
15
- try {
16
- data = JSON.parse(text ?? 'undefined');
17
- }
18
- catch (e) { /* Ignore any error as we'll fall-back to HTML injection */ }
19
- if (!data)
20
- return _jsx("div", { dangerouslySetInnerHTML: { __html: text ?? '' }, className: className, "data-epi-edit": editId });
21
- if (!isRichTextData(data)) {
22
- if (debug)
23
- console.warn(`[Rich Text] Invalid rich text data received: ${text}`);
24
- return _jsx("div", { className: className, "data-epi-edit": editId });
25
- }
26
- return _jsx("div", { className: className, "data-epi-edit": editId, children: _jsx(RichTextElement, { factory: factory, ...data }) });
27
- };
28
- const RichTextElement = ({ type, children, text, factory, ...props }) => {
29
- const debug = process.env.NODE_ENV != 'production';
30
- if (!type && text)
31
- return _jsx(_Fragment, { children: text });
32
- if (!type) {
33
- if (debug)
34
- console.warn(`[Rich Text] Invalid rich text element data received: ${{ type, children, text, ...props }}`);
35
- return _jsx(_Fragment, {});
36
- }
37
- const DivElement = 'div';
38
- const Component = factory.resolve(type) ?? DivElement;
39
- const uid = Math.round(Math.random() * 10000);
40
- return _jsx(Component, { ...props, children: children?.map(child => _jsx(RichTextElement, { factory: factory, ...child }, `${uid}::${child.type ?? 'text'}`)) });
41
- };
42
- export default RichText;
43
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/rich-text/index.tsx"],"names":[],"mappings":";AAiCA,MAAM,UAAU,cAAc,CAAC,MAAW;IAEtC,IAAI,OAAM,CAAC,MAAM,CAAC,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;QAC5C,OAAO,KAAK,CAAA;IAChB,OAAO,OAAQ,MAAuB,CAAC,IAAI,IAAI,QAAQ,IAAK,MAAuB,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAW;IAEtC,IAAI,OAAM,CAAC,MAAM,CAAC,IAAI,QAAQ,IAAI,MAAM,IAAI,IAAI;QAC5C,OAAO,KAAK,CAAA;IAChB,OAAO,OAAQ,MAA2B,CAAC,IAAI,IAAI,QAAQ,IAAK,MAA2B,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;AAC/G,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAA2C,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE;IAErG,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CA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IACxB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAA;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAA;IAC7C,OAAO,KAAC,SAAS,OAAM,KAAK,YACtB,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAC,eAAe,IAA8D,OAAO,EAAG,OAAO,KAAO,KAAK,IAApF,GAAG,GAAG,KAAO,KAAsB,CAAC,IAAI,IAAI,MAAO,EAAE,CAAmC,CAAC,GACjI,CAAA;AAChB,CAAC,CAAA;AAED,eAAe,QAAQ,CAAA"}
@@ -1,10 +0,0 @@
1
- import type { ContentType, ContentLinkWithLocale } from "../../types";
2
- import type { IOptiGraphClient } from "@remkoj/optimizely-graph-client";
3
- /**
4
- * Resolve the ContentType of an Optimizely CMS Component, identified by its content link
5
- *
6
- * @param link The ContentLink of the content item
7
- * @param gqlClient The GraphQL client to use
8
- * @returns The ContentType, or undefined if it cannot be resolved
9
- */
10
- export declare function getContentType(link: ContentLinkWithLocale, gqlClient: IOptiGraphClient): Promise<ContentType | undefined>;
@@ -1,28 +0,0 @@
1
- import * as Utils from "../../utilities";
2
- import * as Queries from "./queries";
3
- const DEBUG = false;
4
- /**
5
- * Resolve the ContentType of an Optimizely CMS Component, identified by its content link
6
- *
7
- * @param link The ContentLink of the content item
8
- * @param gqlClient The GraphQL client to use
9
- * @returns The ContentType, or undefined if it cannot be resolved
10
- */
11
- export async function getContentType(link, gqlClient) {
12
- if ((!link.id || link.id < 1) && (!link.guidValue || link.guidValue == ""))
13
- throw new Error("Cannot dynamically determine the content type of an inline block");
14
- const gqlQueryVars = Utils.contentLinkToRequestVariables(link);
15
- const gqlResponse = await gqlClient.request(Queries.getContentTypeQuery, gqlQueryVars);
16
- if (gqlResponse.Content?.total != 1) {
17
- if (DEBUG)
18
- console.error(`getContentType: Expected exactly one type, received ${gqlResponse.Content?.total ?? 0} types for`, gqlQueryVars);
19
- return undefined;
20
- }
21
- const items = gqlResponse.Content?.items;
22
- if (!items || items.length == 0)
23
- throw new Error("The content item could not be found!");
24
- const contentType = Utils.normalizeContentType(items[0]?.ContentType);
25
- if (!contentType)
26
- throw new Error("The item did not contain type information");
27
- return contentType;
28
- }