@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/dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, memo, Dynamic, use } from 'solid-js/web';
|
|
2
2
|
import { createContext, Show, useContext, For, createSignal, onMount, createEffect, on } from 'solid-js';
|
|
3
3
|
import { css } from 'solid-styled-components';
|
|
4
4
|
|
|
@@ -176,6 +176,75 @@ var getUserAttributes = () => {
|
|
|
176
176
|
};
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
+
// src/functions/evaluate/helpers.js
|
|
180
|
+
var getFunctionArguments = ({
|
|
181
|
+
builder,
|
|
182
|
+
context,
|
|
183
|
+
event,
|
|
184
|
+
state
|
|
185
|
+
}) => {
|
|
186
|
+
return Object.entries({
|
|
187
|
+
state,
|
|
188
|
+
Builder: builder,
|
|
189
|
+
builder,
|
|
190
|
+
context,
|
|
191
|
+
event
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
var getBuilderGlobals = () => ({
|
|
195
|
+
isEditing: isEditing(),
|
|
196
|
+
isBrowser: isBrowser(),
|
|
197
|
+
isServer: !isBrowser(),
|
|
198
|
+
getUserAttributes: () => getUserAttributes()
|
|
199
|
+
});
|
|
200
|
+
var parseCode = (code, {
|
|
201
|
+
isExpression = true
|
|
202
|
+
}) => {
|
|
203
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
204
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
205
|
+
return useCode;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/functions/evaluate/browser-runtime/browser.js
|
|
209
|
+
var runInBrowser = ({
|
|
210
|
+
code,
|
|
211
|
+
builder,
|
|
212
|
+
context,
|
|
213
|
+
event,
|
|
214
|
+
localState,
|
|
215
|
+
rootSetState,
|
|
216
|
+
rootState
|
|
217
|
+
}) => {
|
|
218
|
+
const functionArgs = getFunctionArguments({
|
|
219
|
+
builder,
|
|
220
|
+
context,
|
|
221
|
+
event,
|
|
222
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
223
|
+
});
|
|
224
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
225
|
+
};
|
|
226
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
227
|
+
if (rootState === localState) {
|
|
228
|
+
throw new Error("rootState === localState");
|
|
229
|
+
}
|
|
230
|
+
return new Proxy(rootState, {
|
|
231
|
+
get: (_, prop) => {
|
|
232
|
+
if (localState && prop in localState) {
|
|
233
|
+
return localState[prop];
|
|
234
|
+
}
|
|
235
|
+
return rootState[prop];
|
|
236
|
+
},
|
|
237
|
+
set: (_, prop, value) => {
|
|
238
|
+
if (localState && prop in localState) {
|
|
239
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
240
|
+
}
|
|
241
|
+
rootState[prop] = value;
|
|
242
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
179
248
|
// src/functions/set.js
|
|
180
249
|
var set = (obj, _path, value) => {
|
|
181
250
|
if (Object(obj) !== obj) {
|
|
@@ -3254,22 +3323,6 @@ t.prototype.setStateStack = t.prototype.ec;
|
|
|
3254
3323
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3255
3324
|
var stdin_default = t;
|
|
3256
3325
|
|
|
3257
|
-
// src/functions/evaluate/helpers.js
|
|
3258
|
-
var getFunctionArguments = ({
|
|
3259
|
-
builder,
|
|
3260
|
-
context,
|
|
3261
|
-
event,
|
|
3262
|
-
state
|
|
3263
|
-
}) => {
|
|
3264
|
-
return Object.entries({
|
|
3265
|
-
state,
|
|
3266
|
-
Builder: builder,
|
|
3267
|
-
builder,
|
|
3268
|
-
context,
|
|
3269
|
-
event
|
|
3270
|
-
});
|
|
3271
|
-
};
|
|
3272
|
-
|
|
3273
3326
|
// src/functions/evaluate/edge-runtime/edge-runtime.js
|
|
3274
3327
|
var __defProp = Object.defineProperty;
|
|
3275
3328
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -3367,6 +3420,9 @@ theFunction();
|
|
|
3367
3420
|
}
|
|
3368
3421
|
};
|
|
3369
3422
|
|
|
3423
|
+
// src/functions/evaluate/choose-eval.js
|
|
3424
|
+
var chooseBrowserOrServerEval = (args) => isBrowser() ? runInBrowser(args) : runInEdge(args);
|
|
3425
|
+
|
|
3370
3426
|
// src/functions/evaluate/evaluate.js
|
|
3371
3427
|
function evaluate({
|
|
3372
3428
|
code,
|
|
@@ -3381,17 +3437,11 @@ function evaluate({
|
|
|
3381
3437
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3382
3438
|
return;
|
|
3383
3439
|
}
|
|
3384
|
-
const builder = {
|
|
3385
|
-
isEditing: isEditing(),
|
|
3386
|
-
isBrowser: isBrowser(),
|
|
3387
|
-
isServer: !isBrowser(),
|
|
3388
|
-
getUserAttributes: () => getUserAttributes()
|
|
3389
|
-
};
|
|
3390
|
-
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
3391
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3392
3440
|
const args = {
|
|
3393
|
-
code:
|
|
3394
|
-
|
|
3441
|
+
code: parseCode(code, {
|
|
3442
|
+
isExpression
|
|
3443
|
+
}),
|
|
3444
|
+
builder: getBuilderGlobals(),
|
|
3395
3445
|
context,
|
|
3396
3446
|
event,
|
|
3397
3447
|
rootSetState,
|
|
@@ -3399,7 +3449,7 @@ function evaluate({
|
|
|
3399
3449
|
localState
|
|
3400
3450
|
};
|
|
3401
3451
|
try {
|
|
3402
|
-
return
|
|
3452
|
+
return chooseBrowserOrServerEval(args);
|
|
3403
3453
|
} catch (e) {
|
|
3404
3454
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3405
3455
|
code
|
|
@@ -5814,42 +5864,40 @@ var _tmpl$13 = /* @__PURE__ */ template(`<div>`);
|
|
|
5814
5864
|
function CustomCode(props) {
|
|
5815
5865
|
const [scriptsInserted, setScriptsInserted] = createSignal([]);
|
|
5816
5866
|
const [scriptsRun, setScriptsRun] = createSignal([]);
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5867
|
+
let elementRef;
|
|
5868
|
+
onMount(() => {
|
|
5869
|
+
if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
|
|
5870
|
+
return;
|
|
5871
|
+
}
|
|
5872
|
+
const scripts = elementRef.getElementsByTagName("script");
|
|
5873
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
5874
|
+
const script = scripts[i];
|
|
5875
|
+
if (script.src) {
|
|
5876
|
+
if (scriptsInserted().includes(script.src)) {
|
|
5877
|
+
continue;
|
|
5878
|
+
}
|
|
5879
|
+
scriptsInserted().push(script.src);
|
|
5880
|
+
const newScript = document.createElement("script");
|
|
5881
|
+
newScript.async = true;
|
|
5882
|
+
newScript.src = script.src;
|
|
5883
|
+
document.head.appendChild(newScript);
|
|
5884
|
+
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
5885
|
+
if (scriptsRun().includes(script.innerText)) {
|
|
5886
|
+
continue;
|
|
5887
|
+
}
|
|
5888
|
+
try {
|
|
5889
|
+
scriptsRun().push(script.innerText);
|
|
5890
|
+
new Function(script.innerText)();
|
|
5891
|
+
} catch (error) {
|
|
5892
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
5841
5893
|
}
|
|
5842
5894
|
}
|
|
5843
5895
|
}
|
|
5844
|
-
}
|
|
5845
|
-
let elem;
|
|
5846
|
-
onMount(() => {
|
|
5847
|
-
findAndRunScripts();
|
|
5848
5896
|
});
|
|
5849
5897
|
return (() => {
|
|
5850
5898
|
const _el$ = _tmpl$13();
|
|
5851
|
-
const _ref$ =
|
|
5852
|
-
typeof _ref$ === "function" ? use(_ref$, _el$) :
|
|
5899
|
+
const _ref$ = elementRef;
|
|
5900
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
|
|
5853
5901
|
effect((_p$) => {
|
|
5854
5902
|
const _v$ = "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""), _v$2 = props.code;
|
|
5855
5903
|
_v$ !== _p$._v$ && className(_el$, _p$._v$ = _v$);
|
|
@@ -6512,7 +6560,7 @@ var track = (args) => _track(__spreadProps9(__spreadValues13({}, args), {
|
|
|
6512
6560
|
}));
|
|
6513
6561
|
|
|
6514
6562
|
// src/constants/sdk-version.js
|
|
6515
|
-
var SDK_VERSION = "0.7.0";
|
|
6563
|
+
var SDK_VERSION = "0.7.1-0";
|
|
6516
6564
|
|
|
6517
6565
|
// src/functions/register.js
|
|
6518
6566
|
var registry = {};
|
|
@@ -6966,6 +7014,7 @@ var __spreadValues16 = (a, b) => {
|
|
|
6966
7014
|
}
|
|
6967
7015
|
return a;
|
|
6968
7016
|
};
|
|
7017
|
+
var isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6969
7018
|
var generateContentUrl = (options) => {
|
|
6970
7019
|
let {
|
|
6971
7020
|
noTraverse = false
|
|
@@ -6979,7 +7028,14 @@ var generateContentUrl = (options) => {
|
|
|
6979
7028
|
includeRefs = true,
|
|
6980
7029
|
enrich,
|
|
6981
7030
|
locale,
|
|
6982
|
-
apiVersion = DEFAULT_API_VERSION
|
|
7031
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
7032
|
+
fields,
|
|
7033
|
+
omit,
|
|
7034
|
+
offset,
|
|
7035
|
+
cacheSeconds,
|
|
7036
|
+
staleCacheSeconds,
|
|
7037
|
+
sort,
|
|
7038
|
+
includeUnpublished
|
|
6983
7039
|
} = options;
|
|
6984
7040
|
if (!apiKey) {
|
|
6985
7041
|
throw new Error("Missing API key");
|
|
@@ -6991,6 +7047,30 @@ var generateContentUrl = (options) => {
|
|
|
6991
7047
|
noTraverse = true;
|
|
6992
7048
|
}
|
|
6993
7049
|
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}` : ""}`);
|
|
7050
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
7051
|
+
if (fields) {
|
|
7052
|
+
url.searchParams.set("fields", fields);
|
|
7053
|
+
}
|
|
7054
|
+
if (Number.isFinite(offset) && offset > -1) {
|
|
7055
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
7056
|
+
}
|
|
7057
|
+
if (typeof includeUnpublished === "boolean") {
|
|
7058
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
7059
|
+
}
|
|
7060
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds)) {
|
|
7061
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
7062
|
+
}
|
|
7063
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds)) {
|
|
7064
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
7065
|
+
}
|
|
7066
|
+
if (sort) {
|
|
7067
|
+
const flattened2 = flatten({
|
|
7068
|
+
sort
|
|
7069
|
+
});
|
|
7070
|
+
for (const key in flattened2) {
|
|
7071
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
7072
|
+
}
|
|
7073
|
+
}
|
|
6994
7074
|
const queryOptions = __spreadValues16(__spreadValues16({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
6995
7075
|
const flattened = flatten(queryOptions);
|
|
6996
7076
|
for (const key in flattened) {
|
|
@@ -7281,11 +7361,8 @@ function EnableEditor(props) {
|
|
|
7281
7361
|
}
|
|
7282
7362
|
let elementRef;
|
|
7283
7363
|
onMount(() => {
|
|
7284
|
-
if (!props.apiKey) {
|
|
7285
|
-
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
7286
|
-
}
|
|
7287
7364
|
if (isBrowser()) {
|
|
7288
|
-
if (isEditing()) {
|
|
7365
|
+
if (isEditing() && true) {
|
|
7289
7366
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
7290
7367
|
window.addEventListener("message", processMessage);
|
|
7291
7368
|
registerInsertMenu();
|
|
@@ -7306,18 +7383,20 @@ function EnableEditor(props) {
|
|
|
7306
7383
|
});
|
|
7307
7384
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
7308
7385
|
}
|
|
7309
|
-
|
|
7386
|
+
const shouldTrackImpression = props.builderContextSignal.content && getDefaultCanTrack(props.canTrack);
|
|
7387
|
+
if (shouldTrackImpression) {
|
|
7310
7388
|
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
7311
7389
|
const contentId = props.builderContextSignal.content?.id;
|
|
7390
|
+
const apiKeyProp = props.apiKey;
|
|
7312
7391
|
_track({
|
|
7313
7392
|
type: "impression",
|
|
7314
|
-
canTrack:
|
|
7393
|
+
canTrack: true,
|
|
7315
7394
|
contentId,
|
|
7316
|
-
apiKey:
|
|
7395
|
+
apiKey: apiKeyProp,
|
|
7317
7396
|
variationId: variationId !== contentId ? variationId : void 0
|
|
7318
7397
|
});
|
|
7319
7398
|
}
|
|
7320
|
-
if (isPreviewing()) {
|
|
7399
|
+
if (isPreviewing() && true) {
|
|
7321
7400
|
const searchParams = new URL(location.href).searchParams;
|
|
7322
7401
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
7323
7402
|
const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
|
|
@@ -7334,11 +7413,16 @@ function EnableEditor(props) {
|
|
|
7334
7413
|
});
|
|
7335
7414
|
}
|
|
7336
7415
|
}
|
|
7337
|
-
evaluateJsCode();
|
|
7338
|
-
runHttpRequests();
|
|
7339
|
-
emitStateUpdate();
|
|
7340
7416
|
}
|
|
7341
7417
|
});
|
|
7418
|
+
onMount(() => {
|
|
7419
|
+
if (!props.apiKey) {
|
|
7420
|
+
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
7421
|
+
}
|
|
7422
|
+
evaluateJsCode();
|
|
7423
|
+
runHttpRequests();
|
|
7424
|
+
emitStateUpdate();
|
|
7425
|
+
});
|
|
7342
7426
|
function onUpdateFn_0() {
|
|
7343
7427
|
if (props.content) {
|
|
7344
7428
|
mergeNewContent(props.content);
|
|
@@ -7371,16 +7455,17 @@ function EnableEditor(props) {
|
|
|
7371
7455
|
},
|
|
7372
7456
|
get children() {
|
|
7373
7457
|
const _el$ = _tmpl$14();
|
|
7374
|
-
_el$.$$click = (event) => onClick(event);
|
|
7375
7458
|
const _ref$ = elementRef;
|
|
7376
7459
|
typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
|
|
7377
7460
|
spread(_el$, mergeProps({
|
|
7378
7461
|
get ["class"]() {
|
|
7379
7462
|
return props.classNameProp;
|
|
7380
|
-
}
|
|
7463
|
+
}
|
|
7464
|
+
}, {}, {
|
|
7381
7465
|
get key() {
|
|
7382
7466
|
return forceReRenderCount();
|
|
7383
7467
|
},
|
|
7468
|
+
"onClick": (event) => onClick(event),
|
|
7384
7469
|
get ["builder-content-id"]() {
|
|
7385
7470
|
return props.builderContextSignal.content?.id;
|
|
7386
7471
|
},
|
|
@@ -7399,7 +7484,6 @@ function EnableEditor(props) {
|
|
|
7399
7484
|
});
|
|
7400
7485
|
}
|
|
7401
7486
|
var enable_editor_default = EnableEditor;
|
|
7402
|
-
delegateEvents(["click"]);
|
|
7403
7487
|
var _tmpl$15 = /* @__PURE__ */ template(`<script>`);
|
|
7404
7488
|
function InlinedScript(props) {
|
|
7405
7489
|
return (() => {
|