@builder.io/sdk-react-nextjs 0.4.5
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 +80 -0
- package/dist/blocks/button/button.d.ts +11 -0
- package/dist/blocks/button/button.js +12 -0
- package/dist/blocks/button/component-info.d.ts +2 -0
- package/dist/blocks/button/component-info.js +34 -0
- package/dist/blocks/columns/columns.d.ts +16 -0
- package/dist/blocks/columns/columns.js +119 -0
- package/dist/blocks/columns/component-info.d.ts +2 -0
- package/dist/blocks/columns/component-info.js +219 -0
- package/dist/blocks/custom-code/component-info.d.ts +2 -0
- package/dist/blocks/custom-code/component-info.js +23 -0
- package/dist/blocks/custom-code/custom-code.d.ts +6 -0
- package/dist/blocks/custom-code/custom-code.js +51 -0
- package/dist/blocks/embed/component-info.d.ts +2 -0
- package/dist/blocks/embed/component-info.js +38 -0
- package/dist/blocks/embed/embed.d.ts +5 -0
- package/dist/blocks/embed/embed.js +42 -0
- package/dist/blocks/embed/helpers.d.ts +1 -0
- package/dist/blocks/embed/helpers.js +2 -0
- package/dist/blocks/fragment/component-info.d.ts +2 -0
- package/dist/blocks/fragment/component-info.js +7 -0
- package/dist/blocks/fragment/fragment.d.ts +7 -0
- package/dist/blocks/fragment/fragment.js +6 -0
- package/dist/blocks/helpers.d.ts +13 -0
- package/dist/blocks/helpers.js +40 -0
- package/dist/blocks/image/component-info.d.ts +2 -0
- package/dist/blocks/image/component-info.js +121 -0
- package/dist/blocks/image/image.d.ts +21 -0
- package/dist/blocks/image/image.helpers.d.ts +1 -0
- package/dist/blocks/image/image.helpers.js +47 -0
- package/dist/blocks/image/image.js +81 -0
- package/dist/blocks/img/component-info.d.ts +2 -0
- package/dist/blocks/img/component-info.js +15 -0
- package/dist/blocks/img/img.d.ts +13 -0
- package/dist/blocks/img/img.js +10 -0
- package/dist/blocks/section/component-info.d.ts +2 -0
- package/dist/blocks/section/component-info.js +40 -0
- package/dist/blocks/section/section.d.ts +11 -0
- package/dist/blocks/section/section.js +17 -0
- package/dist/blocks/symbol/component-info.d.ts +2 -0
- package/dist/blocks/symbol/component-info.js +34 -0
- package/dist/blocks/symbol/symbol.d.ts +25 -0
- package/dist/blocks/symbol/symbol.helpers.d.ts +14 -0
- package/dist/blocks/symbol/symbol.helpers.js +30 -0
- package/dist/blocks/symbol/symbol.js +29 -0
- package/dist/blocks/text/component-info.d.ts +2 -0
- package/dist/blocks/text/component-info.js +19 -0
- package/dist/blocks/text/text.d.ts +5 -0
- package/dist/blocks/text/text.js +7 -0
- package/dist/blocks/video/component-info.d.ts +2 -0
- package/dist/blocks/video/component-info.js +82 -0
- package/dist/blocks/video/video.d.ts +19 -0
- package/dist/blocks/video/video.js +47 -0
- package/dist/components/block/block.d.ts +9 -0
- package/dist/components/block/block.helpers.d.ts +13 -0
- package/dist/components/block/block.helpers.js +67 -0
- package/dist/components/block/block.js +92 -0
- package/dist/components/block/components/block-styles.d.ts +8 -0
- package/dist/components/block/components/block-styles.js +65 -0
- package/dist/components/block/components/block-wrapper.d.ts +17 -0
- package/dist/components/block/components/block-wrapper.js +36 -0
- package/dist/components/block/components/component-ref/component-ref.d.ts +3 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +28 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.js +21 -0
- package/dist/components/block/components/component-ref/component-ref.js +21 -0
- package/dist/components/block/components/interactive-element.d.ts +11 -0
- package/dist/components/block/components/interactive-element.js +20 -0
- package/dist/components/block/components/repeated-block.d.ts +9 -0
- package/dist/components/block/components/repeated-block.js +7 -0
- package/dist/components/block/types.d.ts +6 -0
- package/dist/components/block/types.js +1 -0
- package/dist/components/blocks/blocks-wrapper.d.ts +10 -0
- package/dist/components/blocks/blocks-wrapper.js +38 -0
- package/dist/components/blocks/blocks.d.ts +8 -0
- package/dist/components/blocks/blocks.js +10 -0
- package/dist/components/content/components/enable-editor.d.ts +9 -0
- package/dist/components/content/components/enable-editor.js +249 -0
- package/dist/components/content/components/styles.d.ts +8 -0
- package/dist/components/content/components/styles.helpers.d.ts +15 -0
- package/dist/components/content/components/styles.helpers.js +56 -0
- package/dist/components/content/components/styles.js +30 -0
- package/dist/components/content/content.d.ts +3 -0
- package/dist/components/content/content.helpers.d.ts +7 -0
- package/dist/components/content/content.helpers.js +25 -0
- package/dist/components/content/content.js +72 -0
- package/dist/components/content/content.types.d.ts +24 -0
- package/dist/components/content/content.types.js +1 -0
- package/dist/components/content/wrap-component-ref.d.ts +6 -0
- package/dist/components/content/wrap-component-ref.js +6 -0
- package/dist/components/content-variants/content-variants.d.ts +9 -0
- package/dist/components/content-variants/content-variants.js +39 -0
- package/dist/components/content-variants/content-variants.types.d.ts +20 -0
- package/dist/components/content-variants/content-variants.types.js +1 -0
- package/dist/components/content-variants/helpers.d.ts +41 -0
- package/dist/components/content-variants/helpers.js +188 -0
- package/dist/components/inlined-script.d.ts +6 -0
- package/dist/components/inlined-script.js +5 -0
- package/dist/components/inlined-styles.d.ts +6 -0
- package/dist/components/inlined-styles.js +5 -0
- package/dist/constants/builder-registered-components.d.ts +6 -0
- package/dist/constants/builder-registered-components.js +60 -0
- package/dist/constants/device-sizes.d.ts +13 -0
- package/dist/constants/device-sizes.js +45 -0
- package/dist/constants/sdk-version.d.ts +1 -0
- package/dist/constants/sdk-version.js +1 -0
- package/dist/constants/target.d.ts +2 -0
- package/dist/constants/target.js +2 -0
- package/dist/context/builder.context.d.ts +3 -0
- package/dist/context/builder.context.js +12 -0
- package/dist/context/types.d.ts +35 -0
- package/dist/context/types.js +1 -0
- package/dist/functions/apply-patch-with-mutation.d.ts +10 -0
- package/dist/functions/apply-patch-with-mutation.js +54 -0
- package/dist/functions/camel-to-kebab-case.d.ts +1 -0
- package/dist/functions/camel-to-kebab-case.js +1 -0
- package/dist/functions/evaluate.d.ts +7 -0
- package/dist/functions/evaluate.js +46 -0
- package/dist/functions/event-handler-name.d.ts +1 -0
- package/dist/functions/event-handler-name.js +4 -0
- package/dist/functions/extract-text-styles.d.ts +4 -0
- package/dist/functions/extract-text-styles.js +21 -0
- package/dist/functions/fast-clone.d.ts +4 -0
- package/dist/functions/fast-clone.js +4 -0
- package/dist/functions/get-block-actions-handler.d.ts +8 -0
- package/dist/functions/get-block-actions-handler.js +10 -0
- package/dist/functions/get-block-actions.d.ts +10 -0
- package/dist/functions/get-block-actions.js +28 -0
- package/dist/functions/get-block-component-options.d.ts +2 -0
- package/dist/functions/get-block-component-options.js +8 -0
- package/dist/functions/get-block-properties.d.ts +6 -0
- package/dist/functions/get-block-properties.js +71 -0
- package/dist/functions/get-builder-search-params/index.d.ts +12 -0
- package/dist/functions/get-builder-search-params/index.js +38 -0
- package/dist/functions/get-content/generate-content-url.d.ts +2 -0
- package/dist/functions/get-content/generate-content-url.js +32 -0
- package/dist/functions/get-content/index.d.ts +16 -0
- package/dist/functions/get-content/index.js +82 -0
- package/dist/functions/get-content/processCookies.d.ts +2 -0
- package/dist/functions/get-content/processCookies.js +35 -0
- package/dist/functions/get-content/types.d.ts +51 -0
- package/dist/functions/get-content/types.js +1 -0
- package/dist/functions/get-fetch.d.ts +1 -0
- package/dist/functions/get-fetch.js +11 -0
- package/dist/functions/get-global-this.d.ts +4 -0
- package/dist/functions/get-global-this.js +15 -0
- package/dist/functions/get-processed-block.d.ts +10 -0
- package/dist/functions/get-processed-block.js +43 -0
- package/dist/functions/get-react-native-block-styles.d.ts +7 -0
- package/dist/functions/get-react-native-block-styles.js +16 -0
- package/dist/functions/is-browser.d.ts +1 -0
- package/dist/functions/is-browser.js +3 -0
- package/dist/functions/is-editing.d.ts +1 -0
- package/dist/functions/is-editing.js +5 -0
- package/dist/functions/is-iframe.d.ts +1 -0
- package/dist/functions/is-iframe.js +4 -0
- package/dist/functions/is-previewing.d.ts +1 -0
- package/dist/functions/is-previewing.js +11 -0
- package/dist/functions/register-component.d.ts +15 -0
- package/dist/functions/register-component.js +34 -0
- package/dist/functions/register.d.ts +16 -0
- package/dist/functions/register.js +27 -0
- package/dist/functions/sanitize-react-native-block-styles.d.ts +3 -0
- package/dist/functions/sanitize-react-native-block-styles.js +58 -0
- package/dist/functions/set-editor-settings.d.ts +4 -0
- package/dist/functions/set-editor-settings.js +12 -0
- package/dist/functions/set.d.ts +7 -0
- package/dist/functions/set.js +14 -0
- package/dist/functions/track/helpers.d.ts +5 -0
- package/dist/functions/track/helpers.js +50 -0
- package/dist/functions/track/index.d.ts +51 -0
- package/dist/functions/track/index.js +69 -0
- package/dist/functions/track/interaction.d.ts +13 -0
- package/dist/functions/track/interaction.js +53 -0
- package/dist/functions/transform-block-properties.d.ts +1 -0
- package/dist/functions/transform-block-properties.js +5 -0
- package/dist/functions/transform-block.d.ts +2 -0
- package/dist/functions/transform-block.js +3 -0
- package/dist/helpers/ab-tests.d.ts +9 -0
- package/dist/helpers/ab-tests.js +116 -0
- package/dist/helpers/canTrack.d.ts +1 -0
- package/dist/helpers/canTrack.js +2 -0
- package/dist/helpers/cookie.d.ts +19 -0
- package/dist/helpers/cookie.js +54 -0
- package/dist/helpers/css.d.ts +7 -0
- package/dist/helpers/css.js +27 -0
- package/dist/helpers/flatten.d.ts +6 -0
- package/dist/helpers/flatten.js +17 -0
- package/dist/helpers/localStorage.d.ts +9 -0
- package/dist/helpers/localStorage.js +24 -0
- package/dist/helpers/logger.d.ts +6 -0
- package/dist/helpers/logger.js +7 -0
- package/dist/helpers/nullable.d.ts +2 -0
- package/dist/helpers/nullable.js +1 -0
- package/dist/helpers/preview-lru-cache/get.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/get.js +7 -0
- package/dist/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/helpers.js +9 -0
- package/dist/helpers/preview-lru-cache/init.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/init.js +15 -0
- package/dist/helpers/preview-lru-cache/set.d.ts +7 -0
- package/dist/helpers/preview-lru-cache/set.js +9 -0
- package/dist/helpers/preview-lru-cache/types.d.ts +12 -0
- package/dist/helpers/preview-lru-cache/types.js +1 -0
- package/dist/helpers/sessionId.d.ts +6 -0
- package/dist/helpers/sessionId.js +30 -0
- package/dist/helpers/url.d.ts +6 -0
- package/dist/helpers/url.js +15 -0
- package/dist/helpers/uuid.d.ts +8 -0
- package/dist/helpers/uuid.js +15 -0
- package/dist/helpers/visitorId.d.ts +6 -0
- package/dist/helpers/visitorId.js +30 -0
- package/dist/index-helpers/blocks-exports.d.ts +10 -0
- package/dist/index-helpers/blocks-exports.js +10 -0
- package/dist/index-helpers/top-of-file.d.ts +1 -0
- package/dist/index-helpers/top-of-file.js +4 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +10 -0
- package/dist/scripts/init-editing.d.ts +6 -0
- package/dist/scripts/init-editing.js +109 -0
- package/dist/types/api-version.d.ts +2 -0
- package/dist/types/api-version.js +1 -0
- package/dist/types/builder-block.d.ts +66 -0
- package/dist/types/builder-block.js +1 -0
- package/dist/types/builder-content.d.ts +44 -0
- package/dist/types/builder-content.js +1 -0
- package/dist/types/builder-props.d.ts +9 -0
- package/dist/types/builder-props.js +1 -0
- package/dist/types/can-track.d.ts +3 -0
- package/dist/types/can-track.js +1 -0
- package/dist/types/components.d.ts +111 -0
- package/dist/types/components.js +1 -0
- package/dist/types/deep-partial.d.ts +3 -0
- package/dist/types/deep-partial.js +1 -0
- package/dist/types/element.d.ts +59 -0
- package/dist/types/element.js +1 -0
- package/dist/types/enforced-partials.d.ts +21 -0
- package/dist/types/enforced-partials.js +1 -0
- package/dist/types/input.d.ts +121 -0
- package/dist/types/input.js +1 -0
- package/dist/types/targets.d.ts +1 -0
- package/dist/types/targets.js +1 -0
- package/dist/types/typescript.d.ts +11 -0
- package/dist/types/typescript.js +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useState, useRef, useEffect } from "react";
|
|
4
|
+
import { isJsScript } from "./helpers.js";
|
|
5
|
+
function Embed(props) {
|
|
6
|
+
const elem = useRef(null);
|
|
7
|
+
const [scriptsInserted, setScriptsInserted] = useState(() => []);
|
|
8
|
+
const [scriptsRun, setScriptsRun] = useState(() => []);
|
|
9
|
+
const [ranInitFn, setRanInitFn] = useState(() => false);
|
|
10
|
+
function findAndRunScripts() {
|
|
11
|
+
if (!elem.current || !elem.current.getElementsByTagName)
|
|
12
|
+
return;
|
|
13
|
+
const scripts = elem.current.getElementsByTagName("script");
|
|
14
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
15
|
+
const script = scripts[i];
|
|
16
|
+
if (script.src && !scriptsInserted.includes(script.src)) {
|
|
17
|
+
scriptsInserted.push(script.src);
|
|
18
|
+
const newScript = document.createElement("script");
|
|
19
|
+
newScript.async = true;
|
|
20
|
+
newScript.src = script.src;
|
|
21
|
+
document.head.appendChild(newScript);
|
|
22
|
+
}
|
|
23
|
+
else if (isJsScript(script) && !scriptsRun.includes(script.innerText)) {
|
|
24
|
+
try {
|
|
25
|
+
scriptsRun.push(script.innerText);
|
|
26
|
+
new Function(script.innerText)();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.warn("`Embed`: Error running script:", error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (elem.current && !ranInitFn) {
|
|
36
|
+
setRanInitFn(true);
|
|
37
|
+
findAndRunScripts();
|
|
38
|
+
}
|
|
39
|
+
}, [elem.current, ranInitFn]);
|
|
40
|
+
return (React.createElement("div", { className: "builder-embed", ref: elem, dangerouslySetInnerHTML: { __html: props.content } }));
|
|
41
|
+
}
|
|
42
|
+
export default Embed;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isJsScript: (script: HTMLScriptElement) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function filterAttrs(attrs: {
|
|
2
|
+
[index: string]: any;
|
|
3
|
+
}, prefix: string, isEvent: boolean): {
|
|
4
|
+
[index: string]: any;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Svelte SDK: workaround to dynamically provide event handlers to components/elements.
|
|
8
|
+
* https://svelte.dev/repl/1246699e266f41218a8eeb45b9b58b54?version=3.24.1
|
|
9
|
+
*/
|
|
10
|
+
export declare function setAttrs(node: HTMLElement, attrs?: Record<string, (event: Event) => void>): {
|
|
11
|
+
update(attrs?: {}): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function filterAttrs(attrs = {}, prefix, isEvent) {
|
|
2
|
+
const result = {};
|
|
3
|
+
for (const attr in attrs) {
|
|
4
|
+
if (!attrs[attr])
|
|
5
|
+
continue;
|
|
6
|
+
if (isEvent && !attr.startsWith(prefix))
|
|
7
|
+
continue;
|
|
8
|
+
const eventName = isEvent ? attr.replace(prefix, '') : attr;
|
|
9
|
+
result[eventName] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Svelte SDK: workaround to dynamically provide event handlers to components/elements.
|
|
15
|
+
* https://svelte.dev/repl/1246699e266f41218a8eeb45b9b58b54?version=3.24.1
|
|
16
|
+
*/
|
|
17
|
+
export function setAttrs(node, attrs = {}) {
|
|
18
|
+
const attrKeys = Object.keys(attrs);
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {string} attr
|
|
22
|
+
*/
|
|
23
|
+
const setup = (attr) => node.addEventListener(attr, attrs[attr]);
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {string} attr
|
|
27
|
+
*/
|
|
28
|
+
const teardown = (attr) => node.removeEventListener(attr, attrs[attr]);
|
|
29
|
+
attrKeys.forEach(setup);
|
|
30
|
+
return {
|
|
31
|
+
update(attrs = {}) {
|
|
32
|
+
const attrKeys = Object.keys(attrs);
|
|
33
|
+
attrKeys.forEach(teardown);
|
|
34
|
+
attrKeys.forEach(setup);
|
|
35
|
+
},
|
|
36
|
+
destroy() {
|
|
37
|
+
attrKeys.forEach(teardown);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const componentInfo = {
|
|
2
|
+
name: 'Image',
|
|
3
|
+
static: true,
|
|
4
|
+
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',
|
|
5
|
+
defaultStyles: {
|
|
6
|
+
position: 'relative',
|
|
7
|
+
minHeight: '20px',
|
|
8
|
+
minWidth: '20px',
|
|
9
|
+
overflow: 'hidden'
|
|
10
|
+
},
|
|
11
|
+
canHaveChildren: true,
|
|
12
|
+
inputs: [{
|
|
13
|
+
name: 'image',
|
|
14
|
+
type: 'file',
|
|
15
|
+
bubble: true,
|
|
16
|
+
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg'],
|
|
17
|
+
required: true,
|
|
18
|
+
defaultValue: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a',
|
|
19
|
+
onChange: (options) => {
|
|
20
|
+
const DEFAULT_ASPECT_RATIO = 0.7041;
|
|
21
|
+
options.delete('srcset');
|
|
22
|
+
options.delete('noWebp');
|
|
23
|
+
function loadImage(url, timeout = 60000) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const img = document.createElement('img');
|
|
26
|
+
let loaded = false;
|
|
27
|
+
img.onload = () => {
|
|
28
|
+
loaded = true;
|
|
29
|
+
resolve(img);
|
|
30
|
+
};
|
|
31
|
+
img.addEventListener('error', event => {
|
|
32
|
+
console.warn('Image load failed', event.error);
|
|
33
|
+
reject(event.error);
|
|
34
|
+
});
|
|
35
|
+
img.src = url;
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
if (!loaded) {
|
|
38
|
+
reject(new Error('Image load timed out'));
|
|
39
|
+
}
|
|
40
|
+
}, timeout);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function round(num) {
|
|
44
|
+
return Math.round(num * 1000) / 1000;
|
|
45
|
+
}
|
|
46
|
+
const value = options.get('image');
|
|
47
|
+
const aspectRatio = options.get('aspectRatio'); // For SVG images - don't render as webp, keep them as SVG
|
|
48
|
+
fetch(value).then(res => res.blob()).then(blob => {
|
|
49
|
+
if (blob.type.includes('svg')) {
|
|
50
|
+
options.set('noWebp', true);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) {
|
|
54
|
+
return loadImage(value).then(img => {
|
|
55
|
+
const possiblyUpdatedAspectRatio = options.get('aspectRatio');
|
|
56
|
+
if (options.get('image') === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)) {
|
|
57
|
+
if (img.width && img.height) {
|
|
58
|
+
options.set('aspectRatio', round(img.height / img.width));
|
|
59
|
+
options.set('height', img.height);
|
|
60
|
+
options.set('width', img.width);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
name: 'backgroundSize',
|
|
68
|
+
type: 'text',
|
|
69
|
+
defaultValue: 'cover',
|
|
70
|
+
enum: [{
|
|
71
|
+
label: 'contain',
|
|
72
|
+
value: 'contain',
|
|
73
|
+
helperText: 'The image should never get cropped'
|
|
74
|
+
}, {
|
|
75
|
+
label: 'cover',
|
|
76
|
+
value: 'cover',
|
|
77
|
+
helperText: "The image should fill it's box, cropping when needed"
|
|
78
|
+
}]
|
|
79
|
+
}, {
|
|
80
|
+
name: 'backgroundPosition',
|
|
81
|
+
type: 'text',
|
|
82
|
+
defaultValue: 'center',
|
|
83
|
+
enum: ['center', 'top', 'left', 'right', 'bottom', 'top left', 'top right', 'bottom left', 'bottom right']
|
|
84
|
+
}, {
|
|
85
|
+
name: 'altText',
|
|
86
|
+
type: 'string',
|
|
87
|
+
helperText: 'Text to display when the user has images off'
|
|
88
|
+
}, {
|
|
89
|
+
name: 'height',
|
|
90
|
+
type: 'number',
|
|
91
|
+
hideFromUI: true
|
|
92
|
+
}, {
|
|
93
|
+
name: 'width',
|
|
94
|
+
type: 'number',
|
|
95
|
+
hideFromUI: true
|
|
96
|
+
}, {
|
|
97
|
+
name: 'sizes',
|
|
98
|
+
type: 'string',
|
|
99
|
+
hideFromUI: true
|
|
100
|
+
}, {
|
|
101
|
+
name: 'srcset',
|
|
102
|
+
type: 'string',
|
|
103
|
+
hideFromUI: true
|
|
104
|
+
}, {
|
|
105
|
+
name: 'lazy',
|
|
106
|
+
type: 'boolean',
|
|
107
|
+
defaultValue: true,
|
|
108
|
+
hideFromUI: true
|
|
109
|
+
}, {
|
|
110
|
+
name: 'fitContent',
|
|
111
|
+
type: 'boolean',
|
|
112
|
+
helperText: "When child blocks are provided, fit to them instead of using the image's aspect ratio",
|
|
113
|
+
defaultValue: true
|
|
114
|
+
}, {
|
|
115
|
+
name: 'aspectRatio',
|
|
116
|
+
type: 'number',
|
|
117
|
+
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",
|
|
118
|
+
advanced: true,
|
|
119
|
+
defaultValue: 0.7041
|
|
120
|
+
}]
|
|
121
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ImageProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
image: string;
|
|
4
|
+
sizes?: string;
|
|
5
|
+
lazy?: boolean;
|
|
6
|
+
height?: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
altText?: string;
|
|
9
|
+
backgroundSize?: "cover" | "contain";
|
|
10
|
+
backgroundPosition?: string;
|
|
11
|
+
srcset?: string;
|
|
12
|
+
aspectRatio?: number;
|
|
13
|
+
children?: JSX.Element;
|
|
14
|
+
fitContent?: boolean;
|
|
15
|
+
builderBlock?: BuilderBlock;
|
|
16
|
+
noWebp?: boolean;
|
|
17
|
+
src?: string;
|
|
18
|
+
}
|
|
19
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
20
|
+
declare function Image(props: ImageProps): JSX.Element;
|
|
21
|
+
export default Image;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSrcSet(url: string): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Taken from (and modified) the shopify theme script repo
|
|
2
|
+
// https://github.com/Shopify/theme-scripts/blob/bcfb471f2a57d439e2f964a1bb65b67708cc90c3/packages/theme-images/images.js#L59
|
|
3
|
+
function removeProtocol(path) {
|
|
4
|
+
return path.replace(/http(s)?:/, '');
|
|
5
|
+
}
|
|
6
|
+
function updateQueryParam(uri = '', key, value) {
|
|
7
|
+
const re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
|
8
|
+
const separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
|
9
|
+
if (uri.match(re)) {
|
|
10
|
+
return uri.replace(re, '$1' + key + '=' + encodeURIComponent(value) + '$2');
|
|
11
|
+
}
|
|
12
|
+
return uri + separator + key + '=' + encodeURIComponent(value);
|
|
13
|
+
}
|
|
14
|
+
function getShopifyImageUrl(src, size) {
|
|
15
|
+
if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
|
|
16
|
+
return src;
|
|
17
|
+
}
|
|
18
|
+
if (size === 'master') {
|
|
19
|
+
return removeProtocol(src);
|
|
20
|
+
}
|
|
21
|
+
const match = src.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
|
|
22
|
+
if (match) {
|
|
23
|
+
const prefix = src.split(match[0]);
|
|
24
|
+
const suffix = match[3];
|
|
25
|
+
const useSize = size.match('x') ? size : `${size}x`;
|
|
26
|
+
return removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export function getSrcSet(url) {
|
|
31
|
+
if (!url) {
|
|
32
|
+
return url;
|
|
33
|
+
}
|
|
34
|
+
const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
|
|
35
|
+
if (url.match(/builder\.io/)) {
|
|
36
|
+
let srcUrl = url;
|
|
37
|
+
const widthInSrc = Number(url.split('?width=')[1]);
|
|
38
|
+
if (!isNaN(widthInSrc)) {
|
|
39
|
+
srcUrl = `${srcUrl} ${widthInSrc}w`;
|
|
40
|
+
}
|
|
41
|
+
return sizes.filter(size => size !== widthInSrc).map(size => `${updateQueryParam(url, 'width', size)} ${size}w`).concat([srcUrl]).join(', ');
|
|
42
|
+
}
|
|
43
|
+
if (url.match(/cdn\.shopify\.com/)) {
|
|
44
|
+
return sizes.map(size => [getShopifyImageUrl(url, `${size}x${size}`), size]).filter(([sizeUrl]) => !!sizeUrl).map(([sizeUrl, size]) => `${sizeUrl} ${size}w`).concat([url]).join(', ');
|
|
45
|
+
}
|
|
46
|
+
return url;
|
|
47
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { getSrcSet } from "./image.helpers.js";
|
|
4
|
+
function Image(props) {
|
|
5
|
+
function srcSetToUse() {
|
|
6
|
+
const imageToUse = props.image || props.src;
|
|
7
|
+
const url = imageToUse;
|
|
8
|
+
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
9
|
+
// images, otherwise you can supply this prop manually
|
|
10
|
+
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
11
|
+
return props.srcset;
|
|
12
|
+
}
|
|
13
|
+
if (props.srcset && props.image?.includes("builder.io/api/v1/image")) {
|
|
14
|
+
if (!props.srcset.includes(props.image.split("?")[0])) {
|
|
15
|
+
console.debug("Removed given srcset");
|
|
16
|
+
return getSrcSet(url);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (props.image && !props.srcset) {
|
|
20
|
+
return getSrcSet(url);
|
|
21
|
+
}
|
|
22
|
+
return getSrcSet(url);
|
|
23
|
+
}
|
|
24
|
+
function webpSrcSet() {
|
|
25
|
+
if (srcSetToUse?.()?.match(/builder\.io/) && !props.noWebp) {
|
|
26
|
+
return srcSetToUse().replace(/\?/g, "?format=webp&");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function aspectRatioCss() {
|
|
33
|
+
const aspectRatioStyles = {
|
|
34
|
+
position: "absolute",
|
|
35
|
+
height: "100%",
|
|
36
|
+
width: "100%",
|
|
37
|
+
left: "0px",
|
|
38
|
+
top: "0px",
|
|
39
|
+
};
|
|
40
|
+
const out = props.aspectRatio ? aspectRatioStyles : undefined;
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
return (React.createElement(React.Fragment, null,
|
|
44
|
+
React.createElement(React.Fragment, null,
|
|
45
|
+
React.createElement("picture", null,
|
|
46
|
+
webpSrcSet() ? (React.createElement(React.Fragment, null,
|
|
47
|
+
React.createElement("source", { type: "image/webp", srcSet: webpSrcSet() }))) : null,
|
|
48
|
+
React.createElement("img", { loading: "lazy", alt: props.altText, role: props.altText ? "presentation" : undefined, style: {
|
|
49
|
+
objectPosition: props.backgroundPosition || "center",
|
|
50
|
+
objectFit: props.backgroundSize || "cover",
|
|
51
|
+
...aspectRatioCss(),
|
|
52
|
+
}, className: "builder-image" +
|
|
53
|
+
(props.className ? " " + props.className : "") +
|
|
54
|
+
" img-0abd4ebe", src: props.image, srcSet: srcSetToUse(), sizes: props.sizes })),
|
|
55
|
+
props.aspectRatio &&
|
|
56
|
+
!(props.builderBlock?.children?.length && props.fitContent) ? (React.createElement(React.Fragment, null,
|
|
57
|
+
React.createElement("div", { className: "builder-image-sizer div-0abd4ebe", style: {
|
|
58
|
+
paddingTop: props.aspectRatio * 100 + "%",
|
|
59
|
+
} }))) : null,
|
|
60
|
+
props.builderBlock?.children?.length && props.fitContent ? (React.createElement(React.Fragment, null, props.children)) : null,
|
|
61
|
+
!props.fitContent && props.children ? (React.createElement(React.Fragment, null,
|
|
62
|
+
React.createElement("div", { className: "div-0abd4ebe-2" }, props.children))) : null),
|
|
63
|
+
React.createElement("style", null, `.img-0abd4ebe {
|
|
64
|
+
opacity: 1;
|
|
65
|
+
transition: opacity 0.2s ease-in-out;
|
|
66
|
+
}.div-0abd4ebe {
|
|
67
|
+
width: 100%;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
font-size: 0;
|
|
70
|
+
}.div-0abd4ebe-2 {
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-direction: column;
|
|
73
|
+
align-items: stretch;
|
|
74
|
+
position: absolute;
|
|
75
|
+
top: 0;
|
|
76
|
+
left: 0;
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
}`)));
|
|
80
|
+
}
|
|
81
|
+
export default Image;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const componentInfo = {
|
|
2
|
+
// friendlyName?
|
|
3
|
+
name: 'Raw:Img',
|
|
4
|
+
hideFromInsertMenu: true,
|
|
5
|
+
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',
|
|
6
|
+
inputs: [{
|
|
7
|
+
name: 'image',
|
|
8
|
+
bubble: true,
|
|
9
|
+
type: 'file',
|
|
10
|
+
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg', 'gif', 'webp'],
|
|
11
|
+
required: true
|
|
12
|
+
}],
|
|
13
|
+
noWrap: true,
|
|
14
|
+
static: true
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
+
*/
|
|
4
|
+
export interface ImgProps {
|
|
5
|
+
attributes?: any;
|
|
6
|
+
imgSrc?: string;
|
|
7
|
+
image?: string;
|
|
8
|
+
altText?: string;
|
|
9
|
+
backgroundSize?: "cover" | "contain";
|
|
10
|
+
backgroundPosition?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
|
|
11
|
+
}
|
|
12
|
+
declare function ImgComponent(props: ImgProps): JSX.Element;
|
|
13
|
+
export default ImgComponent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
4
|
+
function ImgComponent(props) {
|
|
5
|
+
return (React.createElement("img", { style: {
|
|
6
|
+
objectFit: props.backgroundSize || "cover",
|
|
7
|
+
objectPosition: props.backgroundPosition || "center",
|
|
8
|
+
}, key: (isEditing() && props.imgSrc) || "default-key", alt: props.altText, src: props.imgSrc || props.image, ...props.attributes }));
|
|
9
|
+
}
|
|
10
|
+
export default ImgComponent;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const componentInfo = {
|
|
2
|
+
name: 'Core:Section',
|
|
3
|
+
static: true,
|
|
4
|
+
image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F682efef23ace49afac61748dd305c70a',
|
|
5
|
+
inputs: [{
|
|
6
|
+
name: 'maxWidth',
|
|
7
|
+
type: 'number',
|
|
8
|
+
defaultValue: 1200
|
|
9
|
+
}, {
|
|
10
|
+
name: 'lazyLoad',
|
|
11
|
+
type: 'boolean',
|
|
12
|
+
defaultValue: false,
|
|
13
|
+
advanced: true,
|
|
14
|
+
description: 'Only render this section when in view'
|
|
15
|
+
}],
|
|
16
|
+
defaultStyles: {
|
|
17
|
+
paddingLeft: '20px',
|
|
18
|
+
paddingRight: '20px',
|
|
19
|
+
paddingTop: '50px',
|
|
20
|
+
paddingBottom: '50px',
|
|
21
|
+
marginTop: '0px',
|
|
22
|
+
width: '100vw',
|
|
23
|
+
marginLeft: 'calc(50% - 50vw)'
|
|
24
|
+
},
|
|
25
|
+
canHaveChildren: true,
|
|
26
|
+
defaultChildren: [{
|
|
27
|
+
'@type': '@builder.io/sdk:Element',
|
|
28
|
+
responsiveStyles: {
|
|
29
|
+
large: {
|
|
30
|
+
textAlign: 'center'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
component: {
|
|
34
|
+
name: 'Text',
|
|
35
|
+
options: {
|
|
36
|
+
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>"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}]
|
|
40
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
+
*/
|
|
4
|
+
export interface SectionProps {
|
|
5
|
+
maxWidth?: number;
|
|
6
|
+
attributes?: any;
|
|
7
|
+
children?: any;
|
|
8
|
+
builderBlock?: any;
|
|
9
|
+
}
|
|
10
|
+
declare function SectionComponent(props: SectionProps): JSX.Element;
|
|
11
|
+
export default SectionComponent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
function SectionComponent(props) {
|
|
4
|
+
return (React.createElement("section", { ...props.attributes, style: {
|
|
5
|
+
width: "100%",
|
|
6
|
+
alignSelf: "stretch",
|
|
7
|
+
flexGrow: 1,
|
|
8
|
+
boxSizing: "border-box",
|
|
9
|
+
maxWidth: props.maxWidth || 1200,
|
|
10
|
+
display: "flex",
|
|
11
|
+
flexDirection: "column",
|
|
12
|
+
alignItems: "stretch",
|
|
13
|
+
marginLeft: "auto",
|
|
14
|
+
marginRight: "auto",
|
|
15
|
+
} }, props.children));
|
|
16
|
+
}
|
|
17
|
+
export default SectionComponent;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const componentInfo = {
|
|
2
|
+
name: 'Symbol',
|
|
3
|
+
noWrap: true,
|
|
4
|
+
static: true,
|
|
5
|
+
isRSC: true,
|
|
6
|
+
inputs: [{
|
|
7
|
+
name: 'symbol',
|
|
8
|
+
type: 'uiSymbol'
|
|
9
|
+
}, {
|
|
10
|
+
name: 'dataOnly',
|
|
11
|
+
helperText: "Make this a data symbol that doesn't display any UI",
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
defaultValue: false,
|
|
14
|
+
advanced: true,
|
|
15
|
+
hideFromUI: true
|
|
16
|
+
}, {
|
|
17
|
+
name: 'inheritState',
|
|
18
|
+
helperText: 'Inherit the parent component state and data',
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
defaultValue: false,
|
|
21
|
+
advanced: true
|
|
22
|
+
}, {
|
|
23
|
+
name: 'renderToLiquid',
|
|
24
|
+
helperText: 'Render this symbols contents to liquid. Turn off to fetch with javascript and use custom targeting',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
defaultValue: false,
|
|
27
|
+
advanced: true,
|
|
28
|
+
hideFromUI: true
|
|
29
|
+
}, {
|
|
30
|
+
name: 'useChildren',
|
|
31
|
+
hideFromUI: true,
|
|
32
|
+
type: 'boolean'
|
|
33
|
+
}]
|
|
34
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
3
|
+
*/
|
|
4
|
+
export interface SymbolInfo {
|
|
5
|
+
model?: string;
|
|
6
|
+
entry?: string;
|
|
7
|
+
data?: any;
|
|
8
|
+
content?: BuilderContent;
|
|
9
|
+
inline?: boolean;
|
|
10
|
+
dynamic?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This import is used by the Svelte SDK. Do not remove.
|
|
14
|
+
*/
|
|
15
|
+
export interface SymbolProps extends BuilderComponentsProp {
|
|
16
|
+
symbol?: SymbolInfo;
|
|
17
|
+
dataOnly?: boolean;
|
|
18
|
+
dynamic?: boolean;
|
|
19
|
+
attributes?: any;
|
|
20
|
+
inheritState?: boolean;
|
|
21
|
+
}
|
|
22
|
+
import type { BuilderContent } from "../../types/builder-content.js";
|
|
23
|
+
import type { BuilderComponentsProp, PropsWithBuilderData } from "../../types/builder-props.js";
|
|
24
|
+
declare function Symbol(props: PropsWithBuilderData<SymbolProps>): Promise<JSX.Element>;
|
|
25
|
+
export default Symbol;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../../context/types.js';
|
|
2
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
3
|
+
export interface SymbolInfo {
|
|
4
|
+
model?: string;
|
|
5
|
+
entry?: string;
|
|
6
|
+
data?: any;
|
|
7
|
+
content?: BuilderContent;
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
dynamic?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const fetchContent: ({ builderContextValue, symbol }: {
|
|
12
|
+
symbol: SymbolInfo | undefined;
|
|
13
|
+
builderContextValue: BuilderContextInterface;
|
|
14
|
+
}) => Promise<any>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getContent } from '../../functions/get-content/index.js';
|
|
2
|
+
import { logger } from '../../helpers/logger.js';
|
|
3
|
+
export const fetchContent = async ({ builderContextValue, symbol }) => {
|
|
4
|
+
/**
|
|
5
|
+
* If:
|
|
6
|
+
* - we have a symbol prop
|
|
7
|
+
* - yet it does not have any content
|
|
8
|
+
* - and we have not already stored content from before
|
|
9
|
+
* - and it has a model name
|
|
10
|
+
*
|
|
11
|
+
* then we want to re-fetch the symbol content.
|
|
12
|
+
*/
|
|
13
|
+
if (symbol?.model && // This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
14
|
+
builderContextValue?.apiKey) {
|
|
15
|
+
return getContent({
|
|
16
|
+
model: symbol.model,
|
|
17
|
+
apiKey: builderContextValue.apiKey,
|
|
18
|
+
apiVersion: builderContextValue.apiVersion,
|
|
19
|
+
...(symbol?.entry && {
|
|
20
|
+
query: {
|
|
21
|
+
id: symbol.entry
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}).catch(err => {
|
|
25
|
+
logger.error('Could not fetch symbol content: ', err);
|
|
26
|
+
return undefined;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|