@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/index.jsx
CHANGED
|
@@ -163,6 +163,75 @@ var getUserAttributes = () => {
|
|
|
163
163
|
};
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
+
// src/functions/evaluate/helpers.js
|
|
167
|
+
var getFunctionArguments = ({
|
|
168
|
+
builder,
|
|
169
|
+
context,
|
|
170
|
+
event,
|
|
171
|
+
state
|
|
172
|
+
}) => {
|
|
173
|
+
return Object.entries({
|
|
174
|
+
state,
|
|
175
|
+
Builder: builder,
|
|
176
|
+
builder,
|
|
177
|
+
context,
|
|
178
|
+
event
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
var getBuilderGlobals = () => ({
|
|
182
|
+
isEditing: isEditing(),
|
|
183
|
+
isBrowser: isBrowser(),
|
|
184
|
+
isServer: !isBrowser(),
|
|
185
|
+
getUserAttributes: () => getUserAttributes()
|
|
186
|
+
});
|
|
187
|
+
var parseCode = (code, {
|
|
188
|
+
isExpression = true
|
|
189
|
+
}) => {
|
|
190
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
191
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
192
|
+
return useCode;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/functions/evaluate/browser-runtime/browser.js
|
|
196
|
+
var runInBrowser = ({
|
|
197
|
+
code,
|
|
198
|
+
builder,
|
|
199
|
+
context,
|
|
200
|
+
event,
|
|
201
|
+
localState,
|
|
202
|
+
rootSetState,
|
|
203
|
+
rootState
|
|
204
|
+
}) => {
|
|
205
|
+
const functionArgs = getFunctionArguments({
|
|
206
|
+
builder,
|
|
207
|
+
context,
|
|
208
|
+
event,
|
|
209
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
210
|
+
});
|
|
211
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
212
|
+
};
|
|
213
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
214
|
+
if (rootState === localState) {
|
|
215
|
+
throw new Error("rootState === localState");
|
|
216
|
+
}
|
|
217
|
+
return new Proxy(rootState, {
|
|
218
|
+
get: (_, prop) => {
|
|
219
|
+
if (localState && prop in localState) {
|
|
220
|
+
return localState[prop];
|
|
221
|
+
}
|
|
222
|
+
return rootState[prop];
|
|
223
|
+
},
|
|
224
|
+
set: (_, prop, value) => {
|
|
225
|
+
if (localState && prop in localState) {
|
|
226
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
227
|
+
}
|
|
228
|
+
rootState[prop] = value;
|
|
229
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
166
235
|
// src/functions/set.js
|
|
167
236
|
var set = (obj, _path, value) => {
|
|
168
237
|
if (Object(obj) !== obj) {
|
|
@@ -3241,22 +3310,6 @@ t.prototype.setStateStack = t.prototype.ec;
|
|
|
3241
3310
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3242
3311
|
var stdin_default = t;
|
|
3243
3312
|
|
|
3244
|
-
// src/functions/evaluate/helpers.js
|
|
3245
|
-
var getFunctionArguments = ({
|
|
3246
|
-
builder,
|
|
3247
|
-
context,
|
|
3248
|
-
event,
|
|
3249
|
-
state
|
|
3250
|
-
}) => {
|
|
3251
|
-
return Object.entries({
|
|
3252
|
-
state,
|
|
3253
|
-
Builder: builder,
|
|
3254
|
-
builder,
|
|
3255
|
-
context,
|
|
3256
|
-
event
|
|
3257
|
-
});
|
|
3258
|
-
};
|
|
3259
|
-
|
|
3260
3313
|
// src/functions/evaluate/edge-runtime/edge-runtime.js
|
|
3261
3314
|
var __defProp = Object.defineProperty;
|
|
3262
3315
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -3354,6 +3407,9 @@ theFunction();
|
|
|
3354
3407
|
}
|
|
3355
3408
|
};
|
|
3356
3409
|
|
|
3410
|
+
// src/functions/evaluate/choose-eval.js
|
|
3411
|
+
var chooseBrowserOrServerEval = (args) => isBrowser() ? runInBrowser(args) : runInEdge(args);
|
|
3412
|
+
|
|
3357
3413
|
// src/functions/evaluate/evaluate.js
|
|
3358
3414
|
function evaluate({
|
|
3359
3415
|
code,
|
|
@@ -3368,17 +3424,11 @@ function evaluate({
|
|
|
3368
3424
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3369
3425
|
return;
|
|
3370
3426
|
}
|
|
3371
|
-
const builder = {
|
|
3372
|
-
isEditing: isEditing(),
|
|
3373
|
-
isBrowser: isBrowser(),
|
|
3374
|
-
isServer: !isBrowser(),
|
|
3375
|
-
getUserAttributes: () => getUserAttributes()
|
|
3376
|
-
};
|
|
3377
|
-
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
3378
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3379
3427
|
const args = {
|
|
3380
|
-
code:
|
|
3381
|
-
|
|
3428
|
+
code: parseCode(code, {
|
|
3429
|
+
isExpression
|
|
3430
|
+
}),
|
|
3431
|
+
builder: getBuilderGlobals(),
|
|
3382
3432
|
context,
|
|
3383
3433
|
event,
|
|
3384
3434
|
rootSetState,
|
|
@@ -3386,7 +3436,7 @@ function evaluate({
|
|
|
3386
3436
|
localState
|
|
3387
3437
|
};
|
|
3388
3438
|
try {
|
|
3389
|
-
return
|
|
3439
|
+
return chooseBrowserOrServerEval(args);
|
|
3390
3440
|
} catch (e) {
|
|
3391
3441
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3392
3442
|
code
|
|
@@ -5535,44 +5585,42 @@ import { onMount, createSignal as createSignal10 } from "solid-js";
|
|
|
5535
5585
|
function CustomCode(props) {
|
|
5536
5586
|
const [scriptsInserted, setScriptsInserted] = createSignal10([]);
|
|
5537
5587
|
const [scriptsRun, setScriptsRun] = createSignal10([]);
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5588
|
+
let elementRef;
|
|
5589
|
+
onMount(() => {
|
|
5590
|
+
if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
|
|
5591
|
+
return;
|
|
5592
|
+
}
|
|
5593
|
+
const scripts = elementRef.getElementsByTagName("script");
|
|
5594
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
5595
|
+
const script = scripts[i];
|
|
5596
|
+
if (script.src) {
|
|
5597
|
+
if (scriptsInserted().includes(script.src)) {
|
|
5598
|
+
continue;
|
|
5599
|
+
}
|
|
5600
|
+
scriptsInserted().push(script.src);
|
|
5601
|
+
const newScript = document.createElement("script");
|
|
5602
|
+
newScript.async = true;
|
|
5603
|
+
newScript.src = script.src;
|
|
5604
|
+
document.head.appendChild(newScript);
|
|
5605
|
+
} else if (!script.type || [
|
|
5606
|
+
"text/javascript",
|
|
5607
|
+
"application/javascript",
|
|
5608
|
+
"application/ecmascript"
|
|
5609
|
+
].includes(script.type)) {
|
|
5610
|
+
if (scriptsRun().includes(script.innerText)) {
|
|
5611
|
+
continue;
|
|
5612
|
+
}
|
|
5613
|
+
try {
|
|
5614
|
+
scriptsRun().push(script.innerText);
|
|
5615
|
+
new Function(script.innerText)();
|
|
5616
|
+
} catch (error) {
|
|
5565
5617
|
}
|
|
5566
5618
|
}
|
|
5567
5619
|
}
|
|
5568
|
-
}
|
|
5569
|
-
let elem;
|
|
5570
|
-
onMount(() => {
|
|
5571
|
-
findAndRunScripts();
|
|
5572
5620
|
});
|
|
5573
5621
|
return <div
|
|
5574
5622
|
class={"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")}
|
|
5575
|
-
ref={
|
|
5623
|
+
ref={elementRef}
|
|
5576
5624
|
innerHTML={props.code}
|
|
5577
5625
|
/>;
|
|
5578
5626
|
}
|
|
@@ -6225,7 +6273,7 @@ var track = (args) => _track(__spreadProps9(__spreadValues13({}, args), {
|
|
|
6225
6273
|
}));
|
|
6226
6274
|
|
|
6227
6275
|
// src/constants/sdk-version.js
|
|
6228
|
-
var SDK_VERSION = "0.
|
|
6276
|
+
var SDK_VERSION = "0.7.1-0";
|
|
6229
6277
|
|
|
6230
6278
|
// src/functions/register.js
|
|
6231
6279
|
var registry = {};
|
|
@@ -6678,18 +6726,28 @@ var __spreadValues16 = (a, b) => {
|
|
|
6678
6726
|
}
|
|
6679
6727
|
return a;
|
|
6680
6728
|
};
|
|
6729
|
+
var isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6681
6730
|
var generateContentUrl = (options) => {
|
|
6731
|
+
let {
|
|
6732
|
+
noTraverse = false
|
|
6733
|
+
} = options;
|
|
6682
6734
|
const {
|
|
6683
6735
|
limit = 30,
|
|
6684
6736
|
userAttributes,
|
|
6685
6737
|
query,
|
|
6686
|
-
noTraverse = false,
|
|
6687
6738
|
model,
|
|
6688
6739
|
apiKey,
|
|
6689
6740
|
includeRefs = true,
|
|
6690
6741
|
enrich,
|
|
6691
6742
|
locale,
|
|
6692
|
-
apiVersion = DEFAULT_API_VERSION
|
|
6743
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
6744
|
+
fields,
|
|
6745
|
+
omit,
|
|
6746
|
+
offset,
|
|
6747
|
+
cacheSeconds,
|
|
6748
|
+
staleCacheSeconds,
|
|
6749
|
+
sort,
|
|
6750
|
+
includeUnpublished
|
|
6693
6751
|
} = options;
|
|
6694
6752
|
if (!apiKey) {
|
|
6695
6753
|
throw new Error("Missing API key");
|
|
@@ -6697,7 +6755,34 @@ var generateContentUrl = (options) => {
|
|
|
6697
6755
|
if (!["v2", "v3"].includes(apiVersion)) {
|
|
6698
6756
|
throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
|
|
6699
6757
|
}
|
|
6758
|
+
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
|
|
6759
|
+
noTraverse = true;
|
|
6760
|
+
}
|
|
6700
6761
|
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}` : ""}`);
|
|
6762
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
6763
|
+
if (fields) {
|
|
6764
|
+
url.searchParams.set("fields", fields);
|
|
6765
|
+
}
|
|
6766
|
+
if (Number.isFinite(offset) && offset > -1) {
|
|
6767
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
6768
|
+
}
|
|
6769
|
+
if (typeof includeUnpublished === "boolean") {
|
|
6770
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
6771
|
+
}
|
|
6772
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds)) {
|
|
6773
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
6774
|
+
}
|
|
6775
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds)) {
|
|
6776
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
6777
|
+
}
|
|
6778
|
+
if (sort) {
|
|
6779
|
+
const flattened2 = flatten({
|
|
6780
|
+
sort
|
|
6781
|
+
});
|
|
6782
|
+
for (const key in flattened2) {
|
|
6783
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
6784
|
+
}
|
|
6785
|
+
}
|
|
6701
6786
|
const queryOptions = __spreadValues16(__spreadValues16({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
6702
6787
|
const flattened = flatten(queryOptions);
|
|
6703
6788
|
for (const key in flattened) {
|
|
@@ -6845,9 +6930,6 @@ function isPreviewing() {
|
|
|
6845
6930
|
|
|
6846
6931
|
// src/components/content/components/enable-editor.jsx
|
|
6847
6932
|
function EnableEditor(props) {
|
|
6848
|
-
const [canTrackToUse, setCanTrackToUse] = createSignal12(
|
|
6849
|
-
checkIsDefined(props.canTrack) ? props.canTrack : true
|
|
6850
|
-
);
|
|
6851
6933
|
const [forceReRenderCount, setForceReRenderCount] = createSignal12(0);
|
|
6852
6934
|
const [lastUpdated, setLastUpdated] = createSignal12(0);
|
|
6853
6935
|
const [shouldSendResetCookie, setShouldSendResetCookie] = createSignal12(false);
|
|
@@ -6923,7 +7005,7 @@ function EnableEditor(props) {
|
|
|
6923
7005
|
const contentId = props.builderContextSignal.content?.id;
|
|
6924
7006
|
_track({
|
|
6925
7007
|
type: "click",
|
|
6926
|
-
canTrack:
|
|
7008
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
6927
7009
|
contentId,
|
|
6928
7010
|
apiKey: props.apiKey,
|
|
6929
7011
|
variationId: variationId !== contentId ? variationId : void 0,
|
|
@@ -6986,13 +7068,8 @@ function EnableEditor(props) {
|
|
|
6986
7068
|
}
|
|
6987
7069
|
let elementRef;
|
|
6988
7070
|
onMount2(() => {
|
|
6989
|
-
if (!props.apiKey) {
|
|
6990
|
-
logger.error(
|
|
6991
|
-
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
6992
|
-
);
|
|
6993
|
-
}
|
|
6994
7071
|
if (isBrowser()) {
|
|
6995
|
-
if (isEditing()) {
|
|
7072
|
+
if (isEditing() && true) {
|
|
6996
7073
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
6997
7074
|
window.addEventListener("message", processMessage);
|
|
6998
7075
|
registerInsertMenu();
|
|
@@ -7018,18 +7095,20 @@ function EnableEditor(props) {
|
|
|
7018
7095
|
emitStateUpdate
|
|
7019
7096
|
);
|
|
7020
7097
|
}
|
|
7021
|
-
|
|
7098
|
+
const shouldTrackImpression = props.builderContextSignal.content && getDefaultCanTrack(props.canTrack);
|
|
7099
|
+
if (shouldTrackImpression) {
|
|
7022
7100
|
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
7023
7101
|
const contentId = props.builderContextSignal.content?.id;
|
|
7102
|
+
const apiKeyProp = props.apiKey;
|
|
7024
7103
|
_track({
|
|
7025
7104
|
type: "impression",
|
|
7026
|
-
canTrack:
|
|
7105
|
+
canTrack: true,
|
|
7027
7106
|
contentId,
|
|
7028
|
-
apiKey:
|
|
7107
|
+
apiKey: apiKeyProp,
|
|
7029
7108
|
variationId: variationId !== contentId ? variationId : void 0
|
|
7030
7109
|
});
|
|
7031
7110
|
}
|
|
7032
|
-
if (isPreviewing()) {
|
|
7111
|
+
if (isPreviewing() && true) {
|
|
7033
7112
|
const searchParams = new URL(location.href).searchParams;
|
|
7034
7113
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
7035
7114
|
const searchParamPreviewId = searchParams.get(
|
|
@@ -7048,11 +7127,18 @@ function EnableEditor(props) {
|
|
|
7048
7127
|
});
|
|
7049
7128
|
}
|
|
7050
7129
|
}
|
|
7051
|
-
evaluateJsCode();
|
|
7052
|
-
runHttpRequests();
|
|
7053
|
-
emitStateUpdate();
|
|
7054
7130
|
}
|
|
7055
7131
|
});
|
|
7132
|
+
onMount2(() => {
|
|
7133
|
+
if (!props.apiKey) {
|
|
7134
|
+
logger.error(
|
|
7135
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
7136
|
+
);
|
|
7137
|
+
}
|
|
7138
|
+
evaluateJsCode();
|
|
7139
|
+
runHttpRequests();
|
|
7140
|
+
emitStateUpdate();
|
|
7141
|
+
});
|
|
7056
7142
|
function onUpdateFn_0() {
|
|
7057
7143
|
if (props.content) {
|
|
7058
7144
|
mergeNewContent(props.content);
|
|
@@ -7089,6 +7175,7 @@ function EnableEditor(props) {
|
|
|
7089
7175
|
createEffect2(on2(() => [props.builderContextSignal.rootState], onUpdateFn_4));
|
|
7090
7176
|
return <stdin_default2.Provider value={props.builderContextSignal}><Show9 when={props.builderContextSignal.content}><div
|
|
7091
7177
|
class={props.classNameProp}
|
|
7178
|
+
{...{}}
|
|
7092
7179
|
key={forceReRenderCount()}
|
|
7093
7180
|
ref={elementRef}
|
|
7094
7181
|
onClick={(event) => onClick(event)}
|