@builder.io/sdk-solid 0.0.7 → 0.0.10

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.
Files changed (102) hide show
  1. package/package.json +58 -1
  2. package/src/blocks/button/button.jsx +13 -0
  3. package/src/blocks/button/button.lite.tsx +20 -0
  4. package/src/blocks/button/component-info.js +41 -0
  5. package/src/blocks/button/index.js +7 -0
  6. package/src/blocks/columns/columns.jsx +91 -0
  7. package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +4 -3
  8. package/src/blocks/columns/component-info.js +217 -0
  9. package/src/blocks/columns/index.js +7 -0
  10. package/src/blocks/custom-code/component-info.js +31 -0
  11. package/src/blocks/{custom-code.jsx → custom-code/custom-code.jsx} +1 -2
  12. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +0 -0
  13. package/src/blocks/custom-code/index.js +7 -0
  14. package/src/blocks/embed/component-info.js +24 -0
  15. package/src/blocks/{embed.jsx → embed/embed.jsx} +1 -2
  16. package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +0 -0
  17. package/src/blocks/embed/index.js +7 -0
  18. package/src/blocks/form/component-info.js +262 -0
  19. package/src/blocks/{form.jsx → form/form.jsx} +8 -8
  20. package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +7 -6
  21. package/src/blocks/form/index.js +7 -0
  22. package/src/blocks/fragment/component-info.js +11 -0
  23. package/src/blocks/fragment/fragment.jsx +5 -0
  24. package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +0 -0
  25. package/src/blocks/fragment/index.js +7 -0
  26. package/src/blocks/image/component-info.js +104 -0
  27. package/src/blocks/image/image.jsx +54 -0
  28. package/src/blocks/image/image.lite.tsx +83 -0
  29. package/src/blocks/image/index.js +7 -0
  30. package/src/blocks/img/component-info.js +20 -0
  31. package/src/blocks/img/img.jsx +10 -0
  32. package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +1 -1
  33. package/src/blocks/img/index.js +7 -0
  34. package/src/blocks/input/component-info.js +74 -0
  35. package/src/blocks/input/index.js +7 -0
  36. package/src/blocks/input/input.jsx +7 -0
  37. package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +1 -1
  38. package/src/blocks/raw-text/component-info.js +16 -0
  39. package/src/blocks/raw-text/index.js +7 -0
  40. package/src/blocks/raw-text/raw-text.jsx +5 -0
  41. package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +0 -0
  42. package/src/blocks/section/component-info.js +49 -0
  43. package/src/blocks/section/index.js +7 -0
  44. package/src/blocks/section/section.jsx +9 -0
  45. package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +0 -0
  46. package/src/blocks/select/component-info.js +59 -0
  47. package/src/blocks/select/index.js +7 -0
  48. package/src/blocks/select/select.jsx +16 -0
  49. package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +1 -1
  50. package/src/blocks/submit-button/component-info.js +28 -0
  51. package/src/blocks/submit-button/index.js +7 -0
  52. package/src/blocks/submit-button/submit-button.jsx +7 -0
  53. package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +0 -0
  54. package/src/blocks/symbol/component-info.js +42 -0
  55. package/src/blocks/symbol/index.js +7 -0
  56. package/src/blocks/symbol/symbol.jsx +24 -0
  57. package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +3 -3
  58. package/src/blocks/text/component-info.js +24 -0
  59. package/src/blocks/text/index.js +7 -0
  60. package/src/blocks/text/text.jsx +5 -0
  61. package/src/blocks/{text.lite.tsx → text/text.lite.tsx} +0 -0
  62. package/src/blocks/textarea/component-info.js +47 -0
  63. package/src/blocks/textarea/index.js +7 -0
  64. package/src/blocks/textarea/textarea.jsx +5 -0
  65. package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -0
  66. package/src/blocks/video/component-info.js +106 -0
  67. package/src/blocks/video/index.js +7 -0
  68. package/src/blocks/video/video.jsx +14 -0
  69. package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -0
  70. package/src/components/render-block/block-styles.jsx +36 -0
  71. package/src/components/render-block/block-styles.lite.tsx +38 -0
  72. package/src/components/{render-block.jsx → render-block/render-block.jsx} +14 -13
  73. package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +13 -10
  74. package/src/components/render-blocks.jsx +1 -1
  75. package/src/components/render-blocks.lite.tsx +1 -1
  76. package/src/components/render-content/components/render-styles.jsx +6 -5
  77. package/src/components/render-content/components/render-styles.lite.tsx +9 -5
  78. package/src/components/render-content/render-content.jsx +16 -15
  79. package/src/components/render-content/render-content.lite.tsx +19 -18
  80. package/src/functions/get-builder-search-params/fn.test.js +1 -1
  81. package/src/functions/get-content/index.js +2 -1
  82. package/src/functions/get-fetch.js +28 -6
  83. package/src/index.js +2 -5
  84. package/src/scripts/init-editing.js +69 -60
  85. package/src/blocks/button.jsx +0 -8
  86. package/src/blocks/button.lite.tsx +0 -14
  87. package/src/blocks/columns.jsx +0 -96
  88. package/src/blocks/fragment.jsx +0 -6
  89. package/src/blocks/image.jsx +0 -120
  90. package/src/blocks/image.lite.tsx +0 -171
  91. package/src/blocks/img.jsx +0 -11
  92. package/src/blocks/input.jsx +0 -8
  93. package/src/blocks/raw-text.jsx +0 -6
  94. package/src/blocks/section.jsx +0 -10
  95. package/src/blocks/select.jsx +0 -17
  96. package/src/blocks/submit-button.jsx +0 -8
  97. package/src/blocks/symbol.jsx +0 -25
  98. package/src/blocks/text.jsx +0 -6
  99. package/src/blocks/textarea.jsx +0 -6
  100. package/src/blocks/video.jsx +0 -15
  101. package/src/components/block-styles.jsx +0 -5
  102. 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
