@builder.io/sdk-solid 0.0.17 → 0.0.18
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/package.json +3 -3
- package/src/blocks/symbol/symbol.jsx +11 -9
- package/src/scripts/init-editing.js +34 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-solid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./solid-index.jsx",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"solid-styled-components": "^0.27.6"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"solid-js": "^1.
|
|
20
|
+
"solid-js": "^1.5.7"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"babel-preset-solid": "^1.3.17",
|
|
24
|
-
"solid-js": "^1.
|
|
24
|
+
"solid-js": "^1.5.7",
|
|
25
25
|
"vite": "^3.0.4",
|
|
26
26
|
"vite-plugin-solid": "^2.2.6"
|
|
27
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext,
|
|
1
|
+
import { useContext, on, createEffect, createSignal } from "solid-js";
|
|
2
2
|
import RenderContent from "../../components/render-content/render-content.jsx";
|
|
3
3
|
import BuilderContext from "../../context/builder.context.js";
|
|
4
4
|
import { getContent } from "../../functions/get-content/index.js";
|
|
@@ -6,11 +6,13 @@ import { markMutable } from "../../functions/mark-mutable";
|
|
|
6
6
|
|
|
7
7
|
function Symbol(props) {
|
|
8
8
|
const [className, setClassName] = createSignal("builder-symbol");
|
|
9
|
-
const [
|
|
9
|
+
const [fetchedContent, setFetchedContent] = createSignal(null);
|
|
10
|
+
|
|
11
|
+
function contentToUse() {
|
|
12
|
+
return props.symbol?.content || fetchedContent();
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
const builderContext = useContext(BuilderContext);
|
|
11
|
-
onMount(() => {
|
|
12
|
-
setContent(props.symbol?.content);
|
|
13
|
-
});
|
|
14
16
|
|
|
15
17
|
function onUpdateFn_0() {
|
|
16
18
|
const symbolToUse = props.symbol;
|
|
@@ -24,7 +26,7 @@ function Symbol(props) {
|
|
|
24
26
|
* then we want to re-fetch the symbol content.
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
|
-
if (symbolToUse && !symbolToUse.content && !
|
|
29
|
+
if (symbolToUse && !symbolToUse.content && !fetchedContent() && symbolToUse.model) {
|
|
28
30
|
getContent({
|
|
29
31
|
model: symbolToUse.model,
|
|
30
32
|
apiKey: builderContext.apiKey,
|
|
@@ -32,19 +34,19 @@ function Symbol(props) {
|
|
|
32
34
|
id: symbolToUse.entry
|
|
33
35
|
}
|
|
34
36
|
}).then(response => {
|
|
35
|
-
|
|
37
|
+
setFetchedContent(response);
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
createEffect(on(() => [props.symbol,
|
|
42
|
+
createEffect(on(() => [props.symbol, fetchedContent()], onUpdateFn_0));
|
|
41
43
|
return <div class={className()} {...props.attributes} dataSet={{
|
|
42
44
|
class: className()
|
|
43
45
|
}}>
|
|
44
46
|
<RenderContent apiKey={builderContext.apiKey} context={builderContext.context} customComponents={markMutable(Object.values(builderContext.registeredComponents))} data={markMutable({ ...props.symbol?.data,
|
|
45
47
|
...builderContext.state,
|
|
46
48
|
...props.symbol?.content?.data?.state
|
|
47
|
-
})} model={props.symbol?.model} content={markMutable(
|
|
49
|
+
})} model={props.symbol?.model} content={markMutable(contentToUse())}></RenderContent>
|
|
48
50
|
</div>;
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -31,43 +31,44 @@ const setupBrowserForEditing = () => {
|
|
|
31
31
|
}, "*");
|
|
32
32
|
window.addEventListener("message", ({ data }) => {
|
|
33
33
|
var _a2, _b;
|
|
34
|
-
if (data) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, "*");
|
|
61
|
-
}).catch(console.error);
|
|
62
|
-
} else {
|
|
63
|
-
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
34
|
+
if (!(data == null ? void 0 : data.type)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
switch (data.type) {
|
|
38
|
+
case "builder.evaluate": {
|
|
39
|
+
const text = data.data.text;
|
|
40
|
+
const args = data.data.arguments || [];
|
|
41
|
+
const id = data.data.id;
|
|
42
|
+
const fn = new Function(text);
|
|
43
|
+
let result;
|
|
44
|
+
let error = null;
|
|
45
|
+
try {
|
|
46
|
+
result = fn.apply(null, args);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
error = err;
|
|
49
|
+
}
|
|
50
|
+
if (error) {
|
|
51
|
+
(_a2 = window.parent) == null ? void 0 : _a2.postMessage({
|
|
52
|
+
type: "builder.evaluateError",
|
|
53
|
+
data: { id, error: error.message }
|
|
54
|
+
}, "*");
|
|
55
|
+
} else {
|
|
56
|
+
if (result && typeof result.then === "function") {
|
|
57
|
+
result.then((finalResult) => {
|
|
58
|
+
var _a3;
|
|
59
|
+
(_a3 = window.parent) == null ? void 0 : _a3.postMessage({
|
|
64
60
|
type: "builder.evaluateResult",
|
|
65
|
-
data: {
|
|
61
|
+
data: { id, result: finalResult }
|
|
66
62
|
}, "*");
|
|
67
|
-
}
|
|
63
|
+
}).catch(console.error);
|
|
64
|
+
} else {
|
|
65
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
66
|
+
type: "builder.evaluateResult",
|
|
67
|
+
data: { result, id }
|
|
68
|
+
}, "*");
|
|
68
69
|
}
|
|
69
|
-
break;
|
|
70
70
|
}
|
|
71
|
+
break;
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
});
|