@builder.io/sdk-solid 0.1.1 → 0.1.3-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/dist/sdk-solid.cjs +34 -0
- package/dist/sdk-solid.js +3863 -0
- package/package.json +5 -6
- package/src/blocks/BaseText.jsx +5 -1
- package/src/blocks/button/button.jsx +25 -7
- package/src/blocks/columns/columns.jsx +84 -38
- package/src/blocks/custom-code/custom-code.jsx +25 -3
- package/src/blocks/embed/embed.jsx +14 -2
- package/src/blocks/form/form.jsx +175 -121
- package/src/blocks/fragment/fragment.jsx +2 -1
- package/src/blocks/image/image.jsx +75 -38
- package/src/blocks/img/img.jsx +15 -5
- package/src/blocks/input/input.jsx +17 -2
- package/src/blocks/raw-text/raw-text.jsx +8 -2
- package/src/blocks/section/section.jsx +24 -14
- package/src/blocks/select/select.jsx +21 -6
- package/src/blocks/submit-button/submit-button.jsx +6 -3
- package/src/blocks/symbol/symbol.jsx +54 -15
- package/src/blocks/text/text.jsx +2 -1
- package/src/blocks/textarea/textarea.jsx +11 -2
- package/src/blocks/video/video.jsx +49 -27
- package/src/components/render-block/block-styles.jsx +45 -21
- package/src/components/render-block/render-block.helpers.js +90 -0
- package/src/components/render-block/render-block.jsx +110 -131
- package/src/components/render-block/render-component.jsx +26 -9
- package/src/components/render-block/render-repeated-block.jsx +20 -24
- package/src/components/render-blocks.jsx +70 -30
- package/src/components/render-content/builder-editing.jsx +2 -1
- package/src/components/render-content/components/render-styles.jsx +17 -8
- package/src/components/render-content/render-content.jsx +225 -146
- package/src/components/render-inlined-styles.jsx +14 -4
- package/src/helpers/cookie.js +4 -2
- package/src/helpers/localStorage.js +1 -0
- package/src/helpers/sessionId.js +4 -1
- package/src/helpers/url.js +3 -0
- package/src/helpers/url.test.js +6 -0
- package/src/helpers/visitorId.js +1 -0
- package/vite.config.ts +18 -0
- package/solid-index.jsx +0 -5
- package/src/components/render-block/render-component-with-context.jsx +0 -28
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Show, onMount, on, createEffect, createSignal } from "solid-js";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { createStore, reconcile } from "solid-js/store";
|
|
4
|
+
|
|
4
5
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
6
|
import { TARGET } from "../../constants/target.js";
|
|
6
7
|
import { evaluate } from "../../functions/evaluate.js";
|
|
@@ -9,88 +10,108 @@ import { fetch } from "../../functions/get-fetch.js";
|
|
|
9
10
|
import { isBrowser } from "../../functions/is-browser.js";
|
|
10
11
|
import { isEditing } from "../../functions/is-editing.js";
|
|
11
12
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
components,
|
|
15
|
+
createRegisterComponentMessage,
|
|
16
|
+
} from "../../functions/register-component.js";
|
|
13
17
|
import { _track } from "../../functions/track.js";
|
|
14
18
|
import RenderBlocks from "../render-blocks.jsx";
|
|
15
19
|
import RenderContentStyles from "./components/render-styles.jsx";
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
20
|
+
import builderContext from "../../context/builder.context.js";
|
|
21
|
+
import {
|
|
22
|
+
registerInsertMenu,
|
|
23
|
+
setupBrowserForEditing,
|
|
24
|
+
} from "../../scripts/init-editing.js";
|
|
25
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
26
|
+
|
|
18
27
|
function RenderContent(props) {
|
|
19
28
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
29
|
+
|
|
20
30
|
const [overrideContent, setOverrideContent] = createSignal(null);
|
|
31
|
+
|
|
21
32
|
const [update, setUpdate] = createSignal(0);
|
|
33
|
+
|
|
22
34
|
const [useBreakpoints, setUseBreakpoints] = createSignal(null);
|
|
35
|
+
|
|
36
|
+
const [canTrackToUse, setCanTrackToUse] = createSignal(
|
|
37
|
+
checkIsDefined(props.canTrack) ? props.canTrack : true
|
|
38
|
+
);
|
|
39
|
+
|
|
23
40
|
const [overrideState, setOverrideState] = createSignal({});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
|
|
42
|
+
const [contextContext, setContextContext] = createSignal(props.context || {});
|
|
43
|
+
|
|
44
|
+
const [allRegisteredComponents, setAllRegisteredComponents] = createSignal(
|
|
45
|
+
[
|
|
46
|
+
...getDefaultRegisteredComponents(),
|
|
47
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
48
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
49
|
+
// existing usage.
|
|
50
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
51
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
52
|
+
...components,
|
|
53
|
+
...(props.customComponents || []),
|
|
54
|
+
].reduce(
|
|
55
|
+
(acc, curr) => ({
|
|
56
|
+
...acc,
|
|
57
|
+
[curr.name]: curr,
|
|
58
|
+
}),
|
|
59
|
+
{}
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const [httpReqsData, setHttpReqsData] = createSignal({});
|
|
64
|
+
|
|
27
65
|
function contentState() {
|
|
28
66
|
return {
|
|
29
67
|
...props.content?.data?.state,
|
|
30
68
|
...props.data,
|
|
31
|
-
...(props.locale
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
69
|
+
...(props.locale
|
|
70
|
+
? {
|
|
71
|
+
locale: props.locale,
|
|
72
|
+
}
|
|
73
|
+
: {}),
|
|
74
|
+
...overrideState(),
|
|
35
75
|
};
|
|
36
76
|
}
|
|
37
|
-
|
|
38
|
-
return props.context || {};
|
|
39
|
-
}
|
|
40
|
-
function allRegisteredComponents() {
|
|
41
|
-
const allComponentsArray = [...getDefaultRegisteredComponents(),
|
|
42
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
43
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
44
|
-
// existing usage.
|
|
45
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
46
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
47
|
-
...components, ...(props.customComponents || [])];
|
|
48
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
49
|
-
...acc,
|
|
50
|
-
[curr.name]: curr
|
|
51
|
-
}), {});
|
|
52
|
-
return allComponents;
|
|
53
|
-
}
|
|
77
|
+
|
|
54
78
|
function processMessage(event) {
|
|
55
|
-
const {
|
|
56
|
-
data
|
|
57
|
-
} = event;
|
|
79
|
+
const { data } = event;
|
|
58
80
|
if (data) {
|
|
59
81
|
switch (data.type) {
|
|
60
|
-
case "builder.configureSdk":
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
case "builder.configureSdk": {
|
|
83
|
+
const messageContent = data.data;
|
|
84
|
+
const { breakpoints, contentId } = messageContent;
|
|
85
|
+
if (!contentId || contentId !== useContent?.id) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
setUseBreakpoints(breakpoints);
|
|
89
|
+
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case "builder.contentUpdate": {
|
|
93
|
+
const messageContent = data.data;
|
|
94
|
+
const key =
|
|
95
|
+
messageContent.key ||
|
|
96
|
+
messageContent.alias ||
|
|
97
|
+
messageContent.entry ||
|
|
98
|
+
messageContent.modelName;
|
|
99
|
+
const contentData = messageContent.data;
|
|
100
|
+
if (key === props.model) {
|
|
101
|
+
setOverrideContent(contentData);
|
|
71
102
|
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
72
|
-
break;
|
|
73
103
|
}
|
|
74
|
-
case "builder.contentUpdate":
|
|
75
|
-
{
|
|
76
|
-
const messageContent = data.data;
|
|
77
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
78
|
-
const contentData = messageContent.data;
|
|
79
|
-
if (key === props.model) {
|
|
80
|
-
setOverrideContent(contentData);
|
|
81
|
-
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
82
|
-
}
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
case "builder.patchUpdates":
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "builder.patchUpdates": {
|
|
108
|
+
// TODO
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
91
111
|
}
|
|
92
112
|
}
|
|
93
113
|
}
|
|
114
|
+
|
|
94
115
|
function evaluateJsCode() {
|
|
95
116
|
// run any dynamic JS code attached to content
|
|
96
117
|
const jsCode = useContent?.data?.jsCode;
|
|
@@ -98,13 +119,11 @@ function RenderContent(props) {
|
|
|
98
119
|
evaluate({
|
|
99
120
|
code: jsCode,
|
|
100
121
|
context: contextContext(),
|
|
101
|
-
state: contentState()
|
|
122
|
+
state: contentState(),
|
|
102
123
|
});
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
|
-
|
|
106
|
-
return {};
|
|
107
|
-
}
|
|
126
|
+
|
|
108
127
|
function onClick(_event) {
|
|
109
128
|
if (useContent) {
|
|
110
129
|
const variationId = useContent?.testVariationId;
|
|
@@ -114,31 +133,36 @@ function RenderContent(props) {
|
|
|
114
133
|
canTrack: canTrackToUse(),
|
|
115
134
|
contentId,
|
|
116
135
|
apiKey: props.apiKey,
|
|
117
|
-
variationId: variationId !== contentId ? variationId : undefined
|
|
136
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
118
137
|
});
|
|
119
138
|
}
|
|
120
139
|
}
|
|
140
|
+
|
|
121
141
|
function evalExpression(expression) {
|
|
122
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
143
|
+
evaluate({
|
|
144
|
+
code: group,
|
|
145
|
+
context: contextContext(),
|
|
146
|
+
state: contentState(),
|
|
147
|
+
})
|
|
148
|
+
);
|
|
127
149
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
|
|
151
|
+
function handleRequest({ url, key }) {
|
|
152
|
+
fetch(url)
|
|
153
|
+
.then((response) => response.json())
|
|
154
|
+
.then((json) => {
|
|
155
|
+
const newOverrideState = {
|
|
156
|
+
...overrideState(),
|
|
157
|
+
[key]: json,
|
|
158
|
+
};
|
|
159
|
+
setOverrideState(newOverrideState);
|
|
160
|
+
})
|
|
161
|
+
.catch((err) => {
|
|
162
|
+
console.log("error fetching dynamic data", url, err);
|
|
163
|
+
});
|
|
141
164
|
}
|
|
165
|
+
|
|
142
166
|
function runHttpRequests() {
|
|
143
167
|
const requests = useContent?.data?.httpRequests ?? {};
|
|
144
168
|
Object.entries(requests).forEach(([key, url]) => {
|
|
@@ -146,71 +170,99 @@ function RenderContent(props) {
|
|
|
146
170
|
const evaluatedUrl = evalExpression(url);
|
|
147
171
|
handleRequest({
|
|
148
172
|
url: evaluatedUrl,
|
|
149
|
-
key
|
|
173
|
+
key,
|
|
150
174
|
});
|
|
151
175
|
}
|
|
152
176
|
});
|
|
153
177
|
}
|
|
178
|
+
|
|
154
179
|
function emitStateUpdate() {
|
|
155
180
|
if (isEditing()) {
|
|
156
|
-
window.dispatchEvent(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
181
|
+
window.dispatchEvent(
|
|
182
|
+
new CustomEvent("builder:component:stateChange", {
|
|
183
|
+
detail: {
|
|
184
|
+
state: contentState(),
|
|
185
|
+
ref: {
|
|
186
|
+
name: props.model,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
})
|
|
190
|
+
);
|
|
164
191
|
}
|
|
165
192
|
}
|
|
193
|
+
|
|
166
194
|
function shouldRenderContentStyles() {
|
|
167
|
-
return Boolean(
|
|
195
|
+
return Boolean(
|
|
196
|
+
(useContent?.data?.cssCode || useContent?.data?.customFonts?.length) &&
|
|
197
|
+
TARGET !== "reactNative"
|
|
198
|
+
);
|
|
168
199
|
}
|
|
200
|
+
|
|
169
201
|
const updateUseContent = function useContent() {
|
|
170
202
|
if (!props.content && !overrideContent()) {
|
|
171
203
|
return undefined;
|
|
172
204
|
}
|
|
173
|
-
|
|
205
|
+
return {
|
|
174
206
|
...props.content,
|
|
175
207
|
...overrideContent(),
|
|
176
208
|
data: {
|
|
177
209
|
...props.content?.data,
|
|
178
210
|
...props.data,
|
|
179
|
-
...overrideContent()?.data
|
|
211
|
+
...overrideContent()?.data,
|
|
180
212
|
},
|
|
181
213
|
meta: {
|
|
182
214
|
...props.content?.meta,
|
|
183
215
|
...overrideContent()?.meta,
|
|
184
|
-
breakpoints:
|
|
185
|
-
|
|
216
|
+
breakpoints:
|
|
217
|
+
useBreakpoints() ||
|
|
218
|
+
overrideContent()?.meta?.breakpoints ||
|
|
219
|
+
props.content?.meta?.breakpoints,
|
|
220
|
+
},
|
|
186
221
|
};
|
|
187
|
-
return mergedContent;
|
|
188
222
|
};
|
|
189
223
|
const [useContent, setUseContent] = createStore(updateUseContent());
|
|
190
|
-
createEffect(
|
|
224
|
+
createEffect(
|
|
225
|
+
on(
|
|
226
|
+
() => [overrideContent(), useBreakpoints(), props.content, props.data],
|
|
227
|
+
() => setUseContent(reconcile(updateUseContent()))
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
|
|
191
231
|
let elementRef;
|
|
232
|
+
|
|
192
233
|
onMount(() => {
|
|
193
234
|
if (!props.apiKey) {
|
|
194
|
-
console.error(
|
|
235
|
+
console.error(
|
|
236
|
+
"[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
237
|
+
);
|
|
195
238
|
}
|
|
196
239
|
if (isBrowser()) {
|
|
197
240
|
if (isEditing()) {
|
|
198
241
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
199
242
|
registerInsertMenu();
|
|
200
243
|
setupBrowserForEditing({
|
|
201
|
-
...(props.locale
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
244
|
+
...(props.locale
|
|
245
|
+
? {
|
|
246
|
+
locale: props.locale,
|
|
247
|
+
}
|
|
248
|
+
: {}),
|
|
249
|
+
...(props.includeRefs
|
|
250
|
+
? {
|
|
251
|
+
includeRefs: props.includeRefs,
|
|
252
|
+
}
|
|
253
|
+
: {}),
|
|
211
254
|
});
|
|
255
|
+
Object.values(allRegisteredComponents()).forEach(
|
|
256
|
+
(registeredComponent) => {
|
|
257
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
258
|
+
window.parent?.postMessage(message, "*");
|
|
259
|
+
}
|
|
260
|
+
);
|
|
212
261
|
window.addEventListener("message", processMessage);
|
|
213
|
-
window.addEventListener(
|
|
262
|
+
window.addEventListener(
|
|
263
|
+
"builder:component:stateChangeListenerActivated",
|
|
264
|
+
emitStateUpdate
|
|
265
|
+
);
|
|
214
266
|
}
|
|
215
267
|
if (useContent) {
|
|
216
268
|
const variationId = useContent?.testVariationId;
|
|
@@ -220,25 +272,40 @@ function RenderContent(props) {
|
|
|
220
272
|
canTrack: canTrackToUse(),
|
|
221
273
|
contentId,
|
|
222
274
|
apiKey: props.apiKey,
|
|
223
|
-
variationId: variationId !== contentId ? variationId : undefined
|
|
275
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
224
276
|
});
|
|
225
277
|
}
|
|
226
278
|
|
|
227
279
|
// override normal content in preview mode
|
|
228
280
|
if (isPreviewing()) {
|
|
229
281
|
const searchParams = new URL(location.href).searchParams;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
282
|
+
const searchParamPreview = searchParams.get("builder.preview");
|
|
283
|
+
const previewApiKey =
|
|
284
|
+
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Make sure that:
|
|
288
|
+
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
289
|
+
* at the same time, e.g. header/page/footer.
|
|
290
|
+
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
291
|
+
*
|
|
292
|
+
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
293
|
+
* this break scenarios where the item is not published yet?
|
|
294
|
+
*
|
|
295
|
+
* TO-DO: should we only update the state when there is a change?
|
|
296
|
+
**/
|
|
297
|
+
if (
|
|
298
|
+
searchParamPreview === props.model &&
|
|
299
|
+
previewApiKey === props.apiKey
|
|
300
|
+
) {
|
|
301
|
+
getContent({
|
|
302
|
+
model: props.model,
|
|
303
|
+
apiKey: props.apiKey,
|
|
304
|
+
}).then((content) => {
|
|
305
|
+
if (content) {
|
|
306
|
+
setOverrideContent(content);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
242
309
|
}
|
|
243
310
|
}
|
|
244
311
|
evaluateJsCode();
|
|
@@ -246,43 +313,55 @@ function RenderContent(props) {
|
|
|
246
313
|
emitStateUpdate();
|
|
247
314
|
}
|
|
248
315
|
});
|
|
316
|
+
|
|
249
317
|
function onUpdateFn_0() {
|
|
250
318
|
evaluateJsCode();
|
|
251
319
|
}
|
|
252
|
-
createEffect(
|
|
320
|
+
createEffect(
|
|
321
|
+
on(() => [useContent?.data?.jsCode, contentState()], onUpdateFn_0)
|
|
322
|
+
);
|
|
323
|
+
|
|
253
324
|
function onUpdateFn_1() {
|
|
254
325
|
runHttpRequests();
|
|
255
326
|
}
|
|
256
327
|
createEffect(on(() => [useContent?.data?.httpRequests], onUpdateFn_1));
|
|
328
|
+
|
|
257
329
|
function onUpdateFn_2() {
|
|
258
330
|
emitStateUpdate();
|
|
259
331
|
}
|
|
260
332
|
createEffect(on(() => [contentState()], onUpdateFn_2));
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return props.apiKey;
|
|
273
|
-
},
|
|
274
|
-
get registeredComponents() {
|
|
275
|
-
return allRegisteredComponents();
|
|
276
|
-
}
|
|
277
|
-
}} component={BuilderContext.Provider}>
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<builderContext.Provider
|
|
336
|
+
value={{
|
|
337
|
+
content: useContent,
|
|
338
|
+
state: contentState(),
|
|
339
|
+
context: contextContext(),
|
|
340
|
+
apiKey: props.apiKey,
|
|
341
|
+
registeredComponents: allRegisteredComponents(),
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
278
344
|
<Show when={useContent}>
|
|
279
|
-
<div
|
|
345
|
+
<div
|
|
346
|
+
ref={elementRef}
|
|
347
|
+
onClick={(event) => onClick(event)}
|
|
348
|
+
builder-content-id={useContent?.id}
|
|
349
|
+
builder-model={props.model}
|
|
350
|
+
>
|
|
280
351
|
<Show when={shouldRenderContentStyles()}>
|
|
281
|
-
<RenderContentStyles
|
|
352
|
+
<RenderContentStyles
|
|
353
|
+
cssCode={useContent?.data?.cssCode}
|
|
354
|
+
customFonts={useContent?.data?.customFonts}
|
|
355
|
+
></RenderContentStyles>
|
|
282
356
|
</Show>
|
|
283
|
-
<RenderBlocks
|
|
357
|
+
<RenderBlocks
|
|
358
|
+
blocks={useContent?.data?.blocks}
|
|
359
|
+
key={forceReRenderCount()}
|
|
360
|
+
></RenderBlocks>
|
|
284
361
|
</div>
|
|
285
362
|
</Show>
|
|
286
|
-
</
|
|
363
|
+
</builderContext.Provider>
|
|
364
|
+
);
|
|
287
365
|
}
|
|
288
|
-
|
|
366
|
+
|
|
367
|
+
export default RenderContent;
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
1
|
+
import { Show, createSignal } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
|
+
|
|
3
4
|
import { TARGET } from "../constants/target.js";
|
|
5
|
+
|
|
4
6
|
function RenderInlinedStyles(props) {
|
|
5
7
|
function injectedStyleScript() {
|
|
6
8
|
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
7
9
|
}
|
|
10
|
+
|
|
8
11
|
function tag() {
|
|
9
12
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
10
13
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
11
14
|
return "sty" + "le";
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Show
|
|
19
|
+
fallback={<Dynamic component={tag()}>{props.styles}</Dynamic>}
|
|
20
|
+
when={TARGET === "svelte"}
|
|
21
|
+
>
|
|
14
22
|
<div innerHTML={injectedStyleScript()}></div>
|
|
15
|
-
</Show
|
|
23
|
+
</Show>
|
|
24
|
+
);
|
|
16
25
|
}
|
|
17
|
-
|
|
26
|
+
|
|
27
|
+
export default RenderInlinedStyles;
|
package/src/helpers/cookie.js
CHANGED
|
@@ -19,6 +19,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
import { isBrowser } from "../functions/is-browser.js";
|
|
22
|
+
import { checkIsDefined } from "./nullable.js";
|
|
22
23
|
import { getTopLevelDomain } from "./url.js";
|
|
23
24
|
const getCookie = (_0) => __async(void 0, [_0], function* ({
|
|
24
25
|
name,
|
|
@@ -32,9 +33,10 @@ const getCookie = (_0) => __async(void 0, [_0], function* ({
|
|
|
32
33
|
return (_a = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _a.split("=")[1];
|
|
33
34
|
} catch (err) {
|
|
34
35
|
console.debug("[COOKIE] GET error: ", err);
|
|
36
|
+
return void 0;
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
|
-
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).join("; ");
|
|
39
|
+
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
|
|
38
40
|
const SECURE_CONFIG = [
|
|
39
41
|
["secure", ""],
|
|
40
42
|
["SameSite", "None"]
|
|
@@ -65,7 +67,7 @@ const setCookie = (_0) => __async(void 0, [_0], function* ({
|
|
|
65
67
|
}) {
|
|
66
68
|
try {
|
|
67
69
|
if (!canTrack) {
|
|
68
|
-
return
|
|
70
|
+
return;
|
|
69
71
|
}
|
|
70
72
|
const cookie = createCookieString({ name, value, expires });
|
|
71
73
|
document.cookie = cookie;
|
package/src/helpers/sessionId.js
CHANGED
|
@@ -22,7 +22,9 @@ import { getCookie, setCookie } from "./cookie.js";
|
|
|
22
22
|
import { checkIsDefined } from "./nullable.js";
|
|
23
23
|
import { uuid } from "./uuid.js";
|
|
24
24
|
const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
25
|
-
const getSessionId = (_0) => __async(void 0, [_0], function* ({
|
|
25
|
+
const getSessionId = (_0) => __async(void 0, [_0], function* ({
|
|
26
|
+
canTrack
|
|
27
|
+
}) {
|
|
26
28
|
if (!canTrack) {
|
|
27
29
|
return void 0;
|
|
28
30
|
}
|
|
@@ -35,6 +37,7 @@ const getSessionId = (_0) => __async(void 0, [_0], function* ({ canTrack }) {
|
|
|
35
37
|
} else {
|
|
36
38
|
const newSessionId = createSessionId();
|
|
37
39
|
setSessionId({ id: newSessionId, canTrack });
|
|
40
|
+
return newSessionId;
|
|
38
41
|
}
|
|
39
42
|
});
|
|
40
43
|
const createSessionId = () => uuid();
|
package/src/helpers/url.js
CHANGED
package/src/helpers/url.test.js
CHANGED
|
@@ -12,4 +12,10 @@ describe("getTopLevelDomain", () => {
|
|
|
12
12
|
const output = getTopLevelDomain("www.example.co.uk");
|
|
13
13
|
expect(output).toBe("example.co.uk");
|
|
14
14
|
});
|
|
15
|
+
test("handles localhost", () => {
|
|
16
|
+
const output = getTopLevelDomain("localhost");
|
|
17
|
+
expect(output).toBe("localhost");
|
|
18
|
+
const output2 = getTopLevelDomain("127.0.0.1");
|
|
19
|
+
expect(output2).toBe("127.0.0.1");
|
|
20
|
+
});
|
|
15
21
|
});
|
package/src/helpers/visitorId.js
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import solidPlugin from 'vite-plugin-solid';
|
|
4
|
+
// import dts from 'vite-plugin-dts';
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
solidPlugin(),
|
|
10
|
+
// dts({ insertTypesEntry: true })
|
|
11
|
+
],
|
|
12
|
+
build: {
|
|
13
|
+
lib: {
|
|
14
|
+
entry: resolve(__dirname, 'src/index.js'),
|
|
15
|
+
formats: ['cjs', 'es'],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
package/solid-index.jsx
DELETED