@builder.io/sdk-vue 0.0.1-68 → 0.0.1-70
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 +2 -2
- package/vue2/src/blocks/button/button.vue +31 -5
- package/vue2/src/blocks/columns/columns.vue +76 -63
- package/vue2/src/blocks/columns/component-info.js +3 -2
- package/vue2/src/blocks/custom-code/custom-code.vue +70 -60
- package/vue2/src/blocks/embed/component-info.js +3 -2
- package/vue2/src/blocks/embed/embed.vue +68 -55
- package/vue2/src/blocks/form/form.vue +294 -260
- package/vue2/src/blocks/fragment/fragment.vue +31 -6
- package/vue2/src/blocks/image/component-info.js +3 -2
- package/vue2/src/blocks/image/image.vue +77 -62
- package/vue2/src/blocks/img/img.vue +38 -17
- package/vue2/src/blocks/input/input.vue +37 -18
- package/vue2/src/blocks/raw-text/raw-text.vue +34 -13
- package/vue2/src/blocks/section/section.vue +32 -6
- package/vue2/src/blocks/select/select.vue +35 -7
- package/vue2/src/blocks/submit-button/submit-button.vue +29 -5
- package/vue2/src/blocks/symbol/symbol.vue +102 -84
- package/vue2/src/blocks/text/text.vue +28 -5
- package/vue2/src/blocks/textarea/textarea.vue +32 -5
- package/vue2/src/blocks/util.js +7 -0
- package/vue2/src/blocks/video/video.vue +69 -57
- package/vue2/src/components/render-block/block-styles.vue +56 -54
- package/vue2/src/components/render-block/render-block.vue +168 -168
- package/vue2/src/components/render-block/render-component.vue +35 -9
- package/vue2/src/components/render-block/render-repeated-block.vue +55 -32
- package/vue2/src/components/render-blocks.vue +66 -52
- package/vue2/src/components/render-content/components/render-styles.vue +80 -56
- package/vue2/src/components/render-content/render-content.vue +280 -285
- package/vue2/src/components/render-inlined-styles.vue +39 -21
- package/vue2/src/constants/builder-registered-components.js +3 -0
- package/vue2/src/functions/get-fetch.js +2 -2
- package/vue2/src/functions/get-processed-block.js +10 -6
- package/vue2/src/functions/get-processed-block.test.js +1 -1
- package/vue2/src/functions/track.js +71 -2
- package/vue2/src/helpers/cookie.js +59 -0
- package/vue2/src/helpers/localStorage.js +34 -0
- package/vue2/src/helpers/nullable.js +4 -0
- package/vue2/src/helpers/sessionId.js +26 -0
- package/vue2/src/helpers/time.js +5 -0
- package/vue2/src/helpers/url.js +10 -0
- package/vue2/src/helpers/url.test.js +15 -0
- package/vue2/src/helpers/uuid.js +13 -0
- package/vue2/src/helpers/visitorId.js +33 -0
- package/vue2/src/scripts/init-editing.js +4 -5
- package/vue2/src/types/can-track.js +0 -0
- package/vue3/src/blocks/button/button.vue +32 -8
- package/vue3/src/blocks/columns/columns.vue +84 -73
- package/vue3/src/blocks/columns/component-info.js +3 -2
- package/vue3/src/blocks/custom-code/custom-code.vue +70 -62
- package/vue3/src/blocks/embed/component-info.js +3 -2
- package/vue3/src/blocks/embed/embed.vue +68 -57
- package/vue3/src/blocks/form/form.vue +297 -268
- package/vue3/src/blocks/fragment/fragment.vue +30 -7
- package/vue3/src/blocks/image/component-info.js +3 -2
- package/vue3/src/blocks/image/image.vue +86 -73
- package/vue3/src/blocks/img/img.vue +34 -15
- package/vue3/src/blocks/input/input.vue +37 -20
- package/vue3/src/blocks/raw-text/raw-text.vue +33 -14
- package/vue3/src/blocks/section/section.vue +31 -7
- package/vue3/src/blocks/select/select.vue +34 -8
- package/vue3/src/blocks/submit-button/submit-button.vue +28 -6
- package/vue3/src/blocks/symbol/symbol.vue +102 -86
- package/vue3/src/blocks/text/text.vue +27 -6
- package/vue3/src/blocks/textarea/textarea.vue +31 -6
- package/vue3/src/blocks/util.js +7 -0
- package/vue3/src/blocks/video/video.vue +69 -59
- package/vue3/src/components/render-block/block-styles.vue +56 -58
- package/vue3/src/components/render-block/render-block.vue +171 -173
- package/vue3/src/components/render-block/render-component.vue +35 -16
- package/vue3/src/components/render-block/render-repeated-block.vue +55 -34
- package/vue3/src/components/render-blocks.vue +65 -58
- package/vue3/src/components/render-content/components/render-styles.vue +80 -60
- package/vue3/src/components/render-content/render-content.vue +283 -287
- package/vue3/src/components/render-inlined-styles.vue +34 -18
- package/vue3/src/constants/builder-registered-components.js +3 -0
- package/vue3/src/functions/get-fetch.js +2 -2
- package/vue3/src/functions/get-processed-block.js +10 -6
- package/vue3/src/functions/get-processed-block.test.js +1 -1
- package/vue3/src/functions/track.js +71 -2
- package/vue3/src/helpers/cookie.js +59 -0
- package/vue3/src/helpers/localStorage.js +34 -0
- package/vue3/src/helpers/nullable.js +4 -0
- package/vue3/src/helpers/sessionId.js +26 -0
- package/vue3/src/helpers/time.js +5 -0
- package/vue3/src/helpers/url.js +10 -0
- package/vue3/src/helpers/url.test.js +15 -0
- package/vue3/src/helpers/uuid.js +13 -0
- package/vue3/src/helpers/visitorId.js +33 -0
- package/vue3/src/scripts/init-editing.js +4 -5
- package/vue3/src/types/can-track.js +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-vue",
|
|
3
3
|
"description": "Builder.io SDK for Vue",
|
|
4
|
-
"version": "0.0.1-
|
|
4
|
+
"version": "0.0.1-70",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"node-fetch": "^2.6.1"
|
|
7
7
|
},
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"vue": ">= 2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"vue": "^2.
|
|
40
|
+
"vue": "^2.7"
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -12,12 +12,38 @@
|
|
|
12
12
|
{{ text }}
|
|
13
13
|
</button>
|
|
14
14
|
</template>
|
|
15
|
-
<script>
|
|
16
|
-
export default {
|
|
17
|
-
name: "builder-button",
|
|
15
|
+
<script lang="ts">
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export interface ButtonProps {
|
|
24
|
+
attributes?: any;
|
|
25
|
+
text?: string;
|
|
26
|
+
link?: string;
|
|
27
|
+
openLinkInNewTab?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
name: 'builder-button',
|
|
32
|
+
|
|
33
|
+
props: ["attributes","text","link","openLinkInNewTab"],
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}
|
|
21
47
|
</script>
|
|
22
48
|
<style scoped>
|
|
23
49
|
.button-16nol0lwi20 {
|
|
@@ -18,70 +18,83 @@
|
|
|
18
18
|
</div>
|
|
19
19
|
</div>
|
|
20
20
|
</template>
|
|
21
|
-
<script>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
],
|
|
34
|
-
|
|
35
|
-
computed: {
|
|
36
|
-
columnsCssVars() {
|
|
37
|
-
const flexDir =
|
|
38
|
-
this.stackColumnsAt === "never"
|
|
39
|
-
? "inherit"
|
|
40
|
-
: this.reverseColumnsWhenStacked
|
|
41
|
-
? "column-reverse"
|
|
42
|
-
: "column";
|
|
43
|
-
return {
|
|
44
|
-
"--flex-dir": flexDir,
|
|
45
|
-
"--flex-dir-tablet": this.maybeApplyForTablet(flexDir),
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
columnCssVars() {
|
|
49
|
-
const width = "100%";
|
|
50
|
-
const marginLeft = "0";
|
|
51
|
-
return {
|
|
52
|
-
"--column-width": width,
|
|
53
|
-
"--column-margin-left": marginLeft,
|
|
54
|
-
"--column-width-tablet": this.maybeApplyForTablet(width),
|
|
55
|
-
"--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft),
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
methods: {
|
|
61
|
-
getGutterSize() {
|
|
62
|
-
return typeof this.space === "number" ? this.space || 0 : 20;
|
|
63
|
-
},
|
|
64
|
-
getColumns() {
|
|
65
|
-
return this.columns || [];
|
|
66
|
-
},
|
|
67
|
-
getWidth(index) {
|
|
68
|
-
const columns = this.getColumns();
|
|
69
|
-
return columns[index]?.width || 100 / columns.length;
|
|
70
|
-
},
|
|
71
|
-
getColumnCssWidth(index) {
|
|
72
|
-
const columns = this.getColumns();
|
|
73
|
-
const gutterSize = this.getGutterSize();
|
|
74
|
-
const subtractWidth =
|
|
75
|
-
(gutterSize * (columns.length - 1)) / columns.length;
|
|
76
|
-
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
77
|
-
},
|
|
78
|
-
maybeApplyForTablet(prop) {
|
|
79
|
-
const _stackColumnsAt = this.stackColumnsAt || "tablet";
|
|
80
|
-
|
|
81
|
-
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
82
|
-
},
|
|
83
|
-
},
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const RenderBlocks = () => import('../../components/render-blocks.vue')
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
type Column = {
|
|
30
|
+
blocks: any; // TODO: Implement this when support for dynamic CSS lands
|
|
31
|
+
|
|
32
|
+
width?: number;
|
|
84
33
|
};
|
|
34
|
+
type StackColumnsAt = 'tablet' | 'mobile' | 'never';
|
|
35
|
+
export interface ColumnProps {
|
|
36
|
+
columns?: Column[];
|
|
37
|
+
builderBlock: BuilderBlock; // TODO: Implement this when support for dynamic CSS lands
|
|
38
|
+
|
|
39
|
+
space?: number; // TODO: Implement this when support for dynamic CSS lands
|
|
40
|
+
|
|
41
|
+
stackColumnsAt?: StackColumnsAt; // TODO: Implement this when support for dynamic CSS lands
|
|
42
|
+
|
|
43
|
+
reverseColumnsWhenStacked?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
name: 'builder-columns',
|
|
48
|
+
components: { 'render-blocks': RenderBlocks },
|
|
49
|
+
props: ["space","columns","stackColumnsAt","reverseColumnsWhenStacked","builderBlock"],
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
computed: { columnsCssVars() {
|
|
62
|
+
const flexDir = this.stackColumnsAt === 'never' ? 'inherit' : this.reverseColumnsWhenStacked ? 'column-reverse' : 'column';
|
|
63
|
+
return {
|
|
64
|
+
'--flex-dir': flexDir,
|
|
65
|
+
'--flex-dir-tablet': this.maybeApplyForTablet(flexDir)
|
|
66
|
+
};
|
|
67
|
+
}, columnCssVars() {
|
|
68
|
+
const width = '100%';
|
|
69
|
+
const marginLeft = '0';
|
|
70
|
+
return {
|
|
71
|
+
'--column-width': width,
|
|
72
|
+
'--column-margin-left': marginLeft,
|
|
73
|
+
'--column-width-tablet': this.maybeApplyForTablet(width),
|
|
74
|
+
'--column-margin-left-tablet': this.maybeApplyForTablet(marginLeft)
|
|
75
|
+
};
|
|
76
|
+
},},
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
methods: { getGutterSize() {
|
|
80
|
+
return typeof this.space === 'number' ? this.space || 0 : 20;
|
|
81
|
+
}, getColumns() {
|
|
82
|
+
return this.columns || [];
|
|
83
|
+
}, getWidth(index) {
|
|
84
|
+
const columns = this.getColumns();
|
|
85
|
+
return columns[index]?.width || 100 / columns.length;
|
|
86
|
+
}, getColumnCssWidth(index) {
|
|
87
|
+
const columns = this.getColumns();
|
|
88
|
+
const gutterSize = this.getGutterSize();
|
|
89
|
+
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
90
|
+
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
91
|
+
}, maybeApplyForTablet(prop) {
|
|
92
|
+
const _stackColumnsAt = this.stackColumnsAt || 'tablet';
|
|
93
|
+
|
|
94
|
+
return _stackColumnsAt === 'tablet' ? prop : 'inherit';
|
|
95
|
+
},},
|
|
96
|
+
|
|
97
|
+
}
|
|
85
98
|
</script>
|
|
86
99
|
<style scoped>
|
|
87
100
|
.div-2fnk003dqad {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Columns",
|
|
3
4
|
builtIn: true,
|
|
@@ -186,7 +187,7 @@ const componentInfo = {
|
|
|
186
187
|
]
|
|
187
188
|
}
|
|
188
189
|
],
|
|
189
|
-
onChange(options) {
|
|
190
|
+
onChange: markSerializable((options) => {
|
|
190
191
|
function clearWidths() {
|
|
191
192
|
columns.forEach((col) => {
|
|
192
193
|
col.delete("width");
|
|
@@ -210,7 +211,7 @@ const componentInfo = {
|
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
|
-
}
|
|
214
|
+
})
|
|
214
215
|
},
|
|
215
216
|
{
|
|
216
217
|
name: "space",
|
|
@@ -3,76 +3,86 @@
|
|
|
3
3
|
ref="elem"
|
|
4
4
|
:class="
|
|
5
5
|
_classStringToObject(
|
|
6
|
-
'builder-custom-code' + (
|
|
6
|
+
'builder-custom-code' + (replaceNodes ? ' replace-nodes' : '')
|
|
7
7
|
)
|
|
8
8
|
"
|
|
9
9
|
v-html="code"
|
|
10
10
|
></div>
|
|
11
11
|
</template>
|
|
12
|
-
<script>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.scriptsRun.push(script.innerText);
|
|
57
|
-
new Function(script.innerText)();
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn("`CustomCode`: Error running script:", error);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export interface CustomCodeProps {
|
|
21
|
+
code: string;
|
|
22
|
+
replaceNodes?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
name: 'builder-custom-code',
|
|
27
|
+
|
|
28
|
+
props: ["replaceNodes","code"],
|
|
29
|
+
|
|
30
|
+
data: () => ({ scriptsInserted: [], scriptsRun: [],}),
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
mounted() {
|
|
37
|
+
this.findAndRunScripts()
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
methods: { findAndRunScripts() {
|
|
46
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
47
|
+
if (this.$refs.elem && typeof window !== 'undefined') {
|
|
48
|
+
const scripts = this.$refs.elem.getElementsByTagName('script');
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
51
|
+
const script = scripts[i];
|
|
52
|
+
|
|
53
|
+
if (script.src) {
|
|
54
|
+
if (this.scriptsInserted.includes(script.src)) {
|
|
55
|
+
continue;
|
|
63
56
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
|
|
58
|
+
this.scriptsInserted.push(script.src);
|
|
59
|
+
const newScript = document.createElement('script');
|
|
60
|
+
newScript.async = true;
|
|
61
|
+
newScript.src = script.src;
|
|
62
|
+
document.head.appendChild(newScript);
|
|
63
|
+
} else if (!script.type || ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(script.type)) {
|
|
64
|
+
if (this.scriptsRun.includes(script.innerText)) {
|
|
65
|
+
continue;
|
|
69
66
|
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
this.scriptsRun.push(script.innerText);
|
|
70
|
+
new Function(script.innerText)();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.warn('`CustomCode`: Error running script:', error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},_classStringToObject(str) {
|
|
78
|
+
const obj = {};
|
|
79
|
+
if (typeof str !== 'string') { return obj }
|
|
70
80
|
const classNames = str.trim().split(/\s+/);
|
|
71
81
|
for (const name of classNames) {
|
|
72
82
|
obj[name] = true;
|
|
73
83
|
}
|
|
74
84
|
return obj;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
}
|
|
85
|
+
} },
|
|
86
|
+
|
|
87
|
+
}
|
|
78
88
|
</script>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Embed",
|
|
3
4
|
static: true,
|
|
@@ -9,7 +10,7 @@ const componentInfo = {
|
|
|
9
10
|
required: true,
|
|
10
11
|
defaultValue: "",
|
|
11
12
|
helperText: "e.g. enter a youtube url, google map, etc",
|
|
12
|
-
onChange(options) {
|
|
13
|
+
onChange: markSerializable((options) => {
|
|
13
14
|
const url = options.get("url");
|
|
14
15
|
if (url) {
|
|
15
16
|
options.set("content", "Loading...");
|
|
@@ -28,7 +29,7 @@ const componentInfo = {
|
|
|
28
29
|
} else {
|
|
29
30
|
options.delete("content");
|
|
30
31
|
}
|
|
31
|
-
}
|
|
32
|
+
})
|
|
32
33
|
},
|
|
33
34
|
{
|
|
34
35
|
name: "content",
|
|
@@ -1,60 +1,73 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="builder-embed" ref="elem" v-html="content"></div>
|
|
3
3
|
</template>
|
|
4
|
-
<script>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} else if (
|
|
46
|
-
isJsScript(script) &&
|
|
47
|
-
!this.scriptsRun.includes(script.innerText)
|
|
48
|
-
) {
|
|
49
|
-
try {
|
|
50
|
-
this.scriptsRun.push(script.innerText);
|
|
51
|
-
new Function(script.innerText)();
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.warn("`Embed`: Error running script:", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
},
|
|
4
|
+
<script lang="ts">
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import { isJsScript } from './helpers';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export interface EmbedProps {
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
name: 'builder-embed',
|
|
18
|
+
|
|
19
|
+
props: ["content"],
|
|
20
|
+
|
|
21
|
+
data: () => ({ scriptsInserted: [], scriptsRun: [], ranInitFn: false,}),
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
watch: {
|
|
30
|
+
onUpdateHook0() {
|
|
31
|
+
if (this.$refs.elem && !this.ranInitFn) {
|
|
32
|
+
this.ranInitFn = true;
|
|
33
|
+
this.findAndRunScripts();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
computed: { onUpdateHook0() {
|
|
42
|
+
return {
|
|
43
|
+
0: this.$refs.elem,
|
|
44
|
+
1: this.ranInitFn
|
|
59
45
|
};
|
|
46
|
+
},},
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
methods: { findAndRunScripts() {
|
|
50
|
+
const scripts = this.$refs.elem.getElementsByTagName('script');
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
53
|
+
const script = scripts[i];
|
|
54
|
+
|
|
55
|
+
if (script.src && !this.scriptsInserted.includes(script.src)) {
|
|
56
|
+
this.scriptsInserted.push(script.src);
|
|
57
|
+
const newScript = document.createElement('script');
|
|
58
|
+
newScript.async = true;
|
|
59
|
+
newScript.src = script.src;
|
|
60
|
+
document.head.appendChild(newScript);
|
|
61
|
+
} else if (isJsScript(script) && !this.scriptsRun.includes(script.innerText)) {
|
|
62
|
+
try {
|
|
63
|
+
this.scriptsRun.push(script.innerText);
|
|
64
|
+
new Function(script.innerText)();
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.warn('`Embed`: Error running script:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},},
|
|
71
|
+
|
|
72
|
+
}
|
|
60
73
|
</script>
|