@contentful/experiences-core 0.0.1-alpha.2

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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/dist/communication/sendMessage.d.ts +6 -0
  3. package/dist/constants.d.ts +122 -0
  4. package/dist/constants.js +159 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/deep-binding/DeepReference.d.ts +28 -0
  7. package/dist/definitions/components.d.ts +8 -0
  8. package/dist/definitions/styles.d.ts +9 -0
  9. package/dist/entity/EditorEntityStore.d.ts +34 -0
  10. package/dist/entity/EditorModeEntityStore.d.ts +29 -0
  11. package/dist/entity/EntityStore.d.ts +54 -0
  12. package/dist/entity/EntityStoreBase.d.ts +39 -0
  13. package/dist/enums.d.ts +6 -0
  14. package/dist/exports.d.ts +3 -0
  15. package/dist/exports.js +2 -0
  16. package/dist/exports.js.map +1 -0
  17. package/dist/fetchers/createExperience.d.ts +20 -0
  18. package/dist/fetchers/fetchById.d.ts +20 -0
  19. package/dist/fetchers/fetchBySlug.d.ts +20 -0
  20. package/dist/index.d.ts +24 -0
  21. package/dist/index.js +2169 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/registries/designTokenRegistry.d.ts +12 -0
  24. package/dist/types.d.ts +223 -0
  25. package/dist/utils/breakpoints.d.ts +12 -0
  26. package/dist/utils/components.d.ts +4 -0
  27. package/dist/utils/domValues.d.ts +15 -0
  28. package/dist/utils/isLink.d.ts +5 -0
  29. package/dist/utils/isLinkToAsset.d.ts +5 -0
  30. package/dist/utils/pathSchema.d.ts +30 -0
  31. package/dist/utils/stylesUtils.d.ts +20 -0
  32. package/dist/utils/supportedModes.d.ts +5 -0
  33. package/dist/utils/transformers.d.ts +24 -0
  34. package/dist/utils/typeguards.d.ts +7 -0
  35. package/dist/utils/utils.d.ts +46 -0
  36. package/dist/utils/validations.d.ts +15 -0
  37. package/package.json +75 -0
