@contentful/experiences-sdk-react 1.10.0 → 1.10.1-dev-20240711T1654-17c6587.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.
|
@@ -19,6 +19,9 @@ const useDetectEditorMode = ({ isClientSide = false } = {}) => {
|
|
|
19
19
|
receivedMessage.current = true;
|
|
20
20
|
if (typeof window !== 'undefined') {
|
|
21
21
|
//Once we definitely know that we are in editor mode, we set this flag so future postMessage connect calls are not made
|
|
22
|
+
if (!window.__EB__) {
|
|
23
|
+
window.__EB__ = {};
|
|
24
|
+
}
|
|
22
25
|
window.__EB__.isEditorMode = true;
|
|
23
26
|
window.removeEventListener('message', onMessage);
|
|
24
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDetectEditorMode.js","sources":["../../../src/hooks/useDetectEditorMode.tsx"],"sourcesContent":["'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n doesMismatchMessageSchema,\n sendMessage,\n tryParseMessage,\n} from '@contentful/experiences-core';\nimport { INCOMING_EVENTS, OUTGOING_EVENTS } from '@contentful/experiences-core/constants';\nimport { sdkFeatures } from '../core/sdkFeatures';\n\ntype UseDetectEditorModeArgs = {\n /** If running from a known client side only situation (ie: useFetchBySlug),\n * set this to true to kick in editor mode check sooner (which avoids a render cycle) */\n isClientSide?: boolean;\n};\n\nexport const useDetectEditorMode = ({ isClientSide = false }: UseDetectEditorModeArgs = {}) => {\n const [mounted, setMounted] = useState(false);\n const [isEditorMode, setIsEditorMode] = useState(isClientSide ? inIframe() : false);\n const receivedMessage = useRef(false);\n\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n if (doesMismatchMessageSchema(event)) {\n return;\n }\n const eventData = tryParseMessage(event);\n\n if (eventData.eventType === INCOMING_EVENTS.RequestEditorMode) {\n setIsEditorMode(true);\n receivedMessage.current = true;\n if (typeof window !== 'undefined') {\n //Once we definitely know that we are in editor mode, we set this flag so future postMessage connect calls are not made\n window.__EB__.isEditorMode = true;\n window.removeEventListener('message', onMessage);\n }\n }\n };\n\n //Only run check after component is mounted on the client to avoid hydration ssr issues\n if (mounted) {\n setIsEditorMode(inIframe());\n //Double check if we are in editor mode by listening to postMessage events\n if (typeof window !== 'undefined' && !window.__EB__?.isEditorMode) {\n window.addEventListener('message', onMessage);\n sendMessage(OUTGOING_EVENTS.Connected, undefined);\n sendMessage(OUTGOING_EVENTS.SDKFeatures, sdkFeatures);\n\n setTimeout(() => {\n if (!receivedMessage.current) {\n // if message is not received back in time, set editorMode back to false\n setIsEditorMode(false);\n }\n }, 100);\n }\n } else {\n setMounted(true);\n }\n\n return () => window.removeEventListener('message', onMessage);\n }, [mounted]);\n\n return isEditorMode;\n};\n\nfunction inIframe() {\n try {\n return window.self !== window.top;\n } catch (e) {\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;;AAgBO;;AAEL;AACA;;AAGE;AACE;;;AAGA;;;AAIE;AACA;;AAEE;AACA;;;AAGN;;;AAIE;;AAEA;AACE;AACA;AACA;;AAGE;;;;;;;;;;;AAWR;AAEA;AACF;AAEA;AACE;AACE;;;AAEA;;AAEJ;;"}
|
|
1
|
+
{"version":3,"file":"useDetectEditorMode.js","sources":["../../../src/hooks/useDetectEditorMode.tsx"],"sourcesContent":["'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport {\n doesMismatchMessageSchema,\n sendMessage,\n tryParseMessage,\n} from '@contentful/experiences-core';\nimport { INCOMING_EVENTS, OUTGOING_EVENTS } from '@contentful/experiences-core/constants';\nimport { sdkFeatures } from '../core/sdkFeatures';\n\ntype UseDetectEditorModeArgs = {\n /** If running from a known client side only situation (ie: useFetchBySlug),\n * set this to true to kick in editor mode check sooner (which avoids a render cycle) */\n isClientSide?: boolean;\n};\n\nexport const useDetectEditorMode = ({ isClientSide = false }: UseDetectEditorModeArgs = {}) => {\n const [mounted, setMounted] = useState(false);\n const [isEditorMode, setIsEditorMode] = useState(isClientSide ? inIframe() : false);\n const receivedMessage = useRef(false);\n\n useEffect(() => {\n const onMessage = (event: MessageEvent) => {\n if (doesMismatchMessageSchema(event)) {\n return;\n }\n const eventData = tryParseMessage(event);\n\n if (eventData.eventType === INCOMING_EVENTS.RequestEditorMode) {\n setIsEditorMode(true);\n receivedMessage.current = true;\n if (typeof window !== 'undefined') {\n //Once we definitely know that we are in editor mode, we set this flag so future postMessage connect calls are not made\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.isEditorMode = true;\n window.removeEventListener('message', onMessage);\n }\n }\n };\n\n //Only run check after component is mounted on the client to avoid hydration ssr issues\n if (mounted) {\n setIsEditorMode(inIframe());\n //Double check if we are in editor mode by listening to postMessage events\n if (typeof window !== 'undefined' && !window.__EB__?.isEditorMode) {\n window.addEventListener('message', onMessage);\n sendMessage(OUTGOING_EVENTS.Connected, undefined);\n sendMessage(OUTGOING_EVENTS.SDKFeatures, sdkFeatures);\n\n setTimeout(() => {\n if (!receivedMessage.current) {\n // if message is not received back in time, set editorMode back to false\n setIsEditorMode(false);\n }\n }, 100);\n }\n } else {\n setMounted(true);\n }\n\n return () => window.removeEventListener('message', onMessage);\n }, [mounted]);\n\n return isEditorMode;\n};\n\nfunction inIframe() {\n try {\n return window.self !== window.top;\n } catch (e) {\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;;AAgBO;;AAEL;AACA;;AAGE;AACE;;;AAGA;;;AAIE;AACA;;AAEE;AACE;;AAEF;AACA;;;AAGN;;;AAIE;;AAEA;AACE;AACA;AACA;;AAGE;;;;;;;;;;;AAWR;AAEA;AACF;AAEA;AACE;AACE;;;AAEA;;AAEJ;;"}
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,9 @@ export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } fro
|
|
|
9
9
|
|
|
10
10
|
// Simple state store to store a few things that are needed across the SDK
|
|
11
11
|
if (typeof window !== 'undefined') {
|
|
12
|
-
window.__EB__
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
if (!window.__EB__) {
|
|
13
|
+
window.__EB__ = {};
|
|
14
|
+
}
|
|
15
|
+
window.__EB__.sdkVersion = SDK_VERSION;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { SDK_VERSION } from './sdkVersion';\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n window.__EB__ = {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { SDK_VERSION } from './sdkVersion';\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.sdkVersion = SDK_VERSION;\n}\n\nexport type { ExternalSDKMode, ComponentDefinition } from '@contentful/experiences-core/types';\n\nexport { detachExperienceStyles } from '@contentful/experiences-core';\n"],"names":[],"mappings":";;;;;;;;;AAmBA;AACA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACjC,IAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAClB,QAAA,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;KACpB;AACD,IAAA,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC;AACzC"}
|
package/dist/sdkVersion.js
CHANGED
package/dist/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.10.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.10.1-dev-20240711T1654-17c6587.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
package/dist/src/sdkVersion.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.10.0";
|
|
1
|
+
export declare const SDK_VERSION = "1.10.1-dev-20240711T1654-17c6587.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-sdk-react",
|
|
3
|
-
"version": "1.10.0",
|
|
3
|
+
"version": "1.10.1-dev-20240711T1654-17c6587.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/src/index.d.ts",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"depcruise": "depcruise src"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@contentful/experiences-components-react": "1.10.0",
|
|
37
|
-
"@contentful/experiences-core": "1.10.0",
|
|
38
|
-
"@contentful/experiences-validators": "1.10.0",
|
|
39
|
-
"@contentful/experiences-visual-editor-react": "1.10.0",
|
|
36
|
+
"@contentful/experiences-components-react": "1.10.1-dev-20240711T1654-17c6587.0",
|
|
37
|
+
"@contentful/experiences-core": "1.10.1-dev-20240711T1654-17c6587.0",
|
|
38
|
+
"@contentful/experiences-validators": "1.10.1-dev-20240711T1654-17c6587.0",
|
|
39
|
+
"@contentful/experiences-visual-editor-react": "1.10.1-dev-20240711T1654-17c6587.0",
|
|
40
40
|
"@contentful/rich-text-types": "^16.2.1",
|
|
41
41
|
"classnames": "^2.3.2",
|
|
42
42
|
"csstype": "^3.1.2",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"dist",
|
|
95
95
|
"package.json"
|
|
96
96
|
],
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "1189bf8f1db503135f3876a0e2c0940b73cdf7ed"
|
|
98
98
|
}
|