@contentful/experiences-sdk-react 1.9.0-dev-20240628T2235-7a4f71f.0 → 1.9.0-dev-20240628T2250-7a4f71f.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 (89) hide show
  1. package/dist/ExperienceRoot.js +25 -0
  2. package/dist/ExperienceRoot.js.map +1 -0
  3. package/dist/blocks/editor/VisualEditorInjectScript.js +38 -0
  4. package/dist/blocks/editor/VisualEditorInjectScript.js.map +1 -0
  5. package/dist/blocks/editor/VisualEditorLoader.js +28 -0
  6. package/dist/blocks/editor/VisualEditorLoader.js.map +1 -0
  7. package/dist/blocks/editor/VisualEditorRoot.js +17 -0
  8. package/dist/blocks/editor/VisualEditorRoot.js.map +1 -0
  9. package/dist/blocks/preview/CompositionBlock.js +132 -0
  10. package/dist/blocks/preview/CompositionBlock.js.map +1 -0
  11. package/dist/blocks/preview/PreviewDeliveryRoot.js +23 -0
  12. package/dist/blocks/preview/PreviewDeliveryRoot.js.map +1 -0
  13. package/dist/components/Assembly.js +13 -0
  14. package/dist/components/Assembly.js.map +1 -0
  15. package/dist/components/ErrorBoundary.js +37 -0
  16. package/dist/components/ErrorBoundary.js.map +1 -0
  17. package/dist/constants.js +5 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/core/componentRegistry.js +292 -0
  20. package/dist/core/componentRegistry.js.map +1 -0
  21. package/dist/core/preview/assemblyUtils.js +71 -0
  22. package/dist/core/preview/assemblyUtils.js.map +1 -0
  23. package/dist/core/sdkFeatures.js +7 -0
  24. package/dist/core/sdkFeatures.js.map +1 -0
  25. package/dist/hooks/useBreakpoints.js +40 -0
  26. package/dist/hooks/useBreakpoints.js.map +1 -0
  27. package/dist/hooks/useClassName.js +42 -0
  28. package/dist/hooks/useClassName.js.map +1 -0
  29. package/dist/hooks/useDetectEditorMode.js +60 -0
  30. package/dist/hooks/useDetectEditorMode.js.map +1 -0
  31. package/dist/hooks/useFetchByBase.js +38 -0
  32. package/dist/hooks/useFetchByBase.js.map +1 -0
  33. package/dist/hooks/useFetchById.js +16 -0
  34. package/dist/hooks/useFetchById.js.map +1 -0
  35. package/dist/hooks/useFetchBySlug.js +16 -0
  36. package/dist/hooks/useFetchBySlug.js.map +1 -0
  37. package/dist/hooks/useInitializeVisualEditor.js +56 -0
  38. package/dist/hooks/useInitializeVisualEditor.js.map +1 -0
  39. package/dist/index.d.ts +67 -0
  40. package/dist/index.js +16 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/sdkVersion.js +4 -0
  43. package/dist/sdkVersion.js.map +1 -0
  44. package/dist/src/ExperienceRoot.d.ts +10 -0
  45. package/dist/src/blocks/editor/VisualEditorInjectScript.d.ts +4 -0
  46. package/dist/src/blocks/editor/VisualEditorLoader.d.ts +9 -0
  47. package/dist/src/blocks/editor/VisualEditorRoot.d.ts +10 -0
  48. package/dist/src/blocks/preview/CompositionBlock.d.ts +11 -0
  49. package/dist/src/blocks/preview/CompositionBlock.spec.d.ts +1 -0
  50. package/dist/src/blocks/preview/PreviewDeliveryRoot.d.ts +8 -0
  51. package/dist/src/blocks/preview/PreviewDeliveryRoot.test.d.ts +1 -0
  52. package/dist/src/components/Assembly.d.ts +3 -0
  53. package/dist/src/components/ErrorBoundary.d.ts +19 -0
  54. package/dist/src/components/Flex.d.ts +64 -0
  55. package/dist/src/constants.d.ts +3 -0
  56. package/dist/src/core/componentRegistry.d.ts +32 -0
  57. package/dist/src/core/componentRegistry.test.d.ts +1 -0
  58. package/dist/src/core/index.d.ts +1 -0
  59. package/dist/src/core/preview/assemblyUtils.d.ts +10 -0
  60. package/dist/src/core/preview/assemblyUtils.spec.d.ts +1 -0
  61. package/dist/src/core/sdkFeatures.d.ts +1 -0
  62. package/dist/src/hooks/index.d.ts +3 -0
  63. package/dist/src/hooks/useBreakpoints.d.ts +4 -0
  64. package/dist/src/hooks/useBreakpoints.spec.d.ts +1 -0
  65. package/dist/src/hooks/useClassName.d.ts +13 -0
  66. package/dist/src/hooks/useClassName.spec.d.ts +1 -0
  67. package/dist/src/hooks/useDetectEditorMode.d.ts +7 -0
  68. package/dist/src/hooks/useFetchByBase.d.ts +8 -0
  69. package/dist/src/hooks/useFetchById.d.ts +17 -0
  70. package/dist/src/hooks/useFetchById.spec.d.ts +1 -0
  71. package/dist/src/hooks/useFetchBySlug.d.ts +18 -0
  72. package/dist/src/hooks/useFetchBySlug.spec.d.ts +1 -0
  73. package/dist/src/hooks/useInitializeVisualEditor.d.ts +7 -0
  74. package/dist/src/hooks/usePrevious.d.ts +6 -0
  75. package/dist/src/index.d.ts +7 -0
  76. package/dist/src/sdkVersion.d.ts +1 -0
  77. package/dist/src/utils/withComponentWrapper.d.ts +22 -0
  78. package/dist/src/utils/withComponentWrapper.spec.d.ts +1 -0
  79. package/dist/styles/ErrorBoundary.css.js +7 -0
  80. package/dist/styles/ErrorBoundary.css.js.map +1 -0
  81. package/dist/test/__fixtures__/assembly.d.ts +96 -0
  82. package/dist/test/__fixtures__/composition.d.ts +7 -0
  83. package/dist/test/__fixtures__/entities.d.ts +9 -0
  84. package/dist/test/components/Test.d.ts +1 -0
  85. package/dist/test/components/Test.spec.d.ts +1 -0
  86. package/dist/utils/withComponentWrapper.js +32 -0
  87. package/dist/utils/withComponentWrapper.js.map +1 -0
  88. package/dist/vite.config.d.ts +2 -0
  89. package/package.json +6 -6
