@builder.io/sdk-solid 0.7.0 → 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 +102 -58
- package/lib/browser/dev.jsx +104 -59
- package/lib/browser/index.js +101 -57
- package/lib/browser/index.jsx +103 -58
- package/lib/edge/dev.js +158 -74
- package/lib/edge/dev.jsx +160 -75
- package/lib/edge/index.js +157 -73
- package/lib/edge/index.jsx +159 -74
- package/lib/node/dev.js +555 -374
- package/lib/node/dev.jsx +556 -374
- package/lib/node/index.js +553 -373
- package/lib/node/index.jsx +554 -373
- package/package.json +2 -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.7.0";
|
|
6276
|
+
var SDK_VERSION = "0.7.1-0";
|
|
6229
6277
|
|
|
6230
6278
|
// src/functions/register.js
|
|
6231
6279
|
var registry = {};
|
|
@@ -6678,6 +6726,7 @@ 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) => {
|
|
6682
6731
|
let {
|
|
6683
6732
|
noTraverse = false
|
|
@@ -6691,7 +6740,14 @@ var generateContentUrl = (options) => {
|
|
|
6691
6740
|
includeRefs = true,
|
|
6692
6741
|
enrich,
|
|
6693
6742
|
locale,
|
|
6694
|
-
apiVersion = DEFAULT_API_VERSION
|
|
6743
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
6744
|
+
fields,
|
|
6745
|
+
omit,
|
|
6746
|
+
offset,
|
|
6747
|
+
cacheSeconds,
|
|
6748
|
+
staleCacheSeconds,
|
|
6749
|
+
sort,
|
|
6750
|
+
includeUnpublished
|
|
6695
6751
|
} = options;
|
|
6696
6752
|
if (!apiKey) {
|
|
6697
6753
|
throw new Error("Missing API key");
|
|
@@ -6703,6 +6759,30 @@ var generateContentUrl = (options) => {
|
|
|
6703
6759
|
noTraverse = true;
|
|
6704
6760
|
}
|
|
6705
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
|
+
}
|
|
6706
6786
|
const queryOptions = __spreadValues16(__spreadValues16({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
6707
6787
|
const flattened = flatten(queryOptions);
|
|
6708
6788
|
for (const key in flattened) {
|
|
@@ -6988,13 +7068,8 @@ function EnableEditor(props) {
|
|
|
6988
7068
|
}
|
|
6989
7069
|
let elementRef;
|
|
6990
7070
|
onMount2(() => {
|
|
6991
|
-
if (!props.apiKey) {
|
|
6992
|
-
logger.error(
|
|
6993
|
-
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
6994
|
-
);
|
|
6995
|
-
}
|
|
6996
7071
|
if (isBrowser()) {
|
|
6997
|
-
if (isEditing()) {
|
|
7072
|
+
if (isEditing() && true) {
|
|
6998
7073
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
6999
7074
|
window.addEventListener("message", processMessage);
|
|
7000
7075
|
registerInsertMenu();
|
|
@@ -7020,18 +7095,20 @@ function EnableEditor(props) {
|
|
|
7020
7095
|
emitStateUpdate
|
|
7021
7096
|
);
|
|
7022
7097
|
}
|
|
7023
|
-
|
|
7098
|
+
const shouldTrackImpression = props.builderContextSignal.content && getDefaultCanTrack(props.canTrack);
|
|
7099
|
+
if (shouldTrackImpression) {
|
|
7024
7100
|
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
7025
7101
|
const contentId = props.builderContextSignal.content?.id;
|
|
7102
|
+
const apiKeyProp = props.apiKey;
|
|
7026
7103
|
_track({
|
|
7027
7104
|
type: "impression",
|
|
7028
|
-
canTrack:
|
|
7105
|
+
canTrack: true,
|
|
7029
7106
|
contentId,
|
|
7030
|
-
apiKey:
|
|
7107
|
+
apiKey: apiKeyProp,
|
|
7031
7108
|
variationId: variationId !== contentId ? variationId : void 0
|
|
7032
7109
|
});
|
|
7033
7110
|
}
|
|
7034
|
-
if (isPreviewing()) {
|
|
7111
|
+
if (isPreviewing() && true) {
|
|
7035
7112
|
const searchParams = new URL(location.href).searchParams;
|
|
7036
7113
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
7037
7114
|
const searchParamPreviewId = searchParams.get(
|
|
@@ -7050,11 +7127,18 @@ function EnableEditor(props) {
|
|
|
7050
7127
|
});
|
|
7051
7128
|
}
|
|
7052
7129
|
}
|
|
7053
|
-
evaluateJsCode();
|
|
7054
|
-
runHttpRequests();
|
|
7055
|
-
emitStateUpdate();
|
|
7056
7130
|
}
|
|
7057
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
|
+
});
|
|
7058
7142
|
function onUpdateFn_0() {
|
|
7059
7143
|
if (props.content) {
|
|
7060
7144
|
mergeNewContent(props.content);
|
|
@@ -7091,6 +7175,7 @@ function EnableEditor(props) {
|
|
|
7091
7175
|
createEffect2(on2(() => [props.builderContextSignal.rootState], onUpdateFn_4));
|
|
7092
7176
|
return <stdin_default2.Provider value={props.builderContextSignal}><Show9 when={props.builderContextSignal.content}><div
|
|
7093
7177
|
class={props.classNameProp}
|
|
7178
|
+
{...{}}
|
|
7094
7179
|
key={forceReRenderCount()}
|
|
7095
7180
|
ref={elementRef}
|
|
7096
7181
|
onClick={(event) => onClick(event)}
|