@remkoj/optimizely-cms-react 2.1.0 → 3.1.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 (150) hide show
  1. package/README.md +38 -2
  2. package/dist/components/client.d.ts +42 -0
  3. package/dist/components/client.js +52 -0
  4. package/dist/components/client.js.map +1 -0
  5. package/dist/components/cms-content/client.d.ts +11 -0
  6. package/dist/components/cms-content/client.js +72 -0
  7. package/dist/components/cms-content/client.js.map +1 -0
  8. package/dist/components/cms-content/get-content-type.d.ts +13 -0
  9. package/dist/components/cms-content/get-content-type.js +70 -0
  10. package/dist/components/cms-content/get-content-type.js.map +1 -0
  11. package/dist/components/cms-content/get-content.d.ts +4 -0
  12. package/dist/components/cms-content/get-content.js +91 -0
  13. package/dist/components/cms-content/get-content.js.map +1 -0
  14. package/dist/components/cms-content/resolve-component.d.ts +18 -0
  15. package/dist/components/cms-content/resolve-component.js +53 -0
  16. package/dist/components/cms-content/resolve-component.js.map +1 -0
  17. package/dist/components/cms-content/resolve-content-type.d.ts +15 -0
  18. package/dist/components/cms-content/resolve-content-type.js +29 -0
  19. package/dist/components/cms-content/resolve-content-type.js.map +1 -0
  20. package/dist/components/cms-content/rsc.d.ts +11 -0
  21. package/dist/components/cms-content/rsc.js +50 -0
  22. package/dist/components/cms-content/rsc.js.map +1 -0
  23. package/dist/components/cms-content/types.d.ts +59 -0
  24. package/dist/components/cms-content/types.js +2 -0
  25. package/dist/components/cms-content/types.js.map +1 -0
  26. package/dist/components/cms-content/utils.d.ts +3 -0
  27. package/dist/components/cms-content/utils.js +6 -0
  28. package/dist/components/cms-content/utils.js.map +1 -0
  29. package/dist/components/cms-content-area/index.d.ts +17 -0
  30. package/dist/{server/components/cms-content-area.js → components/cms-content-area/index.js} +43 -43
  31. package/dist/components/cms-content-area/index.js.map +1 -0
  32. package/dist/{server/components → components/cms-content-area}/types.d.ts +31 -94
  33. package/dist/components/cms-content-area/types.js.map +1 -0
  34. package/dist/{server/components/cms-editable.d.ts → components/cms-editable/index.d.ts} +5 -3
  35. package/dist/components/cms-editable/index.js +15 -0
  36. package/dist/components/cms-editable/index.js.map +1 -0
  37. package/dist/components/{cms-styles.js → cms-styles/index.js} +1 -1
  38. package/dist/components/cms-styles/index.js.map +1 -0
  39. package/dist/components/rich-text/components.d.ts +14 -0
  40. package/dist/components/rich-text/components.js +63 -0
  41. package/dist/components/rich-text/components.js.map +1 -0
  42. package/dist/components/rich-text/index.d.ts +4 -0
  43. package/dist/components/rich-text/index.js +47 -0
  44. package/dist/components/rich-text/index.js.map +1 -0
  45. package/dist/components/{rich-text.d.ts → rich-text/types.d.ts} +13 -18
  46. package/dist/components/rich-text/types.js +2 -0
  47. package/dist/components/rich-text/types.js.map +1 -0
  48. package/dist/components/rich-text/utils.d.ts +5 -0
  49. package/dist/components/rich-text/utils.js +24 -0
  50. package/dist/components/rich-text/utils.js.map +1 -0
  51. package/dist/components/rsc.d.ts +47 -0
  52. package/dist/components/rsc.js +55 -0
  53. package/dist/components/rsc.js.map +1 -0
  54. package/dist/{server → components}/type-utils.js.map +1 -1
  55. package/dist/{server/components → components}/visual-builder/functions.d.ts +7 -2
  56. package/dist/{server/components → components}/visual-builder/functions.js +8 -3
  57. package/dist/components/visual-builder/functions.js.map +1 -0
  58. package/dist/{server/components/visual-builder/Composition.d.ts → components/visual-builder/index.d.ts} +4 -3
  59. package/dist/{server/components/visual-builder/Composition.js → components/visual-builder/index.js} +9 -18
  60. package/dist/components/visual-builder/index.js.map +1 -0
  61. package/dist/{server/components → components}/visual-builder/types.d.ts +6 -1
  62. package/dist/components/visual-builder/types.js.map +1 -0
  63. package/dist/components.d.ts +27 -0
  64. package/dist/components.js +20 -0
  65. package/dist/components.js.map +1 -0
  66. package/dist/context/client.d.ts +70 -0
  67. package/dist/context/client.js +78 -0
  68. package/dist/context/client.js.map +1 -0
  69. package/dist/context/rsc.d.ts +33 -0
  70. package/dist/context/rsc.js +75 -0
  71. package/dist/context/rsc.js.map +1 -0
  72. package/dist/context/types.d.ts +15 -0
  73. package/dist/context/types.js +2 -0
  74. package/dist/{server/components → context}/types.js.map +1 -1
  75. package/dist/{server/components → data}/queries.js +121 -121
  76. package/dist/data/queries.js.map +1 -0
  77. package/dist/{factory.d.ts → factory/default.d.ts} +1 -18
  78. package/dist/{factory.js → factory/default.js} +2 -34
  79. package/dist/factory/default.js.map +1 -0
  80. package/dist/factory/index.d.ts +17 -0
  81. package/dist/factory/index.js +21 -0
  82. package/dist/factory/index.js.map +1 -0
  83. package/dist/factory/types.d.ts +51 -0
  84. package/dist/factory/types.js +2 -0
  85. package/dist/factory/types.js.map +1 -0
  86. package/dist/factory/undef.d.ts +9 -0
  87. package/dist/factory/undef.js +19 -0
  88. package/dist/factory/undef.js.map +1 -0
  89. package/dist/index.d.ts +4 -2
  90. package/dist/index.js +4 -2
  91. package/dist/index.js.map +1 -1
  92. package/dist/{server/is-debug.d.ts → rsc-utilities.d.ts} +0 -1
  93. package/dist/{server/is-debug.js → rsc-utilities.js} +1 -2
  94. package/dist/{server/is-debug.js.map → rsc-utilities.js.map} +1 -1
  95. package/dist/rsc.d.ts +11 -0
  96. package/dist/rsc.js +14 -0
  97. package/dist/rsc.js.map +1 -0
  98. package/dist/types.d.ts +10 -56
  99. package/dist/utilities.d.ts +23 -9
  100. package/dist/utilities.js +22 -1
  101. package/dist/utilities.js.map +1 -1
  102. package/package.json +12 -24
  103. package/dist/browser/context.d.ts +0 -6
  104. package/dist/browser/context.js +0 -15
  105. package/dist/browser/context.js.map +0 -1
  106. package/dist/browser/index.d.ts +0 -1
  107. package/dist/browser/index.js +0 -2
  108. package/dist/browser/index.js.map +0 -1
  109. package/dist/components/cms-styles.js.map +0 -1
  110. package/dist/components/index.d.ts +0 -2
  111. package/dist/components/index.js +0 -3
  112. package/dist/components/index.js.map +0 -1
  113. package/dist/components/rich-text.js +0 -138
  114. package/dist/components/rich-text.js.map +0 -1
  115. package/dist/factory.js.map +0 -1
  116. package/dist/server/components/cms-content-area.d.ts +0 -13
  117. package/dist/server/components/cms-content-area.js.map +0 -1
  118. package/dist/server/components/cms-content.d.ts +0 -11
  119. package/dist/server/components/cms-content.js +0 -154
  120. package/dist/server/components/cms-content.js.map +0 -1
  121. package/dist/server/components/cms-editable.js +0 -18
  122. package/dist/server/components/cms-editable.js.map +0 -1
  123. package/dist/server/components/get-content-type.d.ts +0 -12
  124. package/dist/server/components/get-content-type.js +0 -51
  125. package/dist/server/components/get-content-type.js.map +0 -1
  126. package/dist/server/components/index.d.ts +0 -4
  127. package/dist/server/components/index.js +0 -5
  128. package/dist/server/components/index.js.map +0 -1
  129. package/dist/server/components/queries.js.map +0 -1
  130. package/dist/server/components/visual-builder/Composition.js.map +0 -1
  131. package/dist/server/components/visual-builder/functions.js.map +0 -1
  132. package/dist/server/components/visual-builder/index.d.ts +0 -4
  133. package/dist/server/components/visual-builder/index.js +0 -4
  134. package/dist/server/components/visual-builder/index.js.map +0 -1
  135. package/dist/server/components/visual-builder/types.js.map +0 -1
  136. package/dist/server/context.d.ts +0 -22
  137. package/dist/server/context.js +0 -81
  138. package/dist/server/context.js.map +0 -1
  139. package/dist/server/factory.d.ts +0 -10
  140. package/dist/server/factory.js +0 -18
  141. package/dist/server/factory.js.map +0 -1
  142. package/dist/server/index.d.ts +0 -6
  143. package/dist/server/index.js +0 -6
  144. package/dist/server/index.js.map +0 -1
  145. /package/dist/{server/components → components/cms-content-area}/types.js +0 -0
  146. /package/dist/components/{cms-styles.d.ts → cms-styles/index.d.ts} +0 -0
  147. /package/dist/{server → components}/type-utils.d.ts +0 -0
  148. /package/dist/{server → components}/type-utils.js +0 -0
  149. /package/dist/{server/components → components}/visual-builder/types.js +0 -0
  150. /package/dist/{server/components → data}/queries.d.ts +0 -0
