@builder.io/sdk-svelte 0.0.1-21 → 0.0.1-22
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 +1 -1
- package/src/blocks/embed/component-info.js +20 -1
- package/src/blocks/embed/embed.svelte +28 -39
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/symbol/symbol.svelte +1 -8
- package/src/blocks/video/video.svelte +1 -1
- package/src/constants/builder-registered-components.js +4 -1
- package/src/functions/register-component.js +10 -18
- package/src/functions/fast-clone.js +0 -4
package/package.json
CHANGED
|
@@ -9,7 +9,26 @@ const componentInfo = {
|
|
|
9
9
|
required: true,
|
|
10
10
|
defaultValue: "",
|
|
11
11
|
helperText: "e.g. enter a youtube url, google map, etc",
|
|
12
|
-
onChange:
|
|
12
|
+
onChange: (options) => {
|
|
13
|
+
const url = options.get("url");
|
|
14
|
+
if (url) {
|
|
15
|
+
options.set("content", "Loading...");
|
|
16
|
+
const apiKey = "ae0e60e78201a3f2b0de4b";
|
|
17
|
+
return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
|
|
18
|
+
if (options.get("url") === url) {
|
|
19
|
+
if (data.html) {
|
|
20
|
+
options.set("content", data.html);
|
|
21
|
+
} else {
|
|
22
|
+
options.set("content", "Invalid url, please try another");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}).catch((_err) => {
|
|
26
|
+
options.set("content", "There was an error embedding this URL, please try again or another URL");
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
options.delete("content");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
13
32
|
},
|
|
14
33
|
{
|
|
15
34
|
name: "content",
|
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
2
|
+
import { afterUpdate } from "svelte";
|
|
3
|
+
|
|
4
|
+
import { isJsScript } from "./helpers";
|
|
3
5
|
|
|
4
6
|
export let elem;
|
|
5
7
|
export let content;
|
|
6
8
|
|
|
7
9
|
const findAndRunScripts = function findAndRunScripts() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} else if (
|
|
26
|
-
!script.type ||
|
|
27
|
-
[
|
|
28
|
-
"text/javascript",
|
|
29
|
-
"application/javascript",
|
|
30
|
-
"application/ecmascript",
|
|
31
|
-
].includes(script.type)
|
|
32
|
-
) {
|
|
33
|
-
if (scriptsRun.includes(script.innerText)) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
scriptsRun.push(script.innerText);
|
|
39
|
-
new Function(script.innerText)();
|
|
40
|
-
} catch (error) {
|
|
41
|
-
console.warn("`Embed`: Error running script:", error);
|
|
42
|
-
}
|
|
10
|
+
const scripts = elem.getElementsByTagName("script");
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
13
|
+
const script = scripts[i];
|
|
14
|
+
|
|
15
|
+
if (script.src && !scriptsInserted.includes(script.src)) {
|
|
16
|
+
scriptsInserted.push(script.src);
|
|
17
|
+
const newScript = document.createElement("script");
|
|
18
|
+
newScript.async = true;
|
|
19
|
+
newScript.src = script.src;
|
|
20
|
+
document.head.appendChild(newScript);
|
|
21
|
+
} else if (isJsScript(script) && !scriptsRun.includes(script.innerText)) {
|
|
22
|
+
try {
|
|
23
|
+
scriptsRun.push(script.innerText);
|
|
24
|
+
new Function(script.innerText)();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.warn("`Embed`: Error running script:", error);
|
|
43
27
|
}
|
|
44
28
|
}
|
|
45
29
|
}
|
|
@@ -47,10 +31,15 @@
|
|
|
47
31
|
|
|
48
32
|
let scriptsInserted = [];
|
|
49
33
|
let scriptsRun = [];
|
|
34
|
+
let ranInitFn = false;
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
function onUpdateFn_0() {
|
|
37
|
+
if (elem && !ranInitFn) {
|
|
38
|
+
ranInitFn = true;
|
|
39
|
+
findAndRunScripts();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
$: onUpdateFn_0(...[elem, ranInitFn]);
|
|
54
43
|
</script>
|
|
55
44
|
|
|
56
45
|
<div class="builder-embed" bind:this={elem}>{@html content}</div>
|
|
@@ -35,14 +35,7 @@
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
$: onUpdateFn_0(
|
|
39
|
-
...[
|
|
40
|
-
props.symbol?.content,
|
|
41
|
-
props.symbol?.model,
|
|
42
|
-
props.symbol?.entry,
|
|
43
|
-
state.content,
|
|
44
|
-
]
|
|
45
|
-
);
|
|
38
|
+
$: onUpdateFn_0(...[symbol?.content, symbol?.model, symbol?.entry, content]);
|
|
46
39
|
</script>
|
|
47
40
|
|
|
48
41
|
<div
|
|
@@ -30,6 +30,8 @@ import { componentInfo as textComponentInfo } from "../blocks/text/component-inf
|
|
|
30
30
|
import { default as Text } from "../blocks/text/text.svelte";
|
|
31
31
|
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
32
32
|
import { default as Video } from "../blocks/video/video.svelte";
|
|
33
|
+
import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
|
|
34
|
+
import { default as embed } from "../blocks/embed/embed.svelte";
|
|
33
35
|
const getDefaultRegisteredComponents = () => [
|
|
34
36
|
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
35
37
|
__spreadValues({ component: Image }, imageComponentInfo),
|
|
@@ -38,7 +40,8 @@ const getDefaultRegisteredComponents = () => [
|
|
|
38
40
|
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
39
41
|
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
40
42
|
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
41
|
-
__spreadValues({ component: Fragment }, fragmentComponentInfo)
|
|
43
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo),
|
|
44
|
+
__spreadValues({ component: embed }, embedComponentInfo)
|
|
42
45
|
];
|
|
43
46
|
export {
|
|
44
47
|
getDefaultRegisteredComponents
|
|
@@ -29,7 +29,6 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import { fastClone } from "./fast-clone.js";
|
|
33
32
|
const components = [];
|
|
34
33
|
function registerComponent(component, info) {
|
|
35
34
|
components.push(__spreadValues({ component }, info));
|
|
@@ -38,31 +37,24 @@ function registerComponent(component, info) {
|
|
|
38
37
|
}
|
|
39
38
|
const createRegisterComponentMessage = (_a) => {
|
|
40
39
|
var _b = _a, {
|
|
41
|
-
component
|
|
40
|
+
component: _
|
|
42
41
|
} = _b, info = __objRest(_b, [
|
|
43
42
|
"component"
|
|
44
43
|
]);
|
|
45
44
|
return {
|
|
46
45
|
type: "builder.registerComponent",
|
|
47
|
-
data: prepareComponentInfoToSend(
|
|
46
|
+
data: prepareComponentInfoToSend(info)
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
input = __spreadProps(__spreadValues({}, input), {
|
|
58
|
-
[key]: `return (${fn.toString()}).apply(this, arguments)`
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return input;
|
|
63
|
-
})
|
|
49
|
+
const serializeFn = (fn) => `return (${fn.toString()}).apply(this, arguments)`;
|
|
50
|
+
const prepareComponentInfoToSend = (info) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return __spreadProps(__spreadValues({}, info), {
|
|
53
|
+
inputs: (_a = info.inputs) == null ? void 0 : _a.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
54
|
+
[key]: typeof value === "function" ? serializeFn(value) : value
|
|
55
|
+
}), {}))
|
|
64
56
|
});
|
|
65
|
-
}
|
|
57
|
+
};
|
|
66
58
|
export {
|
|
67
59
|
components,
|
|
68
60
|
createRegisterComponentMessage,
|