@builder.io/sdk-solid 0.0.6 → 0.0.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/package.json +59 -2
- package/src/blocks/button/button.jsx +13 -0
- package/src/blocks/button/button.lite.tsx +20 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/button/index.js +7 -0
- package/src/blocks/columns/columns.jsx +91 -0
- package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +4 -3
- package/src/blocks/columns/component-info.js +217 -0
- package/src/blocks/columns/index.js +7 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/{custom-code.jsx → custom-code/custom-code.jsx} +1 -2
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +0 -0
- package/src/blocks/custom-code/index.js +7 -0
- package/src/blocks/embed/component-info.js +24 -0
- package/src/blocks/{embed.jsx → embed/embed.jsx} +1 -2
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +0 -0
- package/src/blocks/embed/index.js +7 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/{form.jsx → form/form.jsx} +8 -8
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +7 -6
- package/src/blocks/form/index.js +7 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +5 -0
- package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +0 -0
- package/src/blocks/fragment/index.js +7 -0
- package/src/blocks/image/component-info.js +104 -0
- package/src/blocks/image/image.jsx +54 -0
- package/src/blocks/image/image.lite.tsx +83 -0
- package/src/blocks/image/index.js +7 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +10 -0
- package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +1 -1
- package/src/blocks/img/index.js +7 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/index.js +7 -0
- package/src/blocks/input/input.jsx +7 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +1 -1
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/index.js +7 -0
- package/src/blocks/raw-text/raw-text.jsx +5 -0
- package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +0 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/index.js +7 -0
- package/src/blocks/section/section.jsx +9 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +0 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/index.js +7 -0
- package/src/blocks/select/select.jsx +16 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +1 -1
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/index.js +7 -0
- package/src/blocks/submit-button/submit-button.jsx +7 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +0 -0
- package/src/blocks/symbol/component-info.js +42 -0
- package/src/blocks/symbol/index.js +7 -0
- package/src/blocks/symbol/symbol.jsx +24 -0
- package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +3 -3
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/index.js +7 -0
- package/src/blocks/text/text.jsx +5 -0
- package/src/blocks/{text.lite.tsx → text/text.lite.tsx} +0 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/index.js +7 -0
- package/src/blocks/textarea/textarea.jsx +5 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/index.js +7 -0
- package/src/blocks/video/video.jsx +14 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -0
- package/src/components/render-block/block-styles.jsx +36 -0
- package/src/components/render-block/block-styles.lite.tsx +38 -0
- package/src/components/{render-block.jsx → render-block/render-block.jsx} +13 -10
- package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +13 -10
- package/src/components/render-blocks.jsx +1 -1
- package/src/components/render-blocks.lite.tsx +1 -1
- package/src/components/render-content/components/render-styles.jsx +6 -5
- package/src/components/render-content/components/render-styles.lite.tsx +9 -5
- package/src/components/render-content/render-content.jsx +16 -15
- package/src/components/render-content/render-content.lite.tsx +19 -18
- package/src/functions/get-builder-search-params/fn.test.js +1 -1
- package/src/functions/get-content/index.js +2 -1
- package/src/functions/get-fetch.js +28 -6
- package/src/index.js +2 -5
- package/src/scripts/init-editing.js +69 -60
- package/src/blocks/button.jsx +0 -8
- package/src/blocks/button.lite.tsx +0 -14
- package/src/blocks/columns.jsx +0 -91
- package/src/blocks/fragment.jsx +0 -6
- package/src/blocks/image.jsx +0 -120
- package/src/blocks/image.lite.tsx +0 -171
- package/src/blocks/img.jsx +0 -11
- package/src/blocks/input.jsx +0 -8
- package/src/blocks/raw-text.jsx +0 -6
- package/src/blocks/section.jsx +0 -10
- package/src/blocks/select.jsx +0 -17
- package/src/blocks/submit-button.jsx +0 -8
- package/src/blocks/symbol.jsx +0 -25
- package/src/blocks/text.jsx +0 -6
- package/src/blocks/textarea.jsx +0 -6
- package/src/blocks/video.jsx +0 -15
- package/src/components/block-styles.jsx +0 -5
- package/src/components/block-styles.lite.tsx +0 -5
|
@@ -1,71 +1,80 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import { TARGET } from "../constants/target";
|
|
3
2
|
import { isBrowser } from "../functions/is-browser";
|
|
3
|
+
import { isEditing } from "../functions/is-editing";
|
|
4
4
|
import { register } from "../functions/register";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
const registerInsertMenu = () => {
|
|
6
|
+
register("insertMenu", {
|
|
7
|
+
name: "_default",
|
|
8
|
+
default: true,
|
|
9
|
+
items: [
|
|
10
|
+
{ name: "Box" },
|
|
11
|
+
{ name: "Text" },
|
|
12
|
+
{ name: "Image" },
|
|
13
|
+
{ name: "Columns" },
|
|
14
|
+
...TARGET === "reactNative" ? [] : [
|
|
15
|
+
{ name: "Core:Section" },
|
|
16
|
+
{ name: "Core:Button" },
|
|
17
|
+
{ name: "Embed" },
|
|
18
|
+
{ name: "Custom Code" }
|
|
19
|
+
]
|
|
18
20
|
]
|
|
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
|
-
(
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const setupBrowserForEditing = () => {
|
|
24
|
+
var _a;
|
|
25
|
+
if (isBrowser()) {
|
|
26
|
+
(_a = window.parent) == null ? void 0 : _a.postMessage({
|
|
27
|
+
type: "builder.sdkInfo",
|
|
28
|
+
data: {
|
|
29
|
+
target: TARGET,
|
|
30
|
+
supportsPatchUpdates: false
|
|
31
|
+
}
|
|
32
|
+
}, "*");
|
|
33
|
+
window.addEventListener("message", ({ data }) => {
|
|
34
|
+
var _a2, _b;
|
|
35
|
+
if (data) {
|
|
36
|
+
switch (data.type) {
|
|
37
|
+
case "builder.evaluate": {
|
|
38
|
+
const text = data.data.text;
|
|
39
|
+
const args = data.data.arguments || [];
|
|
40
|
+
const id = data.data.id;
|
|
41
|
+
const fn = new Function(text);
|
|
42
|
+
let result;
|
|
43
|
+
let error = null;
|
|
44
|
+
try {
|
|
45
|
+
result = fn.apply(null, args);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
error = err;
|
|
48
|
+
}
|
|
49
|
+
if (error) {
|
|
50
|
+
(_a2 = window.parent) == null ? void 0 : _a2.postMessage({
|
|
51
|
+
type: "builder.evaluateError",
|
|
52
|
+
data: { id, error: error.message }
|
|
53
|
+
}, "*");
|
|
54
|
+
} else {
|
|
55
|
+
if (result && typeof result.then === "function") {
|
|
56
|
+
result.then((finalResult) => {
|
|
57
|
+
var _a3;
|
|
58
|
+
(_a3 = window.parent) == null ? void 0 : _a3.postMessage({
|
|
59
|
+
type: "builder.evaluateResult",
|
|
60
|
+
data: { id, result: finalResult }
|
|
61
|
+
}, "*");
|
|
62
|
+
}).catch(console.error);
|
|
63
|
+
} else {
|
|
64
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
55
65
|
type: "builder.evaluateResult",
|
|
56
|
-
data: {
|
|
66
|
+
data: { result, id }
|
|
57
67
|
}, "*");
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
61
|
-
type: "builder.evaluateResult",
|
|
62
|
-
data: { result, id }
|
|
63
|
-
}, "*");
|
|
68
|
+
}
|
|
64
69
|
}
|
|
70
|
+
break;
|
|
65
71
|
}
|
|
66
|
-
break;
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (isEditing()) {
|
|
78
|
+
registerInsertMenu();
|
|
79
|
+
setupBrowserForEditing();
|
|
71
80
|
}
|
package/src/blocks/button.jsx
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function Button(props) {
|
|
2
|
-
return <a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
|
|
3
|
-
{props.text}
|
|
4
|
-
</a>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default Button;import { registerComponent } from '../functions/register-component';
|
|
8
|
-
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});
|
package/src/blocks/columns.jsx
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { For } from "solid-js";
|
|
2
|
-
import { createMutable } from "solid-js/store";
|
|
3
|
-
import { css } from "solid-styled-components";
|
|
4
|
-
import RenderBlocks from "../components/render-blocks";
|
|
5
|
-
|
|
6
|
-
function Columns(props) {
|
|
7
|
-
const state = createMutable({
|
|
8
|
-
getGutterSize() {
|
|
9
|
-
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
getColumns() {
|
|
13
|
-
return props.columns || [];
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
getWidth(index) {
|
|
17
|
-
const columns = this.getColumns();
|
|
18
|
-
return columns[index]?.width || 100 / columns.length;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
getColumnCssWidth(index) {
|
|
22
|
-
const columns = this.getColumns();
|
|
23
|
-
const gutterSize = this.getGutterSize();
|
|
24
|
-
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
25
|
-
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
maybeApplyForTablet(prop) {
|
|
29
|
-
const stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
30
|
-
return stackColumnsAt === "tablet" ? prop : "inherit";
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
get columnsCssVars() {
|
|
34
|
-
const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
|
|
35
|
-
return {
|
|
36
|
-
"--flex-dir": flexDir,
|
|
37
|
-
"--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
get columnCssVars() {
|
|
42
|
-
const width = "100%";
|
|
43
|
-
const marginLeft = "0";
|
|
44
|
-
return {
|
|
45
|
-
"--column-width": width,
|
|
46
|
-
"--column-margin-left": marginLeft,
|
|
47
|
-
"--column-width-tablet": this.maybeApplyForTablet(width),
|
|
48
|
-
"--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return <div class={css({
|
|
54
|
-
display: "flex",
|
|
55
|
-
alignItems: "stretch",
|
|
56
|
-
lineHeight: "normal",
|
|
57
|
-
"@media (max-width: 999px)": {
|
|
58
|
-
flexDirection: "var(--flex-dir-tablet)"
|
|
59
|
-
},
|
|
60
|
-
"@media (max-width: 639px)": {
|
|
61
|
-
flexDirection: "var(--flex-dir)"
|
|
62
|
-
}
|
|
63
|
-
})} style={state.columnsCssVars}>
|
|
64
|
-
<For each={props.columns}>
|
|
65
|
-
{(column, _index) => {
|
|
66
|
-
const index = _index();
|
|
67
|
-
|
|
68
|
-
return <div class={css({
|
|
69
|
-
flexGrow: "1",
|
|
70
|
-
"@media (max-width: 999px)": {
|
|
71
|
-
width: "var(--column-width-tablet) !important",
|
|
72
|
-
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
73
|
-
},
|
|
74
|
-
"@media (max-width: 639px)": {
|
|
75
|
-
width: "var(--column-width) !important",
|
|
76
|
-
marginLeft: "var(--column-margin-left) !important"
|
|
77
|
-
}
|
|
78
|
-
})} style={{
|
|
79
|
-
width: state.getColumnCssWidth(index),
|
|
80
|
-
"margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
81
|
-
...state.columnCssVars
|
|
82
|
-
}}>
|
|
83
|
-
<RenderBlocks blocks={column.blocks}></RenderBlocks>
|
|
84
|
-
</div>;
|
|
85
|
-
}}
|
|
86
|
-
</For>
|
|
87
|
-
</div>;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export default Columns;import { registerComponent } from '../functions/register-component';
|
|
91
|
-
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}]});
|
package/src/blocks/fragment.jsx
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
function FragmentComponent(props) {
|
|
2
|
-
return <span>{props.children}</span>;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export default FragmentComponent;import { registerComponent } from '../functions/register-component';
|
|
6
|
-
registerComponent(FragmentComponent, {name:'Fragment',static:true,hidden:true,builtIn:true,canHaveChildren:true,noWrap:true});
|
package/src/blocks/image.jsx
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
2
|
-
import { createMutable } from "solid-js/store";
|
|
3
|
-
import { css } from "solid-styled-components";
|
|
4
|
-
|
|
5
|
-
function Image(props) {
|
|
6
|
-
const state = createMutable({
|
|
7
|
-
updateQueryParam: function updateQueryParam(uri = "", key, value) {
|
|
8
|
-
const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
|
9
|
-
const separator = uri.indexOf("?") !== -1 ? "&" : "?";
|
|
10
|
-
|
|
11
|
-
if (uri.match(re)) {
|
|
12
|
-
return uri.replace(re, "$1" + key + "=" + encodeURIComponent(value) + "$2");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return uri + separator + key + "=" + encodeURIComponent(value);
|
|
16
|
-
},
|
|
17
|
-
removeProtocol: function removeProtocol(path) {
|
|
18
|
-
return path.replace(/http(s)?:/, "");
|
|
19
|
-
},
|
|
20
|
-
getShopifyImageUrl: function getShopifyImageUrl(src, size) {
|
|
21
|
-
if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
|
|
22
|
-
return src;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (size === "master") {
|
|
26
|
-
return state.removeProtocol(src);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const match = src.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
|
|
30
|
-
|
|
31
|
-
if (match) {
|
|
32
|
-
const prefix = src.split(match[0]);
|
|
33
|
-
const suffix = match[3];
|
|
34
|
-
const useSize = size.match("x") ? size : `${size}x`;
|
|
35
|
-
return state.removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return null;
|
|
39
|
-
},
|
|
40
|
-
getSrcSet: function getSrcSet(url) {
|
|
41
|
-
if (!url) {
|
|
42
|
-
return url;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
|
|
46
|
-
|
|
47
|
-
if (url.match(/builder\.io/)) {
|
|
48
|
-
let srcUrl = url;
|
|
49
|
-
const widthInSrc = Number(url.split("?width=")[1]);
|
|
50
|
-
|
|
51
|
-
if (!isNaN(widthInSrc)) {
|
|
52
|
-
srcUrl = `${srcUrl} ${widthInSrc}w`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return sizes.filter(size => size !== widthInSrc).map(size => `${state.updateQueryParam(url, "width", size)} ${size}w`).concat([srcUrl]).join(", ");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (url.match(/cdn\.shopify\.com/)) {
|
|
59
|
-
return sizes.map(size => [state.getShopifyImageUrl(url, `${size}x${size}`), size]).filter(([sizeUrl]) => !!sizeUrl).map(([sizeUrl, size]) => `${sizeUrl} ${size}w`).concat([url]).join(", ");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return url;
|
|
63
|
-
},
|
|
64
|
-
useSrcSet: function useSrcSet() {
|
|
65
|
-
return props.srcset || state.getSrcSet(props.image) || "";
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return <div class={css({
|
|
69
|
-
position: "relative"
|
|
70
|
-
})}>
|
|
71
|
-
<picture>
|
|
72
|
-
<img class={"builder-image" + (props.class ? " " + props.class : "") + " " + css({
|
|
73
|
-
opacity: "1",
|
|
74
|
-
transition: "opacity 0.2s ease-in-out",
|
|
75
|
-
position: "absolute",
|
|
76
|
-
height: "100%",
|
|
77
|
-
width: "100%",
|
|
78
|
-
top: "0px",
|
|
79
|
-
left: "0px"
|
|
80
|
-
})} loading="lazy" alt={props.altText} aria-role={props.altText ? "presentation" : undefined} style={{
|
|
81
|
-
"object-position": props.backgroundSize || "center",
|
|
82
|
-
"object-fit": props.backgroundSize || "cover"
|
|
83
|
-
}} src={props.image} srcset={props.srcset || state.getSrcSet(props.image)} sizes={props.sizes} />
|
|
84
|
-
<Show when={!props.noWebp && state.useSrcSet().includes("builder.io")}>
|
|
85
|
-
<source type="image/webp" srcSet={state.useSrcSet().replace(/\?/g, "?format=webp&")} />
|
|
86
|
-
</Show>
|
|
87
|
-
</picture>
|
|
88
|
-
<Show when={props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length)}>
|
|
89
|
-
<div class={css({
|
|
90
|
-
width: "100%",
|
|
91
|
-
pointerEvents: "none",
|
|
92
|
-
fontSize: "0"
|
|
93
|
-
})} style={{
|
|
94
|
-
"padding-top": props.aspectRatio * 100 + "%"
|
|
95
|
-
}}>
|
|
96
|
-
{" "}
|
|
97
|
-
</div>
|
|
98
|
-
</Show>
|
|
99
|
-
<Show when={props.builderBlock?.children?.length && props.fitContent}>
|
|
100
|
-
{props.children}
|
|
101
|
-
</Show>
|
|
102
|
-
<Show when={!props.fitContent}>
|
|
103
|
-
<div class={css({
|
|
104
|
-
display: "flex",
|
|
105
|
-
flexDirection: "column",
|
|
106
|
-
alignItems: "stretch",
|
|
107
|
-
position: "absolute",
|
|
108
|
-
top: "0",
|
|
109
|
-
left: "0",
|
|
110
|
-
width: "100%",
|
|
111
|
-
height: "100%"
|
|
112
|
-
})}>
|
|
113
|
-
{props.children}
|
|
114
|
-
</div>
|
|
115
|
-
</Show>
|
|
116
|
-
</div>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export default Image;import { registerComponent } from '../functions/register-component';
|
|
120
|
-
registerComponent(Image, {name:'Image',static:true,builtIn:true,image:'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',defaultStyles:{position:'relative',minHeight:'20px',minWidth:'20px',overflow:'hidden'},canHaveChildren:true,inputs:[{name:'image',type:'file',bubble:true,allowedFileTypes:['jpeg','jpg','png','svg'],required:true,defaultValue:'https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',onChange:" const DEFAULT_ASPECT_RATIO = 0.7041; options.delete('srcset'); options.delete('noWebp'); function loadImage(url, timeout) { return new Promise((resolve, reject) => { const img = document.createElement('img'); let loaded = false; img.onload = () => { loaded = true; resolve(img); }; img.addEventListener('error', event => { console.warn('Image load failed', event.error); reject(event.error); }); img.src = url; setTimeout(() => { if (!loaded) { reject(new Error('Image load timed out')); } }, timeout); }); } function round(num) { return Math.round(num * 1000) / 1000; } const value = options.get('image'); const aspectRatio = options.get('aspectRatio'); // For SVG images - don't render as webp, keep them as SVG fetch(value) .then(res => res.blob()) .then(blob => { if (blob.type.includes('svg')) { options.set('noWebp', true); } }); if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) { return loadImage(value).then(img => { const possiblyUpdatedAspectRatio = options.get('aspectRatio'); if ( options.get('image') === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO) ) { if (img.width && img.height) { options.set('aspectRatio', round(img.height / img.width)); options.set('height', img.height); options.set('width', img.width); } } }); }"},{name:'backgroundSize',type:'text',defaultValue:'cover',enum:[{label:'contain',value:'contain',helperText:'The image should never get cropped'},{label:'cover',value:'cover',helperText:"The image should fill it's box, cropping when needed"}]},{name:'backgroundPosition',type:'text',defaultValue:'center',enum:['center','top','left','right','bottom','top left','top right','bottom left','bottom right']},{name:'altText',type:'string',helperText:'Text to display when the user has images off'},{name:'height',type:'number',hideFromUI:true},{name:'width',type:'number',hideFromUI:true},{name:'sizes',type:'string',hideFromUI:true},{name:'srcset',type:'string',hideFromUI:true},{name:'lazy',type:'boolean',defaultValue:true,hideFromUI:true},{name:'fitContent',type:'boolean',helperText:"When child blocks are provided, fit to them instead of using the image's aspect ratio",defaultValue:true},{name:'aspectRatio',type:'number',helperText:"This is the ratio of height/width, e.g. set to 1.5 for a 300px wide and 200px tall photo. Set to 0 to not force the image to maintain it's aspect ratio",advanced:true,defaultValue:0.7041}]});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
2
|
-
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
import { css } from "solid-styled-components";
|
|
5
|
-
|
|
6
|
-
function Image(props) {
|
|
7
|
-
const state = createMutable({
|
|
8
|
-
updateQueryParam: function updateQueryParam(uri = "", key, value) {
|
|
9
|
-
const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
|
10
|
-
const separator = uri.indexOf("?") !== -1 ? "&" : "?";
|
|
11
|
-
|
|
12
|
-
if (uri.match(re)) {
|
|
13
|
-
return uri.replace(
|
|
14
|
-
re,
|
|
15
|
-
"$1" + key + "=" + encodeURIComponent(value) + "$2"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return uri + separator + key + "=" + encodeURIComponent(value);
|
|
20
|
-
},
|
|
21
|
-
removeProtocol: function removeProtocol(path) {
|
|
22
|
-
return path.replace(/http(s)?:/, "");
|
|
23
|
-
},
|
|
24
|
-
getShopifyImageUrl: function getShopifyImageUrl(src, size) {
|
|
25
|
-
if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
|
|
26
|
-
return src;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (size === "master") {
|
|
30
|
-
return state.removeProtocol(src);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const match = src.match(
|
|
34
|
-
/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (match) {
|
|
38
|
-
const prefix = src.split(match[0]);
|
|
39
|
-
const suffix = match[3];
|
|
40
|
-
const useSize = size.match("x") ? size : `${size}x`;
|
|
41
|
-
return state.removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
},
|
|
46
|
-
getSrcSet: function getSrcSet(url) {
|
|
47
|
-
if (!url) {
|
|
48
|
-
return url;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
|
|
52
|
-
|
|
53
|
-
if (url.match(/builder\.io/)) {
|
|
54
|
-
let srcUrl = url;
|
|
55
|
-
const widthInSrc = Number(url.split("?width=")[1]);
|
|
56
|
-
|
|
57
|
-
if (!isNaN(widthInSrc)) {
|
|
58
|
-
srcUrl = `${srcUrl} ${widthInSrc}w`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return sizes
|
|
62
|
-
.filter((size) => size !== widthInSrc)
|
|
63
|
-
.map(
|
|
64
|
-
(size) => `${state.updateQueryParam(url, "width", size)} ${size}w`
|
|
65
|
-
)
|
|
66
|
-
.concat([srcUrl])
|
|
67
|
-
.join(", ");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (url.match(/cdn\.shopify\.com/)) {
|
|
71
|
-
return sizes
|
|
72
|
-
.map((size) => [
|
|
73
|
-
state.getShopifyImageUrl(url, `${size}x${size}`),
|
|
74
|
-
size,
|
|
75
|
-
])
|
|
76
|
-
.filter(([sizeUrl]) => !!sizeUrl)
|
|
77
|
-
.map(([sizeUrl, size]) => `${sizeUrl} ${size}w`)
|
|
78
|
-
.concat([url])
|
|
79
|
-
.join(", ");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return url;
|
|
83
|
-
},
|
|
84
|
-
useSrcSet: function useSrcSet() {
|
|
85
|
-
return props.srcset || state.getSrcSet(props.image) || "";
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<div
|
|
91
|
-
class={css({
|
|
92
|
-
position: "relative",
|
|
93
|
-
})}
|
|
94
|
-
>
|
|
95
|
-
<picture>
|
|
96
|
-
<img
|
|
97
|
-
class={
|
|
98
|
-
"builder-image" +
|
|
99
|
-
(props.class ? " " + props.class : "") +
|
|
100
|
-
" " +
|
|
101
|
-
css({
|
|
102
|
-
opacity: "1",
|
|
103
|
-
transition: "opacity 0.2s ease-in-out",
|
|
104
|
-
position: "absolute",
|
|
105
|
-
height: "100%",
|
|
106
|
-
width: "100%",
|
|
107
|
-
top: "0px",
|
|
108
|
-
left: "0px",
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
loading="lazy"
|
|
112
|
-
alt={props.altText}
|
|
113
|
-
aria-role={props.altText ? "presentation" : undefined}
|
|
114
|
-
style={{
|
|
115
|
-
"object-position": props.backgroundSize || "center",
|
|
116
|
-
"object-fit": props.backgroundSize || "cover",
|
|
117
|
-
}}
|
|
118
|
-
src={props.image}
|
|
119
|
-
srcset={props.srcset || state.getSrcSet(props.image)}
|
|
120
|
-
sizes={props.sizes}
|
|
121
|
-
/>
|
|
122
|
-
<Show when={!props.noWebp && state.useSrcSet().includes("builder.io")}>
|
|
123
|
-
<source
|
|
124
|
-
type="image/webp"
|
|
125
|
-
srcSet={state.useSrcSet().replace(/\?/g, "?format=webp&")}
|
|
126
|
-
/>
|
|
127
|
-
</Show>
|
|
128
|
-
</picture>
|
|
129
|
-
<Show
|
|
130
|
-
when={
|
|
131
|
-
props.aspectRatio &&
|
|
132
|
-
!(props.fitContent && props.builderBlock?.children?.length)
|
|
133
|
-
}
|
|
134
|
-
>
|
|
135
|
-
<div
|
|
136
|
-
class={css({
|
|
137
|
-
width: "100%",
|
|
138
|
-
pointerEvents: "none",
|
|
139
|
-
fontSize: "0",
|
|
140
|
-
})}
|
|
141
|
-
style={{
|
|
142
|
-
"padding-top": props.aspectRatio * 100 + "%",
|
|
143
|
-
}}
|
|
144
|
-
>
|
|
145
|
-
{" "}
|
|
146
|
-
</div>
|
|
147
|
-
</Show>
|
|
148
|
-
<Show when={props.builderBlock?.children?.length && props.fitContent}>
|
|
149
|
-
{props.children}
|
|
150
|
-
</Show>
|
|
151
|
-
<Show when={!props.fitContent}>
|
|
152
|
-
<div
|
|
153
|
-
class={css({
|
|
154
|
-
display: "flex",
|
|
155
|
-
flexDirection: "column",
|
|
156
|
-
alignItems: "stretch",
|
|
157
|
-
position: "absolute",
|
|
158
|
-
top: "0",
|
|
159
|
-
left: "0",
|
|
160
|
-
width: "100%",
|
|
161
|
-
height: "100%",
|
|
162
|
-
})}
|
|
163
|
-
>
|
|
164
|
-
{props.children}
|
|
165
|
-
</div>
|
|
166
|
-
</Show>
|
|
167
|
-
</div>
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export default Image;
|
package/src/blocks/img.jsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { isEditing } from "../functions/is-editing";
|
|
2
|
-
|
|
3
|
-
function ImgComponent(props) {
|
|
4
|
-
return <img {...props.attributes} style={{
|
|
5
|
-
"object-fit": props.backgroundSize || "cover",
|
|
6
|
-
"object-position": props.backgroundPosition || "center"
|
|
7
|
-
}} key={isEditing() && props.imgSrc || "default-key"} alt={props.altText} src={props.imgSrc} />;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default ImgComponent;import { registerComponent } from '../functions/register-component';
|
|
11
|
-
registerComponent(ImgComponent, {name:'Raw:Img',hideFromInsertMenu:true,builtIn:true,image:'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',inputs:[{name:'image',bubble:true,type:'file',allowedFileTypes:['jpeg','jpg','png','svg'],required:true}],noWrap:true,static:true});
|
package/src/blocks/input.jsx
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { isEditing } from "../functions/is-editing";
|
|
2
|
-
|
|
3
|
-
function FormInputComponent(props) {
|
|
4
|
-
return <input {...props.attributes} key={isEditing() && props.defaultValue ? props.defaultValue : "default-key"} placeholder={props.placeholder} type={props.type} name={props.name} value={props.value} defaultValue={props.defaultValue} required={props.required} />;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default FormInputComponent;import { registerComponent } from '../functions/register-component';
|
|
8
|
-
registerComponent(FormInputComponent, {name:'Form:Input',builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',inputs:[{name:'type',type:'text',enum:['text','number','email','url','checkbox','radio','range','date','datetime-local','search','tel','time','file','month','week','password','color','hidden'],defaultValue:'text'},{name:'name',type:'string',required:true,helperText:'Every input in a form needs a unique name describing what it takes, e.g. "email"'},{name:'placeholder',type:'string',defaultValue:'Hello there',helperText:'Text to display when there is no value'},{name:'defaultValue',type:'string'},{name:'value',type:'string',advanced:true},{name:'required',type:'boolean',helperText:'Is this input required to be filled out to submit a form',defaultValue:false}],noWrap:true,static:true,defaultStyles:{paddingTop:'10px',paddingBottom:'10px',paddingLeft:'10px',paddingRight:'10px',borderRadius:'3px',borderWidth:'1px',borderStyle:'solid',borderColor:'#ccc'}});
|
package/src/blocks/raw-text.jsx
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
function RawText(props) {
|
|
2
|
-
return <span class={props.attributes?.class || props.attributes?.className} innerHTML={props.text || ""}></span>;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export default RawText;import { registerComponent } from '../functions/register-component';
|
|
6
|
-
registerComponent(RawText, {name:'Builder:RawText',hideFromInsertMenu:true,builtIn:true,inputs:[{name:'text',bubble:true,type:'longText',required:true}]});
|
package/src/blocks/section.jsx
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
function SectionComponent(props) {
|
|
2
|
-
return <section {...props.attributes} style={props.maxWidth && typeof props.maxWidth === "number" ? {
|
|
3
|
-
"max-width": props.maxWidth
|
|
4
|
-
} : undefined}>
|
|
5
|
-
{props.children}
|
|
6
|
-
</section>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default SectionComponent;import { registerComponent } from '../functions/register-component';
|
|
10
|
-
registerComponent(SectionComponent, {name:'Core:Section',static:true,builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F682efef23ace49afac61748dd305c70a',inputs:[{name:'maxWidth',type:'number',defaultValue:1200},{name:'lazyLoad',type:'boolean',defaultValue:false,advanced:true,description:'Only render this section when in view'}],defaultStyles:{paddingLeft:'20px',paddingRight:'20px',paddingTop:'50px',paddingBottom:'50px',marginTop:'0px',width:'100vw',marginLeft:'calc(50% - 50vw)'},canHaveChildren:true,defaultChildren:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{textAlign:'center'}},component:{name:'Text',options:{text:"<p><b>I am a section! My content keeps from getting too wide, so that it's easy to read even on big screens.</b></p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur</p>"}}}]});
|
package/src/blocks/select.jsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { For } from "solid-js";
|
|
2
|
-
import { isEditing } from "../functions/is-editing";
|
|
3
|
-
|
|
4
|
-
function SelectComponent(props) {
|
|
5
|
-
return <select {...props.attributes} value={props.value} key={isEditing() && props.defaultValue ? props.defaultValue : "default-key"} defaultValue={props.defaultValue} name={props.name}>
|
|
6
|
-
<For each={props.options}>
|
|
7
|
-
{(option, _index) => {
|
|
8
|
-
const index = _index();
|
|
9
|
-
|
|
10
|
-
return <option value={option.value}>{option.name || option.value}</option>;
|
|
11
|
-
}}
|
|
12
|
-
</For>
|
|
13
|
-
</select>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default SelectComponent;import { registerComponent } from '../functions/register-component';
|
|
17
|
-
registerComponent(SelectComponent, {name:'Form:Select',builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045',defaultStyles:{alignSelf:'flex-start'},inputs:[{name:'options',type:'list',required:true,subFields:[{name:'value',type:'text',required:true},{name:'name',type:'text'}],defaultValue:[{value:'option 1'},{value:'option 2'}]},{name:'name',type:'string',required:true,helperText:'Every select in a form needs a unique name describing what it gets, e.g. "email"'},{name:'defaultValue',type:'string'},{name:'value',type:'string',advanced:true},{name:'required',type:'boolean',defaultValue:false}],static:true,noWrap:true});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function SubmitButton(props) {
|
|
2
|
-
return <button {...props.attributes} type="submit">
|
|
3
|
-
{props.text}
|
|
4
|
-
</button>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default SubmitButton;import { registerComponent } from '../functions/register-component';
|
|
8
|
-
registerComponent(SubmitButton, {name:'Form:SubmitButton',builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98',defaultStyles:{appearance:'none',paddingTop:'15px',paddingBottom:'15px',paddingLeft:'25px',paddingRight:'25px',backgroundColor:'#3898EC',color:'white',borderRadius:'4px',cursor:'pointer'},inputs:[{name:'text',type:'text',defaultValue:'Click me'}],static:true,noWrap:true});
|