@contentful/experiences-core 3.8.2-dev-20251008T0828-a06681d.0 → 3.8.3-beta.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/{constants.cjs → cjs/constants.cjs} +2 -0
- package/dist/cjs/constants.cjs.map +1 -0
- package/dist/{index.cjs → cjs/index.cjs} +129 -127
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/index.d.ts +1675 -0
- package/package.json +17 -21
- package/dist/communication/sendMessage.d.ts +0 -5
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/deep-binding/DeepReference.d.ts +0 -44
- package/dist/definitions/styles.d.ts +0 -11
- package/dist/entity/EditorEntityStore.d.ts +0 -34
- package/dist/entity/EditorModeEntityStore.d.ts +0 -28
- package/dist/entity/EntityStore.d.ts +0 -99
- package/dist/entity/EntityStoreBase.d.ts +0 -53
- package/dist/entity/InMemoryEntitiesPublicApi.d.ts +0 -41
- package/dist/entity/InMemoryEntitiesStore.d.ts +0 -17
- package/dist/enums.d.ts +0 -6
- package/dist/exports.d.ts +0 -3
- package/dist/fetchers/createExperience.d.ts +0 -25
- package/dist/fetchers/fetchAllEntities.d.ts +0 -30
- package/dist/fetchers/fetchById.d.ts +0 -24
- package/dist/fetchers/fetchBySlug.d.ts +0 -24
- package/dist/fetchers/fetchExperienceEntry.d.ts +0 -30
- package/dist/fetchers/fetchReferencedEntities.d.ts +0 -28
- package/dist/fetchers/gatherAutoFetchedReferentsFromIncludes.d.ts +0 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -42
- package/dist/index.js.map +0 -1
- package/dist/registries/breakpointsRegistry.d.ts +0 -43
- package/dist/registries/designTokenRegistry.d.ts +0 -13
- package/dist/registries/sdkOptionsRegistry.d.ts +0 -11
- package/dist/types.d.ts +0 -630
- package/dist/utils/breakpoints.d.ts +0 -26
- package/dist/utils/components.d.ts +0 -17
- package/dist/utils/debugLogger.d.ts +0 -36
- package/dist/utils/domValues.d.ts +0 -16
- package/dist/utils/extractPrebindingData.d.ts +0 -46
- package/dist/utils/isLink.d.ts +0 -7
- package/dist/utils/isLinkToAsset.d.ts +0 -5
- package/dist/utils/isLinkToEntry.d.ts +0 -5
- package/dist/utils/localizeEntity.d.ts +0 -24
- package/dist/utils/pathSchema.d.ts +0 -43
- package/dist/utils/resolveHyperlinkPattern.d.ts +0 -17
- package/dist/utils/sanitizeNodeProps.d.ts +0 -7
- package/dist/utils/schema/experienceSchema.d.ts +0 -23
- package/dist/utils/schema/references.d.ts +0 -18
- package/dist/utils/splitDirectAndSlotChildren.d.ts +0 -12
- package/dist/utils/styleUtils/ssrStyles.d.ts +0 -75
- package/dist/utils/styleUtils/styleTransformers.d.ts +0 -6
- package/dist/utils/styleUtils/stylesUtils.d.ts +0 -64
- package/dist/utils/styleUtils/toMediaQuery.d.ts +0 -15
- package/dist/utils/transformers/transformBoundContentValue.d.ts +0 -8
- package/dist/utils/treeTraversal.d.ts +0 -17
- package/dist/utils/typeguards.d.ts +0 -15
- package/dist/utils/utils.d.ts +0 -32
- package/dist/utils/validations.d.ts +0 -11
- package/dist/{constants.js → esm/constants.js} +0 -0
- package/dist/{index.js → esm/index.js} +127 -127
- /package/dist/{constants.d.ts → types/constants.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["/** @deprecated will be removed when dropping backward compatibility for old DND */\nexport const SCROLL_STATES = {\n Start: 'scrollStart',\n IsScrolling: 'isScrolling',\n End: 'scrollEnd',\n} as const;\n\nexport const OUTGOING_EVENTS = {\n Connected: 'connected',\n DesignTokens: 'registerDesignTokens',\n RegisteredBreakpoints: 'registeredBreakpoints',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n MouseMove: 'mouseMove',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentSelected: 'componentSelected',\n RegisteredComponents: 'registeredComponents',\n RequestComponentTreeUpdate: 'requestComponentTreeUpdate',\n CanvasReload: 'canvasReload',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n UpdateSelectedComponentCoordinates: 'updateSelectedComponentCoordinates',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n CanvasScroll: 'canvasScrolling',\n CanvasError: 'canvasError',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n OutsideCanvasClick: 'outsideCanvasClick',\n SDKFeatures: 'sdkFeatures',\n RequestEntities: 'REQUEST_ENTITIES',\n CanvasGeometryUpdated: 'canvasGeometryUpdated',\n CanvasPan: 'canvasPan',\n} as const;\n\nexport const INCOMING_EVENTS = {\n RequestEditorMode: 'requestEditorMode',\n RequestReadOnlyMode: 'requestReadOnlyMode',\n ExperienceUpdated: 'componentTreeUpdated',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentDraggingChanged: 'componentDraggingChanged',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentDragCanceled: 'componentDragCanceled',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentDragStarted: 'componentDragStarted',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentDragEnded: 'componentDragEnded',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n ComponentMoveEnded: 'componentMoveEnded',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n CanvasResized: 'canvasResized',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n SelectComponent: 'selectComponent',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n HoverComponent: 'hoverComponent',\n UpdatedEntity: 'updatedEntity',\n /** @deprecated not needed after `patternResolution` was introduced. Will be removed in the next major version. */\n AssembliesAdded: 'assembliesAdded',\n /** @deprecated not needed after `patternResolution` was introduced. Will be removed in the next major version. */\n AssembliesRegistered: 'assembliesRegistered',\n /** @deprecated will be removed when dropping backward compatibility for old DND */\n MouseMove: 'mouseMove',\n RequestedEntities: 'REQUESTED_ENTITIES',\n} as const;\n\nexport const INTERNAL_EVENTS = {\n ComponentsRegistered: 'cfComponentsRegistered',\n VisualEditorInitialize: 'cfVisualEditorInitialize',\n} as const;\n\nexport const VISUAL_EDITOR_EVENTS = {\n Ready: 'cfVisualEditorReady',\n};\n\n/**\n * These modes are ONLY intended to be internally used within the context of\n * editing an experience inside of Contentful Studio. i.e. these modes\n * intentionally do not include preview/delivery modes.\n */\nexport enum StudioCanvasMode {\n READ_ONLY = 'readOnlyMode',\n EDITOR = 'editorMode',\n NONE = 'none',\n}\n\nexport const VISUAL_EDITOR_CONTAINER_ID = 'cf-visual-editor';\nexport const CONTENTFUL_COMPONENT_CATEGORY = 'contentful-component';\nexport const CONTENTFUL_DEFAULT_CATEGORY = 'Contentful';\n\nexport const CONTENTFUL_COMPONENTS = {\n section: {\n id: 'contentful-section',\n name: 'Section',\n },\n container: {\n id: 'contentful-container',\n name: 'Container',\n },\n columns: {\n id: 'contentful-columns',\n name: 'Columns',\n },\n singleColumn: {\n id: 'contentful-single-column',\n name: 'Column',\n },\n button: {\n id: 'contentful-button',\n name: 'Button',\n },\n heading: {\n id: 'contentful-heading',\n name: 'Heading',\n },\n image: {\n id: 'contentful-image',\n name: 'Image',\n },\n richText: {\n id: 'contentful-richText',\n name: 'Rich Text',\n },\n text: {\n id: 'contentful-text',\n name: 'Text',\n },\n divider: {\n id: 'contentful-divider',\n name: 'Divider',\n },\n carousel: {\n id: 'contentful-carousel',\n name: 'Carousel',\n },\n} as const;\n\nexport const ASSEMBLY_NODE_TYPE = 'assembly';\nexport const ASSEMBLY_DEFAULT_CATEGORY = 'Assemblies';\nexport const ASSEMBLY_BLOCK_NODE_TYPE = 'assemblyBlock';\nexport const ASSEMBLY_NODE_TYPES = [ASSEMBLY_NODE_TYPE, ASSEMBLY_BLOCK_NODE_TYPE];\nexport const LATEST_SCHEMA_VERSION = '2023-09-28';\nexport const CF_STYLE_ATTRIBUTES = [\n 'cfVisibility',\n 'cfHorizontalAlignment',\n 'cfVerticalAlignment',\n 'cfMargin',\n 'cfPadding',\n 'cfBackgroundColor',\n 'cfWidth',\n 'cfMaxWidth',\n 'cfHeight',\n 'cfImageAsset',\n 'cfImageOptions',\n 'cfBackgroundImageUrl',\n 'cfBackgroundImageOptions',\n 'cfFlexDirection',\n 'cfFlexWrap',\n 'cfFlexReverse',\n 'cfBorder',\n 'cfBorderRadius',\n 'cfGap',\n 'cfColumnSpan',\n 'cfColumnSpanLock',\n 'cfColumns',\n 'cfFontSize',\n 'cfFontWeight',\n 'cfLineHeight',\n 'cfLetterSpacing',\n 'cfTextColor',\n 'cfTextAlign',\n 'cfTextTransform',\n 'cfTextBold',\n 'cfTextItalic',\n 'cfTextUnderline',\n];\n\nexport const EMPTY_CONTAINER_SIZE = '80px';\n\nexport const HYPERLINK_DEFAULT_PATTERN = `/{locale}/{entry.fields.slug}/`;\n\nexport enum PostMessageMethods {\n REQUEST_ENTITIES = 'REQUEST_ENTITIES',\n REQUESTED_ENTITIES = 'REQUESTED_ENTITIES',\n}\n\nexport const SUPPORTED_IMAGE_FORMATS = ['jpg', 'png', 'webp', 'gif', 'avif'] as const;\n"],"names":["StudioCanvasMode","PostMessageMethods"],"mappings":";;;;AAAA;AACa,MAAA,aAAa,GAAG;AAC3B,IAAA,KAAK,EAAE,aAAa;AACpB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,GAAG,EAAE,WAAW;EACP;AAEE,MAAA,eAAe,GAAG;AAC7B,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,YAAY,EAAE,sBAAsB;AACpC,IAAA,qBAAqB,EAAE,uBAAuB;;AAE9C,IAAA,SAAS,EAAE,WAAW;;AAEtB,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C,IAAA,0BAA0B,EAAE,4BAA4B;AACxD,IAAA,YAAY,EAAE,cAAc;;AAE5B,IAAA,kCAAkC,EAAE,o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|
|
4
6
|
var cloneDeep = require('lodash.clonedeep');
|
|
5
7
|
var md5 = require('md5');
|
|
@@ -2356,6 +2358,133 @@ const calculateNodeDefaultHeight = ({ blockId, children, value, }) => {
|
|
|
2356
2358
|
return EMPTY_CONTAINER_SIZE;
|
|
2357
2359
|
};
|
|
2358
2360
|
|
|
2361
|
+
const getDataFromTree = (tree) => {
|
|
2362
|
+
let dataSource = {};
|
|
2363
|
+
let unboundValues = {};
|
|
2364
|
+
const queue = [...tree.root.children];
|
|
2365
|
+
while (queue.length) {
|
|
2366
|
+
const node = queue.shift();
|
|
2367
|
+
if (!node) {
|
|
2368
|
+
continue;
|
|
2369
|
+
}
|
|
2370
|
+
dataSource = { ...dataSource, ...node.data.dataSource };
|
|
2371
|
+
unboundValues = { ...unboundValues, ...node.data.unboundValues };
|
|
2372
|
+
if (node.children.length) {
|
|
2373
|
+
queue.push(...node.children);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return {
|
|
2377
|
+
dataSource,
|
|
2378
|
+
unboundValues,
|
|
2379
|
+
};
|
|
2380
|
+
};
|
|
2381
|
+
const generateRandomId = (letterCount) => {
|
|
2382
|
+
const LETTERS = 'abcdefghijklmnopqvwxyzABCDEFGHIJKLMNOPQVWXYZ';
|
|
2383
|
+
const NUMS = '0123456789';
|
|
2384
|
+
const ALNUM = NUMS + LETTERS;
|
|
2385
|
+
const times = (n, callback) => Array.from({ length: n }, callback);
|
|
2386
|
+
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
2387
|
+
return times(letterCount, () => ALNUM[random(0, ALNUM.length - 1)]).join('');
|
|
2388
|
+
};
|
|
2389
|
+
const checkIsAssemblyNode = ({ componentId, usedComponents, }) => {
|
|
2390
|
+
if (!usedComponents?.length)
|
|
2391
|
+
return false;
|
|
2392
|
+
return usedComponents.some((usedComponent) => usedComponent.sys.id === componentId);
|
|
2393
|
+
};
|
|
2394
|
+
/**
|
|
2395
|
+
* This check assumes that the entry is already ensured to be an experience, i.e. the
|
|
2396
|
+
* content type of the entry is an experience type with the necessary annotations.
|
|
2397
|
+
**/
|
|
2398
|
+
const checkIsAssemblyEntry = (entry) => {
|
|
2399
|
+
return Boolean(entry.fields?.componentSettings);
|
|
2400
|
+
};
|
|
2401
|
+
const checkIsAssemblyDefinition = (component) => component?.category === ASSEMBLY_DEFAULT_CATEGORY;
|
|
2402
|
+
function parseCSSValue(input) {
|
|
2403
|
+
const regex = /^(\d+(\.\d+)?)(px|em|rem)$/;
|
|
2404
|
+
const match = input.match(regex);
|
|
2405
|
+
if (match) {
|
|
2406
|
+
return {
|
|
2407
|
+
value: parseFloat(match[1]),
|
|
2408
|
+
unit: match[3],
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
return null;
|
|
2412
|
+
}
|
|
2413
|
+
function getTargetValueInPixels(targetWidthObject) {
|
|
2414
|
+
switch (targetWidthObject.unit) {
|
|
2415
|
+
case 'px':
|
|
2416
|
+
return targetWidthObject.value;
|
|
2417
|
+
case 'em':
|
|
2418
|
+
return targetWidthObject.value * 16;
|
|
2419
|
+
case 'rem':
|
|
2420
|
+
return targetWidthObject.value * 16;
|
|
2421
|
+
default:
|
|
2422
|
+
return targetWidthObject.value;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Creates a component definition for an assembly. As all assemblies use the same definition in the SDK,
|
|
2427
|
+
* all should be registered via this function.
|
|
2428
|
+
*/
|
|
2429
|
+
const createAssemblyDefinition = (definitionId) => {
|
|
2430
|
+
return {
|
|
2431
|
+
id: definitionId,
|
|
2432
|
+
name: 'Component',
|
|
2433
|
+
variables: {},
|
|
2434
|
+
children: true,
|
|
2435
|
+
category: ASSEMBLY_DEFAULT_CATEGORY,
|
|
2436
|
+
};
|
|
2437
|
+
};
|
|
2438
|
+
|
|
2439
|
+
/**
|
|
2440
|
+
* Turns a condition like `<768px` or `>1024px` into a media query rule.
|
|
2441
|
+
* For example, `<768px` becomes `max-width:768px` and `>1024px` becomes `min-width:1024px`.
|
|
2442
|
+
*/
|
|
2443
|
+
const toMediaQueryRule = (condition) => {
|
|
2444
|
+
const [evaluation, pixelValue] = [condition[0], condition.substring(1)];
|
|
2445
|
+
const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
|
|
2446
|
+
return `(${mediaQueryRule}:${pixelValue})`;
|
|
2447
|
+
};
|
|
2448
|
+
/**
|
|
2449
|
+
* Converts a map of class names to CSS strings into a single CSS string.
|
|
2450
|
+
*
|
|
2451
|
+
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2452
|
+
* @returns joined string of all CSS class definitions
|
|
2453
|
+
*/
|
|
2454
|
+
const toCompoundCss = (cssByClassName) => {
|
|
2455
|
+
return Object.entries(cssByClassName).reduce((acc, [className, css]) => {
|
|
2456
|
+
if (css === '')
|
|
2457
|
+
return acc;
|
|
2458
|
+
return `${acc}.${className}{${css}}`;
|
|
2459
|
+
}, ``);
|
|
2460
|
+
};
|
|
2461
|
+
/**
|
|
2462
|
+
* Create a single CSS string containing all class definitions for a given media query.
|
|
2463
|
+
*
|
|
2464
|
+
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
2465
|
+
* @param condition e.g. "*", "<520px", ">520px"
|
|
2466
|
+
* @param nextCondition optional next condition to create a disjunct media query that doesn't affect the next breakpoint
|
|
2467
|
+
* @returns joined string of all CSS class definitions wrapped into media queries
|
|
2468
|
+
*/
|
|
2469
|
+
const toMediaQuery = ({ cssByClassName, condition, nextCondition, }) => {
|
|
2470
|
+
const compoundCss = toCompoundCss(cssByClassName);
|
|
2471
|
+
if (compoundCss === '') {
|
|
2472
|
+
return '';
|
|
2473
|
+
}
|
|
2474
|
+
const queryRule = toMediaQueryRule(condition);
|
|
2475
|
+
if (!nextCondition) {
|
|
2476
|
+
if (condition === '*') {
|
|
2477
|
+
return compoundCss;
|
|
2478
|
+
}
|
|
2479
|
+
return `@media${queryRule}{${compoundCss}}`;
|
|
2480
|
+
}
|
|
2481
|
+
const nextRule = toMediaQueryRule(nextCondition);
|
|
2482
|
+
if (condition === '*') {
|
|
2483
|
+
return `@media not ${nextRule}{${compoundCss}}`;
|
|
2484
|
+
}
|
|
2485
|
+
return `@media${queryRule} and (not ${nextRule}){${compoundCss}}`;
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2359
2488
|
function getOptimizedImageUrl(url, width, quality, format) {
|
|
2360
2489
|
if (url.startsWith('//')) {
|
|
2361
2490
|
url = 'https:' + url;
|
|
@@ -2985,55 +3114,6 @@ function mergeDefaultAndOverwriteValues(defaultValue, overwriteValue) {
|
|
|
2985
3114
|
return overwriteValue ?? defaultValue;
|
|
2986
3115
|
}
|
|
2987
3116
|
|
|
2988
|
-
/**
|
|
2989
|
-
* Turns a condition like `<768px` or `>1024px` into a media query rule.
|
|
2990
|
-
* For example, `<768px` becomes `max-width:768px` and `>1024px` becomes `min-width:1024px`.
|
|
2991
|
-
*/
|
|
2992
|
-
const toMediaQueryRule = (condition) => {
|
|
2993
|
-
const [evaluation, pixelValue] = [condition[0], condition.substring(1)];
|
|
2994
|
-
const mediaQueryRule = evaluation === '<' ? 'max-width' : 'min-width';
|
|
2995
|
-
return `(${mediaQueryRule}:${pixelValue})`;
|
|
2996
|
-
};
|
|
2997
|
-
/**
|
|
2998
|
-
* Converts a map of class names to CSS strings into a single CSS string.
|
|
2999
|
-
*
|
|
3000
|
-
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
3001
|
-
* @returns joined string of all CSS class definitions
|
|
3002
|
-
*/
|
|
3003
|
-
const toCompoundCss = (cssByClassName) => {
|
|
3004
|
-
return Object.entries(cssByClassName).reduce((acc, [className, css]) => {
|
|
3005
|
-
if (css === '')
|
|
3006
|
-
return acc;
|
|
3007
|
-
return `${acc}.${className}{${css}}`;
|
|
3008
|
-
}, ``);
|
|
3009
|
-
};
|
|
3010
|
-
/**
|
|
3011
|
-
* Create a single CSS string containing all class definitions for a given media query.
|
|
3012
|
-
*
|
|
3013
|
-
* @param cssByClassName map of class names to CSS strings containing all rules for each class
|
|
3014
|
-
* @param condition e.g. "*", "<520px", ">520px"
|
|
3015
|
-
* @param nextCondition optional next condition to create a disjunct media query that doesn't affect the next breakpoint
|
|
3016
|
-
* @returns joined string of all CSS class definitions wrapped into media queries
|
|
3017
|
-
*/
|
|
3018
|
-
const toMediaQuery = ({ cssByClassName, condition, nextCondition, }) => {
|
|
3019
|
-
const compoundCss = toCompoundCss(cssByClassName);
|
|
3020
|
-
if (compoundCss === '') {
|
|
3021
|
-
return '';
|
|
3022
|
-
}
|
|
3023
|
-
const queryRule = toMediaQueryRule(condition);
|
|
3024
|
-
if (!nextCondition) {
|
|
3025
|
-
if (condition === '*') {
|
|
3026
|
-
return compoundCss;
|
|
3027
|
-
}
|
|
3028
|
-
return `@media${queryRule}{${compoundCss}}`;
|
|
3029
|
-
}
|
|
3030
|
-
const nextRule = toMediaQueryRule(nextCondition);
|
|
3031
|
-
if (condition === '*') {
|
|
3032
|
-
return `@media not ${nextRule}{${compoundCss}}`;
|
|
3033
|
-
}
|
|
3034
|
-
return `@media${queryRule} and (not ${nextRule}){${compoundCss}}`;
|
|
3035
|
-
};
|
|
3036
|
-
|
|
3037
3117
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3038
3118
|
function get(obj, path) {
|
|
3039
3119
|
if (!path.length) {
|
|
@@ -3366,84 +3446,6 @@ function treeMap(node, onNode) {
|
|
|
3366
3446
|
return newNode;
|
|
3367
3447
|
}
|
|
3368
3448
|
|
|
3369
|
-
const getDataFromTree = (tree) => {
|
|
3370
|
-
let dataSource = {};
|
|
3371
|
-
let unboundValues = {};
|
|
3372
|
-
const queue = [...tree.root.children];
|
|
3373
|
-
while (queue.length) {
|
|
3374
|
-
const node = queue.shift();
|
|
3375
|
-
if (!node) {
|
|
3376
|
-
continue;
|
|
3377
|
-
}
|
|
3378
|
-
dataSource = { ...dataSource, ...node.data.dataSource };
|
|
3379
|
-
unboundValues = { ...unboundValues, ...node.data.unboundValues };
|
|
3380
|
-
if (node.children.length) {
|
|
3381
|
-
queue.push(...node.children);
|
|
3382
|
-
}
|
|
3383
|
-
}
|
|
3384
|
-
return {
|
|
3385
|
-
dataSource,
|
|
3386
|
-
unboundValues,
|
|
3387
|
-
};
|
|
3388
|
-
};
|
|
3389
|
-
const generateRandomId = (letterCount) => {
|
|
3390
|
-
const LETTERS = 'abcdefghijklmnopqvwxyzABCDEFGHIJKLMNOPQVWXYZ';
|
|
3391
|
-
const NUMS = '0123456789';
|
|
3392
|
-
const ALNUM = NUMS + LETTERS;
|
|
3393
|
-
const times = (n, callback) => Array.from({ length: n }, callback);
|
|
3394
|
-
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
3395
|
-
return times(letterCount, () => ALNUM[random(0, ALNUM.length - 1)]).join('');
|
|
3396
|
-
};
|
|
3397
|
-
const checkIsAssemblyNode = ({ componentId, usedComponents, }) => {
|
|
3398
|
-
if (!usedComponents?.length)
|
|
3399
|
-
return false;
|
|
3400
|
-
return usedComponents.some((usedComponent) => usedComponent.sys.id === componentId);
|
|
3401
|
-
};
|
|
3402
|
-
/**
|
|
3403
|
-
* This check assumes that the entry is already ensured to be an experience, i.e. the
|
|
3404
|
-
* content type of the entry is an experience type with the necessary annotations.
|
|
3405
|
-
**/
|
|
3406
|
-
const checkIsAssemblyEntry = (entry) => {
|
|
3407
|
-
return Boolean(entry.fields?.componentSettings);
|
|
3408
|
-
};
|
|
3409
|
-
const checkIsAssemblyDefinition = (component) => component?.category === ASSEMBLY_DEFAULT_CATEGORY;
|
|
3410
|
-
function parseCSSValue(input) {
|
|
3411
|
-
const regex = /^(\d+(\.\d+)?)(px|em|rem)$/;
|
|
3412
|
-
const match = input.match(regex);
|
|
3413
|
-
if (match) {
|
|
3414
|
-
return {
|
|
3415
|
-
value: parseFloat(match[1]),
|
|
3416
|
-
unit: match[3],
|
|
3417
|
-
};
|
|
3418
|
-
}
|
|
3419
|
-
return null;
|
|
3420
|
-
}
|
|
3421
|
-
function getTargetValueInPixels(targetWidthObject) {
|
|
3422
|
-
switch (targetWidthObject.unit) {
|
|
3423
|
-
case 'px':
|
|
3424
|
-
return targetWidthObject.value;
|
|
3425
|
-
case 'em':
|
|
3426
|
-
return targetWidthObject.value * 16;
|
|
3427
|
-
case 'rem':
|
|
3428
|
-
return targetWidthObject.value * 16;
|
|
3429
|
-
default:
|
|
3430
|
-
return targetWidthObject.value;
|
|
3431
|
-
}
|
|
3432
|
-
}
|
|
3433
|
-
/**
|
|
3434
|
-
* Creates a component definition for an assembly. As all assemblies use the same definition in the SDK,
|
|
3435
|
-
* all should be registered via this function.
|
|
3436
|
-
*/
|
|
3437
|
-
const createAssemblyDefinition = (definitionId) => {
|
|
3438
|
-
return {
|
|
3439
|
-
id: definitionId,
|
|
3440
|
-
name: 'Component',
|
|
3441
|
-
variables: {},
|
|
3442
|
-
children: true,
|
|
3443
|
-
category: ASSEMBLY_DEFAULT_CATEGORY,
|
|
3444
|
-
};
|
|
3445
|
-
};
|
|
3446
|
-
|
|
3447
3449
|
class ParseError extends Error {
|
|
3448
3450
|
constructor(message) {
|
|
3449
3451
|
super(message);
|