@builder.io/sdk-svelte 0.0.1-20 → 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 -57
- 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 +252 -241
- 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,267 +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
|
-
|
|
58
|
+
case "builder.patchUpdates": {
|
|
59
|
+
// TODO
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
51
62
|
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
66
|
+
const evaluateJsCode = function evaluateJsCode() {
|
|
67
|
+
// run any dynamic JS code attached to content
|
|
68
|
+
const jsCode = useContent?.()?.data?.jsCode;
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
if (jsCode) {
|
|
71
|
+
evaluate({
|
|
72
|
+
code: jsCode,
|
|
73
|
+
context: contextContext(),
|
|
74
|
+
state: contentState(),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
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
|
+
};
|
|
74
88
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
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
|
+
};
|
|
82
97
|
|
|
83
|
-
|
|
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
|
|
98
|
+
fetchAndSetState();
|
|
93
99
|
};
|
|
94
|
-
overrideState = newOverrideState;
|
|
95
|
-
};
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
key
|
|
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
|
+
}
|
|
108
111
|
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
+
};
|
|
112
113
|
|
|
113
|
-
const emitStateUpdate = function emitStateUpdate() {
|
|
114
|
-
if (isEditing()) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
);
|
|
121
126
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
};
|
|
127
|
+
};
|
|
128
|
+
$: useContent = () => {
|
|
129
|
+
const mergedContent = {
|
|
130
|
+
...content,
|
|
131
|
+
...overrideContent,
|
|
132
|
+
data: { ...content?.data, ...data, ...overrideContent?.data },
|
|
133
|
+
};
|
|
134
|
+
return mergedContent;
|
|
135
|
+
};
|
|
146
136
|
|
|
147
|
-
$:
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
};
|
|
137
|
+
$: contentState = () => {
|
|
138
|
+
return { ...content?.data?.state, ...data, ...overrideState };
|
|
139
|
+
};
|
|
159
140
|
|
|
160
|
-
$:
|
|
161
|
-
return {};
|
|
162
|
-
};
|
|
141
|
+
$: contextContext = () => {
|
|
142
|
+
return context || {};
|
|
143
|
+
};
|
|
163
144
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
};
|
|
179
161
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const message = createRegisterComponentMessage(registeredComponent);
|
|
184
|
-
window.parent?.postMessage(message, '*');
|
|
185
|
-
});
|
|
186
|
-
window.addEventListener('message', processMessage);
|
|
187
|
-
window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate);
|
|
188
|
-
}
|
|
162
|
+
$: httpReqsData = () => {
|
|
163
|
+
return {};
|
|
164
|
+
};
|
|
189
165
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
},
|
|
193
182
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
+
}
|
|
201
202
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
}
|
|
210
227
|
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
evaluateJsCode();
|
|
217
|
-
runHttpRequests();
|
|
218
|
-
emitStateUpdate();
|
|
219
|
-
} });
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
function onUpdateFn_0() {
|
|
223
|
-
evaluateJsCode();
|
|
224
|
-
}
|
|
225
|
-
$: onUpdateFn_0(...[useContent?.()?.data?.jsCode])
|
|
226
|
-
;
|
|
227
|
-
function onUpdateFn_1() {
|
|
228
|
-
runHttpRequests();
|
|
229
|
-
}
|
|
230
|
-
$: onUpdateFn_1(...[useContent?.()?.data?.httpRequests])
|
|
231
|
-
;
|
|
232
|
-
function onUpdateFn_2() {
|
|
233
|
-
emitStateUpdate();
|
|
234
|
-
}
|
|
235
|
-
$: onUpdateFn_2(...[contentState()])
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
onDestroy(() => { if (isBrowser()) {
|
|
239
|
-
window.removeEventListener('message', processMessage);
|
|
240
|
-
window.removeEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate);
|
|
241
|
-
} });
|
|
242
|
-
</script>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{#if useContent() }
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
<div on:click="{event => track('click', {
|
|
249
|
-
contentId: useContent().id
|
|
250
|
-
})}" data-builder-content-id={useContent?.()?.id} >
|
|
251
|
-
|
|
228
|
+
}
|
|
252
229
|
|
|
253
|
-
|
|
254
|
-
|
|
230
|
+
evaluateJsCode();
|
|
231
|
+
runHttpRequests();
|
|
232
|
+
emitStateUpdate();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
255
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>
|
|
256
259
|
|
|
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>
|
|
257
278
|
{/if}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<RenderBlocks blocks={useContent?.()?.data?.blocks} ></RenderBlocks>
|
|
261
|
-
|
|
262
|
-
</div>
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
{/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
|