@@ -0,0 +1,12 @@
1
+ import { Breakpoint, ValuesByBreakpoint } from '@contentful/experiences-validators';
2
+
3
+ declare const MEDIA_QUERY_REGEXP: RegExp;
4
+ declare const mediaQueryMatcher: (breakpoints: Breakpoint[]) => [{
5
+ id: string;
6
+ signal: MediaQueryList;
7
+ }[], Record<string, boolean>];
8
+ declare const getActiveBreakpointIndex: (breakpoints: Breakpoint[], mediaQueryMatches: Record<string, boolean>, fallbackBreakpointIndex: number) => number;
9
+ declare const getFallbackBreakpointIndex: (breakpoints: Breakpoint[]) => number;
10
+ declare const getValueForBreakpoint: (valuesByBreakpoint: ValuesByBreakpoint, breakpoints: Breakpoint[], activeBreakpointIndex: number, variableName: string) => string | number | boolean | Record<any, any> | undefined;
11
+
12
+ export { MEDIA_QUERY_REGEXP, getActiveBreakpointIndex, getFallbackBreakpointIndex, getValueForBreakpoint, mediaQueryMatcher };
@@ -0,0 +1,4 @@
1
+ declare const isContentfulStructureComponent: (componentId?: string) => boolean;
2
+ declare const isEmptyStructureWithRelativeHeight: (children: number, componentId?: string, height?: string | number) => boolean;
3
+
4
+ export { isContentfulStructureComponent, isEmptyStructureWithRelativeHeight };
@@ -0,0 +1,15 @@
1
+ type Rect = {
2
+ top: number;
3
+ right: number;
4
+ bottom: number;
5
+ left: number;
6
+ };
7
+ declare const findOutermostCoordinates: (first: Rect, second: Rect) => {
8
+ top: number;
9
+ right: number;
10
+ bottom: number;
11
+ left: number;
12
+ };
13
+ declare const getElementCoordinates: (element: Element) => DOMRect;
14
+
15
+ export { findOutermostCoordinates, getElementCoordinates };
@@ -0,0 +1,5 @@
1
+ import { UnresolvedLink, Entry, Asset } from 'contentful';
2
+
3
+ declare const isLink: (maybeLink: UnresolvedLink<'Entry' | 'Asset'> | Entry | Asset | string | unknown) => maybeLink is UnresolvedLink<"Entry" | "Asset">;
4
+
5
+ export { isLink };
@@ -0,0 +1,5 @@
1
+ import { Link } from '../types.js';
2
+
3
+ declare const isLinkToAsset: (variable: any) => variable is Link<"Asset">;
4
+
5
+ export { isLinkToAsset };
@@ -0,0 +1,30 @@
1
+ import { Entry, Asset } from 'contentful';
2
+
3
+ /**
4
+ * This module encapsulates format of the path to a deep reference.
5
+ */
6
+
7
+ type UnresolvedFieldset = Array<[null, string, string?]>;
8
+ type Fieldset = Array<[Entry | Asset, string, string?]>;
9
+ declare const parseDataSourcePathIntoFieldset: (path: string) => UnresolvedFieldset;
10
+ /**
11
+ * Parse path into components, supports L1 references (one reference follow) atm.
12
+ * @param path from data source. eg. `/uuid123/fields/image/~locale/fields/file/~locale`
13
+ * eg. `/uuid123/fields/file/~locale/fields/title/~locale`
14
+ * @returns
15
+ */
16
+ declare const parseDataSourcePathWithL1DeepBindings: (path: string) => {
17
+ key: string;
18
+ field: string;
19
+ referentField: string;
20
+ };
21
+ /**
22
+ * Detects if paths is valid deep-path, like:
23
+ * - /gV6yKXp61hfYrR7rEyKxY/fields/mainStory/~locale/fields/cover/~locale/fields/title/~locale
24
+ * or regular, like:
25
+ * - /6J8eA60yXwdm5eyUh9fX6/fields/mainStory/~locale
26
+ * @returns
27
+ */
28
+ declare const isDeepPath: (deepPathCandidate: string) => boolean;
29
+
30
+ export { type Fieldset, type UnresolvedFieldset, isDeepPath, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings };
@@ -0,0 +1,20 @@
1
+ import { CSSProperties, StyleProps, CompositionComponentNode } from '../types.js';
2
+ import { PrimitiveValue } from '@contentful/experiences-validators';
3
+
4
+ declare const buildStyleTag: ({ styles, nodeId }: {
5
+ styles: CSSProperties;
6
+ nodeId?: string | undefined;
7
+ }) => string[];
8
+ declare const buildCfStyles: ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirection, cfFlexWrap, cfMargin, cfPadding, cfBackgroundColor, cfWidth, cfHeight, cfMaxWidth, cfBorder, cfGap, cfBackgroundImageUrl, cfBackgroundImageAlignment, cfBackgroundImageScaling, cfFontSize, cfFontWeight, cfLineHeight, cfLetterSpacing, cfTextColor, cfTextAlign, cfTextTransform, cfTextBold, cfTextItalic, cfTextUnderline, cfColumnSpan, }: Partial<StyleProps>) => CSSProperties;
9
+ /**
10
+ * Container/section default behaviour:
11
+ * Default height => height: EMPTY_CONTAINER_HEIGHT (120px)
12
+ * If a container component has children => height: 'fit-content'
13
+ */
14
+ declare const calculateNodeDefaultHeight: ({ blockId, children, value, }: {
15
+ blockId?: string | undefined;
16
+ children: CompositionComponentNode['children'];
17
+ value: PrimitiveValue;
18
+ }) => string | number | boolean | Record<any, any> | undefined;
19
+
20
+ export { buildCfStyles, buildStyleTag, calculateNodeDefaultHeight };
@@ -0,0 +1,5 @@
1
+ import { InternalSDKMode } from '../types.js';
2
+
3
+ declare const supportedModes: InternalSDKMode[];
4
+
5
+ export { supportedModes };
@@ -0,0 +1,24 @@
1
+ import { Document } from '@contentful/rich-text-types';
2
+ import { CSSProperties, StyleProps, ComponentDefinitionVariable } from '../types.js';
3
+ import { Link } from 'contentful';
4
+ import { PrimitiveValue } from '@contentful/experiences-validators';
5
+
6
+ declare const transformFill: (value?: string) => string | undefined;
7
+ declare const transformGridColumn: (span?: string) => CSSProperties;
8
+ declare const transformBorderStyle: (value?: string) => CSSProperties;
9
+ declare const transformAlignment: (cfHorizontalAlignment?: string, cfVerticalAlignment?: string, cfFlexDirection?: string) => CSSProperties;
10
+ interface CSSPropertiesForBackground extends CSSProperties {
11
+ backgroundImage: string;
12
+ backgroundRepeat: 'repeat' | 'no-repeat';
13
+ backgroundSize?: 'cover' | 'contain';
14
+ backgroundPosition?: 'left top' | 'left center' | 'left bottom' | 'right top' | 'right center' | 'right bottom' | 'center top' | 'center center' | 'center bottom';
15
+ }
16
+ declare const transformBackgroundImage: (cfBackgroundImageUrl: string | null | undefined, cfBackgroundImageScaling?: StyleProps['cfBackgroundImageScaling'], cfBackgroundImageAlignment?: StyleProps['cfBackgroundImageAlignment']) => CSSPropertiesForBackground | undefined;
17
+ declare const transformContentValue: (value: PrimitiveValue | Link<'Asset'>, variableDefinition: ComponentDefinitionVariable) => string | number | boolean | Document | Record<any, any> | Link<"Asset"> | undefined;
18
+ declare const transformRichText: (value: PrimitiveValue) => Document | undefined;
19
+ declare const transformWidthSizing: ({ value, cfMargin, }: {
20
+ value: string | undefined;
21
+ cfMargin: string | undefined;
22
+ }) => string | undefined;
23
+
24
+ export { transformAlignment, transformBackgroundImage, transformBorderStyle, transformContentValue, transformFill, transformGridColumn, transformRichText, transformWidthSizing };
@@ -0,0 +1,7 @@
1
+ import { ExperienceEntry, Experience, DeprecatedExperience } from '../types.js';
2
+ import { Entry } from 'contentful';
3
+
4
+ declare const isExperienceEntry: (entry: ExperienceEntry | Entry) => entry is ExperienceEntry;
5
+ declare const isDeprecatedExperience: (experience: Experience | DeprecatedExperience) => experience is DeprecatedExperience;
6
+
7
+ export { isDeprecatedExperience, isExperienceEntry };
@@ -0,0 +1,46 @@
1
+ import { CompositionTree, ExperienceEntry, ComponentDefinition, CompositionComponentNode, StyleProps } from '../types.js';
2
+ import { Entry } from 'contentful';
3
+ import { ExperienceDataSource, ExperienceUnboundValues } from '@contentful/experiences-validators';
4
+
5
+ declare const getDataFromTree: (tree: CompositionTree) => {
6
+ dataSource: ExperienceDataSource;
7
+ unboundValues: ExperienceUnboundValues;
8
+ };
9
+ type GetInsertionDataParams = {
10
+ dropReceiverNode: CompositionComponentNode;
11
+ dropReceiverParentNode: CompositionComponentNode;
12
+ flexDirection?: StyleProps['cfFlexDirection'];
13
+ isMouseAtTopBorder: boolean;
14
+ isMouseAtBottomBorder: boolean;
15
+ isMouseInLeftHalf: boolean;
16
+ isMouseInUpperHalf: boolean;
17
+ isOverTopIndicator: boolean;
18
+ isOverBottomIndicator: boolean;
19
+ };
20
+ type InsertionData = {
21
+ node: CompositionComponentNode;
22
+ index: number;
23
+ };
24
+ /**
25
+ * Gets calculates the index to drop the dragged component based on the mouse position
26
+ * @returns {InsertionData} a object containing a node that will become a parent for dragged component and index at which it must be inserted
27
+ */
28
+ declare const getInsertionData: ({ dropReceiverParentNode, dropReceiverNode, flexDirection, isMouseAtTopBorder, isMouseAtBottomBorder, isMouseInLeftHalf, isMouseInUpperHalf, isOverTopIndicator, isOverBottomIndicator, }: GetInsertionDataParams) => InsertionData;
29
+ declare const generateRandomId: (letterCount: number) => string;
30
+ declare const checkIsAssemblyNode: ({ componentId, usedComponents, }: {
31
+ componentId: string;
32
+ usedComponents: ExperienceEntry['fields']['usedComponents'];
33
+ }) => boolean;
34
+ /** @deprecated use `checkIsAssemblyNode` instead. Will be removed with SDK v5. */
35
+ declare const checkIsAssembly: ({ componentId, usedComponents, }: {
36
+ componentId: string;
37
+ usedComponents: ExperienceEntry['fields']['usedComponents'];
38
+ }) => boolean;
39
+ /**
40
+ * This check assumes that the entry is already ensured to be an experience, i.e. the
41
+ * content type of the entry is an experience type with the necessary annotations.
42
+ **/
43
+ declare const checkIsAssemblyEntry: (entry: Entry) => boolean;
44
+ declare const checkIsAssemblyDefinition: (component?: ComponentDefinition) => boolean;
45
+
46
+ export { checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, generateRandomId, getDataFromTree, getInsertionData };
@@ -0,0 +1,15 @@
1
+ import { IncomingEvent } from '../types.js';
2
+
3
+ type VisualEditorMessagePayload = {
4
+ source: string;
5
+ eventType: IncomingEvent;
6
+ payload: any;
7
+ };
8
+ declare const doesMismatchMessageSchema: (event: MessageEvent) => false | string;
9
+ declare const tryParseMessage: (event: MessageEvent) => VisualEditorMessagePayload;
10
+ declare const validateExperienceBuilderConfig: ({ locale, isEditorMode, }: {
11
+ locale: string;
12
+ isEditorMode: boolean;
13
+ }) => void;
14
+
15
+ export { type VisualEditorMessagePayload, doesMismatchMessageSchema, tryParseMessage, validateExperienceBuilderConfig };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@contentful/experiences-core",
3
+ "version": "0.0.1-alpha.2",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/contentful/experience-builder.git"
12
+ },
13
+ "files": [
14
+ "readme.md",
15
+ "package.json",
16
+ "dist/**/*.*"
17
+ ],
18
+ "exports": {
19
+ ".": "./dist/index.js",
20
+ "./constants": "./dist/constants.js"
21
+ },
22
+ "publishConfig": {
23
+ "registry": "https://npm.pkg.github.com/"
24
+ },
25
+ "typesVersions": {
26
+ "*": {
27
+ "types": [
28
+ "./dist/types.d.ts"
29
+ ],
30
+ "constants": [
31
+ "./dist/constants.d.ts"
32
+ ]
33
+ }
34
+ },
35
+ "scripts": {
36
+ "clean": "rimraf dist",
37
+ "prebuild": "npm run clean",
38
+ "build": "rollup -c ./rollup.config.mjs",
39
+ "predev": "npm run clean",
40
+ "dev": "rollup -c ./rollup.config.mjs --watch --environment DEV",
41
+ "lint": "eslint src --ext '.ts,.tsx,.js,.jsx' --max-warnings 0 --ignore-path ../../.eslintignore",
42
+ "lint:fix": "eslint src --ext '.ts,.tsx,.js,.jsx' --fix",
43
+ "test": "vitest",
44
+ "test:coverage": "vitest run --coverage",
45
+ "depcruise": "depcruise src"
46
+ },
47
+ "author": "",
48
+ "license": "MIT",
49
+ "devDependencies": {
50
+ "@rollup/plugin-commonjs": "^25.0.7",
51
+ "@rollup/plugin-node-resolve": "^15.2.3",
52
+ "@rollup/plugin-terser": "^0.4.4",
53
+ "@rollup/plugin-typescript": "^11.1.5",
54
+ "@types/lodash-es": "^4.17.12",
55
+ "@typescript-eslint/eslint-plugin": "^7.0.2",
56
+ "@typescript-eslint/parser": "^7.0.2",
57
+ "@vitest/coverage-v8": "^1.0.4",
58
+ "contentful": "^10.6.4",
59
+ "eslint": "^8.54.0",
60
+ "happy-dom": "^13.3.8",
61
+ "rimraf": "^5.0.5",
62
+ "rollup-plugin-dts": "^6.1.0",
63
+ "rollup-plugin-ts": "^3.4.5",
64
+ "vite-tsconfig-paths": "^4.2.2",
65
+ "vitest": "^1.0.4"
66
+ },
67
+ "dependencies": {
68
+ "@contentful/experiences-validators": "0.0.1-alpha.3",
69
+ "@contentful/rich-text-types": "^16.3.0"
70
+ },
71
+ "peerDependencies": {
72
+ "contentful": ">=10.6.0"
73
+ },
74
+ "gitHead": "ed1b56b4398d7aaff1b0ea40c14514fb3a2e3d09"
75
+ }