@@ -0,0 +1,33 @@
1
+ import 'server-only';
2
+ import { type IOptiGraphClient, type ContentLink } from '@remkoj/optimizely-graph-client';
3
+ import { type GenericContext } from './types.js';
4
+ import { type ComponentFactory } from '../factory/index.js';
5
+ export * from "./types.js";
6
+ type ServerContextArgs = {
7
+ factory?: ComponentFactory;
8
+ client?: IOptiGraphClient;
9
+ locale?: string;
10
+ };
11
+ declare class ServerContext implements GenericContext {
12
+ private _mode;
13
+ private _locale;
14
+ private _client;
15
+ private _factory;
16
+ private _editable;
17
+ get client(): IOptiGraphClient | undefined;
18
+ get factory(): ComponentFactory;
19
+ get locale(): string | undefined;
20
+ get inEditMode(): boolean;
21
+ get inPreviewMode(): boolean;
22
+ get isDevelopment(): boolean;
23
+ get isDebug(): boolean;
24
+ get isDebugOrDevelopment(): boolean;
25
+ get editableContent(): ContentLink | undefined;
26
+ constructor({ factory, client, locale }: ServerContextArgs);
27
+ setMode(mode: 'edit' | 'preview' | 'public'): ServerContext;
28
+ setLocale(locale: string): ServerContext;
29
+ setOptimizelyGraphClient(client: IOptiGraphClient | ((currentClient: IOptiGraphClient | undefined) => IOptiGraphClient | undefined)): void;
30
+ setComponentFactory(factory: ComponentFactory | ((currentClient: ComponentFactory | undefined) => ComponentFactory)): void;
31
+ setEditableContentId(link: ContentLink): void;
32
+ }
33
+ export declare const getServerContext: () => ServerContext;
@@ -0,0 +1,75 @@
1
+ import 'server-only';
2
+ import { createClient, isOptiGraphClient } from '@remkoj/optimizely-graph-client';
3
+ import React from 'react';
4
+ import { DefaultComponentFactory } from '../factory/index.js';
5
+ import { isDebug, isDevelopment } from '../rsc-utilities.js';
6
+ export * from "./types.js";
7
+ const cachePlaceholder = (factory) => {
8
+ if (isDebug())
9
+ console.warn("🚧 [React Context] Running client/server react code instead of server context, no cache() available.");
10
+ return factory;
11
+ };
12
+ //@ts-expect-error React.cache is only available in the react-server context
13
+ const cache = (React.cache || cachePlaceholder);
14
+ class ServerContext {
15
+ get client() {
16
+ return this._client;
17
+ }
18
+ get factory() {
19
+ return this._factory;
20
+ }
21
+ get locale() {
22
+ return this._locale;
23
+ }
24
+ get inEditMode() {
25
+ return this._mode == 'edit';
26
+ }
27
+ get inPreviewMode() {
28
+ return this._mode == 'preview';
29
+ }
30
+ get isDevelopment() {
31
+ return isDevelopment();
32
+ }
33
+ get isDebug() {
34
+ return isDebug();
35
+ }
36
+ get isDebugOrDevelopment() {
37
+ return this.isDebug || this.isDevelopment;
38
+ }
39
+ get editableContent() {
40
+ return this._editable;
41
+ }
42
+ constructor({ factory, client, locale }) {
43
+ this._mode = 'public';
44
+ this._factory = factory || new DefaultComponentFactory();
45
+ this._client = client || createClient();
46
+ this._locale = locale;
47
+ }
48
+ setMode(mode) {
49
+ this._mode = mode;
50
+ return this;
51
+ }
52
+ setLocale(locale) {
53
+ this._locale = locale;
54
+ return this;
55
+ }
56
+ setOptimizelyGraphClient(client) {
57
+ this._client = typeof (client) == 'function' ? client(this._client) : isOptiGraphClient(client) ? client : undefined;
58
+ }
59
+ setComponentFactory(factory) {
60
+ const newFactory = typeof (factory) == 'function' ? factory(this._factory) : factory;
61
+ if (!newFactory)
62
+ throw new Error("Unsetting the context factory is not allowed!");
63
+ this._factory = newFactory;
64
+ }
65
+ setEditableContentId(link) {
66
+ this._editable = link;
67
+ }
68
+ }
69
+ export const getServerContext = cache(() => {
70
+ const ctx = new ServerContext({});
71
+ if (ctx.isDebug)
72
+ console.log('🦺 [ServerContext] Created new context');
73
+ return ctx;
74
+ });
75
+ //# sourceMappingURL=rsc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../src/context/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAA2C,MAAM,iCAAiC,CAAA;AAC1H,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAyB,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AACpF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE5D,cAAc,YAAY,CAAA;AAG1B,MAAM,gBAAgB,GAAsB,CAAkC,OAAU,EAAE,EAAE;IAExF,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M,SAAS,CAAC,MAAc;QAE3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,OAAO,IAAI,CAAA;IACf,CAAC;IACM,wBAAwB,CAAC,MAA0G;QAEtI,IAAI,CAAC,OAAO,GAAG,OAAM,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IACvH,CAAC;IACM,mBAAmB,CAAC,OAA+F;QAEtH,MAAM,UAAU,GAAG,OAAM,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QACnF,IAAI,CAAC,UAAU;YACX,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QACpE,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAA;IAC9B,CAAC;IACM,oBAAoB,CAAC,IAAiB;QAEzC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;IACzB,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,GAAG,EAAE;IACvC,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAA;IACjC,IAAI,GAAG,CAAC,OAAO;QACX,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAA;IACzD,OAAO,GAAG,CAAA;AACd,CAAC,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { type IOptiGraphClient } from "@remkoj/optimizely-graph-client";
2
+ import { type ComponentFactory } from "../factory/types.js";
3
+ export interface GenericContext {
4
+ readonly client?: IOptiGraphClient;
5
+ readonly factory: ComponentFactory;
6
+ readonly locale?: string;
7
+ readonly inEditMode: boolean;
8
+ readonly inPreviewMode: boolean;
9
+ readonly isDevelopment: boolean;
10
+ readonly isDebug: boolean;
11
+ readonly isDebugOrDevelopment: boolean;
12
+ }
13
+ export type PropsWithContext<P = any> = P & {
14
+ ctx: GenericContext;
15
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/server/components/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":""}
@@ -1,142 +1,142 @@
1
1
  import { gql } from 'graphql-request';
2
2
  export const CmsContentFragments = {
3
3
  IContentDataProps: ["_metadata", "_type", "__typename"],
4
- ContentLink: gql `fragment ContentLink on ContentModelReference {
5
- id: Id,
6
- workId: WorkId,
7
- guidValue: GuidValue
4
+ ContentLink: gql `fragment ContentLink on ContentModelReference {
5
+ id: Id,
6
+ workId: WorkId,
7
+ guidValue: GuidValue
8
8
  }`,
9
- ContentLinkSearch: gql `fragment ContentLinkSearch on ContentModelReferenceSearch {
10
- id: Id,
11
- workId: WorkId,
12
- guidValue: GuidValue
9
+ ContentLinkSearch: gql `fragment ContentLinkSearch on ContentModelReferenceSearch {
10
+ id: Id,
11
+ workId: WorkId,
12
+ guidValue: GuidValue
13
13
  }`,
14
- IContentData: gql `fragment IContentData on IContent {
15
- contentType: ContentType
16
- id: ContentLink {
17
- ...ContentLink
18
- }
19
- locale: Language {
20
- name: Name
21
- }
22
- path:RelativePath
14
+ IContentData: gql `fragment IContentData on IContent {
15
+ contentType: ContentType
16
+ id: ContentLink {
17
+ ...ContentLink
18
+ }
19
+ locale: Language {
20
+ name: Name
21
+ }
22
+ path:RelativePath
23
23
  }`,
24
- ContentAreaItemData: gql `fragment ContentAreaItemData on ContentAreaItemModelSearch {
25
- item: ContentLink {
26
- ...ContentLinkSearch
27
- data: Expanded {
28
- ...BlockData
29
- }
30
- }
31
- displayOption:DisplayOption
24
+ ContentAreaItemData: gql `fragment ContentAreaItemData on ContentAreaItemModelSearch {
25
+ item: ContentLink {
26
+ ...ContentLinkSearch
27
+ data: Expanded {
28
+ ...BlockData
29
+ }
30
+ }
31
+ displayOption:DisplayOption
32
32
  }`,
33
- BlockContentAreaItemSearchData: gql `fragment BlockContentAreaItemSearchData on ContentAreaItemModelSearch {
34
- item: ContentLink {
35
- ...ContentLinkSearch
36
- data: Expanded {
37
- ...IContentData
38
- }
39
- }
40
- displayOption:DisplayOption
33
+ BlockContentAreaItemSearchData: gql `fragment BlockContentAreaItemSearchData on ContentAreaItemModelSearch {
34
+ item: ContentLink {
35
+ ...ContentLinkSearch
36
+ data: Expanded {
37
+ ...IContentData
38
+ }
39
+ }
40
+ displayOption:DisplayOption
41
41
  }`,
42
- BlockContentAreaItemData: gql `fragment BlockContentAreaItemData on ContentAreaItemModel {
43
- item: ContentLink {
44
- ...ContentLink
45
- data: Expanded {
46
- ...IContentData
47
- }
48
- }
49
- displayOption:DisplayOption
42
+ BlockContentAreaItemData: gql `fragment BlockContentAreaItemData on ContentAreaItemModel {
43
+ item: ContentLink {
44
+ ...ContentLink
45
+ data: Expanded {
46
+ ...IContentData
47
+ }
48
+ }
49
+ displayOption:DisplayOption
50
50
  }`,
51
- LinkItemData: gql `fragment LinkItemData on LinkItemNode {
52
- children: Text
53
- title: Title
54
- href: Href
55
- target: Target
56
- content: ContentLink {
57
- href: Url
58
- data: Expanded {
59
- path: RelativePath
60
- }
61
- }
51
+ LinkItemData: gql `fragment LinkItemData on LinkItemNode {
52
+ children: Text
53
+ title: Title
54
+ href: Href
55
+ target: Target
56
+ content: ContentLink {
57
+ href: Url
58
+ data: Expanded {
59
+ path: RelativePath
60
+ }
61
+ }
62
62
  }`,
63
- ImageData: gql `fragment ImageData on ContentModelReference {
64
- ...ContentLink
65
- url: Url
66
- data: Expanded {
67
- ...IContentData
68
- url: Url
69
- alt: Name
70
- path: RelativePath
71
- }
63
+ ImageData: gql `fragment ImageData on ContentModelReference {
64
+ ...ContentLink
65
+ url: Url
66
+ data: Expanded {
67
+ ...IContentData
68
+ url: Url
69
+ alt: Name
70
+ path: RelativePath
71
+ }
72
72
  }`,
73
- ImageDataSearch: gql `fragment ImageDataSearch on ContentModelReferenceSearch {
74
- ...ContentLinkSearch
75
- url: Url
76
- data: Expanded {
77
- ...IContentData
78
- url: Url
79
- alt: Name
80
- path: RelativePath
81
- }
73
+ ImageDataSearch: gql `fragment ImageDataSearch on ContentModelReferenceSearch {
74
+ ...ContentLinkSearch
75
+ url: Url
76
+ data: Expanded {
77
+ ...IContentData
78
+ url: Url
79
+ alt: Name
80
+ path: RelativePath
81
+ }
82
82
  }`,
83
- BlockData: gql `fragment BlockData on IContent {
84
- ...IContentData
83
+ BlockData: gql `fragment BlockData on IContent {
84
+ ...IContentData
85
85
  }`,
86
- PageData: gql `fragment PageData on IContent {
87
- ...IContentData
86
+ PageData: gql `fragment PageData on IContent {
87
+ ...IContentData
88
88
  }`
89
89
  };
90
90
  export const ContentAreaFragments = {
91
- ContentAreaItemBase: gql `fragment ContentAreaItemBase on ContentAreaItemModelSearch {
92
- contentLink:ContentLink {
93
- id:Id
94
- workId:WorkId
95
- guidValue:GuidValue
96
- component:Expanded {
97
- path:RelativePath
98
- type:ContentType
99
- }
100
- }
101
- displayOption:DisplayOption
91
+ ContentAreaItemBase: gql `fragment ContentAreaItemBase on ContentAreaItemModelSearch {
92
+ contentLink:ContentLink {
93
+ id:Id
94
+ workId:WorkId
95
+ guidValue:GuidValue
96
+ component:Expanded {
97
+ path:RelativePath
98
+ type:ContentType
99
+ }
100
+ }
101
+ displayOption:DisplayOption
102
102
  }`
103
103
  };
104
- export const getContentById = gql `query getContentById($id: Int, $workId: Int, $guidValue: String, $locale: [Locales!], $isCommonDraft: Boolean) {
105
- content:_Content(
106
- where: {
107
- ContentLink: {
108
- Id: { eq: $id },
109
- WorkId: { eq: $workId },
110
- GuidValue: { eq: $guidValue }
111
- }
112
- IsCommonDraft: { eq: $isCommonDraft }
113
- }
114
- locale: $locale
115
- ) {
116
- total
117
- items {
118
- ...IContentData
119
- ...PageData
120
- ...BlockData
121
- }
122
- }
104
+ export const getContentById = gql `query getContentById($id: Int, $workId: Int, $guidValue: String, $locale: [Locales!], $isCommonDraft: Boolean) {
105
+ content:_Content(
106
+ where: {
107
+ ContentLink: {
108
+ Id: { eq: $id },
109
+ WorkId: { eq: $workId },
110
+ GuidValue: { eq: $guidValue }
111
+ }
112
+ IsCommonDraft: { eq: $isCommonDraft }
113
+ }
114
+ locale: $locale
115
+ ) {
116
+ total
117
+ items {
118
+ ...IContentData
119
+ ...PageData
120
+ ...BlockData
121
+ }
122
+ }
123
123
  }`;
124
- export const getContentByPath = gql `query getContentByPath($path: String!, $locale: [Locales], $siteId: String)
125
- {
126
- content: _Content(
127
- where: {
128
- RelativePath: {
129
- eq: $path
130
- }
131
- SiteId: {
132
- eq: $siteId
133
- }
134
- },
135
- locale: $locale
136
- ) {
137
- items {
138
- ...PageData
139
- }
140
- }
124
+ export const getContentByPath = gql `query getContentByPath($path: String!, $locale: [Locales], $siteId: String)
125
+ {
126
+ content: _Content(
127
+ where: {
128
+ RelativePath: {
129
+ eq: $path
130
+ }
131
+ SiteId: {
132
+ eq: $siteId
133
+ }
134
+ },
135
+ locale: $locale
136
+ ) {
137
+ items {
138
+ ...PageData
139
+ }
140
+ }
141
141
  }`;
142
142
  //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/data/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAErC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,iBAAiB,EAAE,CAAC,WAAW,EAAC,OAAO,EAAC,YAAY,CAAC;IACrD,WAAW,EAAE,GAAG,CAAA;;;;MAId;IACF,iBAAiB,EAAE,GAAG,CAAA;;;;MAIpB;IACF,YAAY,EAAE,GAAG,CAAA;;;;;;;;;MASf;IACF,mBAAmB,EAAE,GAAG,CAAA;;;;;;;;MAQtB;IACF,8BAA8B,EAAE,GAAG,CAAA;;;;;;;;MAQjC;IACF,wBAAwB,EAAE,GAAG,CAAA;;;;;;;;MAQ3B;IACF,YAAY,EAAE,GAAG,CAAA;;;;;;;;;;;MAWf;IACF,SAAS,EAAE,GAAG,CAAA;;;;;;;;;MASZ;IACF,eAAe,EAAE,GAAG,CAAA;;;;;;;;;MASlB;IACF,SAAS,EAAE,GAAG,CAAA;;MAEZ;IACF,QAAQ,EAAE,GAAG,CAAA;;MAEX;CACL,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,mBAAmB,EAAE,GAAG,CAAA;;;;;;;;;;;IAWtB;CACH,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;EAmB/B,CAAA;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;EAiBjC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import type { ComponentFactory, ComponentType, ComponentTypeHandle, ComponentTypeDictionary } from './types.js';
2
+ export declare const MERGE_SYMBOL = "/";
2
3
  export declare const EmptyComponentHandle = "$$fragment$$";
3
4
  /**
4
5
  * The default implementation of the ComponentFactory interface, which works both
@@ -20,21 +21,3 @@ export declare class DefaultComponentFactory implements ComponentFactory {
20
21
  resolve(type: ComponentTypeHandle): undefined | ComponentType;
21
22
  extract(): ComponentTypeDictionary;
22
23
  }
23
- /**
24
- * Retrieve the currently staticly cached ComponentFactory instance, if there's no
25
- * currently staticly cached ComponentFactory, the default ComponentFactory will be
26
- * returned
27
- *
28
- * @returns The ComponentFactory
29
- */
30
- export declare const getFactory: () => ComponentFactory;
31
- /**
32
- * Update the staticly cached Component Factory, which will be returned by all future
33
- * "getFactory" calls
34
- *
35
- * @param newFactory The ComponentFactory to set as staticly cached instance
36
- * @returns void
37
- */
38
- export declare const setFactory: (newFactory: ComponentFactory) => void;
39
- declare const _default: ComponentFactory;
40
- export default _default;
@@ -1,4 +1,4 @@
1
- const MERGE_SYMBOL = '/';
1
+ export const MERGE_SYMBOL = '/';
2
2
  export const EmptyComponentHandle = '$$fragment$$';
3
3
  /**
4
4
  * The default implementation of the ComponentFactory interface, which works both
@@ -62,36 +62,4 @@ function processComponentTypeHandle(handle) {
62
62
  .join(MERGE_SYMBOL); // Types are processed as a string
63
63
  throw new Error(`Invalid component type handle: ${typeof (handle)}`);
64
64
  }
65
- const _static = {};
66
- /**
67
- * Retrieve the currently staticly cached ComponentFactory instance, if there's no
68
- * currently staticly cached ComponentFactory, the default ComponentFactory will be
69
- * returned
70
- *
71
- * @returns The ComponentFactory
72
- */
73
- export const getFactory = () => {
74
- const DBG = process.env.OPTIMIZELY_DEBUG == '1';
75
- if (!_static.factory) {
76
- if (DBG)
77
- console.log("⚪ [ComponentFactory] Creating new Component Factory");
78
- _static.factory = new DefaultComponentFactory();
79
- }
80
- else {
81
- if (DBG)
82
- console.log("⚪ [ComponentFactory] Reusing existing Component Factory");
83
- }
84
- return _static.factory;
85
- };
86
- /**
87
- * Update the staticly cached Component Factory, which will be returned by all future
88
- * "getFactory" calls
89
- *
90
- * @param newFactory The ComponentFactory to set as staticly cached instance
91
- * @returns void
92
- */
93
- export const setFactory = (newFactory) => {
94
- _static.factory = newFactory;
95
- };
96
- export default getFactory();
97
- //# sourceMappingURL=factory.js.map
65
+ //# sourceMappingURL=default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/factory/default.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAE/B,MAAM,CAAC,MAAM,oBAAoB,GAAI,cAAc,CAAA;AAEnD;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAIhC;;;;;OAKG;IACH,YAAmB,iBAA2C;QATtD,aAAQ,GAA2C,EAAE,CAAA;QAWzD,IAAI,CAAC,GAAG,GAAG,OAAO,CA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types.js";
2
+ export type * from "./types.js";
3
+ export { DefaultComponentFactory } from "./default.js";
4
+ /**
5
+ * The default merge symbol to use when converting between an array based
6
+ * ComponentTypeHandle and strig based ComponentTypeHandle
7
+ */
8
+ export declare const TYPE_MERGE_SYMBOL = "/";
9
+ /**
10
+ * Create a new instance of the included DefaultComponentFactory, which should
11
+ * be wrapped in a form of caching provided by your project.
12
+ *
13
+ * @returns The ComponentFactory
14
+ */
15
+ export declare const getFactory: () => ComponentFactory;
16
+ declare const _default: ComponentFactory;
17
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { DefaultComponentFactory, MERGE_SYMBOL } from "./default.js";
2
+ export { DefaultComponentFactory } from "./default.js";
3
+ /**
4
+ * The default merge symbol to use when converting between an array based
5
+ * ComponentTypeHandle and strig based ComponentTypeHandle
6
+ */
7
+ export const TYPE_MERGE_SYMBOL = MERGE_SYMBOL;
8
+ /**
9
+ * Create a new instance of the included DefaultComponentFactory, which should
10
+ * be wrapped in a form of caching provided by your project.
11
+ *
12
+ * @returns The ComponentFactory
13
+ */
14
+ export const getFactory = () => {
15
+ const DBG = process.env.OPTIMIZELY_DEBUG == '1';
16
+ if (DBG)
17
+ console.log("⚪ [ComponentFactory] Creating new Component Factory");
18
+ return new DefaultComponentFactory();
19
+ };
20
+ export default getFactory();
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAEtD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAA4B,GAAG,EAAE;IACpD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,GAAG,CAAA;IAC/C,IAAI,GAAG;QAAE,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAA;IAC3E,OAAO,IAAI,uBAAuB,EAAE,CAAA;AACxC,CAAC,CAAA;AAED,eAAe,UAAU,EAAE,CAAA"}
@@ -0,0 +1,51 @@
1
+ import type { ComponentType as ReactComponentType, ExoticComponent as ReactExoticComponent } from "react";
2
+ /**
3
+ * Basic Component Type descriptor for the Component Factory
4
+ */
5
+ export type ComponentType = (ReactComponentType<any>) | (ReactExoticComponent<any>) | (keyof JSX.IntrinsicElements);
6
+ /**
7
+ *
8
+ */
9
+ export type ComponentTypeHandle = string | string[];
10
+ export type ComponentTypeDictionary = {
11
+ type: ComponentTypeHandle;
12
+ component: ComponentType;
13
+ }[];
14
+ /**
15
+ * Component Factory
16
+ */
17
+ export interface ComponentFactory {
18
+ /**
19
+ * Check if the component type has been registered within the factory
20
+ *
21
+ * @param type The component type to check for
22
+ * @returns Whether or not the type exists within the factory
23
+ */
24
+ has(type: ComponentTypeHandle): boolean;
25
+ /**
26
+ * Register an individual component
27
+ * @param type The component type to register
28
+ * @param componentType The component to bind to the type
29
+ */
30
+ register(type: ComponentTypeHandle, componentType: ComponentType): void;
31
+ /**
32
+ * Register all components provided through the dictionary
33
+ *
34
+ * @param components The components to register
35
+ */
36
+ registerAll(components: ComponentTypeDictionary): void;
37
+ /**
38
+ * Resolve a component type
39
+ *
40
+ * @param type The type to search the component for
41
+ * @returns The component that was resolved for the provided type
42
+ */
43
+ resolve(type: ComponentTypeHandle): ComponentType | undefined;
44
+ /**
45
+ * Retrieve the registered components as a dictionary that can be used to
46
+ * be imported in a new instance.
47
+ *
48
+ * @returns The dictionary
49
+ */
50
+ extract(): ComponentTypeDictionary;
51
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/factory/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { ComponentType, ComponentTypeDictionary, ComponentTypeHandle, type ComponentFactory } from "./types.js";
2
+ export declare class UndefinedComponentFactory implements ComponentFactory {
3
+ has(type: ComponentTypeHandle): boolean;
4
+ register(type: ComponentTypeHandle, componentType: ComponentType): void;
5
+ registerAll(components: ComponentTypeDictionary): void;
6
+ resolve(type: ComponentTypeHandle): ComponentType | undefined;
7
+ extract(): ComponentTypeDictionary;
8
+ }
9
+ export default UndefinedComponentFactory;
@@ -0,0 +1,19 @@
1
+ export class UndefinedComponentFactory {
2
+ has(type) {
3
+ throw new Error("Factory not specified, please specify a factory.");
4
+ }
5
+ register(type, componentType) {
6
+ throw new Error("Factory not specified, please specify a factory.");
7
+ }
8
+ registerAll(components) {
9
+ throw new Error("Factory not specified, please specify a factory.");
10
+ }
11
+ resolve(type) {
12
+ throw new Error("Factory not specified, please specify a factory.");
13
+ }
14
+ extract() {
15
+ throw new Error("Factory not specified, please specify a factory.");
16
+ }
17
+ }
18
+ export default UndefinedComponentFactory;
19
+ //# sourceMappingURL=undef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"undef.js","sourceRoot":"","sources":["../../src/factory/undef.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,yBAAyB;IAClC,GAAG,CAAC,IAAyB;QACzB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IACD,QAAQ,CAAC,IAAyB,EAAE,aAA4B;QAC5D,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IACD,WAAW,CAAC,UAAmC;QAC3C,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,CAAC,IAAyB;QAC7B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO;QACH,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;CACJ;AAED,eAAe,yBAAyB,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * The version of the current Optimizely DXP React SDK
3
3
  */
4
- export declare const Version = "2.0.0";
4
+ export declare const Version = "3.1.0";
5
5
  export * from './types.js';
6
6
  export * as Errors from './errors.js';
7
7
  export * as Utils from './utilities.js';
8
- export * from './factory.js';
8
+ export * from './context/client.js';
9
+ export * from './factory/index.js';
10
+ export * from './components/client.js';
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * The version of the current Optimizely DXP React SDK
3
3
  */
4
- export const Version = '2.0.0';
4
+ export const Version = '3.1.0';
5
5
  // Export library
6
6
  export * from './types.js';
7
7
  export * as Errors from './errors.js';
8
8
  export * as Utils from './utilities.js';
9
- export * from './factory.js';
9
+ export * from './context/client.js';
10
+ export * from './factory/index.js';
11
+ export * from './components/client.js';
10
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA;AAE9B,iBAAiB;AACjB,cAAc,YAAY,CAAA;AAC1B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA;AAE9B,iBAAiB;AACjB,cAAc,YAAY,CAAA;AAC1B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AAEvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA"}