-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
96 changed files
with
7,705 additions
and
7,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/components/src/components/ContentfulContainer/ContentfulContainer.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 2 additions & 16 deletions
18
packages/components/src/components/ContentfulContainer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/components/src/components/DesignComponent/DesignComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
CompositionComponentNode, | ||
ResolveDesignValueType, | ||
StyleProps, | ||
} from '@contentful/experience-builder-core/types'; | ||
import React from 'react'; | ||
|
||
export type DesignComponentProps<EditorMode = boolean> = EditorMode extends true | ||
? { | ||
children?: React.ReactNode; | ||
className?: string; | ||
cfHyperlink?: StyleProps['cfHyperlink']; | ||
cfOpenInNewTab?: StyleProps['cfOpenInNewTab']; | ||
editorMode?: EditorMode; | ||
node: CompositionComponentNode; | ||
resolveDesignValue?: ResolveDesignValueType; | ||
renderDropZone: ( | ||
node: CompositionComponentNode, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
props?: Record<string, any> | ||
) => React.ReactNode; | ||
} | ||
: // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
Record<string, any>; | ||
|
||
const designComponentStyle = { display: 'contents' }; | ||
|
||
// Feel free to do any magic as regards variable definitions for design components | ||
// Or if this isn't necessary by the time we figure that part out, we can bid this part farewell | ||
export const DesignComponent: React.FC<DesignComponentProps> = (props) => { | ||
if (props.editorMode) { | ||
const { node } = props; | ||
|
||
return props.renderDropZone(node, { | ||
['data-test-id']: 'contentful-container', | ||
['data-cf-node-id']: node.data.id, | ||
['data-cf-node-block-id']: node.data.blockId, | ||
['data-cf-node-block-type']: node.type, | ||
id: 'design-component', | ||
className: props.className, | ||
style: designComponentStyle, | ||
}); | ||
} | ||
// Using a display contents so design component content/children | ||
// can appear as if they are direct children of the div wrapper's parent | ||
return <div data-test-id="design-component" {...props} style={designComponentStyle} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DesignComponent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { ComponentDefinition } from '@/types'; | ||
|
||
import { CONTENTFUL_COMPONENT_CATEGORY, CONTENTFUL_CONTAINER_ID } from '@/constants'; | ||
import { containerBuiltInStyles } from './styles'; | ||
|
||
export const containerDefinition: ComponentDefinition = { | ||
id: CONTENTFUL_CONTAINER_ID, | ||
name: 'Container', | ||
category: CONTENTFUL_COMPONENT_CATEGORY, | ||
children: true, | ||
variables: containerBuiltInStyles, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './components'; | ||
export * from './styles'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './utils'; | ||
export * from './definitions/styles'; | ||
export * from './definitions'; | ||
export * from './entity'; | ||
export * from './communication'; | ||
export * from './enums'; | ||
export * from './registries'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { DesignTokensDefinition } from '@/types'; | ||
import { OUTGOING_EVENTS } from '@/constants'; | ||
import { sendMessage } from '@/communication'; | ||
|
||
const designTokensRegistry = {} as DesignTokensDefinition; | ||
const templateStringRegex = /\${(.+?)}/g; | ||
|
||
/** | ||
* Register design tokens styling | ||
* @param designTokenDefinition - {[key:string]: Record<string, string>} | ||
* @returns void | ||
*/ | ||
export const defineDesignTokens = (designTokenDefinition: DesignTokensDefinition) => { | ||
Object.assign(designTokensRegistry, designTokenDefinition); | ||
sendMessage(OUTGOING_EVENTS.DesignTokens, { | ||
designTokens: designTokenDefinition, | ||
}); | ||
}; | ||
|
||
export const getDesignTokenRegistration = (breakpointValue: string) => { | ||
if (!breakpointValue) return breakpointValue; | ||
|
||
let resolvedValue = ''; | ||
const values = breakpointValue.split(' '); | ||
values.forEach((value) => { | ||
let tokenValue = value; | ||
if (isTemplateStringFormat(value)) tokenValue = resolveSimpleDesignToken(value); | ||
resolvedValue += `${tokenValue} `; | ||
}); | ||
|
||
return resolvedValue.trim(); | ||
}; | ||
|
||
// Using this because export const StringTemplateRegex = /\${(.*?)\}/g doesn't work | ||
const isTemplateStringFormat = (str: string) => { | ||
return templateStringRegex.test(str); | ||
}; | ||
|
||
const resolveSimpleDesignToken = (templateString: string) => { | ||
const nonTemplateValue = templateString.replace(templateStringRegex, '$1'); | ||
const designKeys = nonTemplateValue.split('.'); | ||
const spacingValues = designTokensRegistry[designKeys[0]] as DesignTokensDefinition; | ||
const resolvedValue = spacingValues[designKeys[1]] as string; | ||
return resolvedValue || '0px'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './designTokenRegistry'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.