@builder.io/sdk-solid 0.6.4 → 0.7.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/dev.js +109 -61
- package/lib/browser/dev.jsx +111 -64
- package/lib/browser/index.js +108 -60
- package/lib/browser/index.jsx +110 -63
- package/lib/edge/dev.js +165 -77
- package/lib/edge/dev.jsx +167 -80
- package/lib/edge/index.js +164 -76
- package/lib/edge/index.jsx +166 -79
- package/lib/node/dev.js +561 -376
- package/lib/node/dev.jsx +563 -379
- package/lib/node/index.js +559 -375
- package/lib/node/index.jsx +561 -378
- package/package.json +3 -1
package/lib/edge/dev.jsx
CHANGED
|
@@ -165,6 +165,75 @@ var getUserAttributes = () => {
|
|
|
165
165
|
};
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
+
// src/functions/evaluate/helpers.js
|
|
169
|
+
var getFunctionArguments = ({
|
|
170
|
+
builder,
|
|
171
|
+
context,
|
|
172
|
+
event,
|
|
173
|
+
state
|
|
174
|
+
}) => {
|
|
175
|
+
return Object.entries({
|
|
176
|
+
state,
|
|
177
|
+
Builder: builder,
|
|
178
|
+
builder,
|
|
179
|
+
context,
|
|
180
|
+
event
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
var getBuilderGlobals = () => ({
|
|
184
|
+
isEditing: isEditing(),
|
|
185
|
+
isBrowser: isBrowser(),
|
|
186
|
+
isServer: !isBrowser(),
|
|
187
|
+
getUserAttributes: () => getUserAttributes()
|
|
188
|
+
});
|
|
189
|
+
var parseCode = (code, {
|
|
190
|
+
isExpression = true
|
|
191
|
+
}) => {
|
|
192
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
193
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
194
|
+
return useCode;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/functions/evaluate/browser-runtime/browser.js
|
|
198
|
+
var runInBrowser = ({
|
|
199
|
+
code,
|
|
200
|
+
builder,
|
|
201
|
+
context,
|
|
202
|
+
event,
|
|
203
|
+
localState,
|
|
204
|
+
rootSetState,
|
|
205
|
+
rootState
|
|
206
|
+
}) => {
|
|
207
|
+
const functionArgs = getFunctionArguments({
|
|
208
|
+
builder,
|
|
209
|
+
context,
|
|
210
|
+
event,
|
|
211
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
212
|
+
});
|
|
213
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
214
|
+
};
|
|
215
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
216
|
+
if (rootState === localState) {
|
|
217
|
+
throw new Error("rootState === localState");
|
|
218
|
+
}
|
|
219
|
+
return new Proxy(rootState, {
|
|
220
|
+
get: (_, prop) => {
|
|
221
|
+
if (localState && prop in localState) {
|
|
222
|
+
return localState[prop];
|
|
223
|
+
}
|
|
224
|
+
return rootState[prop];
|
|
225
|
+
},
|
|
226
|
+
set: (_, prop, value) => {
|
|
227
|
+
if (localState && prop in localState) {
|
|
228
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
229
|
+
}
|
|
230
|
+
rootState[prop] = value;
|
|
231
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
168
237
|
// src/functions/set.js
|
|
169
238
|
var set = (obj, _path, value) => {
|
|
170
239
|
if (Object(obj) !== obj) {
|
|
@@ -3243,22 +3312,6 @@ t.prototype.setStateStack = t.prototype.ec;
|
|
|
3243
3312
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3244
3313
|
var stdin_default = t;
|
|
3245
3314
|
|
|
3246
|
-
// src/functions/evaluate/helpers.js
|
|
3247
|
-
var getFunctionArguments = ({
|
|
3248
|
-
builder,
|
|
3249
|
-
context,
|
|
3250
|
-
event,
|
|
3251
|
-
state
|
|
3252
|
-
}) => {
|
|
3253
|
-
return Object.entries({
|
|
3254
|
-
state,
|
|
3255
|
-
Builder: builder,
|
|
3256
|
-
builder,
|
|
3257
|
-
context,
|
|
3258
|
-
event
|
|
3259
|
-
});
|
|
3260
|
-
};
|
|
3261
|
-
|
|
3262
3315
|
// src/functions/evaluate/edge-runtime/edge-runtime.js
|
|
3263
3316
|
var __defProp = Object.defineProperty;
|
|
3264
3317
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -3356,6 +3409,9 @@ theFunction();
|
|
|
3356
3409
|
}
|
|
3357
3410
|
};
|
|
3358
3411
|
|
|
3412
|
+
// src/functions/evaluate/choose-eval.js
|
|
3413
|
+
var chooseBrowserOrServerEval = (args) => isBrowser() ? runInBrowser(args) : runInEdge(args);
|
|
3414
|
+
|
|
3359
3415
|
// src/functions/evaluate/evaluate.js
|
|
3360
3416
|
function evaluate({
|
|
3361
3417
|
code,
|
|
@@ -3370,17 +3426,11 @@ function evaluate({
|
|
|
3370
3426
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3371
3427
|
return;
|
|
3372
3428
|
}
|
|
3373
|
-
const builder = {
|
|
3374
|
-
isEditing: isEditing(),
|
|
3375
|
-
isBrowser: isBrowser(),
|
|
3376
|
-
isServer: !isBrowser(),
|
|
3377
|
-
getUserAttributes: () => getUserAttributes()
|
|
3378
|
-
};
|
|
3379
|
-
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
3380
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3381
3429
|
const args = {
|
|
3382
|
-
code:
|
|
3383
|
-
|
|
3430
|
+
code: parseCode(code, {
|
|
3431
|
+
isExpression
|
|
3432
|
+
}),
|
|
3433
|
+
builder: getBuilderGlobals(),
|
|
3384
3434
|
context,
|
|
3385
3435
|
event,
|
|
3386
3436
|
rootSetState,
|
|
@@ -3388,7 +3438,7 @@ function evaluate({
|
|
|
3388
3438
|
localState
|
|
3389
3439
|
};
|
|
3390
3440
|
try {
|
|
3391
|
-
return
|
|
3441
|
+
return chooseBrowserOrServerEval(args);
|
|
3392
3442
|
} catch (e) {
|
|
3393
3443
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3394
3444
|
code
|
|
@@ -5545,45 +5595,43 @@ import { onMount, createSignal as createSignal10 } from "solid-js";
|
|
|
5545
5595
|
function CustomCode(props) {
|
|
5546
5596
|
const [scriptsInserted, setScriptsInserted] = createSignal10([]);
|
|
5547
5597
|
const [scriptsRun, setScriptsRun] = createSignal10([]);
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5598
|
+
let elementRef;
|
|
5599
|
+
onMount(() => {
|
|
5600
|
+
if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
|
|
5601
|
+
return;
|
|
5602
|
+
}
|
|
5603
|
+
const scripts = elementRef.getElementsByTagName("script");
|
|
5604
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
5605
|
+
const script = scripts[i];
|
|
5606
|
+
if (script.src) {
|
|
5607
|
+
if (scriptsInserted().includes(script.src)) {
|
|
5608
|
+
continue;
|
|
5609
|
+
}
|
|
5610
|
+
scriptsInserted().push(script.src);
|
|
5611
|
+
const newScript = document.createElement("script");
|
|
5612
|
+
newScript.async = true;
|
|
5613
|
+
newScript.src = script.src;
|
|
5614
|
+
document.head.appendChild(newScript);
|
|
5615
|
+
} else if (!script.type || [
|
|
5616
|
+
"text/javascript",
|
|
5617
|
+
"application/javascript",
|
|
5618
|
+
"application/ecmascript"
|
|
5619
|
+
].includes(script.type)) {
|
|
5620
|
+
if (scriptsRun().includes(script.innerText)) {
|
|
5621
|
+
continue;
|
|
5622
|
+
}
|
|
5623
|
+
try {
|
|
5624
|
+
scriptsRun().push(script.innerText);
|
|
5625
|
+
new Function(script.innerText)();
|
|
5626
|
+
} catch (error) {
|
|
5627
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
5576
5628
|
}
|
|
5577
5629
|
}
|
|
5578
5630
|
}
|
|
5579
|
-
}
|
|
5580
|
-
let elem;
|
|
5581
|
-
onMount(() => {
|
|
5582
|
-
findAndRunScripts();
|
|
5583
5631
|
});
|
|
5584
5632
|
return <div
|
|
5585
5633
|
class={"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")}
|
|
5586
|
-
ref={
|
|
5634
|
+
ref={elementRef}
|
|
5587
5635
|
innerHTML={props.code}
|
|
5588
5636
|
/>;
|
|
5589
5637
|
}
|
|
@@ -6241,7 +6289,7 @@ var track = (args) => _track(__spreadProps9(__spreadValues13({}, args), {
|
|
|
6241
6289
|
}));
|
|
6242
6290
|
|
|
6243
6291
|
// src/constants/sdk-version.js
|
|
6244
|
-
var SDK_VERSION = "0.
|
|
6292
|
+
var SDK_VERSION = "0.7.1-0";
|
|
6245
6293
|
|
|
6246
6294
|
// src/functions/register.js
|
|
6247
6295
|
var registry = {};
|
|
@@ -6695,18 +6743,28 @@ var __spreadValues16 = (a, b) => {
|
|
|
6695
6743
|
}
|
|
6696
6744
|
return a;
|
|
6697
6745
|
};
|
|
6746
|
+
var isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6698
6747
|
var generateContentUrl = (options) => {
|
|
6748
|
+
let {
|
|
6749
|
+
noTraverse = false
|
|
6750
|
+
} = options;
|
|
6699
6751
|
const {
|
|
6700
6752
|
limit = 30,
|
|
6701
6753
|
userAttributes,
|
|
6702
6754
|
query,
|
|
6703
|
-
noTraverse = false,
|
|
6704
6755
|
model,
|
|
6705
6756
|
apiKey,
|
|
6706
6757
|
includeRefs = true,
|
|
6707
6758
|
enrich,
|
|
6708
6759
|
locale,
|
|
6709
|
-
apiVersion = DEFAULT_API_VERSION
|
|
6760
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
6761
|
+
fields,
|
|
6762
|
+
omit,
|
|
6763
|
+
offset,
|
|
6764
|
+
cacheSeconds,
|
|
6765
|
+
staleCacheSeconds,
|
|
6766
|
+
sort,
|
|
6767
|
+
includeUnpublished
|
|
6710
6768
|
} = options;
|
|
6711
6769
|
if (!apiKey) {
|
|
6712
6770
|
throw new Error("Missing API key");
|
|
@@ -6714,7 +6772,34 @@ var generateContentUrl = (options) => {
|
|
|
6714
6772
|
if (!["v2", "v3"].includes(apiVersion)) {
|
|
6715
6773
|
throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
|
|
6716
6774
|
}
|
|
6775
|
+
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
|
|
6776
|
+
noTraverse = true;
|
|
6777
|
+
}
|
|
6717
6778
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}${enrich ? `&enrich=${enrich}` : ""}`);
|
|
6779
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
6780
|
+
if (fields) {
|
|
6781
|
+
url.searchParams.set("fields", fields);
|
|
6782
|
+
}
|
|
6783
|
+
if (Number.isFinite(offset) && offset > -1) {
|
|
6784
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
6785
|
+
}
|
|
6786
|
+
if (typeof includeUnpublished === "boolean") {
|
|
6787
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
6788
|
+
}
|
|
6789
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds)) {
|
|
6790
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
6791
|
+
}
|
|
6792
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds)) {
|
|
6793
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
6794
|
+
}
|
|
6795
|
+
if (sort) {
|
|
6796
|
+
const flattened2 = flatten({
|
|
6797
|
+
sort
|
|
6798
|
+
});
|
|
6799
|
+
for (const key in flattened2) {
|
|
6800
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
6801
|
+
}
|
|
6802
|
+
}
|
|
6718
6803
|
const queryOptions = __spreadValues16(__spreadValues16({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
6719
6804
|
const flattened = flatten(queryOptions);
|
|
6720
6805
|
for (const key in flattened) {
|
|
@@ -6862,9 +6947,6 @@ function isPreviewing() {
|
|
|
6862
6947
|
|
|
6863
6948
|
// src/components/content/components/enable-editor.jsx
|
|
6864
6949
|
function EnableEditor(props) {
|
|
6865
|
-
const [canTrackToUse, setCanTrackToUse] = createSignal12(
|
|
6866
|
-
checkIsDefined(props.canTrack) ? props.canTrack : true
|
|
6867
|
-
);
|
|
6868
6950
|
const [forceReRenderCount, setForceReRenderCount] = createSignal12(0);
|
|
6869
6951
|
const [lastUpdated, setLastUpdated] = createSignal12(0);
|
|
6870
6952
|
const [shouldSendResetCookie, setShouldSendResetCookie] = createSignal12(false);
|
|
@@ -6940,7 +7022,7 @@ function EnableEditor(props) {
|
|
|
6940
7022
|
const contentId = props.builderContextSignal.content?.id;
|
|
6941
7023
|
_track({
|
|
6942
7024
|
type: "click",
|
|
6943
|
-
canTrack:
|
|
7025
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
6944
7026
|
contentId,
|
|
6945
7027
|
apiKey: props.apiKey,
|
|
6946
7028
|
variationId: variationId !== contentId ? variationId : void 0,
|
|
@@ -7004,13 +7086,8 @@ function EnableEditor(props) {
|
|
|
7004
7086
|
}
|
|
7005
7087
|
let elementRef;
|
|
7006
7088
|
onMount2(() => {
|
|
7007
|
-
if (!props.apiKey) {
|
|
7008
|
-
logger.error(
|
|
7009
|
-
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
7010
|
-
);
|
|
7011
|
-
}
|
|
7012
7089
|
if (isBrowser()) {
|
|
7013
|
-
if (isEditing()) {
|
|
7090
|
+
if (isEditing() && true) {
|
|
7014
7091
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
7015
7092
|
window.addEventListener("message", processMessage);
|
|
7016
7093
|
registerInsertMenu();
|
|
@@ -7036,18 +7113,20 @@ function EnableEditor(props) {
|
|
|
7036
7113
|
emitStateUpdate
|
|
7037
7114
|
);
|
|
7038
7115
|
}
|
|
7039
|
-
|
|
7116
|
+
const shouldTrackImpression = props.builderContextSignal.content && getDefaultCanTrack(props.canTrack);
|
|
7117
|
+
if (shouldTrackImpression) {
|
|
7040
7118
|
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
7041
7119
|
const contentId = props.builderContextSignal.content?.id;
|
|
7120
|
+
const apiKeyProp = props.apiKey;
|
|
7042
7121
|
_track({
|
|
7043
7122
|
type: "impression",
|
|
7044
|
-
canTrack:
|
|
7123
|
+
canTrack: true,
|
|
7045
7124
|
contentId,
|
|
7046
|
-
apiKey:
|
|
7125
|
+
apiKey: apiKeyProp,
|
|
7047
7126
|
variationId: variationId !== contentId ? variationId : void 0
|
|
7048
7127
|
});
|
|
7049
7128
|
}
|
|
7050
|
-
if (isPreviewing()) {
|
|
7129
|
+
if (isPreviewing() && true) {
|
|
7051
7130
|
const searchParams = new URL(location.href).searchParams;
|
|
7052
7131
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
7053
7132
|
const searchParamPreviewId = searchParams.get(
|
|
@@ -7066,11 +7145,18 @@ function EnableEditor(props) {
|
|
|
7066
7145
|
});
|
|
7067
7146
|
}
|
|
7068
7147
|
}
|
|
7069
|
-
evaluateJsCode();
|
|
7070
|
-
runHttpRequests();
|
|
7071
|
-
emitStateUpdate();
|
|
7072
7148
|
}
|
|
7073
7149
|
});
|
|
7150
|
+
onMount2(() => {
|
|
7151
|
+
if (!props.apiKey) {
|
|
7152
|
+
logger.error(
|
|
7153
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
7154
|
+
);
|
|
7155
|
+
}
|
|
7156
|
+
evaluateJsCode();
|
|
7157
|
+
runHttpRequests();
|
|
7158
|
+
emitStateUpdate();
|
|
7159
|
+
});
|
|
7074
7160
|
function onUpdateFn_0() {
|
|
7075
7161
|
if (props.content) {
|
|
7076
7162
|
mergeNewContent(props.content);
|
|
@@ -7107,6 +7193,7 @@ function EnableEditor(props) {
|
|
|
7107
7193
|
createEffect2(on2(() => [props.builderContextSignal.rootState], onUpdateFn_4));
|
|
7108
7194
|
return <stdin_default2.Provider value={props.builderContextSignal}><Show9 when={props.builderContextSignal.content}><div
|
|
7109
7195
|
class={props.classNameProp}
|
|
7196
|
+
{...{}}
|
|
7110
7197
|
key={forceReRenderCount()}
|
|
7111
7198
|
ref={elementRef}
|
|
7112
7199
|
onClick={(event) => onClick(event)}
|