@builder.io/sdk-solid 0.0.1
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/README.md +3 -0
- package/package.json +9 -0
- package/src/blocks/button.js +41 -0
- package/src/blocks/button.lite.tsx +18 -0
- package/src/blocks/columns.js +133 -0
- package/src/blocks/columns.lite.tsx +96 -0
- package/src/blocks/custom-code.js +72 -0
- package/src/blocks/custom-code.lite.tsx +65 -0
- package/src/blocks/embed.js +62 -0
- package/src/blocks/embed.lite.tsx +57 -0
- package/src/blocks/form.js +355 -0
- package/src/blocks/form.lite.tsx +291 -0
- package/src/blocks/fragment.js +15 -0
- package/src/blocks/fragment.lite.tsx +3 -0
- package/src/blocks/image.js +136 -0
- package/src/blocks/image.lite.tsx +81 -0
- package/src/blocks/img.js +39 -0
- package/src/blocks/img.lite.tsx +16 -0
- package/src/blocks/input.js +45 -0
- package/src/blocks/input.lite.tsx +18 -0
- package/src/blocks/raw-text.js +25 -0
- package/src/blocks/raw-text.lite.tsx +8 -0
- package/src/blocks/section.js +24 -0
- package/src/blocks/section.lite.tsx +16 -0
- package/src/blocks/select.js +57 -0
- package/src/blocks/select.lite.tsx +23 -0
- package/src/blocks/submit-button.js +18 -0
- package/src/blocks/submit-button.lite.tsx +7 -0
- package/src/blocks/symbol.js +69 -0
- package/src/blocks/symbol.lite.tsx +37 -0
- package/src/blocks/text.js +15 -0
- package/src/blocks/text.lite.tsx +3 -0
- package/src/blocks/textarea.js +34 -0
- package/src/blocks/textarea.lite.tsx +11 -0
- package/src/blocks/video.js +54 -0
- package/src/blocks/video.lite.tsx +24 -0
- package/src/components/block-styles.js +3 -0
- package/src/components/block-styles.lite.tsx +3 -0
- package/src/components/error-boundary.js +3 -0
- package/src/components/error-boundary.lite.tsx +3 -0
- package/src/components/render-block.js +154 -0
- package/src/components/render-block.lite.tsx +108 -0
- package/src/components/render-blocks.js +104 -0
- package/src/components/render-blocks.lite.tsx +72 -0
- package/src/components/render-content.js +314 -0
- package/src/components/render-content.lite.tsx +289 -0
- package/src/constants/device-sizes.js +39 -0
- package/src/context/builder.context.js +10 -0
- package/src/functions/evaluate.js +28 -0
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +23 -0
- package/src/functions/get-block-properties.js +29 -0
- package/src/functions/get-block-styles.js +42 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +22 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +137 -0
- package/src/functions/get-fetch.js +12 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +46 -0
- package/src/functions/get-processed-block.test.js +31 -0
- package/src/functions/get-target.js +6 -0
- package/src/functions/if-target.js +6 -0
- package/src/functions/is-browser.js +6 -0
- package/src/functions/is-editing.js +7 -0
- package/src/functions/is-iframe.js +7 -0
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/is-react-native.js +6 -0
- package/src/functions/macro-eval.js +5 -0
- package/src/functions/on-change.js +27 -0
- package/src/functions/on-change.test.js +19 -0
- package/src/functions/previewing-model-name.js +11 -0
- package/src/functions/register-component.js +53 -0
- package/src/functions/register.js +29 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +11 -0
- package/src/functions/set.test.js +16 -0
- package/src/functions/track.js +22 -0
- package/src/functions/transform-block.js +6 -0
- package/src/index-helpers/blocks-exports.js +20 -0
- package/src/index-helpers/top-of-file.js +4 -0
- package/src/index.js +13 -0
- package/src/scripts/init-editing.js +70 -0
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/typescript.js +0 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { template as _$template } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { setAttribute as _$setAttribute } from "solid-js/web";
|
|
4
|
+
import { effect as _$effect } from "solid-js/web";
|
|
5
|
+
import { insert as _$insert } from "solid-js/web";
|
|
6
|
+
import { spread as _$spread } from "solid-js/web";
|
|
7
|
+
|
|
8
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<a role="button"></a>`, 2);
|
|
9
|
+
|
|
10
|
+
import { Show } from "solid-js";
|
|
11
|
+
export default function Button(props) {
|
|
12
|
+
return _$createComponent(Show, {
|
|
13
|
+
get when() {
|
|
14
|
+
return props.link;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
get children() {
|
|
18
|
+
const _el$ = _tmpl$.cloneNode(true);
|
|
19
|
+
|
|
20
|
+
_$spread(_el$, () => props.attributes, false, true);
|
|
21
|
+
|
|
22
|
+
_$insert(_el$, () => props.text);
|
|
23
|
+
|
|
24
|
+
_$effect(_p$ => {
|
|
25
|
+
const _v$ = props.link,
|
|
26
|
+
_v$2 = props.openLinkInNewTab ? "_blank" : undefined;
|
|
27
|
+
|
|
28
|
+
_v$ !== _p$._v$ && _$setAttribute(_el$, "href", _p$._v$ = _v$);
|
|
29
|
+
_v$2 !== _p$._v$2 && _$setAttribute(_el$, "target", _p$._v$2 = _v$2);
|
|
30
|
+
return _p$;
|
|
31
|
+
}, {
|
|
32
|
+
_v$: undefined,
|
|
33
|
+
_v$2: undefined
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return _el$;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
}import { registerComponent } from '../functions/register-component';
|
|
41
|
+
registerComponent(Button, {name:'Core:Button',builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',defaultStyles:{appearance:'none',paddingTop:'15px',paddingBottom:'15px',paddingLeft:'25px',paddingRight:'25px',backgroundColor:'#000000',color:'white',borderRadius:'4px',textAlign:'center',cursor:'pointer'},inputs:[{name:'text',type:'text',defaultValue:'Click me!',bubble:true},{name:'link',type:'url',bubble:true},{name:'openLinkInNewTab',type:'boolean',defaultValue:false,friendlyName:'Open link in new tab'}],static:true,noWrap:true});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
|
|
3
|
+
export default function Button(props) {
|
|
4
|
+
return (
|
|
5
|
+
<>
|
|
6
|
+
<Show when={props.link}>
|
|
7
|
+
<a
|
|
8
|
+
{...props.attributes}
|
|
9
|
+
role="button"
|
|
10
|
+
href={props.link}
|
|
11
|
+
target={props.openLinkInNewTab ? "_blank" : undefined}
|
|
12
|
+
>
|
|
13
|
+
{props.text}
|
|
14
|
+
</a>
|
|
15
|
+
</Show>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { template as _$template } from "solid-js/web";
|
|
2
|
+
import { style as _$style } from "solid-js/web";
|
|
3
|
+
import { effect as _$effect } from "solid-js/web";
|
|
4
|
+
import { insert as _$insert } from "solid-js/web";
|
|
5
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
6
|
+
|
|
7
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
|
|
8
|
+
|
|
9
|
+
import { For } from "solid-js";
|
|
10
|
+
import { createMutable } from "solid-js/store";
|
|
11
|
+
import { css } from "solid-styled-components";
|
|
12
|
+
import RenderBlocks from "../components/render-blocks";
|
|
13
|
+
export default function Columns(props) {
|
|
14
|
+
const state = createMutable({
|
|
15
|
+
getGutterSize() {
|
|
16
|
+
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
getColumns() {
|
|
20
|
+
return props.columns || [];
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
getWidth(index) {
|
|
24
|
+
const columns = this.getColumns();
|
|
25
|
+
return columns[index]?.width || 100 / columns.length;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
getColumnCssWidth(index) {
|
|
29
|
+
const columns = this.getColumns();
|
|
30
|
+
const gutterSize = this.getGutterSize();
|
|
31
|
+
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
32
|
+
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
maybeApplyForTablet(prop) {
|
|
36
|
+
const stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
37
|
+
return stackColumnsAt === "tablet" ? prop : "inherit";
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
get columnsCssVars() {
|
|
41
|
+
const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
|
|
42
|
+
return {
|
|
43
|
+
"--flex-dir": flexDir,
|
|
44
|
+
"--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
get 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
|
+
return (() => {
|
|
61
|
+
const _el$ = _tmpl$.cloneNode(true);
|
|
62
|
+
|
|
63
|
+
_$insert(_el$, _$createComponent(For, {
|
|
64
|
+
get each() {
|
|
65
|
+
return props.columns;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
children: (column, index) => (() => {
|
|
69
|
+
const _el$2 = _tmpl$.cloneNode(true);
|
|
70
|
+
|
|
71
|
+
_$insert(_el$2, _$createComponent(RenderBlocks, {
|
|
72
|
+
get blocks() {
|
|
73
|
+
return column.blocks;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
_$effect(_p$ => {
|
|
79
|
+
const _v$3 = css({
|
|
80
|
+
flexGrow: "1",
|
|
81
|
+
"@media (max-width: 999px)": {
|
|
82
|
+
width: "var(--column-width-tablet) !important",
|
|
83
|
+
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
84
|
+
},
|
|
85
|
+
"@media (max-width: 639px)": {
|
|
86
|
+
width: "var(--column-width) !important",
|
|
87
|
+
marginLeft: "var(--column-margin-left) !important"
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
_v$4 = {
|
|
91
|
+
width: state.getColumnCssWidth(index),
|
|
92
|
+
marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
93
|
+
...state.columnCssVars
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
_v$3 !== _p$._v$3 && (_el$2.className = _p$._v$3 = _v$3);
|
|
97
|
+
_p$._v$4 = _$style(_el$2, _v$4, _p$._v$4);
|
|
98
|
+
return _p$;
|
|
99
|
+
}, {
|
|
100
|
+
_v$3: undefined,
|
|
101
|
+
_v$4: undefined
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return _el$2;
|
|
105
|
+
})()
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
_$effect(_p$ => {
|
|
109
|
+
const _v$ = css({
|
|
110
|
+
display: "flex",
|
|
111
|
+
alignItems: "stretch",
|
|
112
|
+
lineHeight: "normal",
|
|
113
|
+
"@media (max-width: 999px)": {
|
|
114
|
+
flexDirection: "var(--flex-dir-tablet)"
|
|
115
|
+
},
|
|
116
|
+
"@media (max-width: 639px)": {
|
|
117
|
+
flexDirection: "var(--flex-dir)"
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
_v$2 = state.columnsCssVars;
|
|
121
|
+
|
|
122
|
+
_v$ !== _p$._v$ && (_el$.className = _p$._v$ = _v$);
|
|
123
|
+
_p$._v$2 = _$style(_el$, _v$2, _p$._v$2);
|
|
124
|
+
return _p$;
|
|
125
|
+
}, {
|
|
126
|
+
_v$: undefined,
|
|
127
|
+
_v$2: undefined
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return _el$;
|
|
131
|
+
})();
|
|
132
|
+
}import { registerComponent } from '../functions/register-component';
|
|
133
|
+
registerComponent(Columns, {name:'Columns',builtIn:true,inputs:[{name:'columns',type:'array',broadcast:true,subFields:[{name:'blocks',type:'array',hideFromUI:true,defaultValue:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]},{name:'width',type:'number',hideFromUI:true,helperText:'Width %, e.g. set to 50 to fill half of the space'},{name:'link',type:'url',helperText:'Optionally set a url that clicking this column will link to'}],defaultValue:[{blocks:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]},{blocks:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]}],onChange:" function clearWidths() { columns.forEach(col => { col.delete('width'); }); } const columns = options.get('columns') as Array<Map<String, any>>; if (Array.isArray(columns)) { const containsColumnWithWidth = !!columns.find(col => col.get('width')); if (containsColumnWithWidth) { const containsColumnWithoutWidth = !!columns.find(col => !col.get('width')); if (containsColumnWithoutWidth) { clearWidths(); } else { const sumWidths = columns.reduce((memo, col) => { return memo + col.get('width'); }, 0); const widthsDontAddUp = sumWidths !== 100; if (widthsDontAddUp) { clearWidths(); } } } } "},{name:'space',type:'number',defaultValue:20,helperText:'Size of gap between columns',advanced:true},{name:'stackColumnsAt',type:'string',defaultValue:'tablet',helperText:'Convert horizontal columns to vertical at what device size',enum:['tablet','mobile','never'],advanced:true},{name:'reverseColumnsWhenStacked',type:'boolean',defaultValue:false,helperText:'When stacking columns for mobile devices, reverse the ordering',advanced:true}]});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { For } from "solid-js";
|
|
2
|
+
|
|
3
|
+
import { createMutable } from "solid-js/store";
|
|
4
|
+
import { css } from "solid-styled-components";
|
|
5
|
+
|
|
6
|
+
import RenderBlocks from "../components/render-blocks.lite";
|
|
7
|
+
|
|
8
|
+
export default function Columns(props) {
|
|
9
|
+
const state = createMutable({
|
|
10
|
+
getGutterSize() {
|
|
11
|
+
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
12
|
+
},
|
|
13
|
+
getColumns() {
|
|
14
|
+
return props.columns || [];
|
|
15
|
+
},
|
|
16
|
+
getWidth(index: number) {
|
|
17
|
+
const columns = this.getColumns();
|
|
18
|
+
return columns[index]?.width || 100 / columns.length;
|
|
19
|
+
},
|
|
20
|
+
getColumnCssWidth(index: number) {
|
|
21
|
+
const columns = this.getColumns();
|
|
22
|
+
const gutterSize = this.getGutterSize();
|
|
23
|
+
const subtractWidth =
|
|
24
|
+
(gutterSize * (columns.length - 1)) / columns.length;
|
|
25
|
+
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
26
|
+
},
|
|
27
|
+
maybeApplyForTablet(prop: string) {
|
|
28
|
+
const stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
29
|
+
return stackColumnsAt === "tablet" ? prop : "inherit";
|
|
30
|
+
},
|
|
31
|
+
get columnsCssVars() {
|
|
32
|
+
const flexDir =
|
|
33
|
+
props.stackColumnsAt === "never"
|
|
34
|
+
? "inherit"
|
|
35
|
+
: props.reverseColumnsWhenStacked
|
|
36
|
+
? "column-reverse"
|
|
37
|
+
: "column";
|
|
38
|
+
return {
|
|
39
|
+
"--flex-dir": flexDir,
|
|
40
|
+
"--flex-dir-tablet": this.maybeApplyForTablet(flexDir),
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
get columnCssVars() {
|
|
44
|
+
const width = "100%";
|
|
45
|
+
const marginLeft = "0";
|
|
46
|
+
return {
|
|
47
|
+
"--column-width": width,
|
|
48
|
+
"--column-margin-left": marginLeft,
|
|
49
|
+
"--column-width-tablet": this.maybeApplyForTablet(width),
|
|
50
|
+
"--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div
|
|
57
|
+
class={css({
|
|
58
|
+
display: "flex",
|
|
59
|
+
alignItems: "stretch",
|
|
60
|
+
lineHeight: "normal",
|
|
61
|
+
"@media (max-width: 999px)": {
|
|
62
|
+
flexDirection: "var(--flex-dir-tablet)",
|
|
63
|
+
},
|
|
64
|
+
"@media (max-width: 639px)": {
|
|
65
|
+
flexDirection: "var(--flex-dir)",
|
|
66
|
+
},
|
|
67
|
+
})}
|
|
68
|
+
style={state.columnsCssVars}
|
|
69
|
+
>
|
|
70
|
+
<For each={props.columns}>
|
|
71
|
+
{(column, index) => (
|
|
72
|
+
<div
|
|
73
|
+
class={css({
|
|
74
|
+
flexGrow: "1",
|
|
75
|
+
"@media (max-width: 999px)": {
|
|
76
|
+
width: "var(--column-width-tablet) !important",
|
|
77
|
+
marginLeft: "var(--column-margin-left-tablet) !important",
|
|
78
|
+
},
|
|
79
|
+
"@media (max-width: 639px)": {
|
|
80
|
+
width: "var(--column-width) !important",
|
|
81
|
+
marginLeft: "var(--column-margin-left) !important",
|
|
82
|
+
},
|
|
83
|
+
})}
|
|
84
|
+
style={{
|
|
85
|
+
width: state.getColumnCssWidth(index),
|
|
86
|
+
marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
87
|
+
...state.columnCssVars,
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
<RenderBlocks blocks={column.blocks}></RenderBlocks>
|
|
91
|
+
</div>
|
|
92
|
+
)}
|
|
93
|
+
</For>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { template as _$template } from "solid-js/web";
|
|
2
|
+
import { effect as _$effect } from "solid-js/web";
|
|
3
|
+
|
|
4
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
|
|
5
|
+
|
|
6
|
+
import { createMutable } from "solid-js/store";
|
|
7
|
+
export default function CustomCode(props) {
|
|
8
|
+
const state = createMutable({
|
|
9
|
+
scriptsInserted: [],
|
|
10
|
+
scriptsRun: [],
|
|
11
|
+
|
|
12
|
+
findAndRunScripts() {
|
|
13
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
14
|
+
if (elem && typeof window !== "undefined") {
|
|
15
|
+
/** @type {HTMLScriptElement[]} */
|
|
16
|
+
const scripts = elem.getElementsByTagName("script");
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
19
|
+
const script = scripts[i];
|
|
20
|
+
|
|
21
|
+
if (script.src) {
|
|
22
|
+
if (state.scriptsInserted.includes(script.src)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
state.scriptsInserted.push(script.src);
|
|
27
|
+
const newScript = document.createElement("script");
|
|
28
|
+
newScript.async = true;
|
|
29
|
+
newScript.src = script.src;
|
|
30
|
+
document.head.appendChild(newScript);
|
|
31
|
+
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
32
|
+
if (state.scriptsRun.includes(script.innerText)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
state.scriptsRun.push(script.innerText);
|
|
38
|
+
new Function(script.innerText)();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
});
|
|
48
|
+
const elem = useRef();
|
|
49
|
+
onMount(() => {
|
|
50
|
+
state.findAndRunScripts();
|
|
51
|
+
});
|
|
52
|
+
return (() => {
|
|
53
|
+
const _el$ = _tmpl$.cloneNode(true);
|
|
54
|
+
|
|
55
|
+
elem(_el$);
|
|
56
|
+
|
|
57
|
+
_$effect(_p$ => {
|
|
58
|
+
const _v$ = "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
|
|
59
|
+
_v$2 = props.code;
|
|
60
|
+
|
|
61
|
+
_v$ !== _p$._v$ && (_el$.className = _p$._v$ = _v$);
|
|
62
|
+
_v$2 !== _p$._v$2 && (_el$.innerHTML = _p$._v$2 = _v$2);
|
|
63
|
+
return _p$;
|
|
64
|
+
}, {
|
|
65
|
+
_v$: undefined,
|
|
66
|
+
_v$2: undefined
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return _el$;
|
|
70
|
+
})();
|
|
71
|
+
}import { registerComponent } from '../functions/register-component';
|
|
72
|
+
registerComponent(CustomCode, {name:'Custom Code',static:true,builtIn:true,requiredPermissions:['editCode'],inputs:[{name:'code',type:'html',required:true,defaultValue:'<p>Hello there, I am custom HTML code!</p>',code:true},{name:'replaceNodes',type:'boolean',helperText:'Preserve server rendered dom nodes',advanced:true},{name:'scriptsClientOnly',type:'boolean',defaultValue:false,helperText:'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',advanced:true}]});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createMutable } from "solid-js/store";
|
|
2
|
+
|
|
3
|
+
export default function CustomCode(props) {
|
|
4
|
+
const state = createMutable({
|
|
5
|
+
scriptsInserted: [],
|
|
6
|
+
scriptsRun: [],
|
|
7
|
+
findAndRunScripts() {
|
|
8
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
9
|
+
if (elem && typeof window !== "undefined") {
|
|
10
|
+
/** @type {HTMLScriptElement[]} */
|
|
11
|
+
const scripts = elem.getElementsByTagName("script");
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
14
|
+
const script = scripts[i];
|
|
15
|
+
|
|
16
|
+
if (script.src) {
|
|
17
|
+
if (state.scriptsInserted.includes(script.src)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
state.scriptsInserted.push(script.src);
|
|
22
|
+
const newScript = document.createElement("script");
|
|
23
|
+
newScript.async = true;
|
|
24
|
+
newScript.src = script.src;
|
|
25
|
+
document.head.appendChild(newScript);
|
|
26
|
+
} else if (
|
|
27
|
+
!script.type ||
|
|
28
|
+
[
|
|
29
|
+
"text/javascript",
|
|
30
|
+
"application/javascript",
|
|
31
|
+
"application/ecmascript",
|
|
32
|
+
].includes(script.type)
|
|
33
|
+
) {
|
|
34
|
+
if (state.scriptsRun.includes(script.innerText)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
state.scriptsRun.push(script.innerText);
|
|
40
|
+
new Function(script.innerText)();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const elem = useRef();
|
|
51
|
+
|
|
52
|
+
onMount(() => {
|
|
53
|
+
state.findAndRunScripts();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
class={
|
|
59
|
+
"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")
|
|
60
|
+
}
|
|
61
|
+
ref={elem}
|
|
62
|
+
innerHTML={props.code}
|
|
63
|
+
></div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { template as _$template } from "solid-js/web";
|
|
2
|
+
import { effect as _$effect } from "solid-js/web";
|
|
3
|
+
|
|
4
|
+
const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
|
|
5
|
+
|
|
6
|
+
import { createMutable } from "solid-js/store";
|
|
7
|
+
export default function Embed(props) {
|
|
8
|
+
const state = createMutable({
|
|
9
|
+
scriptsInserted: [],
|
|
10
|
+
scriptsRun: [],
|
|
11
|
+
|
|
12
|
+
findAndRunScripts() {
|
|
13
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
14
|
+
if (elem && typeof window !== "undefined") {
|
|
15
|
+
/** @type {HTMLScriptElement[]} */
|
|
16
|
+
const scripts = elem.getElementsByTagName("script");
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
19
|
+
const script = scripts[i];
|
|
20
|
+
|
|
21
|
+
if (script.src) {
|
|
22
|
+
if (state.scriptsInserted.includes(script.src)) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
state.scriptsInserted.push(script.src);
|
|
27
|
+
const newScript = document.createElement("script");
|
|
28
|
+
newScript.async = true;
|
|
29
|
+
newScript.src = script.src;
|
|
30
|
+
document.head.appendChild(newScript);
|
|
31
|
+
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
32
|
+
if (state.scriptsRun.includes(script.innerText)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
state.scriptsRun.push(script.innerText);
|
|
38
|
+
new Function(script.innerText)();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn("`Embed`: Error running script:", error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
});
|
|
48
|
+
const elem = useRef();
|
|
49
|
+
onMount(() => {
|
|
50
|
+
state.findAndRunScripts();
|
|
51
|
+
});
|
|
52
|
+
return (() => {
|
|
53
|
+
const _el$ = _tmpl$.cloneNode(true);
|
|
54
|
+
|
|
55
|
+
elem(_el$);
|
|
56
|
+
|
|
57
|
+
_$effect(() => _el$.innerHTML = props.content);
|
|
58
|
+
|
|
59
|
+
return _el$;
|
|
60
|
+
})();
|
|
61
|
+
}import { registerComponent } from '../functions/register-component';
|
|
62
|
+
registerComponent(Embed, {name:'Embed',static:true,builtIn:true,inputs:[{name:'url',type:'url',required:true,defaultValue:'',helperText:'e.g. enter a youtube url, google map, etc',onChange:" const url = options.get('url'); if (url) { options.set('content', 'Loading...'); // TODO: get this out of here! const apiKey = 'ae0e60e78201a3f2b0de4b'; return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`) .then(res => res.json()) .then(data => { if (options.get('url') === url) { if (data.html) { options.set('content', data.html); } else { options.set('content', 'Invalid url, please try another'); } } }) .catch(err => { options.set( 'content', 'There was an error embedding this URL, please try again or another URL' ); }); } else { options.delete('content'); } "},{name:'content',type:'html',defaultValue:'<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',hideFromUI:true}]});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createMutable } from "solid-js/store";
|
|
2
|
+
|
|
3
|
+
export default function Embed(props) {
|
|
4
|
+
const state = createMutable({
|
|
5
|
+
scriptsInserted: [],
|
|
6
|
+
scriptsRun: [],
|
|
7
|
+
findAndRunScripts() {
|
|
8
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
9
|
+
if (elem && typeof window !== "undefined") {
|
|
10
|
+
/** @type {HTMLScriptElement[]} */
|
|
11
|
+
const scripts = elem.getElementsByTagName("script");
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
14
|
+
const script = scripts[i];
|
|
15
|
+
|
|
16
|
+
if (script.src) {
|
|
17
|
+
if (state.scriptsInserted.includes(script.src)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
state.scriptsInserted.push(script.src);
|
|
22
|
+
const newScript = document.createElement("script");
|
|
23
|
+
newScript.async = true;
|
|
24
|
+
newScript.src = script.src;
|
|
25
|
+
document.head.appendChild(newScript);
|
|
26
|
+
} else if (
|
|
27
|
+
!script.type ||
|
|
28
|
+
[
|
|
29
|
+
"text/javascript",
|
|
30
|
+
"application/javascript",
|
|
31
|
+
"application/ecmascript",
|
|
32
|
+
].includes(script.type)
|
|
33
|
+
) {
|
|
34
|
+
if (state.scriptsRun.includes(script.innerText)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
state.scriptsRun.push(script.innerText);
|
|
40
|
+
new Function(script.innerText)();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn("`Embed`: Error running script:", error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const elem = useRef();
|
|
51
|
+
|
|
52
|
+
onMount(() => {
|
|
53
|
+
state.findAndRunScripts();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return <div ref={elem} innerHTML={props.content}></div>;
|
|
57
|
+
}
|