@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-32
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/README.md +19 -0
- package/package.json +8 -1
- package/src/blocks/button/button.svelte +35 -48
- package/src/blocks/columns/columns.svelte +137 -103
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.svelte +58 -53
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.svelte +45 -57
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.svelte +313 -296
- package/src/blocks/fragment/fragment.svelte +9 -25
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.svelte +146 -117
- package/src/blocks/img/img.svelte +48 -36
- package/src/blocks/input/input.svelte +30 -31
- package/src/blocks/raw-text/raw-text.svelte +12 -26
- package/src/blocks/section/section.svelte +30 -36
- package/src/blocks/select/select.svelte +30 -37
- package/src/blocks/submit-button/submit-button.svelte +12 -30
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.svelte +88 -53
- package/src/blocks/text/text.svelte +8 -25
- package/src/blocks/textarea/textarea.svelte +16 -29
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.svelte +88 -41
- package/src/components/render-block/block-styles.svelte +58 -51
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.svelte +204 -160
- package/src/components/render-block/render-component.svelte +30 -0
- package/src/components/render-block/render-repeated-block.svelte +45 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.svelte +88 -80
- package/src/components/render-content/components/render-styles.svelte +59 -63
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.svelte +316 -207
- package/src/components/render-inlined-styles.svelte +26 -48
- package/src/constants/builder-registered-components.js +51 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +7 -4
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +16 -58
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +19 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/track.js +71 -2
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +26 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +10 -8
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/video/index.js +0 -7
- package/src/components/error-boundary.svelte +0 -26
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
|
@@ -1,228 +1,337 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { isBrowser } from '../../functions/is-browser.js';
|
|
13
|
-
import { isEditing } from '../../functions/is-editing.js';
|
|
14
|
-
import { isPreviewing } from '../../functions/is-previewing.js';
|
|
15
|
-
import { previewingModelName } from '../../functions/previewing-model-name.js';
|
|
16
|
-
import { track } from '../../functions/track.js';
|
|
17
|
-
import RenderBlocks, { } from '../render-blocks.svelte';
|
|
18
|
-
import RenderContentStyles, { } from './components/render-styles.svelte';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { getContext, setContext } from "svelte";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export let content;
|
|
26
|
-
export let data;
|
|
27
|
-
export let model;
|
|
28
|
-
export let apiKey;
|
|
29
|
-
|
|
30
|
-
function processMessage(event) {
|
|
31
|
-
const {
|
|
32
|
-
data
|
|
33
|
-
} = event;
|
|
34
|
-
|
|
35
|
-
if (data) {
|
|
36
|
-
switch (data.type) {
|
|
37
|
-
case 'builder.contentUpdate':
|
|
38
|
-
{
|
|
39
|
-
const messageContent = data.data;
|
|
40
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
41
|
-
const contentData = messageContent.data;
|
|
42
|
-
|
|
43
|
-
if (key === model) {
|
|
44
|
-
overrideContent = contentData;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
case 'builder.patchUpdates':
|
|
51
|
-
{
|
|
52
|
-
// TODO
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function evaluateJsCode() {
|
|
60
|
-
// run any dynamic JS code attached to content
|
|
61
|
-
const jsCode = useContent?.()?.data?.jsCode;
|
|
62
|
-
|
|
63
|
-
if (jsCode) {
|
|
64
|
-
evaluate({
|
|
65
|
-
code: jsCode,
|
|
66
|
-
context: context(),
|
|
67
|
-
state: contentState()
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function evalExpression(expression) {
|
|
73
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
74
|
-
code: group,
|
|
75
|
-
context: context(),
|
|
76
|
-
state: contentState()
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function handleRequest({
|
|
81
|
-
url,
|
|
82
|
-
key
|
|
83
|
-
}) {
|
|
84
|
-
const fetchAndSetState = async () => {
|
|
85
|
-
const fetch = await getFetch();
|
|
86
|
-
const response = await fetch(url);
|
|
87
|
-
const json = await response.json();
|
|
88
|
-
const newOverrideState = { ...overrideState,
|
|
89
|
-
[key]: json
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export type RenderContentProps = {
|
|
3
|
+
content?: Nullable<BuilderContent>;
|
|
4
|
+
model?: string;
|
|
5
|
+
data?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
context?: BuilderRenderContext;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
customComponents?: RegisteredComponent[];
|
|
11
|
+
canTrack?: boolean;
|
|
90
12
|
};
|
|
91
|
-
overrideState = newOverrideState;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
fetchAndSetState();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function runHttpRequests() {
|
|
98
|
-
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
99
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
100
|
-
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
101
|
-
const evaluatedUrl = evalExpression(url);
|
|
102
|
-
handleRequest({
|
|
103
|
-
url: evaluatedUrl,
|
|
104
|
-
key
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
13
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
detail: {
|
|
113
|
-
state: contentState(),
|
|
14
|
+
interface BuilderComponentStateChange {
|
|
15
|
+
state: BuilderRenderState;
|
|
114
16
|
ref: {
|
|
115
|
-
name
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...overrideContent,
|
|
123
|
-
data: { ...content?.data,
|
|
124
|
-
...data,
|
|
125
|
-
...overrideContent?.data
|
|
17
|
+
name?: string;
|
|
18
|
+
props?: {
|
|
19
|
+
builderBlock?: {
|
|
20
|
+
id?: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
126
24
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let
|
|
158
|
-
let
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { onMount } from "svelte";
|
|
29
|
+
import { afterUpdate } from "svelte";
|
|
30
|
+
import { onDestroy } from "svelte";
|
|
31
|
+
|
|
32
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
33
|
+
import { TARGET } from "../../constants/target.js";
|
|
34
|
+
import BuilderContext from "../../context/builder.context";
|
|
35
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
36
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
37
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
38
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
39
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
40
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
41
|
+
import {
|
|
42
|
+
components,
|
|
43
|
+
createRegisterComponentMessage,
|
|
44
|
+
} from "../../functions/register-component.js";
|
|
45
|
+
import { track } from "../../functions/track.js";
|
|
46
|
+
import RenderBlocks from "../render-blocks.svelte";
|
|
47
|
+
import RenderContentStyles from "./components/render-styles.svelte";
|
|
48
|
+
import {
|
|
49
|
+
registerInsertMenu,
|
|
50
|
+
setupBrowserForEditing,
|
|
51
|
+
} from "../../scripts/init-editing.js";
|
|
52
|
+
|
|
53
|
+
import { getContext, setContext } from "svelte";
|
|
54
|
+
|
|
55
|
+
export let elementRef: RenderContentProps["elementRef"];
|
|
56
|
+
export let content: RenderContentProps["content"];
|
|
57
|
+
export let data: RenderContentProps["data"];
|
|
58
|
+
export let canTrack: RenderContentProps["canTrack"];
|
|
59
|
+
export let context: RenderContentProps["context"];
|
|
60
|
+
export let customComponents: RenderContentProps["customComponents"];
|
|
61
|
+
export let model: RenderContentProps["model"];
|
|
62
|
+
export let apiKey: RenderContentProps["apiKey"];
|
|
63
|
+
|
|
64
|
+
setContext(BuilderContext.key, {
|
|
65
|
+
get content() {
|
|
66
|
+
return useContent();
|
|
67
|
+
},
|
|
68
|
+
get state() {
|
|
69
|
+
return contentState();
|
|
70
|
+
},
|
|
71
|
+
get context() {
|
|
72
|
+
return contextContext();
|
|
73
|
+
},
|
|
74
|
+
get apiKey() {
|
|
75
|
+
return apiKey;
|
|
76
|
+
},
|
|
77
|
+
get registeredComponents() {
|
|
78
|
+
return allRegisteredComponents();
|
|
79
|
+
},
|
|
169
80
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
81
|
+
|
|
82
|
+
const processMessage = function processMessage(event) {
|
|
83
|
+
const { data } = event;
|
|
84
|
+
|
|
85
|
+
if (data) {
|
|
86
|
+
switch (data.type) {
|
|
87
|
+
case "builder.contentUpdate": {
|
|
88
|
+
const messageContent = data.data;
|
|
89
|
+
const key =
|
|
90
|
+
messageContent.key ||
|
|
91
|
+
messageContent.alias ||
|
|
92
|
+
messageContent.entry ||
|
|
93
|
+
messageContent.modelName;
|
|
94
|
+
const contentData = messageContent.data;
|
|
95
|
+
|
|
96
|
+
if (key === model) {
|
|
97
|
+
overrideContent = contentData;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case "builder.patchUpdates": {
|
|
104
|
+
// TODO
|
|
105
|
+
break;
|
|
186
106
|
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const evaluateJsCode = function evaluateJsCode() {
|
|
112
|
+
// run any dynamic JS code attached to content
|
|
113
|
+
const jsCode = useContent?.()?.data?.jsCode;
|
|
114
|
+
|
|
115
|
+
if (jsCode) {
|
|
116
|
+
evaluate({
|
|
117
|
+
code: jsCode,
|
|
118
|
+
context: contextContext(),
|
|
119
|
+
state: contentState(),
|
|
187
120
|
});
|
|
188
121
|
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
122
|
+
};
|
|
191
123
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
124
|
+
const onClick = function onClick(_event) {
|
|
125
|
+
if (useContent()) {
|
|
126
|
+
track({
|
|
127
|
+
type: "click",
|
|
128
|
+
canTrack: canTrackToUse(),
|
|
129
|
+
contentId: useContent().id,
|
|
130
|
+
orgId: apiKey,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
196
134
|
|
|
197
|
-
|
|
135
|
+
const evalExpression = function evalExpression(expression) {
|
|
136
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
137
|
+
evaluate({
|
|
138
|
+
code: group,
|
|
139
|
+
context: contextContext(),
|
|
140
|
+
state: contentState(),
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
};
|
|
198
144
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
145
|
+
const handleRequest = function handleRequest({ url, key }) {
|
|
146
|
+
const fetchAndSetState = async () => {
|
|
147
|
+
const fetch = await getFetch();
|
|
148
|
+
const response = await fetch(url);
|
|
149
|
+
const json = await response.json();
|
|
150
|
+
const newOverrideState = { ...overrideState, [key]: json };
|
|
151
|
+
overrideState = newOverrideState;
|
|
152
|
+
};
|
|
204
153
|
|
|
205
|
-
|
|
206
|
-
|
|
154
|
+
fetchAndSetState();
|
|
155
|
+
};
|
|
207
156
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
157
|
+
const runHttpRequests = function runHttpRequests() {
|
|
158
|
+
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
159
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
160
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
161
|
+
const evaluatedUrl = evalExpression(url);
|
|
162
|
+
handleRequest({
|
|
163
|
+
url: evaluatedUrl,
|
|
164
|
+
key,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
};
|
|
213
169
|
|
|
214
|
-
|
|
215
|
-
|
|
170
|
+
const emitStateUpdate = function emitStateUpdate() {
|
|
171
|
+
if (isEditing()) {
|
|
172
|
+
window.dispatchEvent(
|
|
173
|
+
new CustomEvent("builder:component:stateChange", {
|
|
174
|
+
detail: {
|
|
175
|
+
state: contentState(),
|
|
176
|
+
ref: {
|
|
177
|
+
name: model,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
$: useContent = () => {
|
|
185
|
+
const mergedContent = {
|
|
186
|
+
...content,
|
|
187
|
+
...overrideContent,
|
|
188
|
+
data: { ...content?.data, ...data, ...overrideContent?.data },
|
|
189
|
+
};
|
|
190
|
+
return mergedContent;
|
|
191
|
+
};
|
|
216
192
|
|
|
193
|
+
$: canTrackToUse = () => {
|
|
194
|
+
return canTrack || true;
|
|
195
|
+
};
|
|
217
196
|
|
|
218
|
-
{
|
|
197
|
+
$: contentState = () => {
|
|
198
|
+
return { ...content?.data?.state, ...data, ...overrideState };
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
$: contextContext = () => {
|
|
202
|
+
return context || {};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
$: allRegisteredComponents = () => {
|
|
206
|
+
const allComponentsArray = [
|
|
207
|
+
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
208
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
209
|
+
// existing usage.
|
|
210
|
+
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
211
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
212
|
+
...components,
|
|
213
|
+
...(customComponents || []),
|
|
214
|
+
];
|
|
215
|
+
const allComponents = allComponentsArray.reduce(
|
|
216
|
+
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
217
|
+
{}
|
|
218
|
+
);
|
|
219
|
+
return allComponents;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
$: httpReqsData = () => {
|
|
223
|
+
return {};
|
|
224
|
+
};
|
|
219
225
|
|
|
220
|
-
|
|
221
|
-
|
|
226
|
+
$: shouldRenderContentStyles = () => {
|
|
227
|
+
return Boolean(
|
|
228
|
+
(useContent?.()?.data?.cssCode ||
|
|
229
|
+
useContent?.()?.data?.customFonts?.length) &&
|
|
230
|
+
TARGET !== "reactNative"
|
|
231
|
+
);
|
|
232
|
+
};
|
|
222
233
|
|
|
223
|
-
|
|
234
|
+
let forceReRenderCount = 0;
|
|
235
|
+
let overrideContent = null;
|
|
236
|
+
let update = 0;
|
|
237
|
+
let overrideState = {};
|
|
238
|
+
|
|
239
|
+
onMount(() => {
|
|
240
|
+
if (isBrowser()) {
|
|
241
|
+
if (isEditing()) {
|
|
242
|
+
forceReRenderCount = forceReRenderCount + 1; // QWIK-REPLACE: _useMutableProps
|
|
243
|
+
|
|
244
|
+
registerInsertMenu();
|
|
245
|
+
setupBrowserForEditing();
|
|
246
|
+
Object.values(allRegisteredComponents()).forEach(
|
|
247
|
+
(registeredComponent) => {
|
|
248
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
249
|
+
window.parent?.postMessage(message, "*");
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
window.addEventListener("message", processMessage);
|
|
253
|
+
window.addEventListener(
|
|
254
|
+
"builder:component:stateChangeListenerActivated",
|
|
255
|
+
emitStateUpdate
|
|
256
|
+
);
|
|
257
|
+
}
|
|
224
258
|
|
|
225
|
-
|
|
259
|
+
if (useContent()) {
|
|
260
|
+
track({
|
|
261
|
+
type: "impression",
|
|
262
|
+
canTrack: canTrackToUse(),
|
|
263
|
+
contentId: useContent().id,
|
|
264
|
+
orgId: apiKey,
|
|
265
|
+
});
|
|
266
|
+
} // override normal content in preview mode
|
|
267
|
+
|
|
268
|
+
if (isPreviewing()) {
|
|
269
|
+
const searchParams = new URL(location.href).searchParams;
|
|
270
|
+
|
|
271
|
+
if (model && searchParams.get("builder.preview") === model) {
|
|
272
|
+
const previewApiKey =
|
|
273
|
+
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
274
|
+
|
|
275
|
+
if (previewApiKey) {
|
|
276
|
+
getContent({
|
|
277
|
+
model: model,
|
|
278
|
+
apiKey: previewApiKey,
|
|
279
|
+
}).then((content) => {
|
|
280
|
+
if (content) {
|
|
281
|
+
overrideContent = content;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
226
287
|
|
|
288
|
+
evaluateJsCode();
|
|
289
|
+
runHttpRequests();
|
|
290
|
+
emitStateUpdate();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
227
293
|
|
|
228
|
-
{
|
|
294
|
+
function onUpdateFn_0() {
|
|
295
|
+
evaluateJsCode();
|
|
296
|
+
}
|
|
297
|
+
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
|
|
298
|
+
function onUpdateFn_1() {
|
|
299
|
+
runHttpRequests();
|
|
300
|
+
}
|
|
301
|
+
$: onUpdateFn_1(...[useContent?.()?.data?.httpRequests]);
|
|
302
|
+
function onUpdateFn_2() {
|
|
303
|
+
emitStateUpdate();
|
|
304
|
+
}
|
|
305
|
+
$: onUpdateFn_2(...[contentState()]);
|
|
306
|
+
|
|
307
|
+
onDestroy(() => {
|
|
308
|
+
if (isBrowser()) {
|
|
309
|
+
window.removeEventListener("message", processMessage);
|
|
310
|
+
window.removeEventListener(
|
|
311
|
+
"builder:component:stateChangeListenerActivated",
|
|
312
|
+
emitStateUpdate
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
</script>
|
|
317
|
+
|
|
318
|
+
{#if useContent()}
|
|
319
|
+
<div
|
|
320
|
+
bind:this={elementRef}
|
|
321
|
+
on:click={(event) => {
|
|
322
|
+
onClick(event);
|
|
323
|
+
}}
|
|
324
|
+
builder-content-id={useContent?.()?.id}
|
|
325
|
+
>
|
|
326
|
+
{#if shouldRenderContentStyles()}
|
|
327
|
+
<RenderContentStyles
|
|
328
|
+
cssCode={useContent?.()?.data?.cssCode}
|
|
329
|
+
customFonts={useContent?.()?.data?.customFonts}
|
|
330
|
+
/>
|
|
331
|
+
{/if}
|
|
332
|
+
<RenderBlocks
|
|
333
|
+
blocks={useContent?.()?.data?.blocks}
|
|
334
|
+
key={forceReRenderCount}
|
|
335
|
+
/>
|
|
336
|
+
</div>
|
|
337
|
+
{/if}
|
|
@@ -1,49 +1,27 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{#if TARGET === 'svelte' }
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{@html injectedStyleScript()}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
interface Props {
|
|
3
|
+
styles: string;
|
|
4
|
+
}
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { TARGET } from "../constants/target.js";
|
|
9
|
+
|
|
10
|
+
export let styles: Props["styles"];
|
|
11
|
+
|
|
12
|
+
$: injectedStyleScript = () => {
|
|
13
|
+
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
$: tagName = () => {
|
|
17
|
+
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
18
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
19
|
+
return "sty" + "le";
|
|
20
|
+
};
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
{#if TARGET === "svelte"}
|
|
24
|
+
{@html injectedStyleScript()}
|
|
46
25
|
{:else}
|
|
47
|
-
<svelte:component
|
|
48
|
-
|
|
49
|
-
{/if}
|
|
26
|
+
<svelte:component this={tagName()}>{styles}</svelte:component>
|
|
27
|
+
{/if}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { default as Button } from "../blocks/button/button.svelte";
|
|
18
|
+
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
|
|
19
|
+
import { default as Columns } from "../blocks/columns/columns.svelte";
|
|
20
|
+
import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
|
|
21
|
+
import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
|
|
22
|
+
import { default as Fragment } from "../blocks/fragment/fragment.svelte";
|
|
23
|
+
import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
|
|
24
|
+
import { default as Image } from "../blocks/image/image.svelte";
|
|
25
|
+
import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
|
|
26
|
+
import { default as Section } from "../blocks/section/section.svelte";
|
|
27
|
+
import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
|
|
28
|
+
import { default as Symbol } from "../blocks/symbol/symbol.svelte";
|
|
29
|
+
import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
|
|
30
|
+
import { default as Text } from "../blocks/text/text.svelte";
|
|
31
|
+
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
32
|
+
import { default as Video } from "../blocks/video/video.svelte";
|
|
33
|
+
import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
|
|
34
|
+
import { default as embed } from "../blocks/embed/embed.svelte";
|
|
35
|
+
import { default as Img } from "../blocks/img/img.svelte";
|
|
36
|
+
import { componentInfo as imgComponentInfo } from "../blocks/img/component-info";
|
|
37
|
+
const getDefaultRegisteredComponents = () => [
|
|
38
|
+
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
39
|
+
__spreadValues({ component: Image }, imageComponentInfo),
|
|
40
|
+
__spreadValues({ component: Img }, imgComponentInfo),
|
|
41
|
+
__spreadValues({ component: Text }, textComponentInfo),
|
|
42
|
+
__spreadValues({ component: Video }, videoComponentInfo),
|
|
43
|
+
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
44
|
+
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
45
|
+
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
46
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo),
|
|
47
|
+
__spreadValues({ component: embed }, embedComponentInfo)
|
|
48
|
+
];
|
|
49
|
+
export {
|
|
50
|
+
getDefaultRegisteredComponents
|
|
51
|
+
};
|