@builder.io/sdk-solid 0.5.7 → 0.5.9
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/components/block/components/component-ref/component-ref.jsx +1 -0
- package/src/components/content/components/enable-editor.jsx +2 -1
- package/src/constants/sdk-version.js +1 -1
- package/src/functions/evaluate/browser-runtime/browser.js +40 -0
- package/src/functions/evaluate/browser-runtime/index.js +2 -0
- package/src/functions/evaluate/evaluate.js +14 -44
- package/src/functions/evaluate/helpers.js +15 -0
- package/src/functions/evaluate/index.js +1 -1
- package/src/functions/evaluate/node-runtime/index.js +2 -0
- package/src/functions/evaluate/non-node-runtime/non-node-runtime.js +12 -13
- package/src/functions/get-block-actions-handler.js +1 -1
- package/src/functions/register-component.js +1 -1
- package/src/index.js +1 -10
- package/src/server-index.js +11 -0
- package/src/functions/evaluate/types.js +0 -0
- /package/src/functions/evaluate/{acorn-interpreter.js → non-node-runtime/acorn-interpreter.js} +0 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import BlockStyles from "../block-styles";
|
|
|
5
5
|
import Block from "../../block";
|
|
6
6
|
import InteractiveElement from "../interactive-element";
|
|
7
7
|
import { getWrapperProps } from "./component-ref.helpers.js";
|
|
8
|
+
import { wrapComponentRef } from "../../../content/wrap-component-ref.js";
|
|
8
9
|
|
|
9
10
|
function ComponentRef(props) {
|
|
10
11
|
const [Wrapper, setWrapper] = createSignal(
|
|
@@ -17,6 +17,7 @@ import { logger } from "../../../helpers/logger.js";
|
|
|
17
17
|
import { fetchOneEntry } from "../../../functions/get-content/index.js";
|
|
18
18
|
import { isPreviewing } from "../../../functions/is-previewing.js";
|
|
19
19
|
import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
|
|
20
|
+
import { fastClone } from "../../../functions/fast-clone.js";
|
|
20
21
|
|
|
21
22
|
function EnableEditor(props) {
|
|
22
23
|
const [canTrackToUse, setCanTrackToUse] = createSignal(
|
|
@@ -177,7 +178,7 @@ function EnableEditor(props) {
|
|
|
177
178
|
window.dispatchEvent(
|
|
178
179
|
new CustomEvent("builder:component:stateChange", {
|
|
179
180
|
detail: {
|
|
180
|
-
state: props.builderContextSignal.rootState,
|
|
181
|
+
state: fastClone(props.builderContextSignal.rootState),
|
|
181
182
|
ref: {
|
|
182
183
|
name: props.model,
|
|
183
184
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.5.
|
|
1
|
+
export const SDK_VERSION = "0.5.9"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getFunctionArguments } from "../helpers.js";
|
|
2
|
+
const runInBrowser = ({
|
|
3
|
+
code,
|
|
4
|
+
builder,
|
|
5
|
+
context,
|
|
6
|
+
event,
|
|
7
|
+
localState,
|
|
8
|
+
rootSetState,
|
|
9
|
+
rootState
|
|
10
|
+
}) => {
|
|
11
|
+
const functionArgs = getFunctionArguments({
|
|
12
|
+
builder,
|
|
13
|
+
context,
|
|
14
|
+
event,
|
|
15
|
+
state: flattenState(rootState, localState, rootSetState)
|
|
16
|
+
});
|
|
17
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
18
|
+
};
|
|
19
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
20
|
+
if (rootState === localState) {
|
|
21
|
+
throw new Error("rootState === localState");
|
|
22
|
+
}
|
|
23
|
+
return new Proxy(rootState, {
|
|
24
|
+
get: (_, prop) => {
|
|
25
|
+
if (localState && prop in localState) {
|
|
26
|
+
return localState[prop];
|
|
27
|
+
}
|
|
28
|
+
return rootState[prop];
|
|
29
|
+
},
|
|
30
|
+
set: (_, prop, value) => {
|
|
31
|
+
if (localState && prop in localState) {
|
|
32
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
33
|
+
}
|
|
34
|
+
rootState[prop] = value;
|
|
35
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export { flattenState, runInBrowser }
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { logger } from "../../helpers/logger.js";
|
|
2
2
|
import { isBrowser } from "../is-browser.js";
|
|
3
3
|
import { isEditing } from "../is-editing.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getUserAttributes } from "../track/helpers.js";
|
|
5
|
+
import { runInBrowser } from "./browser-runtime/browser.js";
|
|
5
6
|
import { runInNonNode } from "./non-node-runtime/index.js";
|
|
7
|
+
import { isNonNodeServer } from "../is-non-node-server.js";
|
|
6
8
|
function evaluate({
|
|
7
9
|
code,
|
|
8
10
|
context,
|
|
@@ -19,12 +21,13 @@ function evaluate({
|
|
|
19
21
|
const builder = {
|
|
20
22
|
isEditing: isEditing(),
|
|
21
23
|
isBrowser: isBrowser(),
|
|
22
|
-
isServer: !isBrowser()
|
|
24
|
+
isServer: !isBrowser(),
|
|
25
|
+
getUserAttributes: () => getUserAttributes()
|
|
23
26
|
};
|
|
24
27
|
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
25
28
|
const useCode = useReturn ? `return (${code});` : code;
|
|
26
29
|
const args = {
|
|
27
|
-
useCode,
|
|
30
|
+
code: useCode,
|
|
28
31
|
builder,
|
|
29
32
|
context,
|
|
30
33
|
event,
|
|
@@ -32,48 +35,15 @@ function evaluate({
|
|
|
32
35
|
rootState,
|
|
33
36
|
localState
|
|
34
37
|
};
|
|
35
|
-
if (isBrowser()) return runInBrowser(args);
|
|
36
|
-
if (isNonNodeServer()) return runInNonNode(args);
|
|
37
|
-
return runInNode(args);
|
|
38
|
-
}
|
|
39
|
-
const runInBrowser = ({
|
|
40
|
-
useCode,
|
|
41
|
-
builder,
|
|
42
|
-
context,
|
|
43
|
-
event,
|
|
44
|
-
localState,
|
|
45
|
-
rootSetState,
|
|
46
|
-
rootState
|
|
47
|
-
}) => {
|
|
48
|
-
const state = flattenState(rootState, localState, rootSetState);
|
|
49
38
|
try {
|
|
50
|
-
|
|
39
|
+
if (isBrowser()) return runInBrowser(args);
|
|
40
|
+
if (isNonNodeServer()) return runInNonNode(args);
|
|
41
|
+
return runInBrowser(args);
|
|
51
42
|
} catch (e) {
|
|
52
|
-
logger.
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return runInBrowser(args);
|
|
57
|
-
};
|
|
58
|
-
function flattenState(rootState, localState, rootSetState) {
|
|
59
|
-
if (rootState === localState) {
|
|
60
|
-
throw new Error("rootState === localState");
|
|
43
|
+
logger.error("Failed code evaluation: " + e.message, {
|
|
44
|
+
code
|
|
45
|
+
});
|
|
46
|
+
return void 0;
|
|
61
47
|
}
|
|
62
|
-
return new Proxy(rootState, {
|
|
63
|
-
get: (_, prop) => {
|
|
64
|
-
if (localState && prop in localState) {
|
|
65
|
-
return localState[prop];
|
|
66
|
-
}
|
|
67
|
-
return rootState[prop];
|
|
68
|
-
},
|
|
69
|
-
set: (_, prop, value) => {
|
|
70
|
-
if (localState && prop in localState) {
|
|
71
|
-
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
72
|
-
}
|
|
73
|
-
rootState[prop] = value;
|
|
74
|
-
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
48
|
}
|
|
79
|
-
export { evaluate
|
|
49
|
+
export { evaluate }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { evaluate } from "./evaluate";
|
|
1
|
+
import { evaluate } from "./evaluate.js";
|
|
2
2
|
export { evaluate }
|
|
@@ -15,9 +15,10 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
}
|
|
16
16
|
return a;
|
|
17
17
|
};
|
|
18
|
-
import { logger } from "../../../helpers/logger";
|
|
19
|
-
import { set } from "../../set";
|
|
20
|
-
import Interpreter from "
|
|
18
|
+
import { logger } from "../../../helpers/logger.js";
|
|
19
|
+
import { set } from "../../set.js";
|
|
20
|
+
import Interpreter from "./acorn-interpreter.js";
|
|
21
|
+
import { getFunctionArguments } from "../helpers.js";
|
|
21
22
|
const processCode = code => {
|
|
22
23
|
return code.split("\n").map(line => {
|
|
23
24
|
const trimmed = line.trim();
|
|
@@ -41,18 +42,17 @@ const runInNonNode = ({
|
|
|
41
42
|
rootState,
|
|
42
43
|
localState,
|
|
43
44
|
rootSetState,
|
|
44
|
-
|
|
45
|
+
code
|
|
45
46
|
}) => {
|
|
46
47
|
const state = __spreadValues(__spreadValues({}, rootState), localState);
|
|
47
|
-
const properties = {
|
|
48
|
-
state,
|
|
49
|
-
Builder: builder,
|
|
48
|
+
const properties = getFunctionArguments({
|
|
50
49
|
builder,
|
|
51
50
|
context,
|
|
52
|
-
event
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
51
|
+
event,
|
|
52
|
+
state
|
|
53
|
+
});
|
|
54
|
+
const prependedCode = properties.map(([key]) => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
|
|
55
|
+
const cleanedCode = processCode(code);
|
|
56
56
|
if (cleanedCode === "") {
|
|
57
57
|
logger.warn("Skipping evaluation of empty code block.");
|
|
58
58
|
return;
|
|
@@ -70,8 +70,7 @@ theFunction();
|
|
|
70
70
|
rootSetState == null ? void 0 : rootSetState(newState);
|
|
71
71
|
};
|
|
72
72
|
const initFunc = function (interpreter, globalObject) {
|
|
73
|
-
|
|
74
|
-
const val = properties[key] || {};
|
|
73
|
+
properties.forEach(([key, val]) => {
|
|
75
74
|
const jsonVal = JSON.stringify(val);
|
|
76
75
|
interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
|
|
77
76
|
});
|
|
@@ -37,7 +37,7 @@ function registerComponent(component, info) {
|
|
|
37
37
|
}
|
|
38
38
|
const createRegisterComponentMessage = info => ({
|
|
39
39
|
type: "builder.registerComponent",
|
|
40
|
-
data: info
|
|
40
|
+
data: serializeComponentInfo(info)
|
|
41
41
|
});
|
|
42
42
|
const serializeFn = fnValue => {
|
|
43
43
|
const fnStr = fnValue.toString().trim();
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
export * from "./index-helpers/top-of-file.js";
|
|
2
2
|
export * from "./index-helpers/blocks-exports.js";
|
|
3
|
-
|
|
4
|
-
import { isPreviewing } from "./functions/is-previewing.js";
|
|
5
|
-
import { createRegisterComponentMessage } from "./functions/register-component.js";
|
|
6
|
-
import { register } from "./functions/register.js";
|
|
7
|
-
import { setEditorSettings } from "./functions/set-editor-settings.js";
|
|
8
|
-
import { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from "./functions/get-content/index.js";
|
|
9
|
-
import { getBuilderSearchParams } from "./functions/get-builder-search-params/index.js";
|
|
10
|
-
import { track } from "./functions/track/index.js";
|
|
11
|
-
import { fetchBuilderProps } from "./functions/fetch-builder-props.js";
|
|
12
|
-
export { _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getAllContent, getBuilderSearchParams, getContent, isEditing, isPreviewing, register, setEditorSettings, track }
|
|
3
|
+
export * from "./server-index.js"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./index-helpers/top-of-file.js";
|
|
2
|
+
import { isEditing } from "./functions/is-editing.js";
|
|
3
|
+
import { isPreviewing } from "./functions/is-previewing.js";
|
|
4
|
+
import { createRegisterComponentMessage } from "./functions/register-component.js";
|
|
5
|
+
import { register } from "./functions/register.js";
|
|
6
|
+
import { setEditorSettings } from "./functions/set-editor-settings.js";
|
|
7
|
+
import { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from "./functions/get-content/index.js";
|
|
8
|
+
import { getBuilderSearchParams } from "./functions/get-builder-search-params/index.js";
|
|
9
|
+
import { track } from "./functions/track/index.js";
|
|
10
|
+
import { fetchBuilderProps } from "./functions/fetch-builder-props.js";
|
|
11
|
+
export { _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getAllContent, getBuilderSearchParams, getContent, isEditing, isPreviewing, register, setEditorSettings, track }
|
|
File without changes
|
/package/src/functions/evaluate/{acorn-interpreter.js → non-node-runtime/acorn-interpreter.js}
RENAMED
|
File without changes
|