- register("insertMenu", {
6
- name: "_default",
7
- default: true,
8
- items: [
9
- { name: "Box" },
10
- { name: "Text" },
11
- { name: "Image" },
12
- { name: "Columns" },
13
- ...TARGET === "reactNative" ? [] : [
14
- { name: "Core:Section" },
15
- { name: "Core:Button" },
16
- { name: "Embed" },
17
- { name: "Custom Code" }
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
- if (isBrowser()) {
22
- (_a = window.parent) == null ? void 0 : _a.postMessage({
23
- type: "builder.sdkInfo",
24
- data: {
25
- target: TARGET,
26
- supportsPatchUpdates: false
27
- }
28
- }, "*");
29
- window.addEventListener("message", ({ data }) => {
30
- var _a2, _b;
31
- if (data) {
32
- switch (data.type) {
33
- case "builder.evaluate": {
34
- const text = data.data.text;
35
- const args = data.data.arguments || [];
36
- const id = data.data.id;
37
- const fn = new Function(text);
38
- let result;
39
- let error = null;
40
- try {
41
- result = fn.apply(null, args);
42
- } catch (err) {
43
- error = err;
44
- }
45
- if (error) {
46
- (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
47
- type: "builder.evaluateError",
48
- data: { id, error: error.message }
49
- }, "*");
50
- } else {
51
- if (result && typeof result.then === "function") {
52
- result.then((finalResult) => {
53
- var _a3;
54
- (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
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: { id, result: finalResult }
66
+ data: { result, id }
57
67
  }, "*");
58
- }).catch(console.error);
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
  }
@@ -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});
@@ -1,14 +0,0 @@
1
- function Button(props) {
2
- return (
3
- <a
4
- {...props.attributes}
5
- role="button"
6
- href={props.link}
7
- target={props.openLinkInNewTab ? "_blank" : undefined}
8
- >
9
- {props.text}
10
- </a>
11
- );
12
- }
13
-
14
- export default Button;
@@ -1,96 +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
- console.log('columns')
8
- const state = createMutable({
9
- getGutterSize() {
10
- return typeof props.space === "number" ? props.space || 0 : 20;
11
- },
12
-
13
- getColumns() {
14
- return props.columns || [];
15
- },
16
-
17
- getWidth(index) {
18
- const columns = this.getColumns();
19
- return columns[index]?.width || 100 / columns.length;
20
- },
21
-
22
- getColumnCssWidth(index) {
23
- const columns = this.getColumns();
24
- const gutterSize = this.getGutterSize();
25
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
26
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
27
- },
28
-
29
- maybeApplyForTablet(prop) {
30
- const stackColumnsAt = props.stackColumnsAt || "tablet";
31
- return stackColumnsAt === "tablet" ? prop : "inherit";
32
- },
33
-
34
- get columnsCssVars() {
35
- const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
36
- return {
37
- "--flex-dir": flexDir,
38
- "--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
39
- };
40
- },
41
-
42
- get columnCssVars() {
43
- const width = "100%";
44
- const marginLeft = "0";
45
- return {
46
- "--column-width": width,
47
- "--column-margin-left": marginLeft,
48
- "--column-width-tablet": this.maybeApplyForTablet(width),
49
- "--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft)
50
- };
51
- }
52
-
53
- });
54
-
55
- console.log('props.columns', props.columns, props.builderBlock.component.options.columns)
56
- return <div class={css({
57
- display: "flex",
58
- alignItems: "stretch",
59
- lineHeight: "normal",
60
- "@media (max-width: 999px)": {
61
- flexDirection: "var(--flex-dir-tablet)"
62
- },
63
- "@media (max-width: 639px)": {
64
- flexDirection: "var(--flex-dir)"
65
- }
66
- }) + " builder-columns"} style={state.columnsCssVars}>
67
- <For each={props.columns}>
68
- {(column, _index) => {
69
- const index = _index();
70
-
71
- console.log('column', column)
72
-
73
- return <div 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
- }) + "builder-column"} style={{
84
- width: state.getColumnCssWidth(index),
85
- "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
86
- ...state.columnCssVars
87
- }}>
88
- <RenderBlocks blocks={column.blocks}></RenderBlocks>
89
- </div>;
90
- }}
91
- </For>
92
- </div>;
93
- }
94
-
95
- export default Columns;import { registerComponent } from '../functions/register-component';
96
- 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}]});
@@ -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});
@@ -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;
@@ -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});
@@ -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'}});
@@ -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}]});
@@ -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>"}}}]});
@@ -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});