Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALT-830] feat: add sdk feature detection object in core #626

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const OUTGOING_EVENTS = {
ComponentMoveStarted: 'componentMoveStarted',
ComponentMoveEnded: 'componentMoveEnded',
OutsideCanvasClick: 'outsideCanvasClick',
SDKFeatures: 'sdkFeatures',
};

export const INCOMING_EVENTS = {
Expand Down
2 changes: 2 additions & 0 deletions packages/experience-builder-sdk/src/core/sdkFeatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Object to store the SDK features that are enabled/disabled
export const sdkFeatures: Record<string, unknown> = {};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
tryParseMessage,
} from '@contentful/experiences-core';
import { INCOMING_EVENTS, OUTGOING_EVENTS } from '@contentful/experiences-core/constants';
import { sdkFeatures } from '../core/sdkFeatures';

type UseDetectEditorModeArgs = {
/** If running from a known client side only situation (ie: useFetchBySlug),
Expand Down Expand Up @@ -42,6 +43,7 @@ export const useDetectEditorMode = ({ isClientSide = false }: UseDetectEditorMod
if (typeof window !== 'undefined' && !window.__EB__?.isEditorMode) {
window.addEventListener('message', onMessage);
sendMessage(OUTGOING_EVENTS.Connected);
sendMessage(OUTGOING_EVENTS.SDKFeatures, sdkFeatures);

setTimeout(() => {
if (!receivedMessage.current) {
Expand Down
Loading