@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.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
|
|
|
@@ -174,6 +174,75 @@ var getUserAttributes = () => {
|
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
|
|
177
|
+
// src/functions/evaluate/helpers.js
|
|
178
|
+
var getFunctionArguments = ({
|
|
179
|
+
builder,
|
|
180
|
+
context,
|
|
181
|
+
event,
|
|
182
|
+
state
|
|
183
|
+
}) => {
|
|
184
|
+
return Object.entries({
|
|
185
|
+
state,
|
|
186
|
+
Builder: builder,
|
|
187
|
+
builder,
|
|
188
|
+
context,
|
|
189
|
+
event
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
var getBuilderGlobals = () => ({
|
|
193
|
+
isEditing: isEditing(),
|
|
194
|
+
isBrowser: isBrowser(),
|
|
195
|
+
isServer: !isBrowser(),
|
|
196
|
+
getUserAttributes: () => getUserAttributes()
|
|
197
|
+
});
|
|
198
|
+
var parseCode = (code, {
|
|
199
|
+
isExpression = true
|
|
200
|
+
}) => {
|
|
201
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
202
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
203
|
+
return useCode;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/functions/evaluate/browser-runtime/browser.js
|
|
207
|
+
var runInBrowser = ({
|
|
208
|
+
code,
|
|
209
|
+
builder,
|
|
210
|
+
context,
|
|
211
|
+
event,
|
|
212
|
+
localState,
|
|
213
|
+
rootSetState,
|
|
214
|
+
rootState
|
|
215
|
+
}) => {
|
|
216
|
+
const functionArgs = getFunctionArguments({
|
|
217
|
+
builder,
|
|
218
|
+
context,
|
|
219
|
+
event,
|
|
220
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
221
|
+
});
|
|
222
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
223
|
+
};
|
|
224
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
225
|
+
if (rootState === localState) {
|
|
226
|
+
throw new Error("rootState === localState");
|
|
227
|
+
}
|
|
228
|
+
return new Proxy(rootState, {
|
|
229
|
+
get: (_, prop) => {
|
|
230
|
+
if (localState && prop in localState) {
|
|
231
|
+
return localState[prop];
|
|
232
|
+
}
|
|
233
|
+
return rootState[prop];
|
|
234
|
+
},
|
|
235
|
+
set: (_, prop, value) => {
|
|
236
|
+
if (localState && prop in localState) {
|
|
237
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
238
|
+
}
|
|
239
|
+
rootState[prop] = value;
|
|
240
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
177
246
|
// src/functions/set.js
|
|
178
247
|
var set = (obj, _path, value) => {
|
|
179
248
|
if (Object(obj) !== obj) {
|
|
@@ -3252,22 +3321,6 @@ t.prototype.setStateStack = t.prototype.ec;
|
|
|
3252
3321
|
t.VALUE_IN_DESCRIPTOR = Ia;
|
|
3253
3322
|
var stdin_default = t;
|
|
3254
3323
|
|
|
3255
|
-
// src/functions/evaluate/helpers.js
|
|
3256
|
-
var getFunctionArguments = ({
|
|
3257
|
-
builder,
|
|
3258
|
-
context,
|
|
3259
|
-
event,
|
|
3260
|
-
state
|
|
3261
|
-
}) => {
|
|
3262
|
-
return Object.entries({
|
|
3263
|
-
state,
|
|
3264
|
-
Builder: builder,
|
|
3265
|
-
builder,
|
|
3266
|
-
context,
|
|
3267
|
-
event
|
|
3268
|
-
});
|
|
3269
|
-
};
|
|
3270
|
-
|
|
3271
3324
|
// src/functions/evaluate/edge-runtime/edge-runtime.js
|
|
3272
3325
|
var __defProp = Object.defineProperty;
|
|
3273
3326
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -3365,6 +3418,9 @@ theFunction();
|
|
|
3365
3418
|
}
|
|
3366
3419
|
};
|
|
3367
3420
|
|
|
3421
|
+
// src/functions/evaluate/choose-eval.js
|
|
3422
|
+
var chooseBrowserOrServerEval = (args) => isBrowser() ? runInBrowser(args) : runInEdge(args);
|
|
3423
|
+
|
|
3368
3424
|
// src/functions/evaluate/evaluate.js
|
|
3369
3425
|
function evaluate({
|
|
3370
3426
|
code,
|
|
@@ -3379,17 +3435,11 @@ function evaluate({
|
|
|
3379
3435
|
logger.warn("Skipping evaluation of empty code block.");
|
|
3380
3436
|
return;
|
|
3381
3437
|
}
|
|
3382
|
-
const builder = {
|
|
3383
|
-
isEditing: isEditing(),
|
|
3384
|
-
isBrowser: isBrowser(),
|
|
3385
|
-
isServer: !isBrowser(),
|
|
3386
|
-
getUserAttributes: () => getUserAttributes()
|
|
3387
|
-
};
|
|
3388
|
-
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
3389
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
3390
3438
|
const args = {
|
|
3391
|
-
code:
|
|
3392
|
-
|
|
3439
|
+
code: parseCode(code, {
|
|
3440
|
+
isExpression
|
|
3441
|
+
}),
|
|
3442
|
+
builder: getBuilderGlobals(),
|
|
3393
3443
|
context,
|
|
3394
3444
|
event,
|
|
3395
3445
|
rootSetState,
|
|
@@ -3397,7 +3447,7 @@ function evaluate({
|
|
|
3397
3447
|
localState
|
|
3398
3448
|
};
|
|
3399
3449
|
try {
|
|
3400
|
-
return
|
|
3450
|
+
return chooseBrowserOrServerEval(args);
|
|
3401
3451
|
} catch (e) {
|
|
3402
3452
|
logger.error("Failed code evaluation: " + e.message, {
|
|
3403
3453
|
code
|
|
@@ -5799,41 +5849,39 @@ var _tmpl$13 = /* @__PURE__ */ template(`<div>`);
|
|
|
5799
5849
|
function CustomCode(props) {
|
|
5800
5850
|
const [scriptsInserted, setScriptsInserted] = createSignal([]);
|
|
5801
5851
|
const [scriptsRun, setScriptsRun] = createSignal([]);
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5852
|
+
let elementRef;
|
|
5853
|
+
onMount(() => {
|
|
5854
|
+
if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
|
|
5855
|
+
return;
|
|
5856
|
+
}
|
|
5857
|
+
const scripts = elementRef.getElementsByTagName("script");
|
|
5858
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
5859
|
+
const script = scripts[i];
|
|
5860
|
+
if (script.src) {
|
|
5861
|
+
if (scriptsInserted().includes(script.src)) {
|
|
5862
|
+
continue;
|
|
5863
|
+
}
|
|
5864
|
+
scriptsInserted().push(script.src);
|
|
5865
|
+
const newScript = document.createElement("script");
|
|
5866
|
+
newScript.async = true;
|
|
5867
|
+
newScript.src = script.src;
|
|
5868
|
+
document.head.appendChild(newScript);
|
|
5869
|
+
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
5870
|
+
if (scriptsRun().includes(script.innerText)) {
|
|
5871
|
+
continue;
|
|
5872
|
+
}
|
|
5873
|
+
try {
|
|
5874
|
+
scriptsRun().push(script.innerText);
|
|
5875
|
+
new Function(script.innerText)();
|
|
5876
|
+
} catch (error) {
|
|
5825
5877
|
}
|
|
5826
5878
|
}
|
|
5827
5879
|
}
|
|
5828
|
-
}
|
|
5829
|
-
let elem;
|
|
5830
|
-
onMount(() => {
|
|
5831
|
-
findAndRunScripts();
|
|
5832
5880
|
});
|
|
5833
5881
|
return (() => {
|
|
5834
5882
|
const _el$ = _tmpl$13();
|
|
5835
|
-
const _ref$ =
|
|
5836
|
-
typeof _ref$ === "function" ? use(_ref$, _el$) :
|
|
5883
|
+
const _ref$ = elementRef;
|
|
5884
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
|
|
5837
5885
|
effect((_p$) => {
|
|
5838
5886
|
const _v$ = "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""), _v$2 = props.code;
|
|
5839
5887
|
_v$ !== _p$._v$ && className(_el$, _p$._v$ = _v$);
|
|
@@ -6491,7 +6539,7 @@ var track = (args) => _track(__spreadProps9(__spreadValues13({}, args), {
|
|
|
6491
6539
|
}));
|
|
6492
6540
|
|
|
6493
6541
|
// src/constants/sdk-version.js
|
|
6494
|
-
var SDK_VERSION = "0.
|
|
6542
|
+
var SDK_VERSION = "0.7.1-0";
|
|
6495
6543
|
|
|
6496
6544
|
// src/functions/register.js
|
|
6497
6545
|
var registry = {};
|
|
@@ -6944,18 +6992,28 @@ var __spreadValues16 = (a, b) => {
|
|
|
6944
6992
|
}
|
|
6945
6993
|
return a;
|
|
6946
6994
|
};
|
|
6995
|
+
var isPositiveNumber = (thing) => typeof thing === "number" && !isNaN(thing) && thing >= 0;
|
|
6947
6996
|
var generateContentUrl = (options) => {
|
|
6997
|
+
let {
|
|
6998
|
+
noTraverse = false
|
|
6999
|
+
} = options;
|
|
6948
7000
|
const {
|
|
6949
7001
|
limit = 30,
|
|
6950
7002
|
userAttributes,
|
|
6951
7003
|
query,
|
|
6952
|
-
noTraverse = false,
|
|
6953
7004
|
model,
|
|
6954
7005
|
apiKey,
|
|
6955
7006
|
includeRefs = true,
|
|
6956
7007
|
enrich,
|
|
6957
7008
|
locale,
|
|
6958
|
-
apiVersion = DEFAULT_API_VERSION
|
|
7009
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
7010
|
+
fields,
|
|
7011
|
+
omit,
|
|
7012
|
+
offset,
|
|
7013
|
+
cacheSeconds,
|
|
7014
|
+
staleCacheSeconds,
|
|
7015
|
+
sort,
|
|
7016
|
+
includeUnpublished
|
|
6959
7017
|
} = options;
|
|
6960
7018
|
if (!apiKey) {
|
|
6961
7019
|
throw new Error("Missing API key");
|
|
@@ -6963,7 +7021,34 @@ var generateContentUrl = (options) => {
|
|
|
6963
7021
|
if (!["v2", "v3"].includes(apiVersion)) {
|
|
6964
7022
|
throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
|
|
6965
7023
|
}
|
|
7024
|
+
if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
|
|
7025
|
+
noTraverse = true;
|
|
7026
|
+
}
|
|
6966
7027
|
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}` : ""}`);
|
|
7028
|
+
url.searchParams.set("omit", omit || "meta.componentsUsed");
|
|
7029
|
+
if (fields) {
|
|
7030
|
+
url.searchParams.set("fields", fields);
|
|
7031
|
+
}
|
|
7032
|
+
if (Number.isFinite(offset) && offset > -1) {
|
|
7033
|
+
url.searchParams.set("offset", String(Math.floor(offset)));
|
|
7034
|
+
}
|
|
7035
|
+
if (typeof includeUnpublished === "boolean") {
|
|
7036
|
+
url.searchParams.set("includeUnpublished", String(includeUnpublished));
|
|
7037
|
+
}
|
|
7038
|
+
if (cacheSeconds && isPositiveNumber(cacheSeconds)) {
|
|
7039
|
+
url.searchParams.set("cacheSeconds", String(cacheSeconds));
|
|
7040
|
+
}
|
|
7041
|
+
if (staleCacheSeconds && isPositiveNumber(staleCacheSeconds)) {
|
|
7042
|
+
url.searchParams.set("staleCacheSeconds", String(staleCacheSeconds));
|
|
7043
|
+
}
|
|
7044
|
+
if (sort) {
|
|
7045
|
+
const flattened2 = flatten({
|
|
7046
|
+
sort
|
|
7047
|
+
});
|
|
7048
|
+
for (const key in flattened2) {
|
|
7049
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
7050
|
+
}
|
|
7051
|
+
}
|
|
6967
7052
|
const queryOptions = __spreadValues16(__spreadValues16({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
6968
7053
|
const flattened = flatten(queryOptions);
|
|
6969
7054
|
for (const key in flattened) {
|
|
@@ -7112,7 +7197,6 @@ function isPreviewing() {
|
|
|
7112
7197
|
// src/components/content/components/enable-editor.jsx
|
|
7113
7198
|
var _tmpl$14 = /* @__PURE__ */ template(`<div>`);
|
|
7114
7199
|
function EnableEditor(props) {
|
|
7115
|
-
const [canTrackToUse, setCanTrackToUse] = createSignal(checkIsDefined(props.canTrack) ? props.canTrack : true);
|
|
7116
7200
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
7117
7201
|
createSignal(0);
|
|
7118
7202
|
const [shouldSendResetCookie, setShouldSendResetCookie] = createSignal(false);
|
|
@@ -7193,7 +7277,7 @@ function EnableEditor(props) {
|
|
|
7193
7277
|
const contentId = props.builderContextSignal.content?.id;
|
|
7194
7278
|
_track({
|
|
7195
7279
|
type: "click",
|
|
7196
|
-
canTrack:
|
|
7280
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
7197
7281
|
contentId,
|
|
7198
7282
|
apiKey: props.apiKey,
|
|
7199
7283
|
variationId: variationId !== contentId ? variationId : void 0,
|
|
@@ -7254,11 +7338,8 @@ function EnableEditor(props) {
|
|
|
7254
7338
|
}
|
|
7255
7339
|
let elementRef;
|
|
7256
7340
|
onMount(() => {
|
|
7257
|
-
if (!props.apiKey) {
|
|
7258
|
-
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
7259
|
-
}
|
|
7260
7341
|
if (isBrowser()) {
|
|
7261
|
-
if (isEditing()) {
|
|
7342
|
+
if (isEditing() && true) {
|
|
7262
7343
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
7263
7344
|
window.addEventListener("message", processMessage);
|
|
7264
7345
|
registerInsertMenu();
|
|
@@ -7279,18 +7360,20 @@ function EnableEditor(props) {
|
|
|
7279
7360
|
});
|
|
7280
7361
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
7281
7362
|
}
|
|
7282
|
-
|
|
7363
|
+
const shouldTrackImpression = props.builderContextSignal.content && getDefaultCanTrack(props.canTrack);
|
|
7364
|
+
if (shouldTrackImpression) {
|
|
7283
7365
|
const variationId = props.builderContextSignal.content?.testVariationId;
|
|
7284
7366
|
const contentId = props.builderContextSignal.content?.id;
|
|
7367
|
+
const apiKeyProp = props.apiKey;
|
|
7285
7368
|
_track({
|
|
7286
7369
|
type: "impression",
|
|
7287
|
-
canTrack:
|
|
7370
|
+
canTrack: true,
|
|
7288
7371
|
contentId,
|
|
7289
|
-
apiKey:
|
|
7372
|
+
apiKey: apiKeyProp,
|
|
7290
7373
|
variationId: variationId !== contentId ? variationId : void 0
|
|
7291
7374
|
});
|
|
7292
7375
|
}
|
|
7293
|
-
if (isPreviewing()) {
|
|
7376
|
+
if (isPreviewing() && true) {
|
|
7294
7377
|
const searchParams = new URL(location.href).searchParams;
|
|
7295
7378
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
7296
7379
|
const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
|
|
@@ -7307,11 +7390,16 @@ function EnableEditor(props) {
|
|
|
7307
7390
|
});
|
|
7308
7391
|
}
|
|
7309
7392
|
}
|
|
7310
|
-
evaluateJsCode();
|
|
7311
|
-
runHttpRequests();
|
|
7312
|
-
emitStateUpdate();
|
|
7313
7393
|
}
|
|
7314
7394
|
});
|
|
7395
|
+
onMount(() => {
|
|
7396
|
+
if (!props.apiKey) {
|
|
7397
|
+
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
7398
|
+
}
|
|
7399
|
+
evaluateJsCode();
|
|
7400
|
+
runHttpRequests();
|
|
7401
|
+
emitStateUpdate();
|
|
7402
|
+
});
|
|
7315
7403
|
function onUpdateFn_0() {
|
|
7316
7404
|
if (props.content) {
|
|
7317
7405
|
mergeNewContent(props.content);
|
|
@@ -7344,16 +7432,17 @@ function EnableEditor(props) {
|
|
|
7344
7432
|
},
|
|
7345
7433
|
get children() {
|
|
7346
7434
|
const _el$ = _tmpl$14();
|
|
7347
|
-
_el$.$$click = (event) => onClick(event);
|
|
7348
7435
|
const _ref$ = elementRef;
|
|
7349
7436
|
typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
|
|
7350
7437
|
spread(_el$, mergeProps({
|
|
7351
7438
|
get ["class"]() {
|
|
7352
7439
|
return props.classNameProp;
|
|
7353
|
-
}
|
|
7440
|
+
}
|
|
7441
|
+
}, {}, {
|
|
7354
7442
|
get key() {
|
|
7355
7443
|
return forceReRenderCount();
|
|
7356
7444
|
},
|
|
7445
|
+
"onClick": (event) => onClick(event),
|
|
7357
7446
|
get ["builder-content-id"]() {
|
|
7358
7447
|
return props.builderContextSignal.content?.id;
|
|
7359
7448
|
},
|
|
@@ -7372,7 +7461,6 @@ function EnableEditor(props) {
|
|
|
7372
7461
|
});
|
|
7373
7462
|
}
|
|
7374
7463
|
var enable_editor_default = EnableEditor;
|
|
7375
|
-
delegateEvents(["click"]);
|
|
7376
7464
|
var _tmpl$15 = /* @__PURE__ */ template(`<script>`);
|
|
7377
7465
|
function InlinedScript(props) {
|
|
7378
7466
|
return (() => {
|