@builder.io/sdk-svelte 0.12.7 → 0.13.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/components/content/components/enable-editor.svelte +17 -31
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/browser/components/content-variants/helpers.d.ts +1 -1
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/get-content/generate-content-url.js +2 -2
- package/lib/browser/functions/get-content/types.d.ts +2 -2
- package/lib/browser/helpers/subscribe-to-editor.d.ts +35 -0
- package/lib/browser/helpers/subscribe-to-editor.js +60 -0
- package/lib/browser/server-index.d.ts +18 -3
- package/lib/browser/server-index.js +8 -1
- package/lib/browser/types/api-version.d.ts +1 -1
- package/lib/edge/components/content/components/enable-editor.svelte +17 -31
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/edge/components/content-variants/helpers.d.ts +1 -1
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/get-content/generate-content-url.js +2 -2
- package/lib/edge/functions/get-content/types.d.ts +2 -2
- package/lib/edge/helpers/subscribe-to-editor.d.ts +35 -0
- package/lib/edge/helpers/subscribe-to-editor.js +60 -0
- package/lib/edge/server-index.d.ts +18 -3
- package/lib/edge/server-index.js +8 -1
- package/lib/edge/types/api-version.d.ts +1 -1
- package/lib/node/components/content/components/enable-editor.svelte +17 -31
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/node/components/content-variants/helpers.d.ts +1 -1
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/get-content/generate-content-url.js +2 -2
- package/lib/node/functions/get-content/types.d.ts +2 -2
- package/lib/node/helpers/subscribe-to-editor.d.ts +35 -0
- package/lib/node/helpers/subscribe-to-editor.js +60 -0
- package/lib/node/server-index.d.ts +18 -3
- package/lib/node/server-index.js +8 -1
- package/lib/node/types/api-version.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/content/components/enable-editor.svelte +17 -32
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/get-content/generate-content-url.ts +2 -2
- package/src/functions/get-content/types.ts +2 -2
- package/src/helpers/subscribe-to-editor.ts +95 -0
- package/src/server-index.ts +23 -4
- package/src/types/api-version.ts +1 -1
|
@@ -8,7 +8,6 @@ import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
|
8
8
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
9
9
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
10
10
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
11
|
-
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
12
11
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
13
12
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
14
13
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -16,12 +15,13 @@ import { getInteractionPropertiesForEvent } from "../../../functions/track/inter
|
|
|
16
15
|
import { getDefaultCanTrack } from "../../../helpers/canTrack.js";
|
|
17
16
|
import { logger } from "../../../helpers/logger.js";
|
|
18
17
|
import "../../../helpers/preview-lru-cache/set.js";
|
|
18
|
+
import { createEditorListener } from "../../../helpers/subscribe-to-editor.js";
|
|
19
19
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
20
20
|
import { triggerAnimation } from "../../block/animator.js";
|
|
21
21
|
export let builderContextSignal;
|
|
22
22
|
export let contentWrapper = undefined;
|
|
23
|
-
export let trustedHosts = undefined;
|
|
24
23
|
export let model = undefined;
|
|
24
|
+
export let trustedHosts = undefined;
|
|
25
25
|
export let context = undefined;
|
|
26
26
|
export let canTrack = undefined;
|
|
27
27
|
export let apiKey;
|
|
@@ -62,14 +62,11 @@ function mergeNewContent(newContent) {
|
|
|
62
62
|
$builderContextSignal.content = newContentValue;
|
|
63
63
|
}
|
|
64
64
|
function processMessage(event) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
switch (data.type) {
|
|
71
|
-
case "builder.configureSdk": {
|
|
72
|
-
const messageContent = data.data;
|
|
65
|
+
return createEditorListener({
|
|
66
|
+
model: model,
|
|
67
|
+
trustedHosts: trustedHosts,
|
|
68
|
+
callbacks: {
|
|
69
|
+
configureSdk: (messageContent) => {
|
|
73
70
|
const { breakpoints, contentId } = messageContent;
|
|
74
71
|
if (!contentId || contentId !== $builderContextSignal.content?.id) {
|
|
75
72
|
return;
|
|
@@ -80,29 +77,18 @@ function processMessage(event) {
|
|
|
80
77
|
breakpoints,
|
|
81
78
|
},
|
|
82
79
|
});
|
|
83
|
-
}
|
|
84
|
-
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "builder.triggerAnimation": {
|
|
88
|
-
triggerAnimation(data.data);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case "builder.contentUpdate": {
|
|
92
|
-
const messageContent = data.data;
|
|
93
|
-
const key = messageContent.key ||
|
|
94
|
-
messageContent.alias ||
|
|
95
|
-
messageContent.entry ||
|
|
96
|
-
messageContent.modelName;
|
|
97
|
-
const contentData = messageContent.data;
|
|
98
|
-
if (key === model) {
|
|
99
|
-
mergeNewContent(contentData);
|
|
100
80
|
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
101
81
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
},
|
|
83
|
+
animation: (animation) => {
|
|
84
|
+
triggerAnimation(animation);
|
|
85
|
+
},
|
|
86
|
+
contentUpdate: (newContent) => {
|
|
87
|
+
mergeNewContent(newContent);
|
|
88
|
+
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
})(event);
|
|
106
92
|
}
|
|
107
93
|
function evaluateJsCode() {
|
|
108
94
|
// run any dynamic JS code attached to content
|
|
@@ -11,8 +11,8 @@ declare const __propDef: {
|
|
|
11
11
|
props: {
|
|
12
12
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
13
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
14
|
-
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
15
14
|
model?: BuilderEditorProps["model"];
|
|
15
|
+
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
16
16
|
context?: BuilderEditorProps["context"];
|
|
17
17
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
18
18
|
apiKey: BuilderEditorProps["apiKey"];
|
|
@@ -6,7 +6,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
|
|
|
6
6
|
data?: {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
title?: string | undefined;
|
|
9
|
-
blocks?: import("../../
|
|
9
|
+
blocks?: import("../../server-index.js").BuilderBlock[] | undefined;
|
|
10
10
|
inputs?: import("../../types/input.js").Input[] | undefined;
|
|
11
11
|
state?: {
|
|
12
12
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.13.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.13.0";
|
|
@@ -8,8 +8,8 @@ export const generateContentUrl = (options) => {
|
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
11
|
-
if (!['
|
|
12
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
11
|
+
if (!['v3'].includes(apiVersion)) {
|
|
12
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
13
13
|
}
|
|
14
14
|
// Set noTraverse=true if NOT already passed by user, for query performance
|
|
15
15
|
if ((options.limit === undefined || options.limit > 1) && !('noTraverse' in options)) {
|
|
@@ -76,9 +76,9 @@ export interface GetContentOptions {
|
|
|
76
76
|
/**
|
|
77
77
|
* If provided, sets the Builder API version used to fetch content.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* Currently, the only available API version is `v3`.
|
|
80
80
|
*/
|
|
81
|
-
apiVersion?: '
|
|
81
|
+
apiVersion?: 'v3';
|
|
82
82
|
/**
|
|
83
83
|
* Only include these fields.
|
|
84
84
|
* Note: 'omit' takes precedence over 'fields'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
|
+
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
|
+
callbacks: {
|
|
6
|
+
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
7
|
+
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
|
+
configureSdk: (updatedContent: any) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const createEditorListener: ({ model, trustedHosts, callbacks }: ContentListener) => (event: MessageEvent<any>) => void;
|
|
12
|
+
type SubscribeToEditor = (
|
|
13
|
+
/**
|
|
14
|
+
* The Builder `model` to subscribe to
|
|
15
|
+
*/
|
|
16
|
+
model: string,
|
|
17
|
+
/**
|
|
18
|
+
* The callback function to call when the content is updated.
|
|
19
|
+
*/
|
|
20
|
+
callback: (updatedContent: BuilderContent) => void,
|
|
21
|
+
/**
|
|
22
|
+
* Extra options for the listener.
|
|
23
|
+
*/
|
|
24
|
+
options?: {
|
|
25
|
+
/**
|
|
26
|
+
* List of hosts to allow editing content from.
|
|
27
|
+
*/
|
|
28
|
+
trustedHosts?: string[] | undefined;
|
|
29
|
+
}) => () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
32
|
+
* Sends the updated `content` to the `callback` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare const subscribeToEditor: SubscribeToEditor;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { isFromTrustedHost } from '../functions/is-from-trusted-host.js';
|
|
3
|
+
import { setupBrowserForEditing } from '../scripts/init-editing.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
6
|
+
return (event) => {
|
|
7
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const { data } = event;
|
|
11
|
+
if (data) {
|
|
12
|
+
switch (data.type) {
|
|
13
|
+
case 'builder.configureSdk':
|
|
14
|
+
{
|
|
15
|
+
callbacks.configureSdk(data.data);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'builder.triggerAnimation':
|
|
19
|
+
{
|
|
20
|
+
callbacks.animation(data.data);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'builder.contentUpdate':
|
|
24
|
+
{
|
|
25
|
+
const messageContent = data.data;
|
|
26
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
27
|
+
const contentData = messageContent.data;
|
|
28
|
+
if (key === model) {
|
|
29
|
+
callbacks.contentUpdate(contentData);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
39
|
+
* Sends the updated `content` to the `callback` function.
|
|
40
|
+
*/
|
|
41
|
+
export const subscribeToEditor = (model, callback, options) => {
|
|
42
|
+
if (!isBrowser) {
|
|
43
|
+
logger.warn('`subscribeToEditor` only works in the browser. It currently seems to be running on the server.');
|
|
44
|
+
return () => { };
|
|
45
|
+
}
|
|
46
|
+
setupBrowserForEditing();
|
|
47
|
+
const listener = createEditorListener({
|
|
48
|
+
callbacks: {
|
|
49
|
+
contentUpdate: callback,
|
|
50
|
+
animation: () => { },
|
|
51
|
+
configureSdk: () => { }
|
|
52
|
+
},
|
|
53
|
+
model,
|
|
54
|
+
trustedHosts: options?.trustedHosts
|
|
55
|
+
});
|
|
56
|
+
window.addEventListener('message', listener);
|
|
57
|
+
return () => {
|
|
58
|
+
window.removeEventListener('message', listener);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component Prop types
|
|
4
|
+
*/
|
|
2
5
|
export type { ButtonProps } from './blocks/button/button.types.js';
|
|
3
6
|
export type { ColumnProps } from './blocks/columns/columns.types.js';
|
|
4
7
|
export type { FragmentProps } from './blocks/fragment/fragment.types.js';
|
|
@@ -9,6 +12,16 @@ export type { TextProps } from './blocks/text/text.types.js';
|
|
|
9
12
|
export type { VideoProps } from './blocks/video/video.types.js';
|
|
10
13
|
export type { BlocksProps } from './components/blocks/blocks.types.js';
|
|
11
14
|
export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
|
|
15
|
+
/**
|
|
16
|
+
* General Builder types
|
|
17
|
+
*/
|
|
18
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
19
|
+
export type { BuilderBlock } from './types/builder-block.js';
|
|
20
|
+
export type { BuilderContent } from './types/builder-content.js';
|
|
21
|
+
export type { ComponentInfo } from './types/components.js';
|
|
22
|
+
/**
|
|
23
|
+
* Helper functions
|
|
24
|
+
*/
|
|
12
25
|
export { isEditing } from './functions/is-editing.js';
|
|
13
26
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
14
27
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
@@ -16,9 +29,11 @@ export { register } from './functions/register.js';
|
|
|
16
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
17
30
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
18
31
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
19
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
20
32
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
21
33
|
export { track } from './functions/track/index.js';
|
|
22
|
-
export
|
|
23
|
-
|
|
34
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
35
|
+
/**
|
|
36
|
+
* Content fetching
|
|
37
|
+
*/
|
|
24
38
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
39
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions
|
|
4
|
+
*/
|
|
2
5
|
export { isEditing } from './functions/is-editing.js';
|
|
3
6
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
4
7
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
5
8
|
export { register } from './functions/register.js';
|
|
6
9
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
7
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
8
10
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
9
11
|
export { track } from './functions/track/index.js';
|
|
12
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
13
|
+
/**
|
|
14
|
+
* Content fetching
|
|
15
|
+
*/
|
|
10
16
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
17
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type ApiVersion = '
|
|
1
|
+
export type ApiVersion = 'v3';
|
|
2
2
|
export declare const DEFAULT_API_VERSION: ApiVersion;
|
|
@@ -8,7 +8,6 @@ import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
|
8
8
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
9
9
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
10
10
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
11
|
-
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
12
11
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
13
12
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
14
13
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -16,12 +15,13 @@ import { getInteractionPropertiesForEvent } from "../../../functions/track/inter
|
|
|
16
15
|
import { getDefaultCanTrack } from "../../../helpers/canTrack.js";
|
|
17
16
|
import { logger } from "../../../helpers/logger.js";
|
|
18
17
|
import "../../../helpers/preview-lru-cache/set.js";
|
|
18
|
+
import { createEditorListener } from "../../../helpers/subscribe-to-editor.js";
|
|
19
19
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
20
20
|
import { triggerAnimation } from "../../block/animator.js";
|
|
21
21
|
export let builderContextSignal;
|
|
22
22
|
export let contentWrapper = undefined;
|
|
23
|
-
export let trustedHosts = undefined;
|
|
24
23
|
export let model = undefined;
|
|
24
|
+
export let trustedHosts = undefined;
|
|
25
25
|
export let context = undefined;
|
|
26
26
|
export let canTrack = undefined;
|
|
27
27
|
export let apiKey;
|
|
@@ -62,14 +62,11 @@ function mergeNewContent(newContent) {
|
|
|
62
62
|
$builderContextSignal.content = newContentValue;
|
|
63
63
|
}
|
|
64
64
|
function processMessage(event) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
switch (data.type) {
|
|
71
|
-
case "builder.configureSdk": {
|
|
72
|
-
const messageContent = data.data;
|
|
65
|
+
return createEditorListener({
|
|
66
|
+
model: model,
|
|
67
|
+
trustedHosts: trustedHosts,
|
|
68
|
+
callbacks: {
|
|
69
|
+
configureSdk: (messageContent) => {
|
|
73
70
|
const { breakpoints, contentId } = messageContent;
|
|
74
71
|
if (!contentId || contentId !== $builderContextSignal.content?.id) {
|
|
75
72
|
return;
|
|
@@ -80,29 +77,18 @@ function processMessage(event) {
|
|
|
80
77
|
breakpoints,
|
|
81
78
|
},
|
|
82
79
|
});
|
|
83
|
-
}
|
|
84
|
-
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "builder.triggerAnimation": {
|
|
88
|
-
triggerAnimation(data.data);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case "builder.contentUpdate": {
|
|
92
|
-
const messageContent = data.data;
|
|
93
|
-
const key = messageContent.key ||
|
|
94
|
-
messageContent.alias ||
|
|
95
|
-
messageContent.entry ||
|
|
96
|
-
messageContent.modelName;
|
|
97
|
-
const contentData = messageContent.data;
|
|
98
|
-
if (key === model) {
|
|
99
|
-
mergeNewContent(contentData);
|
|
100
80
|
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
101
81
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
},
|
|
83
|
+
animation: (animation) => {
|
|
84
|
+
triggerAnimation(animation);
|
|
85
|
+
},
|
|
86
|
+
contentUpdate: (newContent) => {
|
|
87
|
+
mergeNewContent(newContent);
|
|
88
|
+
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
})(event);
|
|
106
92
|
}
|
|
107
93
|
function evaluateJsCode() {
|
|
108
94
|
// run any dynamic JS code attached to content
|
|
@@ -11,8 +11,8 @@ declare const __propDef: {
|
|
|
11
11
|
props: {
|
|
12
12
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
13
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
14
|
-
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
15
14
|
model?: BuilderEditorProps["model"];
|
|
15
|
+
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
16
16
|
context?: BuilderEditorProps["context"];
|
|
17
17
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
18
18
|
apiKey: BuilderEditorProps["apiKey"];
|
|
@@ -6,7 +6,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
|
|
|
6
6
|
data?: {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
title?: string | undefined;
|
|
9
|
-
blocks?: import("../../
|
|
9
|
+
blocks?: import("../../server-index.js").BuilderBlock[] | undefined;
|
|
10
10
|
inputs?: import("../../types/input.js").Input[] | undefined;
|
|
11
11
|
state?: {
|
|
12
12
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.13.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.13.0";
|
|
@@ -8,8 +8,8 @@ export const generateContentUrl = (options) => {
|
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
11
|
-
if (!['
|
|
12
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
11
|
+
if (!['v3'].includes(apiVersion)) {
|
|
12
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
13
13
|
}
|
|
14
14
|
// Set noTraverse=true if NOT already passed by user, for query performance
|
|
15
15
|
if ((options.limit === undefined || options.limit > 1) && !('noTraverse' in options)) {
|
|
@@ -76,9 +76,9 @@ export interface GetContentOptions {
|
|
|
76
76
|
/**
|
|
77
77
|
* If provided, sets the Builder API version used to fetch content.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* Currently, the only available API version is `v3`.
|
|
80
80
|
*/
|
|
81
|
-
apiVersion?: '
|
|
81
|
+
apiVersion?: 'v3';
|
|
82
82
|
/**
|
|
83
83
|
* Only include these fields.
|
|
84
84
|
* Note: 'omit' takes precedence over 'fields'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
|
+
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
|
+
callbacks: {
|
|
6
|
+
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
7
|
+
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
|
+
configureSdk: (updatedContent: any) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const createEditorListener: ({ model, trustedHosts, callbacks }: ContentListener) => (event: MessageEvent<any>) => void;
|
|
12
|
+
type SubscribeToEditor = (
|
|
13
|
+
/**
|
|
14
|
+
* The Builder `model` to subscribe to
|
|
15
|
+
*/
|
|
16
|
+
model: string,
|
|
17
|
+
/**
|
|
18
|
+
* The callback function to call when the content is updated.
|
|
19
|
+
*/
|
|
20
|
+
callback: (updatedContent: BuilderContent) => void,
|
|
21
|
+
/**
|
|
22
|
+
* Extra options for the listener.
|
|
23
|
+
*/
|
|
24
|
+
options?: {
|
|
25
|
+
/**
|
|
26
|
+
* List of hosts to allow editing content from.
|
|
27
|
+
*/
|
|
28
|
+
trustedHosts?: string[] | undefined;
|
|
29
|
+
}) => () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
32
|
+
* Sends the updated `content` to the `callback` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare const subscribeToEditor: SubscribeToEditor;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { isFromTrustedHost } from '../functions/is-from-trusted-host.js';
|
|
3
|
+
import { setupBrowserForEditing } from '../scripts/init-editing.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
6
|
+
return (event) => {
|
|
7
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const { data } = event;
|
|
11
|
+
if (data) {
|
|
12
|
+
switch (data.type) {
|
|
13
|
+
case 'builder.configureSdk':
|
|
14
|
+
{
|
|
15
|
+
callbacks.configureSdk(data.data);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'builder.triggerAnimation':
|
|
19
|
+
{
|
|
20
|
+
callbacks.animation(data.data);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'builder.contentUpdate':
|
|
24
|
+
{
|
|
25
|
+
const messageContent = data.data;
|
|
26
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
27
|
+
const contentData = messageContent.data;
|
|
28
|
+
if (key === model) {
|
|
29
|
+
callbacks.contentUpdate(contentData);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
39
|
+
* Sends the updated `content` to the `callback` function.
|
|
40
|
+
*/
|
|
41
|
+
export const subscribeToEditor = (model, callback, options) => {
|
|
42
|
+
if (!isBrowser) {
|
|
43
|
+
logger.warn('`subscribeToEditor` only works in the browser. It currently seems to be running on the server.');
|
|
44
|
+
return () => { };
|
|
45
|
+
}
|
|
46
|
+
setupBrowserForEditing();
|
|
47
|
+
const listener = createEditorListener({
|
|
48
|
+
callbacks: {
|
|
49
|
+
contentUpdate: callback,
|
|
50
|
+
animation: () => { },
|
|
51
|
+
configureSdk: () => { }
|
|
52
|
+
},
|
|
53
|
+
model,
|
|
54
|
+
trustedHosts: options?.trustedHosts
|
|
55
|
+
});
|
|
56
|
+
window.addEventListener('message', listener);
|
|
57
|
+
return () => {
|
|
58
|
+
window.removeEventListener('message', listener);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component Prop types
|
|
4
|
+
*/
|
|
2
5
|
export type { ButtonProps } from './blocks/button/button.types.js';
|
|
3
6
|
export type { ColumnProps } from './blocks/columns/columns.types.js';
|
|
4
7
|
export type { FragmentProps } from './blocks/fragment/fragment.types.js';
|
|
@@ -9,6 +12,16 @@ export type { TextProps } from './blocks/text/text.types.js';
|
|
|
9
12
|
export type { VideoProps } from './blocks/video/video.types.js';
|
|
10
13
|
export type { BlocksProps } from './components/blocks/blocks.types.js';
|
|
11
14
|
export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
|
|
15
|
+
/**
|
|
16
|
+
* General Builder types
|
|
17
|
+
*/
|
|
18
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
19
|
+
export type { BuilderBlock } from './types/builder-block.js';
|
|
20
|
+
export type { BuilderContent } from './types/builder-content.js';
|
|
21
|
+
export type { ComponentInfo } from './types/components.js';
|
|
22
|
+
/**
|
|
23
|
+
* Helper functions
|
|
24
|
+
*/
|
|
12
25
|
export { isEditing } from './functions/is-editing.js';
|
|
13
26
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
14
27
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
@@ -16,9 +29,11 @@ export { register } from './functions/register.js';
|
|
|
16
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
17
30
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
18
31
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
19
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
20
32
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
21
33
|
export { track } from './functions/track/index.js';
|
|
22
|
-
export
|
|
23
|
-
|
|
34
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
35
|
+
/**
|
|
36
|
+
* Content fetching
|
|
37
|
+
*/
|
|
24
38
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
39
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
package/lib/edge/server-index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions
|
|
4
|
+
*/
|
|
2
5
|
export { isEditing } from './functions/is-editing.js';
|
|
3
6
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
4
7
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
5
8
|
export { register } from './functions/register.js';
|
|
6
9
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
7
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
8
10
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
9
11
|
export { track } from './functions/track/index.js';
|
|
12
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
13
|
+
/**
|
|
14
|
+
* Content fetching
|
|
15
|
+
*/
|
|
10
16
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
17
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type ApiVersion = '
|
|
1
|
+
export type ApiVersion = 'v3';
|
|
2
2
|
export declare const DEFAULT_API_VERSION: ApiVersion;
|
|
@@ -8,7 +8,6 @@ import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
|
8
8
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
9
9
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
10
10
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
11
|
-
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
12
11
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
13
12
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
14
13
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -16,12 +15,13 @@ import { getInteractionPropertiesForEvent } from "../../../functions/track/inter
|
|
|
16
15
|
import { getDefaultCanTrack } from "../../../helpers/canTrack.js";
|
|
17
16
|
import { logger } from "../../../helpers/logger.js";
|
|
18
17
|
import "../../../helpers/preview-lru-cache/set.js";
|
|
18
|
+
import { createEditorListener } from "../../../helpers/subscribe-to-editor.js";
|
|
19
19
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
|
|
20
20
|
import { triggerAnimation } from "../../block/animator.js";
|
|
21
21
|
export let builderContextSignal;
|
|
22
22
|
export let contentWrapper = undefined;
|
|
23
|
-
export let trustedHosts = undefined;
|
|
24
23
|
export let model = undefined;
|
|
24
|
+
export let trustedHosts = undefined;
|
|
25
25
|
export let context = undefined;
|
|
26
26
|
export let canTrack = undefined;
|
|
27
27
|
export let apiKey;
|
|
@@ -62,14 +62,11 @@ function mergeNewContent(newContent) {
|
|
|
62
62
|
$builderContextSignal.content = newContentValue;
|
|
63
63
|
}
|
|
64
64
|
function processMessage(event) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
switch (data.type) {
|
|
71
|
-
case "builder.configureSdk": {
|
|
72
|
-
const messageContent = data.data;
|
|
65
|
+
return createEditorListener({
|
|
66
|
+
model: model,
|
|
67
|
+
trustedHosts: trustedHosts,
|
|
68
|
+
callbacks: {
|
|
69
|
+
configureSdk: (messageContent) => {
|
|
73
70
|
const { breakpoints, contentId } = messageContent;
|
|
74
71
|
if (!contentId || contentId !== $builderContextSignal.content?.id) {
|
|
75
72
|
return;
|
|
@@ -80,29 +77,18 @@ function processMessage(event) {
|
|
|
80
77
|
breakpoints,
|
|
81
78
|
},
|
|
82
79
|
});
|
|
83
|
-
}
|
|
84
|
-
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "builder.triggerAnimation": {
|
|
88
|
-
triggerAnimation(data.data);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case "builder.contentUpdate": {
|
|
92
|
-
const messageContent = data.data;
|
|
93
|
-
const key = messageContent.key ||
|
|
94
|
-
messageContent.alias ||
|
|
95
|
-
messageContent.entry ||
|
|
96
|
-
messageContent.modelName;
|
|
97
|
-
const contentData = messageContent.data;
|
|
98
|
-
if (key === model) {
|
|
99
|
-
mergeNewContent(contentData);
|
|
100
80
|
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
101
81
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
},
|
|
83
|
+
animation: (animation) => {
|
|
84
|
+
triggerAnimation(animation);
|
|
85
|
+
},
|
|
86
|
+
contentUpdate: (newContent) => {
|
|
87
|
+
mergeNewContent(newContent);
|
|
88
|
+
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
})(event);
|
|
106
92
|
}
|
|
107
93
|
function evaluateJsCode() {
|
|
108
94
|
// run any dynamic JS code attached to content
|
|
@@ -11,8 +11,8 @@ declare const __propDef: {
|
|
|
11
11
|
props: {
|
|
12
12
|
builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
13
13
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
14
|
-
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
15
14
|
model?: BuilderEditorProps["model"];
|
|
15
|
+
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
16
16
|
context?: BuilderEditorProps["context"];
|
|
17
17
|
canTrack?: BuilderEditorProps["canTrack"];
|
|
18
18
|
apiKey: BuilderEditorProps["apiKey"];
|
|
@@ -6,7 +6,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
|
|
|
6
6
|
data?: {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
title?: string | undefined;
|
|
9
|
-
blocks?: import("../../
|
|
9
|
+
blocks?: import("../../server-index.js").BuilderBlock[] | undefined;
|
|
10
10
|
inputs?: import("../../types/input.js").Input[] | undefined;
|
|
11
11
|
state?: {
|
|
12
12
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.13.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.13.0";
|
|
@@ -8,8 +8,8 @@ export const generateContentUrl = (options) => {
|
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
throw new Error('Missing API key');
|
|
10
10
|
}
|
|
11
|
-
if (!['
|
|
12
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
11
|
+
if (!['v3'].includes(apiVersion)) {
|
|
12
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
13
13
|
}
|
|
14
14
|
// Set noTraverse=true if NOT already passed by user, for query performance
|
|
15
15
|
if ((options.limit === undefined || options.limit > 1) && !('noTraverse' in options)) {
|
|
@@ -76,9 +76,9 @@ export interface GetContentOptions {
|
|
|
76
76
|
/**
|
|
77
77
|
* If provided, sets the Builder API version used to fetch content.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* Currently, the only available API version is `v3`.
|
|
80
80
|
*/
|
|
81
|
-
apiVersion?: '
|
|
81
|
+
apiVersion?: 'v3';
|
|
82
82
|
/**
|
|
83
83
|
* Only include these fields.
|
|
84
84
|
* Note: 'omit' takes precedence over 'fields'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
|
+
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
|
+
callbacks: {
|
|
6
|
+
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
7
|
+
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
|
+
configureSdk: (updatedContent: any) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const createEditorListener: ({ model, trustedHosts, callbacks }: ContentListener) => (event: MessageEvent<any>) => void;
|
|
12
|
+
type SubscribeToEditor = (
|
|
13
|
+
/**
|
|
14
|
+
* The Builder `model` to subscribe to
|
|
15
|
+
*/
|
|
16
|
+
model: string,
|
|
17
|
+
/**
|
|
18
|
+
* The callback function to call when the content is updated.
|
|
19
|
+
*/
|
|
20
|
+
callback: (updatedContent: BuilderContent) => void,
|
|
21
|
+
/**
|
|
22
|
+
* Extra options for the listener.
|
|
23
|
+
*/
|
|
24
|
+
options?: {
|
|
25
|
+
/**
|
|
26
|
+
* List of hosts to allow editing content from.
|
|
27
|
+
*/
|
|
28
|
+
trustedHosts?: string[] | undefined;
|
|
29
|
+
}) => () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
32
|
+
* Sends the updated `content` to the `callback` function.
|
|
33
|
+
*/
|
|
34
|
+
export declare const subscribeToEditor: SubscribeToEditor;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { isFromTrustedHost } from '../functions/is-from-trusted-host.js';
|
|
3
|
+
import { setupBrowserForEditing } from '../scripts/init-editing.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
6
|
+
return (event) => {
|
|
7
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const { data } = event;
|
|
11
|
+
if (data) {
|
|
12
|
+
switch (data.type) {
|
|
13
|
+
case 'builder.configureSdk':
|
|
14
|
+
{
|
|
15
|
+
callbacks.configureSdk(data.data);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'builder.triggerAnimation':
|
|
19
|
+
{
|
|
20
|
+
callbacks.animation(data.data);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'builder.contentUpdate':
|
|
24
|
+
{
|
|
25
|
+
const messageContent = data.data;
|
|
26
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
27
|
+
const contentData = messageContent.data;
|
|
28
|
+
if (key === model) {
|
|
29
|
+
callbacks.contentUpdate(contentData);
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
39
|
+
* Sends the updated `content` to the `callback` function.
|
|
40
|
+
*/
|
|
41
|
+
export const subscribeToEditor = (model, callback, options) => {
|
|
42
|
+
if (!isBrowser) {
|
|
43
|
+
logger.warn('`subscribeToEditor` only works in the browser. It currently seems to be running on the server.');
|
|
44
|
+
return () => { };
|
|
45
|
+
}
|
|
46
|
+
setupBrowserForEditing();
|
|
47
|
+
const listener = createEditorListener({
|
|
48
|
+
callbacks: {
|
|
49
|
+
contentUpdate: callback,
|
|
50
|
+
animation: () => { },
|
|
51
|
+
configureSdk: () => { }
|
|
52
|
+
},
|
|
53
|
+
model,
|
|
54
|
+
trustedHosts: options?.trustedHosts
|
|
55
|
+
});
|
|
56
|
+
window.addEventListener('message', listener);
|
|
57
|
+
return () => {
|
|
58
|
+
window.removeEventListener('message', listener);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component Prop types
|
|
4
|
+
*/
|
|
2
5
|
export type { ButtonProps } from './blocks/button/button.types.js';
|
|
3
6
|
export type { ColumnProps } from './blocks/columns/columns.types.js';
|
|
4
7
|
export type { FragmentProps } from './blocks/fragment/fragment.types.js';
|
|
@@ -9,6 +12,16 @@ export type { TextProps } from './blocks/text/text.types.js';
|
|
|
9
12
|
export type { VideoProps } from './blocks/video/video.types.js';
|
|
10
13
|
export type { BlocksProps } from './components/blocks/blocks.types.js';
|
|
11
14
|
export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
|
|
15
|
+
/**
|
|
16
|
+
* General Builder types
|
|
17
|
+
*/
|
|
18
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
19
|
+
export type { BuilderBlock } from './types/builder-block.js';
|
|
20
|
+
export type { BuilderContent } from './types/builder-content.js';
|
|
21
|
+
export type { ComponentInfo } from './types/components.js';
|
|
22
|
+
/**
|
|
23
|
+
* Helper functions
|
|
24
|
+
*/
|
|
12
25
|
export { isEditing } from './functions/is-editing.js';
|
|
13
26
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
14
27
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
@@ -16,9 +29,11 @@ export { register } from './functions/register.js';
|
|
|
16
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
17
30
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
18
31
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
19
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
20
32
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
21
33
|
export { track } from './functions/track/index.js';
|
|
22
|
-
export
|
|
23
|
-
|
|
34
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
35
|
+
/**
|
|
36
|
+
* Content fetching
|
|
37
|
+
*/
|
|
24
38
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
39
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
package/lib/node/server-index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions
|
|
4
|
+
*/
|
|
2
5
|
export { isEditing } from './functions/is-editing.js';
|
|
3
6
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
4
7
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
5
8
|
export { register } from './functions/register.js';
|
|
6
9
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
7
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
8
10
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
9
11
|
export { track } from './functions/track/index.js';
|
|
12
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
13
|
+
/**
|
|
14
|
+
* Content fetching
|
|
15
|
+
*/
|
|
10
16
|
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
17
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type ApiVersion = '
|
|
1
|
+
export type ApiVersion = 'v3';
|
|
2
2
|
export declare const DEFAULT_API_VERSION: ApiVersion;
|
package/package.json
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
import { fetch } from "../../../functions/get-fetch.js";
|
|
25
25
|
import { isBrowser } from "../../../functions/is-browser.js";
|
|
26
26
|
import { isEditing } from "../../../functions/is-editing.js";
|
|
27
|
-
import { isFromTrustedHost } from "../../../functions/is-from-trusted-host.js";
|
|
28
27
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
29
28
|
import { createRegisterComponentMessage } from "../../../functions/register-component.js";
|
|
30
29
|
import { _track } from "../../../functions/track/index.js";
|
|
@@ -32,6 +31,7 @@
|
|
|
32
31
|
import { getDefaultCanTrack } from "../../../helpers/canTrack.js";
|
|
33
32
|
import { logger } from "../../../helpers/logger.js";
|
|
34
33
|
import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
|
|
34
|
+
import { createEditorListener } from "../../../helpers/subscribe-to-editor.js";
|
|
35
35
|
import {
|
|
36
36
|
registerInsertMenu,
|
|
37
37
|
setupBrowserForEditing,
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
|
|
49
49
|
export let builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
50
50
|
export let contentWrapper: BuilderEditorProps["contentWrapper"] = undefined;
|
|
51
|
-
export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
|
|
52
51
|
export let model: BuilderEditorProps["model"] = undefined;
|
|
52
|
+
export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
|
|
53
53
|
export let context: BuilderEditorProps["context"] = undefined;
|
|
54
54
|
export let canTrack: BuilderEditorProps["canTrack"] = undefined;
|
|
55
55
|
export let apiKey: BuilderEditorProps["apiKey"];
|
|
@@ -93,14 +93,11 @@
|
|
|
93
93
|
$builderContextSignal.content = newContentValue;
|
|
94
94
|
}
|
|
95
95
|
function processMessage(event: MessageEvent) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
switch (data.type) {
|
|
102
|
-
case "builder.configureSdk": {
|
|
103
|
-
const messageContent = data.data;
|
|
96
|
+
return createEditorListener({
|
|
97
|
+
model: model,
|
|
98
|
+
trustedHosts: trustedHosts,
|
|
99
|
+
callbacks: {
|
|
100
|
+
configureSdk: (messageContent) => {
|
|
104
101
|
const { breakpoints, contentId } = messageContent;
|
|
105
102
|
if (!contentId || contentId !== $builderContextSignal.content?.id) {
|
|
106
103
|
return;
|
|
@@ -111,30 +108,18 @@
|
|
|
111
108
|
breakpoints,
|
|
112
109
|
},
|
|
113
110
|
});
|
|
114
|
-
}
|
|
115
|
-
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "builder.triggerAnimation": {
|
|
119
|
-
triggerAnimation(data.data);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
case "builder.contentUpdate": {
|
|
123
|
-
const messageContent = data.data;
|
|
124
|
-
const key =
|
|
125
|
-
messageContent.key ||
|
|
126
|
-
messageContent.alias ||
|
|
127
|
-
messageContent.entry ||
|
|
128
|
-
messageContent.modelName;
|
|
129
|
-
const contentData = messageContent.data;
|
|
130
|
-
if (key === model) {
|
|
131
|
-
mergeNewContent(contentData);
|
|
132
111
|
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
133
112
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
113
|
+
},
|
|
114
|
+
animation: (animation) => {
|
|
115
|
+
triggerAnimation(animation);
|
|
116
|
+
},
|
|
117
|
+
contentUpdate: (newContent) => {
|
|
118
|
+
mergeNewContent(newContent);
|
|
119
|
+
forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
})(event);
|
|
138
123
|
}
|
|
139
124
|
function evaluateJsCode() {
|
|
140
125
|
// run any dynamic JS code attached to content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.13.0"
|
|
@@ -28,8 +28,8 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
28
28
|
if (!apiKey) {
|
|
29
29
|
throw new Error('Missing API key');
|
|
30
30
|
}
|
|
31
|
-
if (!['
|
|
32
|
-
throw new Error(`Invalid apiVersion: expected '
|
|
31
|
+
if (!['v3'].includes(apiVersion)) {
|
|
32
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Set noTraverse=true if NOT already passed by user, for query performance
|
|
@@ -88,9 +88,9 @@ export interface GetContentOptions {
|
|
|
88
88
|
/**
|
|
89
89
|
* If provided, sets the Builder API version used to fetch content.
|
|
90
90
|
*
|
|
91
|
-
*
|
|
91
|
+
* Currently, the only available API version is `v3`.
|
|
92
92
|
*/
|
|
93
|
-
apiVersion?: '
|
|
93
|
+
apiVersion?: 'v3';
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* Only include these fields.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
3
|
+
import { isFromTrustedHost } from '../functions/is-from-trusted-host.js';
|
|
4
|
+
import { setupBrowserForEditing } from '../scripts/init-editing.js';
|
|
5
|
+
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
6
|
+
import type { BuilderContent } from '../types/builder-content.js';
|
|
7
|
+
import { logger } from './logger.js';
|
|
8
|
+
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
9
|
+
callbacks: {
|
|
10
|
+
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
11
|
+
animation: (updatedContent: BuilderAnimation) => void;
|
|
12
|
+
configureSdk: (updatedContent: any) => void;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const createEditorListener = ({
|
|
16
|
+
model,
|
|
17
|
+
trustedHosts,
|
|
18
|
+
callbacks
|
|
19
|
+
}: ContentListener) => {
|
|
20
|
+
return (event: MessageEvent<any>): void => {
|
|
21
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
data
|
|
26
|
+
} = event;
|
|
27
|
+
if (data) {
|
|
28
|
+
switch (data.type) {
|
|
29
|
+
case 'builder.configureSdk':
|
|
30
|
+
{
|
|
31
|
+
callbacks.configureSdk(data.data);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case 'builder.triggerAnimation':
|
|
35
|
+
{
|
|
36
|
+
callbacks.animation(data.data);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'builder.contentUpdate':
|
|
40
|
+
{
|
|
41
|
+
const messageContent = data.data;
|
|
42
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
43
|
+
const contentData = messageContent.data;
|
|
44
|
+
if (key === model) {
|
|
45
|
+
callbacks.contentUpdate(contentData);
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
type SubscribeToEditor = (
|
|
54
|
+
/**
|
|
55
|
+
* The Builder `model` to subscribe to
|
|
56
|
+
*/
|
|
57
|
+
model: string,
|
|
58
|
+
/**
|
|
59
|
+
* The callback function to call when the content is updated.
|
|
60
|
+
*/
|
|
61
|
+
callback: (updatedContent: BuilderContent) => void,
|
|
62
|
+
/**
|
|
63
|
+
* Extra options for the listener.
|
|
64
|
+
*/
|
|
65
|
+
options?: {
|
|
66
|
+
/**
|
|
67
|
+
* List of hosts to allow editing content from.
|
|
68
|
+
*/
|
|
69
|
+
trustedHosts?: string[] | undefined;
|
|
70
|
+
}) => () => void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
|
|
74
|
+
* Sends the updated `content` to the `callback` function.
|
|
75
|
+
*/
|
|
76
|
+
export const subscribeToEditor: SubscribeToEditor = (model, callback, options) => {
|
|
77
|
+
if (!isBrowser) {
|
|
78
|
+
logger.warn('`subscribeToEditor` only works in the browser. It currently seems to be running on the server.');
|
|
79
|
+
return () => {};
|
|
80
|
+
}
|
|
81
|
+
setupBrowserForEditing();
|
|
82
|
+
const listener = createEditorListener({
|
|
83
|
+
callbacks: {
|
|
84
|
+
contentUpdate: callback,
|
|
85
|
+
animation: () => {},
|
|
86
|
+
configureSdk: () => {}
|
|
87
|
+
},
|
|
88
|
+
model,
|
|
89
|
+
trustedHosts: options?.trustedHosts
|
|
90
|
+
});
|
|
91
|
+
window.addEventListener('message', listener);
|
|
92
|
+
return () => {
|
|
93
|
+
window.removeEventListener('message', listener);
|
|
94
|
+
};
|
|
95
|
+
}
|
package/src/server-index.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './index-helpers/top-of-file.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component Prop types
|
|
5
|
+
*/
|
|
2
6
|
export type { ButtonProps } from './blocks/button/button.types.js';
|
|
3
7
|
export type { ColumnProps } from './blocks/columns/columns.types.js';
|
|
4
8
|
export type { FragmentProps } from './blocks/fragment/fragment.types.js';
|
|
@@ -9,6 +13,18 @@ export type { TextProps } from './blocks/text/text.types.js';
|
|
|
9
13
|
export type { VideoProps } from './blocks/video/video.types.js';
|
|
10
14
|
export type { BlocksProps } from './components/blocks/blocks.types.js';
|
|
11
15
|
export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* General Builder types
|
|
19
|
+
*/
|
|
20
|
+
export type { RegisteredComponent } from './context/types.js';
|
|
21
|
+
export type { BuilderBlock } from './types/builder-block.js';
|
|
22
|
+
export type { BuilderContent } from './types/builder-content.js';
|
|
23
|
+
export type { ComponentInfo } from './types/components.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Helper functions
|
|
27
|
+
*/
|
|
12
28
|
export { isEditing } from './functions/is-editing.js';
|
|
13
29
|
export { isPreviewing } from './functions/is-previewing.js';
|
|
14
30
|
export { createRegisterComponentMessage } from './functions/register-component.js';
|
|
@@ -16,9 +32,12 @@ export { register } from './functions/register.js';
|
|
|
16
32
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
17
33
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
18
34
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
19
|
-
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
|
|
20
35
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
21
36
|
export { track } from './functions/track/index.js';
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Content fetching
|
|
41
|
+
*/
|
|
42
|
+
export { fetchBuilderProps } from './functions/fetch-builder-props.js';
|
|
43
|
+
export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js'
|
package/src/types/api-version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type ApiVersion = '
|
|
1
|
+
export type ApiVersion = 'v3';
|
|
2
2
|
export const DEFAULT_API_VERSION: ApiVersion = 'v3'
|