@@ -0,0 +1,292 @@
1
+ import * as Components from '@contentful/experiences-components-react';
2
+ import { INTERNAL_EVENTS, CONTENTFUL_COMPONENTS, OUTGOING_EVENTS, ASSEMBLY_DEFAULT_CATEGORY } from '@contentful/experiences-core/constants';
3
+ import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, breakpointsRegistry, designTokensRegistry } from '@contentful/experiences-core';
4
+ import { validateComponentDefinition } from '@contentful/experiences-validators';
5
+ import { withComponentWrapper } from '../utils/withComponentWrapper.js';
6
+ import { SDK_VERSION } from '../sdkVersion.js';
7
+
8
+ const CssVarRegex = /var\(--[\w-]+\)/;
9
+ const cloneObject = (targetObject) => {
10
+ if (typeof structuredClone !== 'undefined') {
11
+ return structuredClone(targetObject);
12
+ }
13
+ return JSON.parse(JSON.stringify(targetObject));
14
+ };
15
+ const applyComponentDefinitionFallbacks = (componentDefinition) => {
16
+ const clone = cloneObject(componentDefinition);
17
+ for (const variable of Object.values(clone.variables)) {
18
+ variable.group = variable.group ?? 'content';
19
+ }
20
+ return clone;
21
+ };
22
+ const applyBuiltInStyleDefinitions = (componentDefinition) => {
23
+ if ([CONTENTFUL_COMPONENTS.container.id].includes(componentDefinition.id)) {
24
+ return componentDefinition;
25
+ }
26
+ const clone = cloneObject(componentDefinition);
27
+ // set margin built-in style by default
28
+ if (!clone.builtInStyles) {
29
+ clone.builtInStyles = ['cfMargin'];
30
+ }
31
+ for (const style of Object.values(clone.builtInStyles || [])) {
32
+ if (builtInStyles[style]) {
33
+ clone.variables[style] = builtInStyles[style];
34
+ }
35
+ if (optionalBuiltInStyles[style]) {
36
+ clone.variables[style] = optionalBuiltInStyles[style];
37
+ }
38
+ }
39
+ return clone;
40
+ };
41
+ const enrichComponentDefinition = ({ component, definition, options, }) => {
42
+ const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);
43
+ const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);
44
+ return {
45
+ component: withComponentWrapper(component, options),
46
+ definition: definitionWithBuiltInStyles,
47
+ options,
48
+ };
49
+ };
50
+ const DEFAULT_COMPONENT_REGISTRATIONS = {
51
+ container: {
52
+ component: Components.ContentfulContainer,
53
+ definition: containerDefinition,
54
+ },
55
+ section: {
56
+ component: Components.ContentfulContainer,
57
+ definition: sectionDefinition,
58
+ },
59
+ columns: {
60
+ component: Components.Columns,
61
+ definition: columnsDefinition,
62
+ },
63
+ singleColumn: {
64
+ component: Components.SingleColumn,
65
+ definition: singleColumnDefinition,
66
+ },
67
+ button: enrichComponentDefinition({
68
+ component: Components.Button,
69
+ definition: Components.ButtonComponentDefinition,
70
+ options: {
71
+ wrapComponent: false,
72
+ },
73
+ }),
74
+ heading: enrichComponentDefinition({
75
+ component: Components.Heading,
76
+ definition: Components.HeadingComponentDefinition,
77
+ options: {
78
+ wrapComponent: false,
79
+ },
80
+ }),
81
+ image: enrichComponentDefinition({
82
+ component: Components.Image,
83
+ definition: Components.ImageComponentDefinition,
84
+ options: { wrapComponent: false },
85
+ }),
86
+ richText: enrichComponentDefinition({
87
+ component: Components.RichText,
88
+ definition: Components.RichTextComponentDefinition,
89
+ options: {
90
+ wrapComponent: false,
91
+ },
92
+ }),
93
+ text: enrichComponentDefinition({
94
+ component: Components.Text,
95
+ definition: Components.TextComponentDefinition,
96
+ options: {
97
+ wrapComponent: false,
98
+ },
99
+ }),
100
+ divider: {
101
+ component: Components.ContentfulDivider,
102
+ definition: dividerDefinition,
103
+ options: {
104
+ wrapComponent: false,
105
+ },
106
+ },
107
+ };
108
+ // pre-filling with the default component registrations
109
+ const componentRegistry = new Map([
110
+ [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],
111
+ [
112
+ DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,
113
+ DEFAULT_COMPONENT_REGISTRATIONS.container,
114
+ ],
115
+ [
116
+ DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,
117
+ DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,
118
+ ],
119
+ [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],
120
+ [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],
121
+ [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],
122
+ [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],
123
+ [
124
+ DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,
125
+ DEFAULT_COMPONENT_REGISTRATIONS.richText,
126
+ ],
127
+ [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],
128
+ [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],
129
+ ]);
130
+ const optionalBuiltInComponents = [
131
+ DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,
132
+ DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,
133
+ DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,
134
+ DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,
135
+ DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,
136
+ ];
137
+ const sendRegisteredComponentsMessage = () => {
138
+ // Send the definitions (without components) via the connection message to the experience builder
139
+ const registeredDefinitions = Array.from(componentRegistry.values()).map(({ definition }) => definition);
140
+ sendMessage(OUTGOING_EVENTS.RegisteredComponents, {
141
+ definitions: registeredDefinitions,
142
+ });
143
+ };
144
+ const runRegisteredComponentValidations = () => {
145
+ Array.from(componentRegistry.values()).map(({ definition }) => {
146
+ const validation = validateComponentDefinition(definition);
147
+ if (!validation.success) {
148
+ throw new Error(`Invalid component definition for component '${definition.name}'. Failed with errors: \n${JSON.stringify(validation.errors, null, 2)}`);
149
+ }
150
+ });
151
+ };
152
+ const getSingleCssVariableValue = (element, cssVariableValue, cssAttribute) => {
153
+ element.style[cssAttribute] = cssVariableValue;
154
+ const styles = getComputedStyle(element);
155
+ const resolvedValue = styles.getPropertyValue(cssAttribute);
156
+ return resolvedValue;
157
+ };
158
+ const getAllCssVariableValues = (element, cssVariable, cssAttribute) => {
159
+ const resolvedCssVariables = {};
160
+ Object.keys(cssVariable).forEach((key) => {
161
+ const cssVariableValue = cssVariable[key];
162
+ if (CssVarRegex.test(cssVariableValue)) {
163
+ const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);
164
+ resolvedCssVariables[cssVariableValue] = resolvedValue;
165
+ }
166
+ });
167
+ return resolvedCssVariables;
168
+ };
169
+ const resolveCssVariables = (designTokensDefinition) => {
170
+ const { spacing, sizing, color, borderRadius, fontSize, lineHeight, letterSpacing, textColor, border, } = designTokensDefinition;
171
+ const resolvedCssVariables = {};
172
+ // Create an element
173
+ const element = document.createElement('div');
174
+ document.body.appendChild(element);
175
+ const cssProperties = [
176
+ { variable: spacing, property: 'margin' },
177
+ { variable: sizing, property: 'width' },
178
+ { variable: color, property: 'background-color' },
179
+ { variable: borderRadius, property: 'border-radius' },
180
+ { variable: fontSize, property: 'font-size' },
181
+ { variable: lineHeight, property: 'line-height' },
182
+ { variable: letterSpacing, property: 'letter-spacing' },
183
+ { variable: textColor, property: 'color' },
184
+ ];
185
+ cssProperties.forEach(({ variable, property }) => {
186
+ if (variable) {
187
+ const rawResolvedValues = getAllCssVariableValues(element, variable, property);
188
+ Object.assign(resolvedCssVariables, rawResolvedValues);
189
+ }
190
+ });
191
+ if (border) {
192
+ const tempResolvedValue = {};
193
+ Object.keys(border).forEach((borderKey) => {
194
+ const { width, style, color } = border[borderKey];
195
+ if (width && CssVarRegex.test(width)) {
196
+ const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');
197
+ tempResolvedValue[width] = resolvedValue;
198
+ }
199
+ if (style && CssVarRegex.test(style)) {
200
+ const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');
201
+ tempResolvedValue[style] = resolvedValue;
202
+ }
203
+ if (color && CssVarRegex.test(color)) {
204
+ const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');
205
+ tempResolvedValue[color] = resolvedValue;
206
+ }
207
+ Object.assign(resolvedCssVariables, tempResolvedValue);
208
+ });
209
+ }
210
+ document.body.removeChild(element);
211
+ return resolvedCssVariables;
212
+ };
213
+ const sendConnectedEventWithRegisteredComponents = () => {
214
+ // Send the definitions (without components) via the connection message to the experience builder
215
+ const registeredDefinitions = Array.from(componentRegistry.values()).map(({ definition }) => definition);
216
+ sendMessage(OUTGOING_EVENTS.Connected, {
217
+ sdkVersion: SDK_VERSION,
218
+ definitions: registeredDefinitions,
219
+ });
220
+ sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {
221
+ breakpoints: breakpointsRegistry,
222
+ });
223
+ sendMessage(OUTGOING_EVENTS.DesignTokens, {
224
+ designTokens: designTokensRegistry,
225
+ resolvedCssVariables: resolveCssVariables(designTokensRegistry),
226
+ });
227
+ };
228
+ /**
229
+ * Registers multiple components and their component definitions at once
230
+ * @param componentRegistrations - ComponentRegistration[]
231
+ * @returns void
232
+ */
233
+ const defineComponents = (componentRegistrations, options) => {
234
+ if (options?.enabledBuiltInComponents) {
235
+ for (const id of optionalBuiltInComponents) {
236
+ if (!options.enabledBuiltInComponents.includes(id)) {
237
+ componentRegistry.delete(id);
238
+ }
239
+ }
240
+ }
241
+ for (const registration of componentRegistrations) {
242
+ // Fill definitions with fallbacks values
243
+ const enrichedComponentRegistration = enrichComponentDefinition(registration);
244
+ componentRegistry.set(enrichedComponentRegistration.definition.id, enrichedComponentRegistration);
245
+ }
246
+ if (typeof window !== 'undefined') {
247
+ window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));
248
+ }
249
+ };
250
+ const getComponentRegistration = (id) => componentRegistry.get(id);
251
+ const addComponentRegistration = (componentRegistration) => {
252
+ componentRegistry.set(componentRegistration.definition.id, componentRegistration);
253
+ };
254
+ const createAssemblyRegistration = ({ definitionId, definitionName, component, }) => {
255
+ const componentRegistration = componentRegistry.get(definitionId);
256
+ if (componentRegistration) {
257
+ return componentRegistration;
258
+ }
259
+ const definition = {
260
+ id: definitionId,
261
+ name: definitionName || 'Component',
262
+ variables: {},
263
+ children: true,
264
+ category: ASSEMBLY_DEFAULT_CATEGORY,
265
+ };
266
+ addComponentRegistration({ component, definition });
267
+ return componentRegistry.get(definitionId);
268
+ };
269
+ /**
270
+ * @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible
271
+ * with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use
272
+ * the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components
273
+ * (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)
274
+ * will be removed in the next major release.
275
+ */
276
+ const maintainBasicComponentIdsWithoutPrefix = () => {
277
+ optionalBuiltInComponents.forEach((id) => {
278
+ if (componentRegistry.has(id) && id.startsWith('contentful-')) {
279
+ const registeredComponent = componentRegistry.get(id);
280
+ const definition = registeredComponent.definition;
281
+ const newDefinition = cloneObject(definition);
282
+ newDefinition.name = newDefinition.name + '[OLD]';
283
+ const newId = id.replace('contentful-', '');
284
+ newDefinition.id = newId;
285
+ const newRegisteredComponent = { ...registeredComponent, definition: newDefinition };
286
+ componentRegistry.set(newId, newRegisteredComponent);
287
+ }
288
+ });
289
+ };
290
+
291
+ export { addComponentRegistration, componentRegistry, createAssemblyRegistration, defineComponents, enrichComponentDefinition, getComponentRegistration, maintainBasicComponentIdsWithoutPrefix, optionalBuiltInComponents, runRegisteredComponentValidations, sendConnectedEventWithRegisteredComponents, sendRegisteredComponentsMessage };
292
+ //# sourceMappingURL=componentRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n containerDefinition,\n sectionDefinition,\n columnsDefinition,\n singleColumnDefinition,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport { dividerDefinition } from '@contentful/experiences-core';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n if ([CONTENTFUL_COMPONENTS.container.id].includes(componentDefinition.id)) {\n return componentDefinition;\n }\n\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n for (const style of Object.values(clone.builtInStyles || [])) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style];\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style];\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: {\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n },\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {} as ComponentDefinition['variables'],\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n\n/**\n * @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible\n * with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use\n * the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components\n * (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)\n * will be removed in the next major release.\n */\nexport const maintainBasicComponentIdsWithoutPrefix = () => {\n optionalBuiltInComponents.forEach((id) => {\n if (componentRegistry.has(id) && id.startsWith('contentful-')) {\n const registeredComponent = componentRegistry.get(id)!;\n const definition = registeredComponent.definition;\n const newDefinition = cloneObject(definition);\n newDefinition.name = newDefinition.name + '[OLD]';\n const newId = id.replace('contentful-', '');\n newDefinition.id = newId;\n const newRegisteredComponent = { ...registeredComponent, definition: newDefinition };\n componentRegistry.set(newId, newRegisteredComponent);\n }\n });\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;AA6BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAAA,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,mBAAwC,KAAI;AACrF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;AAC/C,IAAA,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACrD,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,SAAS,CAAC;KAC9C;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,mBAAwC,KAAI;AAChF,IAAA,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,EAAE;AACzE,QAAA,OAAO,mBAAmB,CAAC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pD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C,EAAE;AAEF;;;;;;AAMG;AACI,MAAM,sCAAsC,GAAG,MAAK;AACzD,IAAA,yBAAyB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAI;AACvC,QAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;YAC7D,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;AACvD,YAAA,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC;AAClD,YAAA,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YAC9C,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,GAAG,OAAO,CAAC;YAClD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC5C,YAAA,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC;YACzB,MAAM,sBAAsB,GAAG,EAAE,GAAG,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACrF,YAAA,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;SACtD;AACH,KAAC,CAAC,CAAC;AACL;;;;"}
@@ -0,0 +1,71 @@
1
+ import { checkIsAssemblyNode } from '@contentful/experiences-core';
2
+
3
+ const deserializeAssemblyNode = ({ node, componentInstanceVariables, }) => {
4
+ const variables = {};
5
+ for (const [variableName, variable] of Object.entries(node.variables)) {
6
+ variables[variableName] = variable;
7
+ if (variable.type === 'ComponentValue') {
8
+ const componentValueKey = variable.key;
9
+ const instanceProperty = componentInstanceVariables[componentValueKey];
10
+ // For assembly, we look up the variable in the assembly instance and
11
+ // replace the componentValue with that one.
12
+ if (instanceProperty?.type === 'UnboundValue') {
13
+ variables[variableName] = {
14
+ type: 'UnboundValue',
15
+ key: instanceProperty.key,
16
+ };
17
+ }
18
+ else if (instanceProperty?.type === 'BoundValue') {
19
+ variables[variableName] = {
20
+ type: 'BoundValue',
21
+ path: instanceProperty.path,
22
+ };
23
+ }
24
+ else if (instanceProperty?.type === 'HyperlinkValue') {
25
+ variables[variableName] = {
26
+ type: 'HyperlinkValue',
27
+ linkTargetKey: instanceProperty.linkTargetKey,
28
+ };
29
+ }
30
+ }
31
+ }
32
+ const children = node.children.map((child) => deserializeAssemblyNode({
33
+ node: child,
34
+ componentInstanceVariables,
35
+ }));
36
+ return {
37
+ definitionId: node.definitionId,
38
+ variables,
39
+ children,
40
+ slotId: node.slotId,
41
+ displayName: node.displayName,
42
+ };
43
+ };
44
+ const resolveAssembly = ({ node, entityStore, }) => {
45
+ const isAssembly = checkIsAssemblyNode({
46
+ componentId: node.definitionId,
47
+ usedComponents: entityStore.usedComponents,
48
+ });
49
+ if (!isAssembly) {
50
+ return node;
51
+ }
52
+ const componentId = node.definitionId;
53
+ const assembly = entityStore.experienceEntryFields?.usedComponents?.find((component) => component.sys.id === componentId);
54
+ if (!assembly || !('fields' in assembly)) {
55
+ return node;
56
+ }
57
+ const componentFields = assembly.fields;
58
+ const deserializedNode = deserializeAssemblyNode({
59
+ node: {
60
+ definitionId: node.definitionId,
61
+ variables: node.variables,
62
+ children: componentFields.componentTree.children,
63
+ },
64
+ componentInstanceVariables: node.variables,
65
+ });
66
+ entityStore.addAssemblyUnboundValues(componentFields.unboundValues);
67
+ return deserializedNode;
68
+ };
69
+
70
+ export { deserializeAssemblyNode, resolveAssembly };
71
+ //# sourceMappingURL=assemblyUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { checkIsAssemblyNode, EntityStore } from '@contentful/experiences-core';\nimport type { ComponentPropertyValue, ComponentTreeNode } from '@contentful/experiences-core/types';\n\nexport const deserializeAssemblyNode = ({\n node,\n componentInstanceVariables,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the componentValue with that one.\n if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) =>\n deserializeAssemblyNode({\n node: child,\n componentInstanceVariables,\n }),\n );\n\n return {\n definitionId: node.definitionId,\n variables,\n children,\n slotId: node.slotId,\n displayName: node.displayName,\n };\n};\n\nexport const resolveAssembly = ({\n node,\n entityStore,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n}) => {\n const isAssembly = checkIsAssemblyNode({\n componentId: node.definitionId,\n usedComponents: entityStore.usedComponents,\n });\n\n if (!isAssembly) {\n return node;\n }\n\n const componentId = node.definitionId as string;\n const assembly = entityStore.experienceEntryFields?.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!assembly || !('fields' in assembly)) {\n return node;\n }\n\n const componentFields = assembly.fields;\n\n const deserializedNode = deserializeAssemblyNode({\n node: {\n definitionId: node.definitionId,\n variables: node.variables,\n children: componentFields.componentTree.children,\n },\n componentInstanceVariables: node.variables,\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;AAGa,MAAA,uBAAuB,GAAG,CAAC,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
+
6
+ export { sdkFeatures };
7
+ //# sourceMappingURL=sdkFeatures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdkFeatures.js","sources":["../../../src/core/sdkFeatures.ts"],"sourcesContent":["// Object to store the SDK features that are enabled/disabled\nexport const sdkFeatures: Record<string, unknown> = {\n hasSDKVersionUI: true,\n};\n"],"names":[],"mappings":"AAAA;AACa,MAAA,WAAW,GAA4B;AAClD,IAAA,eAAe,EAAE,IAAI;;;;;"}
@@ -0,0 +1,40 @@
1
+ import { mediaQueryMatcher, getFallbackBreakpointIndex, getActiveBreakpointIndex, getValueForBreakpoint } from '@contentful/experiences-core';
2
+ import { useState, useEffect, useCallback } from 'react';
3
+
4
+ // TODO: In order to support integrations without React, we should extract this heavy logic into simple
5
+ // functions that we can reuse in other frameworks.
6
+ /*
7
+ * Registers media query change listeners for each breakpoint (except for "*").
8
+ * It will always assume the last matching media query in the list. It therefore,
9
+ * assumes that the breakpoints are sorted beginning with the default value (query: "*")
10
+ * and then decending by screen width. For mobile-first designs, the order would be ascending
11
+ */
12
+ const useBreakpoints = (breakpoints) => {
13
+ const [mediaQueryMatchers, initialMediaQueryMatches] = mediaQueryMatcher(breakpoints);
14
+ const [mediaQueryMatches, setMediaQueryMatches] = useState(initialMediaQueryMatches);
15
+ const fallbackBreakpointIndex = getFallbackBreakpointIndex(breakpoints);
16
+ // Register event listeners to update the media query states
17
+ useEffect(() => {
18
+ const eventListeners = mediaQueryMatchers.map(({ id, signal }) => {
19
+ const onChange = () => setMediaQueryMatches((prev) => ({
20
+ ...prev,
21
+ [id]: signal.matches,
22
+ }));
23
+ signal.addEventListener('change', onChange);
24
+ return onChange;
25
+ });
26
+ return () => {
27
+ eventListeners.forEach((eventListener, index) => {
28
+ mediaQueryMatchers[index].signal.removeEventListener('change', eventListener);
29
+ });
30
+ };
31
+ }, [mediaQueryMatchers]);
32
+ const activeBreakpointIndex = getActiveBreakpointIndex(breakpoints, mediaQueryMatches, fallbackBreakpointIndex);
33
+ const resolveDesignValue = useCallback((valuesByBreakpoint, variableName) => {
34
+ return getValueForBreakpoint(valuesByBreakpoint, breakpoints, activeBreakpointIndex, variableName);
35
+ }, [activeBreakpointIndex, breakpoints]);
36
+ return { resolveDesignValue };
37
+ };
38
+
39
+ export { useBreakpoints };
40
+ //# sourceMappingURL=useBreakpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBreakpoints.js","sources":["../../../src/hooks/useBreakpoints.ts"],"sourcesContent":["import type {\n ValuesByBreakpoint,\n Breakpoint,\n PrimitiveValue,\n ResolveDesignValueType,\n} from '@contentful/experiences-core/types';\nimport {\n mediaQueryMatcher,\n getFallbackBreakpointIndex,\n getActiveBreakpointIndex,\n getValueForBreakpoint,\n} from '@contentful/experiences-core';\nimport { useCallback, useEffect, useState } from 'react';\n\n// TODO: In order to support integrations without React, we should extract this heavy logic into simple\n// functions that we can reuse in other frameworks.\n\n/*\n * Registers media query change listeners for each breakpoint (except for \"*\").\n * It will always assume the last matching media query in the list. It therefore,\n * assumes that the breakpoints are sorted beginning with the default value (query: \"*\")\n * and then decending by screen width. For mobile-first designs, the order would be ascending\n */\nexport const useBreakpoints = (breakpoints: Breakpoint[]) => {\n const [mediaQueryMatchers, initialMediaQueryMatches] = mediaQueryMatcher(breakpoints);\n\n const [mediaQueryMatches, setMediaQueryMatches] =\n useState<Record<string, boolean>>(initialMediaQueryMatches);\n\n const fallbackBreakpointIndex = getFallbackBreakpointIndex(breakpoints);\n\n // Register event listeners to update the media query states\n useEffect(() => {\n const eventListeners = mediaQueryMatchers.map(({ id, signal }) => {\n const onChange = () =>\n setMediaQueryMatches((prev) => ({\n ...prev,\n [id]: signal.matches,\n }));\n signal.addEventListener('change', onChange);\n return onChange;\n });\n\n return () => {\n eventListeners.forEach((eventListener, index) => {\n mediaQueryMatchers[index].signal.removeEventListener('change', eventListener);\n });\n };\n }, [mediaQueryMatchers]);\n\n const activeBreakpointIndex = getActiveBreakpointIndex(\n breakpoints,\n mediaQueryMatches,\n fallbackBreakpointIndex,\n );\n\n const resolveDesignValue: ResolveDesignValueType = useCallback(\n (valuesByBreakpoint: ValuesByBreakpoint, variableName: string): PrimitiveValue => {\n return getValueForBreakpoint(\n valuesByBreakpoint,\n breakpoints,\n activeBreakpointIndex,\n variableName,\n );\n },\n [activeBreakpointIndex, breakpoints],\n );\n\n return { resolveDesignValue };\n};\n"],"names":[],"mappings":";;;AAcA;AACA;AAEA;;;;;AAKG;AACU,MAAA,cAAc,GAAG,CAAC,WAAyB,KAAI;IAC1D,MAAM,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAEtF,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAC7C,QAAQ,CAA0B,wBAAwB,CAAC,CAAC;AAE9D,IAAA,MAAM,uBAAuB,GAAG,0BAA0B,CAAC,WAAW,CAAC,CAAC;;IAGxE,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,cAAc,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAI;AAC/D,YAAA,MAAM,QAAQ,GAAG,MACf,oBAAoB,CAAC,CAAC,IAAI,MAAM;AAC9B,gBAAA,GAAG,IAAI;AACP,gBAAA,CAAC,EAAE,GAAG,MAAM,CAAC,OAAO;AACrB,aAAA,CAAC,CAAC,CAAC;AACN,YAAA,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5C,YAAA,OAAO,QAAQ,CAAC;AAClB,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,MAAK;YACV,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,KAAI;AAC9C,gBAAA,kBAAkB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AAChF,aAAC,CAAC,CAAC;AACL,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAEzB,MAAM,qBAAqB,GAAG,wBAAwB,CACpD,WAAW,EACX,iBAAiB,EACjB,uBAAuB,CACxB,CAAC;IAEF,MAAM,kBAAkB,GAA2B,WAAW,CAC5D,CAAC,kBAAsC,EAAE,YAAoB,KAAoB;QAC/E,OAAO,qBAAqB,CAC1B,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,YAAY,CACb,CAAC;AACJ,KAAC,EACD,CAAC,qBAAqB,EAAE,WAAW,CAAC,CACrC,CAAC;IAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAChC;;;;"}
@@ -0,0 +1,42 @@
1
+ import { useState, useLayoutEffect } from 'react';
2
+ import { buildCfStyles, isStructureWithRelativeHeight, buildStyleTag } from '@contentful/experiences-core';
3
+ import { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';
4
+
5
+ /**
6
+ * This hook can generate className and inject styles on a client side as a <style> tag
7
+ * or it derives the className set on the server side
8
+ *
9
+ * @param node: the componenet node for which the styles will be injected
10
+ * @param props: the props of the component, represented by the node
11
+ * @returns the className that was eitner generated on the client side or derived from the value, set on server side
12
+ */
13
+ const useClassName = ({ node, props, }) => {
14
+ const [className, setClassName] = useState(props.cfSsrClassName ?? '');
15
+ // Once our React support allows it (>=18), this should be implemented with useInsertionEffect.
16
+ useLayoutEffect(() => {
17
+ if (props.cfSsrClassName) {
18
+ // class name has been already set on the server side. No need to calculate it on client side anymore
19
+ return;
20
+ }
21
+ const cfStyles = buildCfStyles(props);
22
+ if (Object.keys(cfStyles).length === 0) {
23
+ return;
24
+ }
25
+ if (!node.children.length &&
26
+ isStructureWithRelativeHeight(node.definitionId, cfStyles.height)) {
27
+ cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;
28
+ }
29
+ const [className, styleRule] = buildStyleTag({ styles: cfStyles });
30
+ if (!className || !styleRule) {
31
+ return;
32
+ }
33
+ const styleTag = document.createElement('style');
34
+ styleTag.dataset['cfStyles'] = className;
35
+ setClassName(className);
36
+ document.head.appendChild(styleTag).innerHTML = styleRule;
37
+ }, [props, node]);
38
+ return className;
39
+ };
40
+
41
+ export { useClassName };
42
+ //# sourceMappingURL=useClassName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClassName.js","sources":["../../../src/hooks/useClassName.ts"],"sourcesContent":["import { useLayoutEffect, useState } from 'react';\n\nimport {\n buildCfStyles,\n buildStyleTag,\n isStructureWithRelativeHeight,\n} from '@contentful/experiences-core';\nimport { ComponentTreeNode } from '@contentful/experiences-core/types';\nimport { EMPTY_CONTAINER_HEIGHT } from '@contentful/experiences-core/constants';\n\n/**\n * This hook can generate className and inject styles on a client side as a <style> tag\n * or it derives the className set on the server side\n *\n * @param node: the componenet node for which the styles will be injected\n * @param props: the props of the component, represented by the node\n * @returns the className that was eitner generated on the client side or derived from the value, set on server side\n */\nexport const useClassName = ({\n node,\n props,\n}: {\n node: ComponentTreeNode;\n props: Record<string, any>;\n}) => {\n const [className, setClassName] = useState<string>(props.cfSsrClassName ?? '');\n // Once our React support allows it (>=18), this should be implemented with useInsertionEffect.\n useLayoutEffect(() => {\n if (props.cfSsrClassName) {\n // class name has been already set on the server side. No need to calculate it on client side anymore\n return;\n }\n\n const cfStyles = buildCfStyles(props);\n\n if (Object.keys(cfStyles).length === 0) {\n return;\n }\n\n if (\n !node.children.length &&\n isStructureWithRelativeHeight(node.definitionId, cfStyles.height)\n ) {\n cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;\n }\n\n const [className, styleRule] = buildStyleTag({ styles: cfStyles });\n\n if (!className || !styleRule) {\n return;\n }\n\n const styleTag = document.createElement('style');\n styleTag.dataset['cfStyles'] = className;\n\n setClassName(className);\n\n document.head.appendChild(styleTag).innerHTML = styleRule;\n }, [props, node]);\n\n return className;\n};\n"],"names":[],"mappings":";;;;AAUA;;;;;;;AAOG;AACU,MAAA,YAAY,GAAG,CAAC,EAC3B,IAAI,EACJ,KAAK,GAIN,KAAI;AACH,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAS,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;;IAE/E,eAAe,CAAC,MAAK;AACnB,QAAA,IAAI,KAAK,CAAC,cAAc,EAAE;;YAExB,OAAO;SACR;AAED,QAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACtC,OAAO;SACR;AAED,QAAA,IACE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YACrB,6BAA6B,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,EACjE;AACA,YAAA,QAAQ,CAAC,SAAS,GAAG,sBAAsB,CAAC;SAC7C;AAED,QAAA,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEnE,QAAA,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE;YAC5B,OAAO;SACR;QAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjD,QAAA,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;QAEzC,YAAY,CAAC,SAAS,CAAC,CAAC;QAExB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC;AAC5D,KAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAElB,IAAA,OAAO,SAAS,CAAC;AACnB;;;;"}
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ import { useState, useRef, useEffect } from 'react';
3
+ import { sendMessage, doesMismatchMessageSchema, tryParseMessage } from '@contentful/experiences-core';
4
+ import { OUTGOING_EVENTS, INCOMING_EVENTS } from '@contentful/experiences-core/constants';
5
+ import { sdkFeatures } from '../core/sdkFeatures.js';
6
+
7
+ const useDetectEditorMode = ({ isClientSide = false } = {}) => {
8
+ const [mounted, setMounted] = useState(false);
9
+ const [isEditorMode, setIsEditorMode] = useState(isClientSide ? inIframe() : false);
10
+ const receivedMessage = useRef(false);
11
+ useEffect(() => {
12
+ const onMessage = (event) => {
13
+ if (doesMismatchMessageSchema(event)) {
14
+ return;
15
+ }
16
+ const eventData = tryParseMessage(event);
17
+ if (eventData.eventType === INCOMING_EVENTS.RequestEditorMode) {
18
+ setIsEditorMode(true);
19
+ receivedMessage.current = true;
20
+ if (typeof window !== 'undefined') {
21
+ //Once we definitely know that we are in editor mode, we set this flag so future postMessage connect calls are not made
22
+ window.__EB__.isEditorMode = true;
23
+ window.removeEventListener('message', onMessage);
24
+ }
25
+ }
26
+ };
27
+ //Only run check after component is mounted on the client to avoid hydration ssr issues
28
+ if (mounted) {
29
+ setIsEditorMode(inIframe());
30
+ //Double check if we are in editor mode by listening to postMessage events
31
+ if (typeof window !== 'undefined' && !window.__EB__?.isEditorMode) {
32
+ window.addEventListener('message', onMessage);
33
+ sendMessage(OUTGOING_EVENTS.Connected, undefined);
34
+ sendMessage(OUTGOING_EVENTS.SDKFeatures, sdkFeatures);
35
+ setTimeout(() => {
36
+ if (!receivedMessage.current) {
37
+ // if message is not received back in time, set editorMode back to false
38
+ setIsEditorMode(false);
39
+ }
40
+ }, 100);
41
+ }
42
+ }
43
+ else {
44
+ setMounted(true);
45
+ }
46
+ return () => window.removeEventListener('message', onMessage);
47
+ }, [mounted]);
48
+ return isEditorMode;
49
+ };
50
+ function inIframe() {
51
+ try {
52
+ return window.self !== window.top;
53
+ }
54
+ catch (e) {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ export { useDetectEditorMode };
60
+ //# sourceMappingURL=useDetectEditorMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDetectEditorMode.js","sources":["../../../src/hooks/useDetectEditorMode.tsx"],"sourcesContent":["'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n doesMismatchMessageSchema,\n sendMessage,\n tryParseMessage,\n} from '@contentful/experiences-core';\nimport { INCOMING_EVENTS, OUTGOING_EVENTS } from '@contentful/experiences-core/constants';\nimport { sdkFeatures } from '../core/sdkFeatures';\n\ntype UseDetectEditorModeArgs = {\n /** If running from a known client side only situation (ie: useFetchBySlug),\n * set this to true to kick in editor mode check sooner (which avoids a render cycle) */\n isClientSide?: boolean;\n};\n\nexport const useDetectEditorMode = ({ isClientSide = false }: UseDetectEditorModeArgs = {}) => {\n const [mounted, setMounted] = useState(false);\n const [isEditorMode, setIsEditorMode] = useState(isClientSide ? inIframe() : false);\n const receivedMessage = useRef(false);\n\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n if (doesMismatchMessageSchema(event)) {\n return;\n }\n const eventData = tryParseMessage(event);\n\n if (eventData.eventType === INCOMING_EVENTS.RequestEditorMode) {\n setIsEditorMode(true);\n receivedMessage.current = true;\n if (typeof window !== 'undefined') {\n //Once we definitely know that we are in editor mode, we set this flag so future postMessage connect calls are not made\n window.__EB__.isEditorMode = true;\n window.removeEventListener('message', onMessage);\n }\n }\n };\n\n //Only run check after component is mounted on the client to avoid hydration ssr issues\n if (mounted) {\n setIsEditorMode(inIframe());\n //Double check if we are in editor mode by listening to postMessage events\n if (typeof window !== 'undefined' && !window.__EB__?.isEditorMode) {\n window.addEventListener('message', onMessage);\n sendMessage(OUTGOING_EVENTS.Connected, undefined);\n sendMessage(OUTGOING_EVENTS.SDKFeatures, sdkFeatures);\n\n setTimeout(() => {\n if (!receivedMessage.current) {\n // if message is not received back in time, set editorMode back to false\n setIsEditorMode(false);\n }\n }, 100);\n }\n } else {\n setMounted(true);\n }\n\n return () => window.removeEventListener('message', onMessage);\n }, [mounted]);\n\n return isEditorMode;\n};\n\nfunction inIframe() {\n try {\n return window.self !== window.top;\n } catch (e) {\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;;AAgBO;;AAEL;AACA;;AAGE;AACE;;;AAGA;;;AAIE;AACA;;AAEE;AACA;;;AAGN;;;AAIE;;AAEA;AACE;AACA;AACA;;AAGE;;;;;;;;;;;AAWR;AAEA;AACF;AAEA;AACE;AACE;;;AAEA;;AAEJ;;"}
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { useState, useEffect } from 'react';
3
+
4
+ const useFetchByBase = (fetchMethod, isEditorMode) => {
5
+ const [experience, setExperience] = useState();
6
+ const [isLoading, setIsLoading] = useState(false);
7
+ const [error, setError] = useState();
8
+ useEffect(() => {
9
+ (async () => {
10
+ // if we are in editor mode, we don't want to fetch the experience here
11
+ // it is passed via postMessage instead
12
+ if (isEditorMode) {
13
+ return;
14
+ }
15
+ setIsLoading(true);
16
+ setError(undefined);
17
+ try {
18
+ const exp = await fetchMethod();
19
+ setExperience(exp);
20
+ }
21
+ catch (error) {
22
+ setError(error);
23
+ }
24
+ finally {
25
+ setIsLoading(false);
26
+ }
27
+ })();
28
+ }, [fetchMethod, isEditorMode]);
29
+ return {
30
+ error,
31
+ experience,
32
+ isLoading,
33
+ isEditorMode,
34
+ };
35
+ };
36
+
37
+ export { useFetchByBase };
38
+ //# sourceMappingURL=useFetchByBase.js.map