@builder.io/sdk-svelte 0.0.1-19 → 0.0.1-21
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/package.json +1 -1
- package/src/blocks/button/button.svelte +17 -48
- package/src/blocks/columns/columns.svelte +110 -102
- package/src/blocks/custom-code/custom-code.svelte +59 -61
- package/src/blocks/embed/embed.svelte +50 -57
- package/src/blocks/form/form.svelte +264 -294
- package/src/blocks/fragment/fragment.svelte +1 -26
- package/src/blocks/image/image.svelte +85 -117
- package/src/blocks/img/img.svelte +22 -32
- package/src/blocks/input/input.svelte +17 -30
- package/src/blocks/raw-text/raw-text.svelte +4 -26
- package/src/blocks/section/section.svelte +20 -36
- package/src/blocks/select/select.svelte +16 -36
- package/src/blocks/submit-button/submit-button.svelte +4 -30
- package/src/blocks/symbol/symbol.svelte +64 -52
- package/src/blocks/text/text.svelte +1 -25
- package/src/blocks/textarea/textarea.svelte +5 -29
- package/src/blocks/video/video.svelte +35 -43
- package/src/components/render-block/block-styles.svelte +49 -59
- package/src/components/render-block/render-block.svelte +197 -167
- package/src/components/render-block/render-component.svelte +13 -51
- package/src/components/render-block/render-repeated-block.svelte +29 -0
- package/src/components/render-blocks.svelte +74 -98
- package/src/components/render-content/components/render-styles.svelte +42 -62
- package/src/components/render-content/render-content.svelte +257 -231
- package/src/components/render-inlined-styles.svelte +15 -45
- package/src/context/builder.context.js +7 -1
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/get-block-styles.js +6 -3
- package/src/functions/get-processed-block.js +15 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/sanitize-styles.js +5 -0
|
@@ -1,252 +1,278 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { getDefaultRegisteredComponents } from
|
|
7
|
-
import { TARGET } from
|
|
8
|
-
import BuilderContext from
|
|
9
|
-
import { evaluate } from
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export let
|
|
31
|
-
export let
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { afterUpdate } from "svelte";
|
|
4
|
+
import { onDestroy } from "svelte";
|
|
5
|
+
|
|
6
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
7
|
+
import { TARGET } from "../../constants/target.js";
|
|
8
|
+
import BuilderContext from "../../context/builder.context";
|
|
9
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
10
|
+
import {
|
|
11
|
+
convertSearchParamsToQueryObject,
|
|
12
|
+
getBuilderSearchParams,
|
|
13
|
+
} from "../../functions/get-builder-search-params/index.js";
|
|
14
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
15
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
16
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
17
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
18
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
19
|
+
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
20
|
+
import {
|
|
21
|
+
components,
|
|
22
|
+
createRegisterComponentMessage,
|
|
23
|
+
} from "../../functions/register-component.js";
|
|
24
|
+
import { track } from "../../functions/track.js";
|
|
25
|
+
import RenderBlocks from "../render-blocks.svelte";
|
|
26
|
+
import RenderContentStyles from "./components/render-styles.svelte";
|
|
27
|
+
|
|
28
|
+
import { getContext, setContext } from "svelte";
|
|
29
|
+
|
|
30
|
+
export let content;
|
|
31
|
+
export let data;
|
|
32
|
+
export let context;
|
|
33
|
+
export let customComponents;
|
|
34
|
+
export let model;
|
|
35
|
+
export let apiKey;
|
|
36
|
+
|
|
37
|
+
const processMessage = function processMessage(event) {
|
|
38
|
+
const { data } = event;
|
|
39
|
+
|
|
40
|
+
if (data) {
|
|
41
|
+
switch (data.type) {
|
|
42
|
+
case "builder.contentUpdate": {
|
|
43
|
+
const messageContent = data.data;
|
|
44
|
+
const key =
|
|
45
|
+
messageContent.key ||
|
|
46
|
+
messageContent.alias ||
|
|
47
|
+
messageContent.entry ||
|
|
48
|
+
messageContent.modelName;
|
|
49
|
+
const contentData = messageContent.data;
|
|
50
|
+
|
|
51
|
+
if (key === model) {
|
|
52
|
+
overrideContent = contentData;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
break;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
// TODO
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function evaluateJsCode() {
|
|
63
|
-
// run any dynamic JS code attached to content
|
|
64
|
-
const jsCode = useContent?.()?.data?.jsCode;
|
|
65
|
-
|
|
66
|
-
if (jsCode) {
|
|
67
|
-
evaluate({
|
|
68
|
-
code: jsCode,
|
|
69
|
-
context: context(),
|
|
70
|
-
state: contentState()
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function evalExpression(expression) {
|
|
76
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
77
|
-
code: group,
|
|
78
|
-
context: context(),
|
|
79
|
-
state: contentState()
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function handleRequest({
|
|
84
|
-
url,
|
|
85
|
-
key
|
|
86
|
-
}) {
|
|
87
|
-
const fetchAndSetState = async () => {
|
|
88
|
-
const fetch = await getFetch();
|
|
89
|
-
const response = await fetch(url);
|
|
90
|
-
const json = await response.json();
|
|
91
|
-
const newOverrideState = { ...overrideState,
|
|
92
|
-
[key]: json
|
|
93
|
-
};
|
|
94
|
-
overrideState = newOverrideState;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
fetchAndSetState();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function runHttpRequests() {
|
|
101
|
-
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
102
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
103
|
-
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
104
|
-
const evaluatedUrl = evalExpression(url);
|
|
105
|
-
handleRequest({
|
|
106
|
-
url: evaluatedUrl,
|
|
107
|
-
key
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function emitStateUpdate() {
|
|
114
|
-
if (isEditing()) {
|
|
115
|
-
window.dispatchEvent(new CustomEvent('builder:component:stateChange', {
|
|
116
|
-
detail: {
|
|
117
|
-
state: contentState(),
|
|
118
|
-
ref: {
|
|
119
|
-
name: model
|
|
58
|
+
case "builder.patchUpdates": {
|
|
59
|
+
// TODO
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
120
62
|
}
|
|
121
63
|
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
$: useContent = () => {
|
|
126
|
-
const mergedContent = { ...content,
|
|
127
|
-
...overrideContent,
|
|
128
|
-
data: { ...content?.data,
|
|
129
|
-
...data,
|
|
130
|
-
...overrideContent?.data
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
return mergedContent;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
$: contentState = () => {
|
|
137
|
-
return { ...content?.data?.state,
|
|
138
|
-
...data,
|
|
139
|
-
...overrideState
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
$: context = () => {
|
|
144
|
-
return {};
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
$: allRegisteredComponents = () => {
|
|
148
|
-
const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
149
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
150
|
-
// existing usage.
|
|
151
|
-
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
152
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
153
|
-
...components, ...(customComponents || [])];
|
|
154
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
|
|
155
|
-
[curr.name]: curr
|
|
156
|
-
}), {});
|
|
157
|
-
return allComponents;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
$: httpReqsData = () => {
|
|
161
|
-
return {};
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
setContext(BuilderContext.key, { get content() {
|
|
166
|
-
return useContent();
|
|
167
|
-
}, get state() {
|
|
168
|
-
return contentState();
|
|
169
|
-
}, get context() {
|
|
170
|
-
return context();
|
|
171
|
-
}, get apiKey() {
|
|
172
|
-
return apiKey;
|
|
173
|
-
}, get registeredComponents() {
|
|
174
|
-
return allRegisteredComponents();
|
|
175
|
-
},});
|
|
176
|
-
let overrideContent = null;
|
|
177
|
-
let update = 0;
|
|
178
|
-
let overrideState = {};
|
|
179
|
-
|
|
180
|
-
onMount(() => { if (isBrowser()) {
|
|
181
|
-
if (isEditing()) {
|
|
182
|
-
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
183
|
-
const message = createRegisterComponentMessage(registeredComponent);
|
|
184
|
-
window.parent?.postMessage(message, '*');
|
|
185
|
-
});
|
|
186
|
-
window.addEventListener('message', processMessage);
|
|
187
|
-
window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate);
|
|
188
|
-
}
|
|
64
|
+
};
|
|
189
65
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const currentUrl = new URL(location.href);
|
|
200
|
-
const previewApiKey = currentUrl.searchParams.get('apiKey');
|
|
201
|
-
|
|
202
|
-
if (previewApiKey) {
|
|
203
|
-
getContent({
|
|
204
|
-
model: model,
|
|
205
|
-
apiKey: previewApiKey,
|
|
206
|
-
options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
|
|
207
|
-
}).then(content => {
|
|
208
|
-
if (content) {
|
|
209
|
-
overrideContent = content;
|
|
210
|
-
}
|
|
66
|
+
const evaluateJsCode = function evaluateJsCode() {
|
|
67
|
+
// run any dynamic JS code attached to content
|
|
68
|
+
const jsCode = useContent?.()?.data?.jsCode;
|
|
69
|
+
|
|
70
|
+
if (jsCode) {
|
|
71
|
+
evaluate({
|
|
72
|
+
code: jsCode,
|
|
73
|
+
context: contextContext(),
|
|
74
|
+
state: contentState(),
|
|
211
75
|
});
|
|
212
76
|
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
77
|
+
};
|
|
215
78
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
79
|
+
const evalExpression = function evalExpression(expression) {
|
|
80
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
81
|
+
evaluate({
|
|
82
|
+
code: group,
|
|
83
|
+
context: contextContext(),
|
|
84
|
+
state: contentState(),
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleRequest = function handleRequest({ url, key }) {
|
|
90
|
+
const fetchAndSetState = async () => {
|
|
91
|
+
const fetch = await getFetch();
|
|
92
|
+
const response = await fetch(url);
|
|
93
|
+
const json = await response.json();
|
|
94
|
+
const newOverrideState = { ...overrideState, [key]: json };
|
|
95
|
+
overrideState = newOverrideState;
|
|
96
|
+
};
|
|
220
97
|
|
|
221
|
-
|
|
98
|
+
fetchAndSetState();
|
|
99
|
+
};
|
|
222
100
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
101
|
+
const runHttpRequests = function runHttpRequests() {
|
|
102
|
+
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
103
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
104
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
105
|
+
const evaluatedUrl = evalExpression(url);
|
|
106
|
+
handleRequest({
|
|
107
|
+
url: evaluatedUrl,
|
|
108
|
+
key,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
228
113
|
|
|
229
|
-
|
|
230
|
-
|
|
114
|
+
const emitStateUpdate = function emitStateUpdate() {
|
|
115
|
+
if (isEditing()) {
|
|
116
|
+
window.dispatchEvent(
|
|
117
|
+
new CustomEvent("builder:component:stateChange", {
|
|
118
|
+
detail: {
|
|
119
|
+
state: contentState(),
|
|
120
|
+
ref: {
|
|
121
|
+
name: model,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
$: useContent = () => {
|
|
129
|
+
const mergedContent = {
|
|
130
|
+
...content,
|
|
131
|
+
...overrideContent,
|
|
132
|
+
data: { ...content?.data, ...data, ...overrideContent?.data },
|
|
133
|
+
};
|
|
134
|
+
return mergedContent;
|
|
135
|
+
};
|
|
231
136
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
})}" data-builder-content-id={useContent?.()?.id} >
|
|
236
|
-
|
|
137
|
+
$: contentState = () => {
|
|
138
|
+
return { ...content?.data?.state, ...data, ...overrideState };
|
|
139
|
+
};
|
|
237
140
|
|
|
238
|
-
|
|
239
|
-
|
|
141
|
+
$: contextContext = () => {
|
|
142
|
+
return context || {};
|
|
143
|
+
};
|
|
240
144
|
|
|
145
|
+
$: allRegisteredComponents = () => {
|
|
146
|
+
const allComponentsArray = [
|
|
147
|
+
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
148
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
149
|
+
// existing usage.
|
|
150
|
+
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
151
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
152
|
+
...components,
|
|
153
|
+
...(customComponents || []),
|
|
154
|
+
];
|
|
155
|
+
const allComponents = allComponentsArray.reduce(
|
|
156
|
+
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
157
|
+
{}
|
|
158
|
+
);
|
|
159
|
+
return allComponents;
|
|
160
|
+
};
|
|
241
161
|
|
|
242
|
-
{
|
|
162
|
+
$: httpReqsData = () => {
|
|
163
|
+
return {};
|
|
164
|
+
};
|
|
243
165
|
|
|
244
|
-
|
|
245
|
-
|
|
166
|
+
setContext(BuilderContext.key, {
|
|
167
|
+
get content() {
|
|
168
|
+
return useContent();
|
|
169
|
+
},
|
|
170
|
+
get state() {
|
|
171
|
+
return contentState();
|
|
172
|
+
},
|
|
173
|
+
get context() {
|
|
174
|
+
return contextContext();
|
|
175
|
+
},
|
|
176
|
+
get apiKey() {
|
|
177
|
+
return apiKey;
|
|
178
|
+
},
|
|
179
|
+
get registeredComponents() {
|
|
180
|
+
return allRegisteredComponents();
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
let overrideContent = null;
|
|
184
|
+
let update = 0;
|
|
185
|
+
let overrideState = {};
|
|
186
|
+
|
|
187
|
+
onMount(() => {
|
|
188
|
+
if (isBrowser()) {
|
|
189
|
+
if (isEditing()) {
|
|
190
|
+
Object.values(allRegisteredComponents()).forEach(
|
|
191
|
+
(registeredComponent) => {
|
|
192
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
193
|
+
window.parent?.postMessage(message, "*");
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
window.addEventListener("message", processMessage);
|
|
197
|
+
window.addEventListener(
|
|
198
|
+
"builder:component:stateChangeListenerActivated",
|
|
199
|
+
emitStateUpdate
|
|
200
|
+
);
|
|
201
|
+
}
|
|
246
202
|
|
|
247
|
-
|
|
203
|
+
if (useContent()) {
|
|
204
|
+
track("impression", {
|
|
205
|
+
contentId: useContent().id,
|
|
206
|
+
});
|
|
207
|
+
} // override normal content in preview mode
|
|
208
|
+
|
|
209
|
+
if (isPreviewing()) {
|
|
210
|
+
if (model && previewingModelName() === model) {
|
|
211
|
+
const currentUrl = new URL(location.href);
|
|
212
|
+
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
213
|
+
|
|
214
|
+
if (previewApiKey) {
|
|
215
|
+
getContent({
|
|
216
|
+
model: model,
|
|
217
|
+
apiKey: previewApiKey,
|
|
218
|
+
options: getBuilderSearchParams(
|
|
219
|
+
convertSearchParamsToQueryObject(currentUrl.searchParams)
|
|
220
|
+
),
|
|
221
|
+
}).then((content) => {
|
|
222
|
+
if (content) {
|
|
223
|
+
overrideContent = content;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
248
229
|
|
|
249
|
-
|
|
230
|
+
evaluateJsCode();
|
|
231
|
+
runHttpRequests();
|
|
232
|
+
emitStateUpdate();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
250
235
|
|
|
236
|
+
function onUpdateFn_0() {
|
|
237
|
+
evaluateJsCode();
|
|
238
|
+
}
|
|
239
|
+
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
|
|
240
|
+
function onUpdateFn_1() {
|
|
241
|
+
runHttpRequests();
|
|
242
|
+
}
|
|
243
|
+
$: onUpdateFn_1(...[useContent?.()?.data?.httpRequests]);
|
|
244
|
+
function onUpdateFn_2() {
|
|
245
|
+
emitStateUpdate();
|
|
246
|
+
}
|
|
247
|
+
$: onUpdateFn_2(...[contentState()]);
|
|
248
|
+
|
|
249
|
+
onDestroy(() => {
|
|
250
|
+
if (isBrowser()) {
|
|
251
|
+
window.removeEventListener("message", processMessage);
|
|
252
|
+
window.removeEventListener(
|
|
253
|
+
"builder:component:stateChangeListenerActivated",
|
|
254
|
+
emitStateUpdate
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
</script>
|
|
251
259
|
|
|
252
|
-
{
|
|
260
|
+
{#if useContent()}
|
|
261
|
+
<div
|
|
262
|
+
on:click={(event) => {
|
|
263
|
+
track("click", {
|
|
264
|
+
contentId: useContent().id,
|
|
265
|
+
});
|
|
266
|
+
}}
|
|
267
|
+
data-builder-content-id={useContent?.()?.id}
|
|
268
|
+
>
|
|
269
|
+
{#if (useContent?.()?.data?.cssCode || useContent?.()?.data?.customFonts?.length) && TARGET !== "reactNative"}
|
|
270
|
+
<RenderContentStyles
|
|
271
|
+
cssCode={useContent().data.cssCode}
|
|
272
|
+
customFonts={useContent().data.customFonts}
|
|
273
|
+
/>
|
|
274
|
+
{/if}
|
|
275
|
+
|
|
276
|
+
<RenderBlocks blocks={useContent?.()?.data?.blocks} />
|
|
277
|
+
</div>
|
|
278
|
+
{/if}
|
|
@@ -1,51 +1,21 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { TARGET } from '../constants/target.js';
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { TARGET } from "../constants/target.js";
|
|
9
3
|
|
|
10
|
-
|
|
4
|
+
export let styles;
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
$: injectedStyleScript = () => {
|
|
17
|
-
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
$: tagName = () => {
|
|
21
|
-
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
22
|
-
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
23
|
-
return 'sty' + 'le';
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{#if TARGET === 'svelte' }
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
{@html injectedStyleScript()}
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
$: injectedStyleScript = () => {
|
|
7
|
+
return `<${tagName()}>${styles}</${tagName()}>`;
|
|
8
|
+
};
|
|
46
9
|
|
|
10
|
+
$: tagName = () => {
|
|
11
|
+
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
12
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
13
|
+
return "sty" + "le";
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
47
16
|
|
|
17
|
+
{#if TARGET === "svelte"}
|
|
18
|
+
{@html injectedStyleScript()}
|
|
48
19
|
{:else}
|
|
49
|
-
<svelte:component
|
|
50
|
-
|
|
51
|
-
{/if}
|
|
20
|
+
<svelte:component this={tagName()}>{styles}</svelte:component>
|
|
21
|
+
{/if}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const key = Symbol();
|
|
2
2
|
var stdin_default = {
|
|
3
|
-
Builder: {
|
|
3
|
+
Builder: {
|
|
4
|
+
content: null,
|
|
5
|
+
context: {},
|
|
6
|
+
state: {},
|
|
7
|
+
apiKey: null,
|
|
8
|
+
registeredComponents: {}
|
|
9
|
+
},
|
|
4
10
|
key
|
|
5
11
|
};
|
|
6
12
|
export {
|
|
@@ -15,15 +15,18 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
17
|
import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
18
|
+
import { convertStyleObject } from "./convert-style-object.js";
|
|
19
|
+
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
18
20
|
function getBlockStyles(block) {
|
|
19
21
|
var _a, _b, _c, _d, _e;
|
|
20
|
-
const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
|
|
22
|
+
const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
|
|
21
23
|
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
22
|
-
styles[getMaxWidthQueryForSize("medium")] = (_c = block.responsiveStyles) == null ? void 0 : _c.medium;
|
|
24
|
+
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
|
|
23
25
|
}
|
|
24
26
|
if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
|
|
25
|
-
styles[getMaxWidthQueryForSize("small")] = (_e = block.responsiveStyles) == null ? void 0 : _e.small;
|
|
27
|
+
styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
|
|
26
28
|
}
|
|
29
|
+
sanitizeBlockStyles(styles);
|
|
27
30
|
return styles;
|
|
28
31
|
}
|
|
29
32
|
export {
|
|
@@ -20,9 +20,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { evaluate } from "./evaluate.js";
|
|
21
21
|
import { set } from "./set.js";
|
|
22
22
|
import { transformBlock } from "./transform-block.js";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const evaluateBindings = ({
|
|
24
|
+
block,
|
|
25
|
+
context,
|
|
26
|
+
state
|
|
27
|
+
}) => {
|
|
26
28
|
if (!block.bindings) {
|
|
27
29
|
return block;
|
|
28
30
|
}
|
|
@@ -32,14 +34,19 @@ function getProcessedBlock(options) {
|
|
|
32
34
|
});
|
|
33
35
|
for (const binding in block.bindings) {
|
|
34
36
|
const expression = block.bindings[binding];
|
|
35
|
-
const value = evaluate({
|
|
36
|
-
code: expression,
|
|
37
|
-
state,
|
|
38
|
-
context
|
|
39
|
-
});
|
|
37
|
+
const value = evaluate({ code: expression, state, context });
|
|
40
38
|
set(copied, binding, value);
|
|
41
39
|
}
|
|
42
40
|
return copied;
|
|
41
|
+
};
|
|
42
|
+
function getProcessedBlock(options) {
|
|
43
|
+
const { state, context } = options;
|
|
44
|
+
const block = transformBlock(options.block);
|
|
45
|
+
if (evaluateBindings) {
|
|
46
|
+
return evaluateBindings({ block, state, context });
|
|
47
|
+
} else {
|
|
48
|
+
return block;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
export {
|
|
45
52
|
getProcessedBlock
|
|
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
|
|
|
20
20
|
const processed = getProcessedBlock({
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
|
-
state: { test: "hello" }
|
|
23
|
+
state: { test: "hello" },
|
|
24
|
+
evaluateBindings: true
|
|
24
25
|
});
|
|
25
26
|
expect(processed).not.toEqual(block);
|
|
26
27
|
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|