@builder.io/sdk-react-nextjs 0.5.9 → 0.6.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/lib/browser/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
- package/lib/browser/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
- package/lib/browser/USE_SERVER_BUNDLE-25e181fa.js +1 -0
- package/lib/browser/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
- package/lib/browser/bundle-5cab6113.js +76 -0
- package/lib/browser/bundle-babbd573.mjs +2419 -0
- package/lib/browser/index.cjs +1 -0
- package/lib/browser/index.mjs +34 -0
- package/lib/edge/USE_CLIENT_BUNDLE-3cbb02d5.mjs +664 -0
- package/lib/edge/USE_CLIENT_BUNDLE-d0b99f60.js +23 -0
- package/lib/edge/USE_SERVER_BUNDLE-4eeb4634.mjs +11 -0
- package/lib/edge/USE_SERVER_BUNDLE-bbd89085.js +1 -0
- package/lib/edge/bundle-9ed99f98.mjs +4863 -0
- package/lib/edge/bundle-e4764e2a.js +96 -0
- package/lib/edge/index.cjs +1 -0
- package/lib/edge/index.mjs +34 -0
- package/lib/node/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
- package/lib/node/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
- package/lib/node/USE_SERVER_BUNDLE-25e181fa.js +1 -0
- package/lib/node/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
- package/lib/node/bundle-5cab6113.js +76 -0
- package/lib/node/bundle-babbd573.mjs +2419 -0
- package/lib/node/index.cjs +1 -0
- package/lib/node/index.mjs +34 -0
- package/package.json +96 -13
- package/types/constants/sdk-version.d.ts +1 -0
- package/types/functions/deopt.d.ts +4 -0
- package/types/functions/evaluate/browser-runtime/index.d.ts +1 -0
- package/{dist → types}/functions/fetch-builder-props.d.ts +2 -1
- package/{dist → types}/functions/get-content/index.d.ts +4 -5
- package/{dist → types}/index-helpers/blocks-exports.d.ts +2 -2
- package/dist/blocks/button/button.js +0 -12
- package/dist/blocks/button/component-info.js +0 -34
- package/dist/blocks/columns/columns.js +0 -119
- package/dist/blocks/columns/component-info.js +0 -219
- package/dist/blocks/custom-code/component-info.js +0 -23
- package/dist/blocks/custom-code/custom-code.js +0 -51
- package/dist/blocks/embed/component-info.js +0 -39
- package/dist/blocks/embed/embed.js +0 -42
- package/dist/blocks/embed/helpers.js +0 -2
- package/dist/blocks/fragment/component-info.js +0 -7
- package/dist/blocks/fragment/fragment.js +0 -6
- package/dist/blocks/helpers.js +0 -40
- package/dist/blocks/image/component-info.js +0 -122
- package/dist/blocks/image/image.helpers.js +0 -47
- package/dist/blocks/image/image.js +0 -82
- package/dist/blocks/img/component-info.js +0 -15
- package/dist/blocks/img/img.js +0 -10
- package/dist/blocks/section/component-info.js +0 -40
- package/dist/blocks/section/section.js +0 -17
- package/dist/blocks/symbol/component-info.js +0 -34
- package/dist/blocks/symbol/symbol.helpers.js +0 -31
- package/dist/blocks/symbol/symbol.js +0 -29
- package/dist/blocks/text/component-info.js +0 -19
- package/dist/blocks/text/text.js +0 -7
- package/dist/blocks/video/component-info.js +0 -82
- package/dist/blocks/video/video.js +0 -50
- package/dist/components/block/block.helpers.js +0 -69
- package/dist/components/block/block.js +0 -92
- package/dist/components/block/components/block-styles.js +0 -65
- package/dist/components/block/components/block-wrapper.js +0 -36
- package/dist/components/block/components/component-ref/component-ref.helpers.js +0 -22
- package/dist/components/block/components/component-ref/component-ref.js +0 -21
- package/dist/components/block/components/interactive-element.js +0 -20
- package/dist/components/block/components/repeated-block.js +0 -7
- package/dist/components/block/types.js +0 -1
- package/dist/components/blocks/blocks-wrapper.js +0 -38
- package/dist/components/blocks/blocks.js +0 -10
- package/dist/components/content/components/enable-editor.js +0 -250
- package/dist/components/content/components/styles.helpers.js +0 -58
- package/dist/components/content/components/styles.js +0 -30
- package/dist/components/content/content.helpers.js +0 -30
- package/dist/components/content/content.js +0 -74
- package/dist/components/content/content.types.js +0 -1
- package/dist/components/content/wrap-component-ref.js +0 -6
- package/dist/components/content-variants/content-variants.js +0 -45
- package/dist/components/content-variants/content-variants.types.js +0 -1
- package/dist/components/content-variants/helpers.js +0 -189
- package/dist/components/inlined-script.js +0 -5
- package/dist/components/inlined-styles.js +0 -5
- package/dist/constants/builder-registered-components.js +0 -60
- package/dist/constants/device-sizes.js +0 -45
- package/dist/constants/sdk-version.d.ts +0 -1
- package/dist/constants/sdk-version.js +0 -1
- package/dist/constants/target.js +0 -2
- package/dist/context/builder.context.js +0 -12
- package/dist/context/components.context.js +0 -2
- package/dist/context/types.js +0 -1
- package/dist/functions/camel-to-kebab-case.js +0 -1
- package/dist/functions/evaluate/browser-runtime/browser.js +0 -31
- package/dist/functions/evaluate/evaluate.js +0 -47
- package/dist/functions/evaluate/helpers.js +0 -10
- package/dist/functions/evaluate/index.js +0 -1
- package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.d.ts +0 -2
- package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.js +0 -3111
- package/dist/functions/evaluate/non-node-runtime/index.d.ts +0 -1
- package/dist/functions/evaluate/non-node-runtime/index.js +0 -2
- package/dist/functions/evaluate/non-node-runtime/non-node-runtime.d.ts +0 -2
- package/dist/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -83
- package/dist/functions/event-handler-name.js +0 -4
- package/dist/functions/extract-text-styles.js +0 -22
- package/dist/functions/fast-clone.js +0 -4
- package/dist/functions/fetch-builder-props.js +0 -25
- package/dist/functions/get-block-actions-handler.js +0 -10
- package/dist/functions/get-block-actions.js +0 -28
- package/dist/functions/get-block-component-options.js +0 -10
- package/dist/functions/get-block-properties.js +0 -72
- package/dist/functions/get-builder-search-params/index.js +0 -38
- package/dist/functions/get-content/generate-content-url.js +0 -33
- package/dist/functions/get-content/index.js +0 -100
- package/dist/functions/get-content/types.js +0 -1
- package/dist/functions/get-fetch.js +0 -11
- package/dist/functions/get-global-this.js +0 -15
- package/dist/functions/get-processed-block.js +0 -46
- package/dist/functions/get-react-native-block-styles.js +0 -17
- package/dist/functions/is-browser.js +0 -3
- package/dist/functions/is-editing.js +0 -5
- package/dist/functions/is-iframe.js +0 -4
- package/dist/functions/is-non-node-server.d.ts +0 -4
- package/dist/functions/is-non-node-server.js +0 -8
- package/dist/functions/is-previewing.js +0 -11
- package/dist/functions/register-component.js +0 -38
- package/dist/functions/register.js +0 -27
- package/dist/functions/sanitize-react-native-block-styles.js +0 -61
- package/dist/functions/set-editor-settings.js +0 -12
- package/dist/functions/set.js +0 -14
- package/dist/functions/track/helpers.js +0 -51
- package/dist/functions/track/index.js +0 -71
- package/dist/functions/track/interaction.js +0 -53
- package/dist/functions/transform-block-properties.js +0 -5
- package/dist/functions/transform-block.js +0 -4
- package/dist/helpers/ab-tests.js +0 -122
- package/dist/helpers/canTrack.js +0 -2
- package/dist/helpers/cookie.js +0 -55
- package/dist/helpers/css.js +0 -27
- package/dist/helpers/flatten.js +0 -19
- package/dist/helpers/localStorage.js +0 -24
- package/dist/helpers/logger.js +0 -7
- package/dist/helpers/nullable.js +0 -1
- package/dist/helpers/preview-lru-cache/get.js +0 -9
- package/dist/helpers/preview-lru-cache/helpers.js +0 -9
- package/dist/helpers/preview-lru-cache/init.js +0 -15
- package/dist/helpers/preview-lru-cache/set.js +0 -7
- package/dist/helpers/preview-lru-cache/types.js +0 -6
- package/dist/helpers/sessionId.js +0 -30
- package/dist/helpers/url.js +0 -15
- package/dist/helpers/uuid.js +0 -15
- package/dist/helpers/visitorId.js +0 -30
- package/dist/index-helpers/blocks-exports.js +0 -19
- package/dist/index-helpers/top-of-file.js +0 -4
- package/dist/index.js +0 -7
- package/dist/scripts/init-editing.js +0 -110
- package/dist/server-index.js +0 -10
- package/dist/types/api-version.js +0 -1
- package/dist/types/builder-block.js +0 -1
- package/dist/types/builder-content.js +0 -1
- package/dist/types/builder-props.js +0 -1
- package/dist/types/can-track.js +0 -1
- package/dist/types/components.js +0 -1
- package/dist/types/deep-partial.js +0 -1
- package/dist/types/element.js +0 -1
- package/dist/types/enforced-partials.js +0 -1
- package/dist/types/input.js +0 -1
- package/dist/types/targets.js +0 -1
- package/dist/types/typescript.js +0 -1
- /package/{dist → types}/blocks/button/button.d.ts +0 -0
- /package/{dist → types}/blocks/button/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/columns/columns.d.ts +0 -0
- /package/{dist → types}/blocks/columns/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/custom-code/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/custom-code/custom-code.d.ts +0 -0
- /package/{dist → types}/blocks/embed/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/embed/embed.d.ts +0 -0
- /package/{dist → types}/blocks/embed/helpers.d.ts +0 -0
- /package/{dist → types}/blocks/fragment/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/fragment/fragment.d.ts +0 -0
- /package/{dist → types}/blocks/helpers.d.ts +0 -0
- /package/{dist → types}/blocks/image/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/image/image.d.ts +0 -0
- /package/{dist → types}/blocks/image/image.helpers.d.ts +0 -0
- /package/{dist → types}/blocks/img/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/img/img.d.ts +0 -0
- /package/{dist → types}/blocks/section/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/section/section.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/symbol.d.ts +0 -0
- /package/{dist → types}/blocks/symbol/symbol.helpers.d.ts +0 -0
- /package/{dist → types}/blocks/text/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/text/text.d.ts +0 -0
- /package/{dist → types}/blocks/video/component-info.d.ts +0 -0
- /package/{dist → types}/blocks/video/video.d.ts +0 -0
- /package/{dist → types}/components/block/block.d.ts +0 -0
- /package/{dist → types}/components/block/block.helpers.d.ts +0 -0
- /package/{dist → types}/components/block/components/block-styles.d.ts +0 -0
- /package/{dist → types}/components/block/components/block-wrapper.d.ts +0 -0
- /package/{dist → types}/components/block/components/component-ref/component-ref.d.ts +0 -0
- /package/{dist → types}/components/block/components/component-ref/component-ref.helpers.d.ts +0 -0
- /package/{dist → types}/components/block/components/interactive-element.d.ts +0 -0
- /package/{dist → types}/components/block/components/repeated-block.d.ts +0 -0
- /package/{dist → types}/components/block/types.d.ts +0 -0
- /package/{dist → types}/components/blocks/blocks-wrapper.d.ts +0 -0
- /package/{dist → types}/components/blocks/blocks.d.ts +0 -0
- /package/{dist → types}/components/content/components/enable-editor.d.ts +0 -0
- /package/{dist → types}/components/content/components/styles.d.ts +0 -0
- /package/{dist → types}/components/content/components/styles.helpers.d.ts +0 -0
- /package/{dist → types}/components/content/content.d.ts +0 -0
- /package/{dist → types}/components/content/content.helpers.d.ts +0 -0
- /package/{dist → types}/components/content/content.types.d.ts +0 -0
- /package/{dist → types}/components/content/wrap-component-ref.d.ts +0 -0
- /package/{dist → types}/components/content-variants/content-variants.d.ts +0 -0
- /package/{dist → types}/components/content-variants/content-variants.types.d.ts +0 -0
- /package/{dist → types}/components/content-variants/helpers.d.ts +0 -0
- /package/{dist → types}/components/inlined-script.d.ts +0 -0
- /package/{dist → types}/components/inlined-styles.d.ts +0 -0
- /package/{dist → types}/constants/builder-registered-components.d.ts +0 -0
- /package/{dist → types}/constants/device-sizes.d.ts +0 -0
- /package/{dist → types}/constants/target.d.ts +0 -0
- /package/{dist → types}/context/builder.context.d.ts +0 -0
- /package/{dist → types}/context/components.context.d.ts +0 -0
- /package/{dist → types}/context/types.d.ts +0 -0
- /package/{dist → types}/functions/camel-to-kebab-case.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/browser-runtime/browser.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/evaluate.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/helpers.d.ts +0 -0
- /package/{dist → types}/functions/evaluate/index.d.ts +0 -0
- /package/{dist → types}/functions/event-handler-name.d.ts +0 -0
- /package/{dist → types}/functions/extract-text-styles.d.ts +0 -0
- /package/{dist → types}/functions/fast-clone.d.ts +0 -0
- /package/{dist → types}/functions/get-block-actions-handler.d.ts +0 -0
- /package/{dist → types}/functions/get-block-actions.d.ts +0 -0
- /package/{dist → types}/functions/get-block-component-options.d.ts +0 -0
- /package/{dist → types}/functions/get-block-properties.d.ts +0 -0
- /package/{dist → types}/functions/get-builder-search-params/index.d.ts +0 -0
- /package/{dist → types}/functions/get-content/generate-content-url.d.ts +0 -0
- /package/{dist → types}/functions/get-content/types.d.ts +0 -0
- /package/{dist → types}/functions/get-fetch.d.ts +0 -0
- /package/{dist → types}/functions/get-global-this.d.ts +0 -0
- /package/{dist → types}/functions/get-processed-block.d.ts +0 -0
- /package/{dist → types}/functions/get-react-native-block-styles.d.ts +0 -0
- /package/{dist → types}/functions/is-browser.d.ts +0 -0
- /package/{dist → types}/functions/is-editing.d.ts +0 -0
- /package/{dist → types}/functions/is-iframe.d.ts +0 -0
- /package/{dist → types}/functions/is-previewing.d.ts +0 -0
- /package/{dist → types}/functions/register-component.d.ts +0 -0
- /package/{dist → types}/functions/register.d.ts +0 -0
- /package/{dist → types}/functions/sanitize-react-native-block-styles.d.ts +0 -0
- /package/{dist → types}/functions/set-editor-settings.d.ts +0 -0
- /package/{dist → types}/functions/set.d.ts +0 -0
- /package/{dist → types}/functions/track/helpers.d.ts +0 -0
- /package/{dist → types}/functions/track/index.d.ts +0 -0
- /package/{dist → types}/functions/track/interaction.d.ts +0 -0
- /package/{dist → types}/functions/transform-block-properties.d.ts +0 -0
- /package/{dist → types}/functions/transform-block.d.ts +0 -0
- /package/{dist → types}/helpers/ab-tests.d.ts +0 -0
- /package/{dist → types}/helpers/canTrack.d.ts +0 -0
- /package/{dist → types}/helpers/cookie.d.ts +0 -0
- /package/{dist → types}/helpers/css.d.ts +0 -0
- /package/{dist → types}/helpers/flatten.d.ts +0 -0
- /package/{dist → types}/helpers/localStorage.d.ts +0 -0
- /package/{dist → types}/helpers/logger.d.ts +0 -0
- /package/{dist → types}/helpers/nullable.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/get.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/helpers.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/init.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/set.d.ts +0 -0
- /package/{dist → types}/helpers/preview-lru-cache/types.d.ts +0 -0
- /package/{dist → types}/helpers/sessionId.d.ts +0 -0
- /package/{dist → types}/helpers/url.d.ts +0 -0
- /package/{dist → types}/helpers/uuid.d.ts +0 -0
- /package/{dist → types}/helpers/visitorId.d.ts +0 -0
- /package/{dist → types}/index-helpers/top-of-file.d.ts +0 -0
- /package/{dist → types}/index.d.ts +0 -0
- /package/{dist → types}/scripts/init-editing.d.ts +0 -0
- /package/{dist → types}/server-index.d.ts +0 -0
- /package/{dist → types}/types/api-version.d.ts +0 -0
- /package/{dist → types}/types/builder-block.d.ts +0 -0
- /package/{dist → types}/types/builder-content.d.ts +0 -0
- /package/{dist → types}/types/builder-props.d.ts +0 -0
- /package/{dist → types}/types/can-track.d.ts +0 -0
- /package/{dist → types}/types/components.d.ts +0 -0
- /package/{dist → types}/types/deep-partial.d.ts +0 -0
- /package/{dist → types}/types/element.d.ts +0 -0
- /package/{dist → types}/types/enforced-partials.d.ts +0 -0
- /package/{dist → types}/types/input.d.ts +0 -0
- /package/{dist → types}/types/targets.d.ts +0 -0
- /package/{dist → types}/types/typescript.d.ts +0 -0
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useState, useRef, useEffect } from "react";
|
|
4
|
-
import { evaluate } from "../../../functions/evaluate/index.js";
|
|
5
|
-
import { fetch } from "../../../functions/get-fetch.js";
|
|
6
|
-
import { isBrowser } from "../../../functions/is-browser.js";
|
|
7
|
-
import { isEditing } from "../../../functions/is-editing.js";
|
|
8
|
-
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
9
|
-
import { _track } from "../../../functions/track/index.js";
|
|
10
|
-
import builderContext from "../../../context/builder.context.js";
|
|
11
|
-
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
12
|
-
import { checkIsDefined } from "../../../helpers/nullable.js";
|
|
13
|
-
import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction.js";
|
|
14
|
-
import { logger } from "../../../helpers/logger.js";
|
|
15
|
-
import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
|
|
16
|
-
import { fastClone } from "../../../functions/fast-clone.js";
|
|
17
|
-
import { useRouter } from "next/navigation";
|
|
18
|
-
function EnableEditor(props) {
|
|
19
|
-
const elementRef = useRef(null);
|
|
20
|
-
const [canTrackToUse, setCanTrackToUse] = useState(() => checkIsDefined(props.canTrack) ? props.canTrack : true);
|
|
21
|
-
const [forceReRenderCount, setForceReRenderCount] = useState(() => 0);
|
|
22
|
-
function mergeNewContent(newContent) {
|
|
23
|
-
const newContentValue = {
|
|
24
|
-
...props.builderContextSignal.content,
|
|
25
|
-
...newContent,
|
|
26
|
-
data: {
|
|
27
|
-
...props.builderContextSignal.content?.data,
|
|
28
|
-
...newContent?.data,
|
|
29
|
-
},
|
|
30
|
-
meta: {
|
|
31
|
-
...props.builderContextSignal.content?.meta,
|
|
32
|
-
...newContent?.meta,
|
|
33
|
-
breakpoints: newContent?.meta?.breakpoints ||
|
|
34
|
-
props.builderContextSignal.content?.meta?.breakpoints,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
postPreviewContent({
|
|
38
|
-
value: newContentValue,
|
|
39
|
-
key: newContentValue.id,
|
|
40
|
-
}).then(() => {
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
router.refresh();
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const [lastUpdated, setLastUpdated] = useState(() => 0);
|
|
47
|
-
const [shouldSendResetCookie, setShouldSendResetCookie] = useState(() => false);
|
|
48
|
-
function processMessage(event) {
|
|
49
|
-
const { data } = event;
|
|
50
|
-
if (data) {
|
|
51
|
-
switch (data.type) {
|
|
52
|
-
case "builder.configureSdk": {
|
|
53
|
-
const messageContent = data.data;
|
|
54
|
-
const { breakpoints, contentId } = messageContent;
|
|
55
|
-
if (!contentId ||
|
|
56
|
-
contentId !== props.builderContextSignal.content?.id) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (breakpoints) {
|
|
60
|
-
mergeNewContent({
|
|
61
|
-
meta: {
|
|
62
|
-
breakpoints,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case "builder.contentUpdate": {
|
|
70
|
-
const messageContent = data.data;
|
|
71
|
-
const key = messageContent.key ||
|
|
72
|
-
messageContent.alias ||
|
|
73
|
-
messageContent.entry ||
|
|
74
|
-
messageContent.modelName;
|
|
75
|
-
const contentData = messageContent.data;
|
|
76
|
-
if (key === props.model) {
|
|
77
|
-
mergeNewContent(contentData);
|
|
78
|
-
setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function evaluateJsCode() {
|
|
86
|
-
// run any dynamic JS code attached to content
|
|
87
|
-
const jsCode = props.builderContextSignal.content?.data?.jsCode;
|
|
88
|
-
if (jsCode) {
|
|
89
|
-
evaluate({
|
|
90
|
-
code: jsCode,
|
|
91
|
-
context: props.context || {},
|
|
92
|
-
localState: undefined,
|
|
93
|
-
rootState: props.builderContextSignal.rootState,
|
|
94
|
-
rootSetState: props.builderContextSignal.rootSetState,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const [httpReqsData, setHttpReqsData] = useState(() => ({}));
|
|
99
|
-
const [clicked, setClicked] = useState(() => false);
|
|
100
|
-
function onClick(event) {
|
|
101
|
-
if (props.builderContextSignal.content) {
|
|
102
|
-
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
103
|
-
const contentId = props.builderContextSignal.content?.id;
|
|
104
|
-
_track({
|
|
105
|
-
type: "click",
|
|
106
|
-
canTrack: canTrackToUse,
|
|
107
|
-
contentId,
|
|
108
|
-
apiKey: props.apiKey,
|
|
109
|
-
variationId: variationId !== contentId ? variationId : undefined,
|
|
110
|
-
...getInteractionPropertiesForEvent(event),
|
|
111
|
-
unique: !clicked,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
if (!clicked) {
|
|
115
|
-
setClicked(true);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function evalExpression(expression) {
|
|
119
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
120
|
-
code: group,
|
|
121
|
-
context: props.context || {},
|
|
122
|
-
localState: undefined,
|
|
123
|
-
rootState: props.builderContextSignal.rootState,
|
|
124
|
-
rootSetState: props.builderContextSignal.rootSetState,
|
|
125
|
-
}));
|
|
126
|
-
}
|
|
127
|
-
function handleRequest({ url, key }) {
|
|
128
|
-
fetch(url)
|
|
129
|
-
.then((response) => response.json())
|
|
130
|
-
.then((json) => {
|
|
131
|
-
const newState = {
|
|
132
|
-
...props.builderContextSignal.rootState,
|
|
133
|
-
[key]: json,
|
|
134
|
-
};
|
|
135
|
-
props.builderContextSignal.rootSetState?.(newState);
|
|
136
|
-
httpReqsData[key] = true;
|
|
137
|
-
})
|
|
138
|
-
.catch((err) => {
|
|
139
|
-
console.error("error fetching dynamic data", url, err);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function runHttpRequests() {
|
|
143
|
-
const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
|
|
144
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
145
|
-
if (url && (!httpReqsData[key] || isEditing())) {
|
|
146
|
-
const evaluatedUrl = evalExpression(url);
|
|
147
|
-
handleRequest({
|
|
148
|
-
url: evaluatedUrl,
|
|
149
|
-
key,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function emitStateUpdate() {
|
|
155
|
-
if (isEditing()) {
|
|
156
|
-
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
157
|
-
detail: {
|
|
158
|
-
state: fastClone(props.builderContextSignal.rootState),
|
|
159
|
-
ref: {
|
|
160
|
-
name: props.model,
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const router = useRouter();
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (!props.apiKey) {
|
|
169
|
-
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
170
|
-
}
|
|
171
|
-
if (isBrowser()) {
|
|
172
|
-
if (isEditing()) {
|
|
173
|
-
setForceReRenderCount(forceReRenderCount + 1);
|
|
174
|
-
window.addEventListener("message", processMessage);
|
|
175
|
-
registerInsertMenu();
|
|
176
|
-
setupBrowserForEditing({
|
|
177
|
-
...(props.locale
|
|
178
|
-
? {
|
|
179
|
-
locale: props.locale,
|
|
180
|
-
}
|
|
181
|
-
: {}),
|
|
182
|
-
...(props.includeRefs
|
|
183
|
-
? {
|
|
184
|
-
includeRefs: props.includeRefs,
|
|
185
|
-
}
|
|
186
|
-
: {}),
|
|
187
|
-
...(props.enrich
|
|
188
|
-
? {
|
|
189
|
-
enrich: props.enrich,
|
|
190
|
-
}
|
|
191
|
-
: {}),
|
|
192
|
-
});
|
|
193
|
-
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
194
|
-
const message = createRegisterComponentMessage(registeredComponent);
|
|
195
|
-
window.parent?.postMessage(message, "*");
|
|
196
|
-
});
|
|
197
|
-
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
198
|
-
}
|
|
199
|
-
if (props.builderContextSignal.content) {
|
|
200
|
-
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
201
|
-
const contentId = props.builderContextSignal.content?.id;
|
|
202
|
-
_track({
|
|
203
|
-
type: "impression",
|
|
204
|
-
canTrack: canTrackToUse,
|
|
205
|
-
contentId,
|
|
206
|
-
apiKey: props.apiKey,
|
|
207
|
-
variationId: variationId !== contentId ? variationId : undefined,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
evaluateJsCode();
|
|
211
|
-
runHttpRequests();
|
|
212
|
-
emitStateUpdate();
|
|
213
|
-
}
|
|
214
|
-
}, []);
|
|
215
|
-
useEffect(() => { }, [props.content]);
|
|
216
|
-
useEffect(() => {
|
|
217
|
-
if (isBrowser()) {
|
|
218
|
-
window.removeEventListener("message", processMessage);
|
|
219
|
-
window.addEventListener("message", processMessage);
|
|
220
|
-
}
|
|
221
|
-
}, [shouldSendResetCookie]);
|
|
222
|
-
useEffect(() => {
|
|
223
|
-
evaluateJsCode();
|
|
224
|
-
}, [
|
|
225
|
-
props.builderContextSignal.content?.data?.jsCode,
|
|
226
|
-
props.builderContextSignal.rootState,
|
|
227
|
-
]);
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
runHttpRequests();
|
|
230
|
-
}, [props.builderContextSignal.content?.data?.httpRequests]);
|
|
231
|
-
useEffect(() => {
|
|
232
|
-
emitStateUpdate();
|
|
233
|
-
}, [props.builderContextSignal.rootState]);
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
return () => {
|
|
236
|
-
if (isBrowser()) {
|
|
237
|
-
window.removeEventListener("message", processMessage);
|
|
238
|
-
window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}, []);
|
|
242
|
-
return (React.createElement(builderContext.Provider, { value: props.builderContextSignal }, props.builderContextSignal.content ? (React.createElement(React.Fragment, null,
|
|
243
|
-
React.createElement("div", { key: forceReRenderCount, ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": props.builderContextSignal.content?.id, "builder-model": props.model, ...(props.showContent
|
|
244
|
-
? {}
|
|
245
|
-
: {
|
|
246
|
-
hidden: true,
|
|
247
|
-
"aria-hidden": true,
|
|
248
|
-
}), className: props.classNameProp }, props.children))) : null));
|
|
249
|
-
}
|
|
250
|
-
export default EnableEditor;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const getCssFromFont = (font) => {
|
|
2
|
-
// TODO: compute what font sizes are used and only load those.......
|
|
3
|
-
const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
|
|
4
|
-
const name = family.split(',')[0];
|
|
5
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
6
|
-
let str = '';
|
|
7
|
-
if (url && family && name) {
|
|
8
|
-
str += `
|
|
9
|
-
@font-face {
|
|
10
|
-
font-family: "${family}";
|
|
11
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
12
|
-
font-display: fallback;
|
|
13
|
-
font-weight: 400;
|
|
14
|
-
}
|
|
15
|
-
`.trim();
|
|
16
|
-
}
|
|
17
|
-
if (font.files) {
|
|
18
|
-
for (const weight in font.files) {
|
|
19
|
-
const isNumber = String(Number(weight)) === weight;
|
|
20
|
-
if (!isNumber) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
// TODO: maybe limit number loaded
|
|
24
|
-
const weightUrl = font.files[weight];
|
|
25
|
-
if (weightUrl && weightUrl !== url) {
|
|
26
|
-
str += `
|
|
27
|
-
@font-face {
|
|
28
|
-
font-family: "${family}";
|
|
29
|
-
src: url('${weightUrl}') format('woff2');
|
|
30
|
-
font-display: fallback;
|
|
31
|
-
font-weight: ${weight};
|
|
32
|
-
}
|
|
33
|
-
`.trim();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return str;
|
|
38
|
-
};
|
|
39
|
-
export const getFontCss = ({ customFonts }) => {
|
|
40
|
-
// TODO: flag for this
|
|
41
|
-
// if (!this.builder.allowCustomFonts) {
|
|
42
|
-
// return '';
|
|
43
|
-
// }
|
|
44
|
-
// TODO: separate internal data from external
|
|
45
|
-
return customFonts?.map(font => getCssFromFont(font))?.join(' ') || '';
|
|
46
|
-
};
|
|
47
|
-
export const getCss = ({ cssCode, contentId }) => {
|
|
48
|
-
if (!cssCode) {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
if (!contentId) {
|
|
52
|
-
return cssCode;
|
|
53
|
-
}
|
|
54
|
-
// Allow using `&` in custom CSS code like @emotion
|
|
55
|
-
// E.g. `& .foobar { ... }` to scope CSS
|
|
56
|
-
// TODO: handle if '&' is within a string like `content: "&"`
|
|
57
|
-
return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || '';
|
|
58
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import InlinedStyles from "../../inlined-styles";
|
|
3
|
-
import { getCss } from "./styles.helpers.js";
|
|
4
|
-
import { getFontCss } from "./styles.helpers.js";
|
|
5
|
-
function ContentStyles(props) {
|
|
6
|
-
const injectedStyles = `
|
|
7
|
-
${getCss({
|
|
8
|
-
cssCode: props.cssCode,
|
|
9
|
-
contentId: props.contentId,
|
|
10
|
-
})}
|
|
11
|
-
${getFontCss({
|
|
12
|
-
customFonts: props.customFonts,
|
|
13
|
-
})}
|
|
14
|
-
|
|
15
|
-
.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
|
|
16
|
-
margin: 0;
|
|
17
|
-
}
|
|
18
|
-
.builder-text > p, .builder-text > .builder-paragraph {
|
|
19
|
-
color: inherit;
|
|
20
|
-
line-height: inherit;
|
|
21
|
-
letter-spacing: inherit;
|
|
22
|
-
font-weight: inherit;
|
|
23
|
-
font-size: inherit;
|
|
24
|
-
text-align: inherit;
|
|
25
|
-
font-family: inherit;
|
|
26
|
-
}
|
|
27
|
-
`.trim();
|
|
28
|
-
return React.createElement(InlinedStyles, { styles: injectedStyles });
|
|
29
|
-
}
|
|
30
|
-
export default ContentStyles;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const getContextStateInitialValue = ({ content, data, locale }) => {
|
|
2
|
-
const defaultValues = {};
|
|
3
|
-
// set default values for content state inputs
|
|
4
|
-
content?.data?.inputs?.forEach(input => {
|
|
5
|
-
if (input.name && input.defaultValue !== undefined && content?.data?.state && content.data.state[input.name] === undefined) {
|
|
6
|
-
defaultValues[input.name] = input.defaultValue;
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
const stateToUse = {
|
|
10
|
-
...content?.data?.state,
|
|
11
|
-
...data,
|
|
12
|
-
...(locale ? {
|
|
13
|
-
locale
|
|
14
|
-
} : {})
|
|
15
|
-
};
|
|
16
|
-
return {
|
|
17
|
-
...defaultValues,
|
|
18
|
-
...stateToUse
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export const getContentInitialValue = ({ content, data }) => {
|
|
22
|
-
return !content ? undefined : {
|
|
23
|
-
...content,
|
|
24
|
-
data: {
|
|
25
|
-
...content?.data,
|
|
26
|
-
...data
|
|
27
|
-
},
|
|
28
|
-
meta: content?.meta
|
|
29
|
-
};
|
|
30
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
3
|
-
import { components, serializeComponentInfo, } from "../../functions/register-component.js";
|
|
4
|
-
import Blocks from "../blocks/blocks";
|
|
5
|
-
import ContentStyles from "./components/styles";
|
|
6
|
-
import { getContentInitialValue, getContextStateInitialValue, } from "./content.helpers.js";
|
|
7
|
-
import { TARGET } from "../../constants/target.js";
|
|
8
|
-
import { getRenderContentScriptString } from "../content-variants/helpers.js";
|
|
9
|
-
import EnableEditor from "./components/enable-editor";
|
|
10
|
-
import InlinedScript from "../inlined-script";
|
|
11
|
-
function ContentComponent(props) {
|
|
12
|
-
const scriptStr = getRenderContentScriptString({
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
14
|
-
variationId: props.content?.testVariationId,
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
16
|
-
contentId: props.content?.id,
|
|
17
|
-
});
|
|
18
|
-
const contentSetState = function contentSetState(newRootState) {
|
|
19
|
-
builderContextSignal.rootState = newRootState;
|
|
20
|
-
};
|
|
21
|
-
const registeredComponents = [
|
|
22
|
-
...getDefaultRegisteredComponents(),
|
|
23
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
24
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
25
|
-
// existing usage.
|
|
26
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
27
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
28
|
-
...components,
|
|
29
|
-
...(props.customComponents || []),
|
|
30
|
-
].reduce((acc, { component, ...info }) => ({
|
|
31
|
-
...acc,
|
|
32
|
-
[info.name]: {
|
|
33
|
-
component: component,
|
|
34
|
-
...serializeComponentInfo(info),
|
|
35
|
-
},
|
|
36
|
-
}), {});
|
|
37
|
-
const builderContextSignal = {
|
|
38
|
-
content: getContentInitialValue({
|
|
39
|
-
content: props.content,
|
|
40
|
-
data: props.data,
|
|
41
|
-
}),
|
|
42
|
-
localState: undefined,
|
|
43
|
-
rootState: getContextStateInitialValue({
|
|
44
|
-
content: props.content,
|
|
45
|
-
data: props.data,
|
|
46
|
-
locale: props.locale,
|
|
47
|
-
}),
|
|
48
|
-
rootSetState: undefined,
|
|
49
|
-
context: props.context || {},
|
|
50
|
-
apiKey: props.apiKey,
|
|
51
|
-
apiVersion: props.apiVersion,
|
|
52
|
-
componentInfos: [
|
|
53
|
-
...getDefaultRegisteredComponents(),
|
|
54
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
55
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
56
|
-
// existing usage.
|
|
57
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
58
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
59
|
-
...components,
|
|
60
|
-
...(props.customComponents || []),
|
|
61
|
-
].reduce((acc, { component: _, ...info }) => ({
|
|
62
|
-
...acc,
|
|
63
|
-
[info.name]: serializeComponentInfo(info),
|
|
64
|
-
}), {}),
|
|
65
|
-
inheritedStyles: {},
|
|
66
|
-
};
|
|
67
|
-
return (React.createElement(EnableEditor, { content: props.content, model: props.model, context: props.context, apiKey: props.apiKey, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, classNameProp: props.classNameProp, showContent: props.showContent, builderContextSignal: builderContextSignal },
|
|
68
|
-
props.isSsrAbTest ? (React.createElement(React.Fragment, null,
|
|
69
|
-
React.createElement(InlinedScript, { scriptStr: scriptStr }))) : null,
|
|
70
|
-
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
71
|
-
React.createElement(ContentStyles, { contentId: builderContextSignal.content?.id, cssCode: builderContextSignal.content?.data?.cssCode, customFonts: builderContextSignal.content?.data?.customFonts }))) : null,
|
|
72
|
-
React.createElement(Blocks, { blocks: builderContextSignal.content?.data?.blocks, context: builderContextSignal, registeredComponents: registeredComponents })));
|
|
73
|
-
}
|
|
74
|
-
export default ContentComponent;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { checkShouldRunVariants, getScriptString, getVariants, getVariantsScriptString, } from "./helpers.js";
|
|
3
|
-
import ContentComponent from "../content/content";
|
|
4
|
-
import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
5
|
-
import InlinedStyles from "../inlined-styles";
|
|
6
|
-
import { handleABTestingSync } from "../../helpers/ab-tests.js";
|
|
7
|
-
import InlinedScript from "../inlined-script";
|
|
8
|
-
import { TARGET } from "../../constants/target.js";
|
|
9
|
-
function ContentVariants(props) {
|
|
10
|
-
const shouldRenderVariants = checkShouldRunVariants({
|
|
11
|
-
canTrack: getDefaultCanTrack(props.canTrack),
|
|
12
|
-
content: props.content,
|
|
13
|
-
});
|
|
14
|
-
const variantScriptStr = function variantScriptStr() {
|
|
15
|
-
return getVariantsScriptString(getVariants(props.content).map((value) => ({
|
|
16
|
-
id: value.testVariationId,
|
|
17
|
-
testRatio: value.testRatio,
|
|
18
|
-
})), props.content?.id || "");
|
|
19
|
-
};
|
|
20
|
-
const hideVariantsStyleString = function hideVariantsStyleString() {
|
|
21
|
-
return getVariants(props.content)
|
|
22
|
-
.map((value) => `.variant-${value.testVariationId} { display: none; } `)
|
|
23
|
-
.join("");
|
|
24
|
-
};
|
|
25
|
-
const defaultContent = function defaultContent() {
|
|
26
|
-
return shouldRenderVariants
|
|
27
|
-
? {
|
|
28
|
-
...props.content,
|
|
29
|
-
testVariationId: props.content?.id,
|
|
30
|
-
}
|
|
31
|
-
: handleABTestingSync({
|
|
32
|
-
item: props.content,
|
|
33
|
-
canTrack: getDefaultCanTrack(props.canTrack),
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
return (React.createElement(React.Fragment, null,
|
|
37
|
-
!props.__isNestedRender && TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
38
|
-
React.createElement(InlinedScript, { scriptStr: getScriptString() }))) : null,
|
|
39
|
-
shouldRenderVariants ? (React.createElement(React.Fragment, null,
|
|
40
|
-
React.createElement(InlinedStyles, { id: `variants-styles-${props.content?.id}`, styles: hideVariantsStyleString() }),
|
|
41
|
-
React.createElement(InlinedScript, { scriptStr: variantScriptStr() }),
|
|
42
|
-
getVariants(props.content)?.map((variant) => (React.createElement(ContentComponent, { key: variant.testVariationId, content: variant, showContent: false, classNameProp: undefined, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants }))))) : null,
|
|
43
|
-
React.createElement(ContentComponent, { content: defaultContent(), classNameProp: `variant-${props.content?.id}`, showContent: true, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants })));
|
|
44
|
-
}
|
|
45
|
-
export default ContentVariants;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|