@builder.io/sdk-svelte 0.0.4 → 0.0.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/package/--package.json +3 -2
- package/package.json +3 -2
- package/src/blocks/BaseText.svelte +27 -0
- package/src/blocks/button/button.svelte +36 -0
- package/src/blocks/button/component-info.ts +42 -0
- package/src/blocks/columns/columns.svelte +148 -0
- package/src/blocks/columns/component-info.ts +254 -0
- package/src/blocks/custom-code/component-info.ts +31 -0
- package/src/blocks/custom-code/custom-code.svelte +66 -0
- package/src/blocks/embed/component-info.ts +53 -0
- package/src/blocks/embed/embed.svelte +51 -0
- package/src/blocks/embed/helpers.ts +8 -0
- package/src/blocks/form/component-info.ts +282 -0
- package/src/blocks/form/form.svelte +332 -0
- package/src/blocks/fragment/component-info.ts +10 -0
- package/src/blocks/fragment/fragment.svelte +12 -0
- package/src/blocks/image/component-info.ts +170 -0
- package/src/blocks/image/image.helpers.ts +75 -0
- package/src/blocks/image/image.svelte +145 -0
- package/src/blocks/img/component-info.ts +21 -0
- package/src/blocks/img/img.svelte +51 -0
- package/src/blocks/input/component-info.ts +78 -0
- package/src/blocks/input/input.svelte +34 -0
- package/src/blocks/raw-text/component-info.ts +15 -0
- package/src/blocks/raw-text/raw-text.svelte +16 -0
- package/src/blocks/section/component-info.ts +50 -0
- package/src/blocks/section/section.svelte +34 -0
- package/src/blocks/select/component-info.ts +61 -0
- package/src/blocks/select/select.svelte +34 -0
- package/src/blocks/submit-button/component-info.ts +32 -0
- package/src/blocks/submit-button/submit-button.svelte +15 -0
- package/src/blocks/symbol/component-info.ts +43 -0
- package/src/blocks/symbol/symbol.svelte +100 -0
- package/src/blocks/text/component-info.ts +24 -0
- package/src/blocks/text/text.svelte +11 -0
- package/src/blocks/textarea/component-info.ts +48 -0
- package/src/blocks/textarea/textarea.svelte +19 -0
- package/src/blocks/util.ts +6 -0
- package/src/blocks/video/component-info.ts +109 -0
- package/src/blocks/video/video.svelte +102 -0
- package/src/components/render-block/block-styles.svelte +62 -0
- package/src/components/render-block/render-block.helpers.ts +27 -0
- package/src/components/render-block/render-block.svelte +228 -0
- package/src/components/render-block/render-component-with-context.svelte +38 -0
- package/src/components/render-block/render-component.svelte +35 -0
- package/src/components/render-block/render-repeated-block.svelte +53 -0
- package/src/components/render-block/types.ts +7 -0
- package/src/components/render-blocks.svelte +104 -0
- package/src/components/render-content/components/render-styles.svelte +80 -0
- package/src/components/render-content/index.ts +1 -0
- package/src/components/render-content/render-content.svelte +354 -0
- package/src/components/render-inlined-styles.svelte +26 -0
- package/src/constants/builder-registered-components.ts +42 -0
- package/src/constants/device-sizes.ts +28 -0
- package/src/constants/target.ts +2 -0
- package/src/context/builder.context.ts +13 -0
- package/src/context/types.ts +23 -0
- package/src/functions/camel-to-kebab-case.ts +2 -0
- package/src/functions/evaluate.ts +52 -0
- package/src/functions/event-handler-name.ts +6 -0
- package/src/functions/extract-text-styles.ts +39 -0
- package/src/functions/fast-clone.ts +5 -0
- package/src/functions/get-block-actions-handler.ts +19 -0
- package/src/functions/get-block-actions.ts +25 -0
- package/src/functions/get-block-component-options.ts +12 -0
- package/src/functions/get-block-properties.ts +11 -0
- package/src/functions/get-block-tag.ts +7 -0
- package/src/functions/get-builder-search-params/fn.test.ts +19 -0
- package/src/functions/get-builder-search-params/index.ts +48 -0
- package/src/functions/get-content/ab-testing.ts +132 -0
- package/src/functions/get-content/fn.test.ts +35 -0
- package/src/functions/get-content/index.ts +77 -0
- package/src/functions/get-content/types.ts +36 -0
- package/src/functions/get-fetch.ts +14 -0
- package/src/functions/get-global-this.ts +15 -0
- package/src/functions/get-processed-block.test.ts +33 -0
- package/src/functions/get-processed-block.ts +54 -0
- package/src/functions/get-react-native-block-styles.ts +30 -0
- package/src/functions/if-target.ts +20 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-editing.ts +7 -0
- package/src/functions/is-iframe.ts +5 -0
- package/src/functions/is-previewing.ts +14 -0
- package/src/functions/mark-mutable.ts +7 -0
- package/src/functions/on-change.test.ts +23 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +67 -0
- package/src/functions/register.ts +46 -0
- package/src/functions/sanitize-react-native-block-styles.ts +65 -0
- package/src/functions/set-editor-settings.ts +16 -0
- package/src/functions/set.test.ts +19 -0
- package/src/functions/set.ts +26 -0
- package/src/functions/track.ts +90 -0
- package/src/functions/transform-block.ts +6 -0
- package/src/helpers/ab-tests.ts +22 -0
- package/src/helpers/cookie.ts +102 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +24 -0
- package/src/helpers/localStorage.ts +38 -0
- package/src/helpers/nullable.ts +4 -0
- package/src/helpers/sessionId.ts +34 -0
- package/src/helpers/time.ts +4 -0
- package/src/helpers/url.test.ts +16 -0
- package/src/helpers/url.ts +12 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +38 -0
- package/src/index-helpers/blocks-exports.ts +10 -0
- package/src/index-helpers/top-of-file.ts +4 -0
- package/src/index.ts +12 -0
- package/src/scripts/init-editing.ts +102 -0
- package/src/types/builder-block.ts +58 -0
- package/src/types/builder-content.ts +39 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +188 -0
- package/src/types/deep-partial.ts +7 -0
- package/src/types/element.ts +60 -0
- package/src/types/targets.ts +6 -0
- package/src/types/typescript.ts +7 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
import { markSerializable } from '../util.js';
|
|
3
|
+
|
|
4
|
+
export const componentInfo: ComponentInfo = {
|
|
5
|
+
name: 'Image',
|
|
6
|
+
static: true,
|
|
7
|
+
builtIn: true,
|
|
8
|
+
image:
|
|
9
|
+
'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',
|
|
10
|
+
defaultStyles: {
|
|
11
|
+
position: 'relative',
|
|
12
|
+
minHeight: '20px',
|
|
13
|
+
minWidth: '20px',
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
},
|
|
16
|
+
canHaveChildren: true,
|
|
17
|
+
inputs: [
|
|
18
|
+
{
|
|
19
|
+
name: 'image',
|
|
20
|
+
type: 'file',
|
|
21
|
+
bubble: true,
|
|
22
|
+
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg'],
|
|
23
|
+
required: true,
|
|
24
|
+
defaultValue:
|
|
25
|
+
'https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
26
|
+
onChange: markSerializable((options: Map<string, any>) => {
|
|
27
|
+
const DEFAULT_ASPECT_RATIO = 0.7041;
|
|
28
|
+
options.delete('srcset');
|
|
29
|
+
options.delete('noWebp');
|
|
30
|
+
function loadImage(
|
|
31
|
+
url: string,
|
|
32
|
+
timeout = 60000
|
|
33
|
+
): Promise<HTMLImageElement> {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const img = document.createElement('img');
|
|
36
|
+
let loaded = false;
|
|
37
|
+
img.onload = () => {
|
|
38
|
+
loaded = true;
|
|
39
|
+
resolve(img);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
img.addEventListener('error', (event) => {
|
|
43
|
+
console.warn('Image load failed', event.error);
|
|
44
|
+
reject(event.error);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
img.src = url;
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
if (!loaded) {
|
|
50
|
+
reject(new Error('Image load timed out'));
|
|
51
|
+
}
|
|
52
|
+
}, timeout);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function round(num: number) {
|
|
57
|
+
return Math.round(num * 1000) / 1000;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const value = options.get('image');
|
|
61
|
+
const aspectRatio = options.get('aspectRatio');
|
|
62
|
+
|
|
63
|
+
// For SVG images - don't render as webp, keep them as SVG
|
|
64
|
+
fetch(value)
|
|
65
|
+
.then((res) => res.blob())
|
|
66
|
+
.then((blob) => {
|
|
67
|
+
if (blob.type.includes('svg')) {
|
|
68
|
+
options.set('noWebp', true);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) {
|
|
73
|
+
return loadImage(value).then((img) => {
|
|
74
|
+
const possiblyUpdatedAspectRatio = options.get('aspectRatio');
|
|
75
|
+
if (
|
|
76
|
+
options.get('image') === value &&
|
|
77
|
+
(!possiblyUpdatedAspectRatio ||
|
|
78
|
+
possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)
|
|
79
|
+
) {
|
|
80
|
+
if (img.width && img.height) {
|
|
81
|
+
options.set('aspectRatio', round(img.height / img.width));
|
|
82
|
+
options.set('height', img.height);
|
|
83
|
+
options.set('width', img.width);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'backgroundSize',
|
|
92
|
+
type: 'text',
|
|
93
|
+
defaultValue: 'cover',
|
|
94
|
+
enum: [
|
|
95
|
+
{
|
|
96
|
+
label: 'contain',
|
|
97
|
+
value: 'contain',
|
|
98
|
+
helperText: 'The image should never get cropped',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
label: 'cover',
|
|
102
|
+
value: 'cover',
|
|
103
|
+
helperText: "The image should fill it's box, cropping when needed",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'backgroundPosition',
|
|
109
|
+
type: 'text',
|
|
110
|
+
defaultValue: 'center',
|
|
111
|
+
enum: [
|
|
112
|
+
'center',
|
|
113
|
+
'top',
|
|
114
|
+
'left',
|
|
115
|
+
'right',
|
|
116
|
+
'bottom',
|
|
117
|
+
'top left',
|
|
118
|
+
'top right',
|
|
119
|
+
'bottom left',
|
|
120
|
+
'bottom right',
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'altText',
|
|
125
|
+
type: 'string',
|
|
126
|
+
helperText: 'Text to display when the user has images off',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'height',
|
|
130
|
+
type: 'number',
|
|
131
|
+
hideFromUI: true,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'width',
|
|
135
|
+
type: 'number',
|
|
136
|
+
hideFromUI: true,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'sizes',
|
|
140
|
+
type: 'string',
|
|
141
|
+
hideFromUI: true,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'srcset',
|
|
145
|
+
type: 'string',
|
|
146
|
+
hideFromUI: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'lazy',
|
|
150
|
+
type: 'boolean',
|
|
151
|
+
defaultValue: true,
|
|
152
|
+
hideFromUI: true,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'fitContent',
|
|
156
|
+
type: 'boolean',
|
|
157
|
+
helperText:
|
|
158
|
+
"When child blocks are provided, fit to them instead of using the image's aspect ratio",
|
|
159
|
+
defaultValue: true,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'aspectRatio',
|
|
163
|
+
type: 'number',
|
|
164
|
+
helperText:
|
|
165
|
+
"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",
|
|
166
|
+
advanced: true,
|
|
167
|
+
defaultValue: 0.7041,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
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: string) {
|
|
4
|
+
return path.replace(/http(s)?:/, '');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function updateQueryParam(
|
|
8
|
+
uri = '',
|
|
9
|
+
key: string,
|
|
10
|
+
value: string | number | boolean
|
|
11
|
+
): string {
|
|
12
|
+
const re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
|
13
|
+
const separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
|
14
|
+
if (uri.match(re)) {
|
|
15
|
+
return uri.replace(re, '$1' + key + '=' + encodeURIComponent(value) + '$2');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return uri + separator + key + '=' + encodeURIComponent(value);
|
|
19
|
+
}
|
|
20
|
+
function getShopifyImageUrl(src: string, size: string): string | null {
|
|
21
|
+
if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
|
|
22
|
+
return src;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (size === 'master') {
|
|
26
|
+
return removeProtocol(src);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const match = src.match(
|
|
30
|
+
/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (match) {
|
|
34
|
+
const prefix = src.split(match[0]);
|
|
35
|
+
const suffix = match[3];
|
|
36
|
+
const useSize = size.match('x') ? size : `${size}x`;
|
|
37
|
+
|
|
38
|
+
return removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getSrcSet(url: string): string {
|
|
45
|
+
if (!url) {
|
|
46
|
+
return url;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
|
|
50
|
+
|
|
51
|
+
if (url.match(/builder\.io/)) {
|
|
52
|
+
let srcUrl = url;
|
|
53
|
+
const widthInSrc = Number(url.split('?width=')[1]);
|
|
54
|
+
if (!isNaN(widthInSrc)) {
|
|
55
|
+
srcUrl = `${srcUrl} ${widthInSrc}w`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return sizes
|
|
59
|
+
.filter((size) => size !== widthInSrc)
|
|
60
|
+
.map((size) => `${updateQueryParam(url, 'width', size)} ${size}w`)
|
|
61
|
+
.concat([srcUrl])
|
|
62
|
+
.join(', ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (url.match(/cdn\.shopify\.com/)) {
|
|
66
|
+
return sizes
|
|
67
|
+
.map((size) => [getShopifyImageUrl(url, `${size}x${size}`), size])
|
|
68
|
+
.filter(([sizeUrl]) => !!sizeUrl)
|
|
69
|
+
.map(([sizeUrl, size]) => `${sizeUrl} ${size}w`)
|
|
70
|
+
.concat([url])
|
|
71
|
+
.join(', ');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return url;
|
|
75
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
3
|
+
|
|
4
|
+
export interface ImageProps {
|
|
5
|
+
className?: string;
|
|
6
|
+
image: string;
|
|
7
|
+
sizes?: string;
|
|
8
|
+
lazy?: boolean;
|
|
9
|
+
height?: number;
|
|
10
|
+
width?: number;
|
|
11
|
+
altText?: string;
|
|
12
|
+
backgroundSize?: string;
|
|
13
|
+
backgroundPosition?: string;
|
|
14
|
+
srcset?: string;
|
|
15
|
+
aspectRatio?: number;
|
|
16
|
+
children?: JSX.Element;
|
|
17
|
+
fitContent?: boolean;
|
|
18
|
+
builderBlock?: BuilderBlock;
|
|
19
|
+
noWebp?: boolean;
|
|
20
|
+
src?: string;
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import { getSrcSet } from "./image.helpers.js";
|
|
26
|
+
|
|
27
|
+
export let image: ImageProps["image"];
|
|
28
|
+
export let src: ImageProps["src"];
|
|
29
|
+
export let srcset: ImageProps["srcset"];
|
|
30
|
+
export let noWebp: ImageProps["noWebp"];
|
|
31
|
+
export let altText: ImageProps["altText"];
|
|
32
|
+
export let backgroundSize: ImageProps["backgroundSize"];
|
|
33
|
+
export let className: ImageProps["className"];
|
|
34
|
+
export let sizes: ImageProps["sizes"];
|
|
35
|
+
export let aspectRatio: ImageProps["aspectRatio"];
|
|
36
|
+
export let builderBlock: ImageProps["builderBlock"];
|
|
37
|
+
export let fitContent: ImageProps["fitContent"];
|
|
38
|
+
|
|
39
|
+
function mitosis_styling(node, vars) {
|
|
40
|
+
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
41
|
+
if (p.startsWith("--")) {
|
|
42
|
+
node.style.setProperty(p, v);
|
|
43
|
+
} else {
|
|
44
|
+
node.style[p] = v;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
$: srcSetToUse = () => {
|
|
50
|
+
const imageToUse = image || src;
|
|
51
|
+
const url = imageToUse;
|
|
52
|
+
if (
|
|
53
|
+
!url ||
|
|
54
|
+
// We can auto add srcset for cdn.builder.io and shopify
|
|
55
|
+
// images, otherwise you can supply this prop manually
|
|
56
|
+
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))
|
|
57
|
+
) {
|
|
58
|
+
return srcset;
|
|
59
|
+
}
|
|
60
|
+
if (srcset && image?.includes("builder.io/api/v1/image")) {
|
|
61
|
+
if (!srcset.includes(image.split("?")[0])) {
|
|
62
|
+
console.debug("Removed given srcset");
|
|
63
|
+
return getSrcSet(url);
|
|
64
|
+
}
|
|
65
|
+
} else if (image && !srcset) {
|
|
66
|
+
return getSrcSet(url);
|
|
67
|
+
}
|
|
68
|
+
return getSrcSet(url);
|
|
69
|
+
};
|
|
70
|
+
$: webpSrcSet = () => {
|
|
71
|
+
if (srcSetToUse?.()?.match(/builder\.io/) && !noWebp) {
|
|
72
|
+
return srcSetToUse().replace(/\?/g, "?format=webp&");
|
|
73
|
+
} else {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<picture>
|
|
80
|
+
{#if webpSrcSet()}
|
|
81
|
+
<source type="image/webp" srcset={webpSrcSet()} />
|
|
82
|
+
{/if}
|
|
83
|
+
<img
|
|
84
|
+
use:mitosis_styling={{
|
|
85
|
+
objectPosition: backgroundSize || "center",
|
|
86
|
+
objectFit: backgroundSize || "cover",
|
|
87
|
+
}}
|
|
88
|
+
loading="lazy"
|
|
89
|
+
alt={altText}
|
|
90
|
+
role={altText ? "presentation" : undefined}
|
|
91
|
+
class={"builder-image" + (className ? " " + className : "") + " img"}
|
|
92
|
+
src={image}
|
|
93
|
+
srcset={srcSetToUse()}
|
|
94
|
+
{sizes}
|
|
95
|
+
/>
|
|
96
|
+
<source srcset={srcSetToUse()} />
|
|
97
|
+
</picture>
|
|
98
|
+
|
|
99
|
+
{#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
|
|
100
|
+
<div
|
|
101
|
+
use:mitosis_styling={{
|
|
102
|
+
paddingTop:
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
104
|
+
aspectRatio * 100 + "%",
|
|
105
|
+
}}
|
|
106
|
+
class="builder-image-sizer div"
|
|
107
|
+
/>
|
|
108
|
+
{/if}
|
|
109
|
+
|
|
110
|
+
{#if builderBlock?.children?.length && fitContent}
|
|
111
|
+
<slot />
|
|
112
|
+
{/if}
|
|
113
|
+
|
|
114
|
+
{#if !fitContent && $$slots.default}
|
|
115
|
+
<div class="div-2">
|
|
116
|
+
<slot />
|
|
117
|
+
</div>
|
|
118
|
+
{/if}
|
|
119
|
+
|
|
120
|
+
<style>
|
|
121
|
+
.img {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
transition: opacity 0.2s ease-in-out;
|
|
124
|
+
position: absolute;
|
|
125
|
+
height: 100%;
|
|
126
|
+
width: 100%;
|
|
127
|
+
top: 0px;
|
|
128
|
+
left: 0px;
|
|
129
|
+
}
|
|
130
|
+
.div {
|
|
131
|
+
width: 100%;
|
|
132
|
+
pointer-events: none;
|
|
133
|
+
font-size: 0;
|
|
134
|
+
}
|
|
135
|
+
.div-2 {
|
|
136
|
+
display: flex;
|
|
137
|
+
flex-direction: column;
|
|
138
|
+
align-items: stretch;
|
|
139
|
+
position: absolute;
|
|
140
|
+
top: 0;
|
|
141
|
+
left: 0;
|
|
142
|
+
width: 100%;
|
|
143
|
+
height: 100%;
|
|
144
|
+
}
|
|
145
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
|
|
3
|
+
export const componentInfo: ComponentInfo = {
|
|
4
|
+
// friendlyName?
|
|
5
|
+
name: 'Raw:Img',
|
|
6
|
+
hideFromInsertMenu: true,
|
|
7
|
+
builtIn: true,
|
|
8
|
+
image:
|
|
9
|
+
'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',
|
|
10
|
+
inputs: [
|
|
11
|
+
{
|
|
12
|
+
name: 'image',
|
|
13
|
+
bubble: true,
|
|
14
|
+
type: 'file',
|
|
15
|
+
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg'],
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
noWrap: true,
|
|
20
|
+
static: true,
|
|
21
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface ImgProps {
|
|
3
|
+
attributes?: any;
|
|
4
|
+
imgSrc?: string; // TODO(misko): I think this is unused
|
|
5
|
+
image?: string;
|
|
6
|
+
altText?: string;
|
|
7
|
+
backgroundSize?: "cover" | "contain";
|
|
8
|
+
backgroundPosition?:
|
|
9
|
+
| "center"
|
|
10
|
+
| "top"
|
|
11
|
+
| "left"
|
|
12
|
+
| "right"
|
|
13
|
+
| "bottom"
|
|
14
|
+
| "top left"
|
|
15
|
+
| "top right"
|
|
16
|
+
| "bottom left"
|
|
17
|
+
| "bottom right";
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
23
|
+
|
|
24
|
+
export let backgroundSize: ImgProps["backgroundSize"];
|
|
25
|
+
export let backgroundPosition: ImgProps["backgroundPosition"];
|
|
26
|
+
export let imgSrc: ImgProps["imgSrc"];
|
|
27
|
+
export let altText: ImgProps["altText"];
|
|
28
|
+
export let image: ImgProps["image"];
|
|
29
|
+
export let attributes: ImgProps["attributes"];
|
|
30
|
+
|
|
31
|
+
function mitosis_styling(node, vars) {
|
|
32
|
+
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
33
|
+
if (p.startsWith("--")) {
|
|
34
|
+
node.style.setProperty(p, v);
|
|
35
|
+
} else {
|
|
36
|
+
node.style[p] = v;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<img
|
|
43
|
+
{...attributes}
|
|
44
|
+
use:mitosis_styling={{
|
|
45
|
+
objectFit: backgroundSize || "cover",
|
|
46
|
+
objectPosition: backgroundPosition || "center",
|
|
47
|
+
}}
|
|
48
|
+
key={(isEditing() && imgSrc) || "default-key"}
|
|
49
|
+
alt={altText}
|
|
50
|
+
src={imgSrc || image}
|
|
51
|
+
/>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
|
|
3
|
+
export const componentInfo: ComponentInfo = {
|
|
4
|
+
name: 'Form:Input',
|
|
5
|
+
builtIn: true,
|
|
6
|
+
image:
|
|
7
|
+
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 'type',
|
|
11
|
+
type: 'text',
|
|
12
|
+
enum: [
|
|
13
|
+
'text',
|
|
14
|
+
'number',
|
|
15
|
+
'email',
|
|
16
|
+
'url',
|
|
17
|
+
'checkbox',
|
|
18
|
+
'radio',
|
|
19
|
+
'range',
|
|
20
|
+
'date',
|
|
21
|
+
'datetime-local',
|
|
22
|
+
'search',
|
|
23
|
+
'tel',
|
|
24
|
+
'time',
|
|
25
|
+
'file',
|
|
26
|
+
'month',
|
|
27
|
+
'week',
|
|
28
|
+
'password',
|
|
29
|
+
'color',
|
|
30
|
+
'hidden',
|
|
31
|
+
],
|
|
32
|
+
defaultValue: 'text',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'name',
|
|
36
|
+
type: 'string',
|
|
37
|
+
required: true,
|
|
38
|
+
helperText:
|
|
39
|
+
'Every input in a form needs a unique name describing what it takes, e.g. "email"',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'placeholder',
|
|
43
|
+
type: 'string',
|
|
44
|
+
defaultValue: 'Hello there',
|
|
45
|
+
helperText: 'Text to display when there is no value',
|
|
46
|
+
},
|
|
47
|
+
// TODO: handle value vs default value automatically like ng-model
|
|
48
|
+
{
|
|
49
|
+
name: 'defaultValue',
|
|
50
|
+
type: 'string',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'value',
|
|
54
|
+
type: 'string',
|
|
55
|
+
advanced: true,
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
{
|
|
59
|
+
name: 'required',
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
helperText: 'Is this input required to be filled out to submit a form',
|
|
62
|
+
defaultValue: false,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
|
|
66
|
+
noWrap: true,
|
|
67
|
+
static: true,
|
|
68
|
+
defaultStyles: {
|
|
69
|
+
paddingTop: '10px',
|
|
70
|
+
paddingBottom: '10px',
|
|
71
|
+
paddingLeft: '10px',
|
|
72
|
+
paddingRight: '10px',
|
|
73
|
+
borderRadius: '3px',
|
|
74
|
+
borderWidth: '1px',
|
|
75
|
+
borderStyle: 'solid',
|
|
76
|
+
borderColor: '#ccc',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface FormInputProps {
|
|
3
|
+
type?: string;
|
|
4
|
+
attributes?: any;
|
|
5
|
+
name?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
15
|
+
|
|
16
|
+
export let attributes: FormInputProps["attributes"];
|
|
17
|
+
export let defaultValue: FormInputProps["defaultValue"];
|
|
18
|
+
export let placeholder: FormInputProps["placeholder"];
|
|
19
|
+
export let type: FormInputProps["type"];
|
|
20
|
+
export let name: FormInputProps["name"];
|
|
21
|
+
export let value: FormInputProps["value"];
|
|
22
|
+
export let required: FormInputProps["required"];
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<input
|
|
26
|
+
{...attributes}
|
|
27
|
+
key={isEditing() && defaultValue ? defaultValue : "default-key"}
|
|
28
|
+
{placeholder}
|
|
29
|
+
{type}
|
|
30
|
+
{name}
|
|
31
|
+
{value}
|
|
32
|
+
{defaultValue}
|
|
33
|
+
{required}
|
|
34
|
+
/>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
|
|
3
|
+
export const componentInfo: ComponentInfo = {
|
|
4
|
+
name: 'Builder:RawText',
|
|
5
|
+
hideFromInsertMenu: true,
|
|
6
|
+
builtIn: true,
|
|
7
|
+
inputs: [
|
|
8
|
+
{
|
|
9
|
+
name: 'text',
|
|
10
|
+
bubble: true,
|
|
11
|
+
type: 'longText',
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface RawTextProps {
|
|
3
|
+
attributes?: any;
|
|
4
|
+
text?: string;
|
|
5
|
+
// builderBlock?: any;
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
export let attributes: RawTextProps["attributes"];
|
|
11
|
+
export let text: RawTextProps["text"];
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<span class={attributes?.class || attributes?.className}
|
|
15
|
+
>{@html text || ""}</span
|
|
16
|
+
>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
|
|
3
|
+
export const componentInfo: ComponentInfo = {
|
|
4
|
+
name: 'Core:Section',
|
|
5
|
+
static: true,
|
|
6
|
+
builtIn: true,
|
|
7
|
+
image:
|
|
8
|
+
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F682efef23ace49afac61748dd305c70a',
|
|
9
|
+
inputs: [
|
|
10
|
+
{
|
|
11
|
+
name: 'maxWidth',
|
|
12
|
+
type: 'number',
|
|
13
|
+
defaultValue: 1200,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'lazyLoad',
|
|
17
|
+
type: 'boolean',
|
|
18
|
+
defaultValue: false,
|
|
19
|
+
advanced: true,
|
|
20
|
+
description: 'Only render this section when in view',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
defaultStyles: {
|
|
24
|
+
paddingLeft: '20px',
|
|
25
|
+
paddingRight: '20px',
|
|
26
|
+
paddingTop: '50px',
|
|
27
|
+
paddingBottom: '50px',
|
|
28
|
+
marginTop: '0px',
|
|
29
|
+
width: '100vw',
|
|
30
|
+
marginLeft: 'calc(50% - 50vw)',
|
|
31
|
+
},
|
|
32
|
+
canHaveChildren: true,
|
|
33
|
+
|
|
34
|
+
defaultChildren: [
|
|
35
|
+
{
|
|
36
|
+
'@type': '@builder.io/sdk:Element',
|
|
37
|
+
responsiveStyles: {
|
|
38
|
+
large: {
|
|
39
|
+
textAlign: 'center',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
component: {
|
|
43
|
+
name: 'Text',
|
|
44
|
+
options: {
|
|
45
|
+
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>",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface SectionProps {
|
|
3
|
+
maxWidth?: number;
|
|
4
|
+
attributes?: any;
|
|
5
|
+
children?: any;
|
|
6
|
+
builderBlock?: any;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
export let attributes: SectionProps["attributes"];
|
|
12
|
+
export let maxWidth: SectionProps["maxWidth"];
|
|
13
|
+
|
|
14
|
+
function mitosis_styling(node, vars) {
|
|
15
|
+
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
16
|
+
if (p.startsWith("--")) {
|
|
17
|
+
node.style.setProperty(p, v);
|
|
18
|
+
} else {
|
|
19
|
+
node.style[p] = v;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<section
|
|
26
|
+
{...attributes}
|
|
27
|
+
use:mitosis_styling={maxWidth && typeof maxWidth === "number"
|
|
28
|
+
? {
|
|
29
|
+
maxWidth: maxWidth,
|
|
30
|
+
}
|
|
31
|
+
: undefined}
|
|
32
|
+
>
|
|
33
|
+
<slot />
|
|
34
|
+
</section>
|