@contentful/experiences-sdk-react 1.7.1 → 1.7.2-dev-20240613T1745-9217fd8.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _contentful_experiences_core from '@contentful/experiences-core';
3
3
  import { EntityStore, VisualEditorMode } from '@contentful/experiences-core';
4
- export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, fetchById, fetchBySlug } from '@contentful/experiences-core';
4
+ export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
5
5
  import { Experience, ComponentRegistration, ComponentRegistrationOptions } from '@contentful/experiences-core/types';
6
6
  export { ComponentDefinition, ExternalSDKMode } from '@contentful/experiences-core/types';
7
7
  import { ContentfulClientApi } from 'contentful';
@@ -64,6 +64,4 @@ declare const defineComponents: (componentRegistrations: ComponentRegistration[]
64
64
  */
65
65
  declare const maintainBasicComponentIdsWithoutPrefix: () => void;
66
66
 
67
- declare const detachExperienceStyles: (experience: Experience) => string | undefined;
68
-
69
- export { ExperienceRoot, defineComponents, detachExperienceStyles, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
67
+ export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
- import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, breakpointsRegistry, designTokensRegistry, buildCfStyles, isStructureWithRelativeHeight, buildStyleTag, checkIsAssemblyNode, resolveHyperlinkPattern, transformBoundContentValue, mediaQueryMatcher, getFallbackBreakpointIndex, getActiveBreakpointIndex, getValueForBreakpoint, doesMismatchMessageSchema, tryParseMessage, fetchById, fetchBySlug, runBreakpointsValidation, validateExperienceBuilderConfig, VisualEditorMode, toCSSAttribute } from '@contentful/experiences-core';
3
- export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, fetchById, fetchBySlug } from '@contentful/experiences-core';
2
+ import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, breakpointsRegistry, designTokensRegistry, buildCfStyles, isStructureWithRelativeHeight, buildStyleTag, checkIsAssemblyNode, resolveHyperlinkPattern, transformBoundContentValue, mediaQueryMatcher, getFallbackBreakpointIndex, getActiveBreakpointIndex, getValueForBreakpoint, doesMismatchMessageSchema, tryParseMessage, fetchById, fetchBySlug, runBreakpointsValidation, validateExperienceBuilderConfig, VisualEditorMode } from '@contentful/experiences-core';
3
+ export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
4
4
  import React, { useState, useLayoutEffect, useMemo, useEffect, useCallback, useRef, Suspense } from 'react';
5
5
  import { omit } from 'lodash-es';
6
6
  import { INTERNAL_EVENTS, CONTENTFUL_COMPONENTS, OUTGOING_EVENTS, ASSEMBLY_DEFAULT_CATEGORY, EMPTY_CONTAINER_HEIGHT, HYPERLINK_DEFAULT_PATTERN, CF_STYLE_ATTRIBUTES, INCOMING_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';
@@ -8,9 +8,8 @@ export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } fro
8
8
  import * as Components from '@contentful/experiences-components-react';
9
9
  import { ContentfulContainer, Columns, SingleColumn } from '@contentful/experiences-components-react';
10
10
  import styleInject from 'style-inject';
11
- import md5 from 'md5';
12
11
 
13
- const SDK_VERSION = '1.7.1';
12
+ const SDK_VERSION = '1.7.2-dev-20240613T1745-9217fd8.0';
14
13
 
15
14
  var util;
16
15
  (function (util) {
@@ -4768,7 +4767,7 @@ const resolveAssembly = ({ node, entityStore, }) => {
4768
4767
  const deserializedNode = deserializeAssemblyNode({
4769
4768
  node: {
4770
4769
  definitionId: node.definitionId,
4771
- variables: {},
4770
+ variables: node.variables,
4772
4771
  children: componentFields.componentTree.children,
4773
4772
  },
4774
4773
  componentInstanceVariables: node.variables,
@@ -4810,15 +4809,15 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
4810
4809
  return registration;
4811
4810
  }, [isAssembly, node.definitionId]);
4812
4811
  const nodeProps = useMemo(() => {
4813
- // Don't enrich the assembly wrapper node with props
4814
- if (!componentRegistration || isAssembly) {
4815
- return {};
4816
- }
4817
4812
  const propMap = {
4818
4813
  cfSsrClassName: node.variables.cfSsrClassName
4819
4814
  ? resolveDesignValue(node.variables.cfSsrClassName.valuesByBreakpoint, 'cfSsrClassName')
4820
4815
  : undefined,
4821
4816
  };
4817
+ // Don't enrich the assembly wrapper node with props
4818
+ if (!componentRegistration || isAssembly) {
4819
+ return propMap;
4820
+ }
4822
4821
  const props = Object.entries(componentRegistration.definition.variables).reduce((acc, [variableName, variableDefinition]) => {
4823
4822
  const variable = node.variables[variableName];
4824
4823
  if (!variable)
@@ -5166,429 +5165,6 @@ const ExperienceRoot = ({ locale, experience, visualEditorMode = VisualEditorMod
5166
5165
  return jsx(PreviewDeliveryRoot, { locale: locale, experience: experience });
5167
5166
  };
5168
5167
 
5169
- const detachExperienceStyles = (experience) => {
5170
- const experienceTreeRoot = experience.entityStore?.experienceEntryFields
5171
- ?.componentTree;
5172
- if (!experienceTreeRoot) {
5173
- return;
5174
- }
5175
- const mapOfDesignVariableKeys = flattenDesignTokenRegistry(designTokensRegistry);
5176
- // getting breakpoints from the entry componentTree field
5177
- /**
5178
- * breakpoints [
5179
- {
5180
- id: 'desktop',
5181
- query: '*',
5182
- displayName: 'All Sizes',
5183
- previewSize: '100%'
5184
- },
5185
- {
5186
- id: 'tablet',
5187
- query: '<992px',
5188
- displayName: 'Tablet',
5189
- previewSize: '820px'
5190
- },
5191
- {
5192
- id: 'mobile',
5193
- query: '<576px',
5194
- displayName: 'Mobile',
5195
- previewSize: '390px'
5196
- }
5197
- ]
5198
- */
5199
- const { breakpoints } = experienceTreeRoot;
5200
- // creating the structure which I thought would work best for aggregation
5201
- const mediaQueriesTemplate = breakpoints.reduce((mediaQueryTemplate, breakpoint) => {
5202
- return {
5203
- ...mediaQueryTemplate,
5204
- [breakpoint.id]: {
5205
- condition: breakpoint.query,
5206
- cssByClassName: {},
5207
- },
5208
- };
5209
- }, {});
5210
- // getting the breakpoint ids
5211
- const breakpointIds = Object.keys(mediaQueriesTemplate);
5212
- const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, }) => {
5213
- // traversing the tree
5214
- const queue = [];
5215
- queue.push(...componentTree.children);
5216
- let currentNode = undefined;
5217
- const registeredComponenIds = Array.from(componentRegistry.values()).map(({ definition }) => definition.id);
5218
- // for each tree node
5219
- while (queue.length) {
5220
- currentNode = queue.shift();
5221
- if (!currentNode) {
5222
- break;
5223
- }
5224
- const isPatternNode = !registeredComponenIds.includes(currentNode.definitionId);
5225
- if (isPatternNode) {
5226
- const patternEntry = experience.entityStore?.entities.find((entry) => entry.sys.id === currentNode.definitionId);
5227
- if (!patternEntry) {
5228
- continue;
5229
- }
5230
- // the node of a used pattern contains only the definitionId (id of the patter entry)
5231
- // as well as the variables overwrites
5232
- // the layout of a pattern is stored in it's entry
5233
- iterateOverTreeAndExtractStyles({
5234
- // that is why we pass it here to iterate of the pattern tree
5235
- componentTree: patternEntry.fields.componentTree,
5236
- // but we pass the data source of the experience entry cause that's where the binding is stored
5237
- dataSource,
5238
- // unbound values of a pattern store the default values of pattern variables
5239
- unboundValues: patternEntry.fields.unboundValues,
5240
- // this is where we can map the pattern variable to it's default value
5241
- componentSettings: patternEntry.fields.componentSettings,
5242
- // and this is where the over-writes for the default values are stored
5243
- // yes, I know, it's a bit confusing
5244
- componentVariablesOverwrites: currentNode.variables,
5245
- });
5246
- continue;
5247
- }
5248
- /** Variables value is stored in `valuesByBreakpoint` object
5249
- * {
5250
- cfVerticalAlignment: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'center' } },
5251
- cfHorizontalAlignment: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'center' } },
5252
- cfMargin: { type: 'DesignValue', valuesByBreakpoint: { desktop: '0 0 0 0' } },
5253
- cfPadding: { type: 'DesignValue', valuesByBreakpoint: { desktop: '0 0 0 0' } },
5254
- cfBackgroundColor: {
5255
- type: 'DesignValue',
5256
- valuesByBreakpoint: { desktop: 'rgba(246, 246, 246, 1)' }
5257
- },
5258
- cfWidth: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'fill' } },
5259
- cfHeight: {
5260
- type: 'DesignValue',
5261
- valuesByBreakpoint: { desktop: 'fit-content' }
5262
- },
5263
- cfMaxWidth: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'none' } },
5264
- cfFlexDirection: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'column' } },
5265
- cfFlexWrap: { type: 'DesignValue', valuesByBreakpoint: { desktop: 'nowrap' } },
5266
- cfBorder: {
5267
- type: 'DesignValue',
5268
- valuesByBreakpoint: { desktop: '0px solid rgba(0, 0, 0, 0)' }
5269
- },
5270
- cfBorderRadius: { type: 'DesignValue', valuesByBreakpoint: { desktop: '0px' } },
5271
- cfGap: { type: 'DesignValue', valuesByBreakpoint: { desktop: '0px 0px' } },
5272
- cfHyperlink: { type: 'UnboundValue', key: 'VNc49Qyepd6IzN7rmKUyS' },
5273
- cfOpenInNewTab: { type: 'UnboundValue', key: 'ZA5YqB2fmREQ4pTKqY5hX' },
5274
- cfBackgroundImageUrl: { type: 'UnboundValue', key: 'FeskH0WbYD5_RQVXX-1T8' },
5275
- cfBackgroundImageOptions: { type: 'DesignValue', valuesByBreakpoint: { desktop: [Object] } }
5276
- }
5277
- */
5278
- // so first, I convert it into a map to help me make it easier to access the values
5279
- const propsByBreakpoint = indexByBreakpoint({
5280
- variables: currentNode.variables,
5281
- breakpointIds,
5282
- unboundValues: unboundValues,
5283
- dataSource: dataSource,
5284
- componentSettings,
5285
- componentVariablesOverwrites,
5286
- getBoundEntityById: (id) => {
5287
- return experience.entityStore?.entities.find((entity) => entity.sys.id === id);
5288
- },
5289
- });
5290
- /**
5291
- * propsByBreakpoint {
5292
- desktop: {
5293
- cfVerticalAlignment: 'center',
5294
- cfHorizontalAlignment: 'center',
5295
- cfMargin: '0 0 0 0',
5296
- cfPadding: '0 0 0 0',
5297
- cfBackgroundColor: 'rgba(246, 246, 246, 1)',
5298
- cfWidth: 'fill',
5299
- cfHeight: 'fit-content',
5300
- cfMaxWidth: 'none',
5301
- cfFlexDirection: 'column',
5302
- cfFlexWrap: 'nowrap',
5303
- cfBorder: '0px solid rgba(0, 0, 0, 0)',
5304
- cfBorderRadius: '0px',
5305
- cfGap: '0px 0px',
5306
- cfBackgroundImageOptions: { scaling: 'fill', alignment: 'left top', targetSize: '2000px' }
5307
- },
5308
- tablet: {},
5309
- mobile: {}
5310
- }
5311
- */
5312
- const currentNodeClassNames = [];
5313
- // then for each breakpoint
5314
- for (const breakpointId of breakpointIds) {
5315
- const propsByBreakpointWithResolvedDesignTokens = Object.entries(propsByBreakpoint[breakpointId]).reduce((acc, [variableName, variableValue]) => {
5316
- return {
5317
- ...acc,
5318
- [variableName]: maybePopulateDesignTokenValue(variableName, variableValue, mapOfDesignVariableKeys),
5319
- };
5320
- }, {});
5321
- // We convert cryptic prop keys to css variables
5322
- // Eg: cfMargin to margin
5323
- const stylesForBreakpoint = buildCfStyles(propsByBreakpointWithResolvedDesignTokens);
5324
- const stylesForBreakpointWithoutUndefined = Object.fromEntries(Object.entries(stylesForBreakpoint)
5325
- .filter(([, value]) => value !== undefined)
5326
- .map(([key, value]) => [toCSSAttribute(key), value]));
5327
- /**
5328
- * stylesForBreakpoint {
5329
- margin: '0 0 0 0',
5330
- padding: '0 0 0 0',
5331
- 'background-color': 'rgba(246, 246, 246, 1)',
5332
- width: '100%',
5333
- height: 'fit-content',
5334
- 'max-width': 'none',
5335
- border: '0px solid rgba(0, 0, 0, 0)',
5336
- 'border-radius': '0px',
5337
- gap: '0px 0px',
5338
- 'align-items': 'center',
5339
- 'justify-content': 'safe center',
5340
- 'flex-direction': 'column',
5341
- 'flex-wrap': 'nowrap',
5342
- 'font-style': 'normal',
5343
- 'text-decoration': 'none',
5344
- 'box-sizing': 'border-box'
5345
- }
5346
- */
5347
- // I create a hash of the object above because that would ensure hash stability
5348
- const styleHash = md5(JSON.stringify(stylesForBreakpointWithoutUndefined));
5349
- // and prefix the className to make sure the value can be processed
5350
- const className = `cf-${styleHash}`;
5351
- // I save the generated hashes into an array to later save it in the tree node
5352
- // as cfSsrClassName prop
5353
- // making sure to avoid the duplicates in case styles for > 1 breakpoints are the same
5354
- if (!currentNodeClassNames.includes(className)) {
5355
- currentNodeClassNames.push(className);
5356
- }
5357
- // if there is already the similar hash - no need to over-write it
5358
- if (mediaQueriesTemplate[breakpointId].cssByClassName[className]) {
5359
- continue;
5360
- }
5361
- // otherwise, save it to the stylesheet
5362
- mediaQueriesTemplate[breakpointId].cssByClassName[className] = toCSSString(stylesForBreakpointWithoutUndefined);
5363
- }
5364
- // all generated classNames are saved in the tree node
5365
- // to be handled by the sdk later
5366
- // each node will get N classNames, where N is the number of breakpoints
5367
- // browsers process classNames in the order they are defined
5368
- // meaning that in case of className1 className2 className3
5369
- // className3 will win over className2 and className1
5370
- // making sure that we respect the order of breakpoints from
5371
- // we can achieve "desktop first" or "mobile first" approach to style over-writes
5372
- currentNode.variables.cfSsrClassName = {
5373
- type: 'DesignValue',
5374
- valuesByBreakpoint: {
5375
- [breakpointIds[0]]: currentNodeClassNames.join(' '),
5376
- },
5377
- };
5378
- queue.push(...currentNode.children);
5379
- }
5380
- };
5381
- iterateOverTreeAndExtractStyles({
5382
- componentTree: experienceTreeRoot,
5383
- dataSource: experience.entityStore?.dataSource ?? {},
5384
- unboundValues: experience.entityStore?.unboundValues ?? {},
5385
- componentSettings: experience.entityStore?.experienceEntryFields?.componentSettings,
5386
- });
5387
- // once the whole tree was traversed, for each breakpoint, I aggregate the styles
5388
- // for each generated className into one css string
5389
- const styleSheet = Object.entries(mediaQueriesTemplate).reduce((acc, [, breakpointPayload]) => {
5390
- return `${acc}${toMediaQuery(breakpointPayload)}`;
5391
- }, '');
5392
- return styleSheet;
5393
- };
5394
- const isCfStyleAttribute = (variableName) => {
5395
- return CF_STYLE_ATTRIBUTES.includes(variableName);
5396
- };
5397
- const maybePopulateDesignTokenValue = (variableName, variableValue, mapOfDesignVariableKeys) => {
5398
- // TODO: refactor to reuse fn from core package
5399
- if (typeof variableValue !== 'string') {
5400
- return variableValue;
5401
- }
5402
- if (!isCfStyleAttribute(variableName)) {
5403
- return variableValue;
5404
- }
5405
- const resolveSimpleDesignToken = (variableName, variableValue) => {
5406
- const nonTemplateDesignTokenValue = variableValue.replace(templateStringRegex, '$1');
5407
- const tokenValue = mapOfDesignVariableKeys[nonTemplateDesignTokenValue];
5408
- if (!tokenValue) {
5409
- if (builtInStyles[variableName]) {
5410
- return builtInStyles[variableName].defaultValue;
5411
- }
5412
- if (optionalBuiltInStyles[variableName]) {
5413
- return optionalBuiltInStyles[variableName].defaultValue;
5414
- }
5415
- return '0px';
5416
- }
5417
- if (variableName === 'cfBorder' || variableName.startsWith('cfBorder_')) {
5418
- const { width, style, color } = tokenValue;
5419
- return `${width} ${style} ${color}`;
5420
- }
5421
- return tokenValue;
5422
- };
5423
- const templateStringRegex = /\${(.+?)}/g;
5424
- const parts = variableValue.split(' ');
5425
- let resolvedValue = '';
5426
- for (const part of parts) {
5427
- const tokenValue = templateStringRegex.test(part)
5428
- ? resolveSimpleDesignToken(variableName, part)
5429
- : part;
5430
- resolvedValue += `${tokenValue} `;
5431
- }
5432
- // Not trimming would end up with a trailing space that breaks the check in `calculateNodeDefaultHeight`
5433
- return resolvedValue.trim();
5434
- };
5435
- const resolveBackgroundImageBinding = ({ variableData, getBoundEntityById, dataSource = {}, unboundValues = {}, componentVariablesOverwrites, componentSettings = { variableDefinitions: {} }, }) => {
5436
- if (variableData.type === 'UnboundValue') {
5437
- const uuid = variableData.key;
5438
- return unboundValues[uuid]?.value;
5439
- }
5440
- if (variableData.type === 'ComponentValue') {
5441
- const variableDefinitionKey = variableData.key;
5442
- const variableDefinition = componentSettings.variableDefinitions[variableDefinitionKey];
5443
- // @ts-expect-error TODO: fix the types as it thinks taht `defaultValue` is of type string
5444
- const defaultValueKey = variableDefinition.defaultValue?.key;
5445
- const defaultValue = unboundValues[defaultValueKey].value;
5446
- const userSetValue = componentVariablesOverwrites?.[variableDefinitionKey];
5447
- if (!userSetValue) {
5448
- return defaultValue;
5449
- }
5450
- // at this point userSetValue will either be type of 'DesignValue' or 'BoundValue'
5451
- // so we recursively run resolution again to resolve it
5452
- const resolvedValue = resolveBackgroundImageBinding({
5453
- variableData: userSetValue,
5454
- getBoundEntityById,
5455
- dataSource,
5456
- unboundValues,
5457
- componentVariablesOverwrites,
5458
- componentSettings,
5459
- });
5460
- return resolvedValue || defaultValue;
5461
- }
5462
- if (variableData.type === 'BoundValue') {
5463
- // '/lUERH7tX7nJTaPX6f0udB/fields/assetReference/~locale/fields/file/~locale'
5464
- const [, uuid] = variableData.path.split('/');
5465
- const binding = dataSource[uuid];
5466
- const boundEntity = getBoundEntityById(binding.sys.id);
5467
- if (!boundEntity) {
5468
- return;
5469
- }
5470
- if (boundEntity.sys.type === 'Asset') {
5471
- return boundEntity.fields.file?.url;
5472
- }
5473
- else {
5474
- // '/lUERH7tX7nJTaPX6f0udB/fields/assetReference/~locale/fields/file/~locale'
5475
- // becomes
5476
- // '/fields/assetReference/~locale/fields/file/~locale'
5477
- const pathWithoutUUID = variableData.path.split(uuid)[1];
5478
- // '/fields/assetReference/~locale/fields/file/~locale'
5479
- // becomes
5480
- // '/fields/assetReference/'
5481
- const pathToReferencedAsset = pathWithoutUUID.split('~locale')[0];
5482
- // '/fields/assetReference/'
5483
- // becomes
5484
- // '[fields, assetReference]'
5485
- const [, fieldName] = pathToReferencedAsset.substring(1).split('/') ?? undefined;
5486
- const referenceToAsset = boundEntity.fields[fieldName];
5487
- if (!referenceToAsset) {
5488
- return;
5489
- }
5490
- if (referenceToAsset.sys?.linkType === 'Asset') {
5491
- const referencedAsset = getBoundEntityById(referenceToAsset.sys.id);
5492
- if (!referencedAsset) {
5493
- return;
5494
- }
5495
- return referencedAsset.fields.file?.url;
5496
- }
5497
- }
5498
- }
5499
- };
5500
- const indexByBreakpoint = ({ variables, breakpointIds, getBoundEntityById, unboundValues = {}, dataSource = {}, componentVariablesOverwrites, componentSettings = { variableDefinitions: {} }, }) => {
5501
- const variableValuesByBreakpoints = breakpointIds.reduce((acc, breakpointId) => {
5502
- return {
5503
- ...acc,
5504
- [breakpointId]: {},
5505
- };
5506
- }, {});
5507
- const defaultBreakpoint = breakpointIds[0];
5508
- for (const [variableName, variableData] of Object.entries(variables)) {
5509
- // handling the special case - cfBackgroundImageUrl variable, which can be bound or unbound
5510
- // so, we need to resolve it here and pass it down as a css property to be convereted into the CSS
5511
- // I used .startsWith() cause it can be part of a pattern node
5512
- if (variableName === 'cfBackgroundImageUrl' ||
5513
- variableName.startsWith('cfBackgroundImageUrl_')) {
5514
- const imageUrl = resolveBackgroundImageBinding({
5515
- variableData,
5516
- getBoundEntityById,
5517
- unboundValues,
5518
- dataSource,
5519
- componentSettings,
5520
- componentVariablesOverwrites,
5521
- });
5522
- if (imageUrl) {
5523
- variableValuesByBreakpoints[defaultBreakpoint][variableName] = imageUrl;
5524
- }
5525
- continue;
5526
- }
5527
- if (variableData.type !== 'DesignValue') {
5528
- continue;
5529
- }
5530
- for (const [breakpointId, variableValue] of Object.entries(variableData.valuesByBreakpoint)) {
5531
- if (!variableValue) {
5532
- continue;
5533
- }
5534
- variableValuesByBreakpoints[breakpointId] = {
5535
- ...variableValuesByBreakpoints[breakpointId],
5536
- [variableName]: variableValue,
5537
- };
5538
- }
5539
- }
5540
- return variableValuesByBreakpoints;
5541
- };
5542
- /**
5543
- * Flattens the object from
5544
- * {
5545
- * color: {
5546
- * [key]: [value]
5547
- * }
5548
- * }
5549
- *
5550
- * to
5551
- *
5552
- * {
5553
- * 'color.key': [value]
5554
- * }
5555
- */
5556
- const flattenDesignTokenRegistry = (designTokenRegistry) => {
5557
- return Object.entries(designTokenRegistry).reduce((acc, [categoryName, tokenCategory]) => {
5558
- const tokensWithCategory = Object.entries(tokenCategory).reduce((acc, [tokenName, tokenValue]) => {
5559
- return {
5560
- ...acc,
5561
- [`${categoryName}.${tokenName}`]: tokenValue,
5562
- };
5563
- }, {});
5564
- return {
5565
- ...acc,
5566
- ...tokensWithCategory,
5567
- };
5568
- }, {});
5569
- };
5570
- // Replaces camelCase with kebab-case
5571
- // converts the <key, value> object into a css string
5572
- const toCSSString = (breakpointStyles) => {
5573
- return Object.entries(breakpointStyles)
5574
- .map(([key, value]) => `${key}:${value};`)
5575
- .join('');
5576
- };
5577
- const toMediaQuery = (breakpointPayload) => {
5578
- const mediaQueryStyles = Object.entries(breakpointPayload.cssByClassName).reduce((acc, [className, css]) => {
5579
- return `${acc}.${className}{${css}}`;
5580
- }, ``);
5581
- if (breakpointPayload.condition === '*') {
5582
- return mediaQueryStyles;
5583
- }
5584
- const [evaluation, pixelValue] = [
5585
- breakpointPayload.condition[0],
5586
- breakpointPayload.condition.substring(1),
5587
- ];
5588
- const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
5589
- return `@media(${mediaQueryRule}:${pixelValue}){${mediaQueryStyles}}`;
5590
- };
5591
-
5592
5168
  // Simple state store to store a few things that are needed across the SDK
5593
5169
  if (typeof window !== 'undefined') {
5594
5170
  window.__EB__ = {
@@ -5596,5 +5172,5 @@ if (typeof window !== 'undefined') {
5596
5172
  };
5597
5173
  }
5598
5174
 
5599
- export { ExperienceRoot, defineComponents, detachExperienceStyles, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
5175
+ export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
5600
5176
  //# sourceMappingURL=index.js.map