@builder.io/sdk-svelte 0.0.4 → 0.0.6
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/components/render-content/render-content.svelte +13 -7
- package/package/functions/track.d.ts +35 -5
- package/package/functions/track.js +5 -4
- package/package/index.d.ts +1 -0
- package/package/index.js +1 -0
- 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 +360 -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 +124 -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 +13 -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
package/package/--package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
-
"package"
|
|
7
|
+
"package",
|
|
8
|
+
"src"
|
|
8
9
|
],
|
|
9
10
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
|
|
10
11
|
"repository": {
|
|
@@ -11,7 +11,7 @@ import { isBrowser } from "../../functions/is-browser.js";
|
|
|
11
11
|
import { isEditing } from "../../functions/is-editing.js";
|
|
12
12
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
13
13
|
import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
|
|
14
|
-
import {
|
|
14
|
+
import { _track } from "../../functions/track.js";
|
|
15
15
|
import RenderBlocks from "../render-blocks.svelte";
|
|
16
16
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
17
17
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
|
|
@@ -77,11 +77,14 @@ function evaluateJsCode() {
|
|
|
77
77
|
}
|
|
78
78
|
function onClick(_event) {
|
|
79
79
|
if (useContent()) {
|
|
80
|
-
|
|
80
|
+
const variationId = useContent?.()?.testVariationId;
|
|
81
|
+
const contentId = useContent?.()?.id;
|
|
82
|
+
_track({
|
|
81
83
|
type: "click",
|
|
82
84
|
canTrack: canTrackToUse(),
|
|
83
|
-
contentId
|
|
84
|
-
|
|
85
|
+
contentId,
|
|
86
|
+
apiKey: apiKey,
|
|
87
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
85
88
|
});
|
|
86
89
|
}
|
|
87
90
|
}
|
|
@@ -204,11 +207,14 @@ onMount(() => {
|
|
|
204
207
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
205
208
|
}
|
|
206
209
|
if (useContent()) {
|
|
207
|
-
|
|
210
|
+
const variationId = useContent?.()?.testVariationId;
|
|
211
|
+
const contentId = useContent?.()?.id;
|
|
212
|
+
_track({
|
|
208
213
|
type: "impression",
|
|
209
214
|
canTrack: canTrackToUse(),
|
|
210
|
-
contentId
|
|
211
|
-
|
|
215
|
+
contentId,
|
|
216
|
+
apiKey: apiKey,
|
|
217
|
+
variationId: variationId !== contentId ? variationId : undefined,
|
|
212
218
|
});
|
|
213
219
|
}
|
|
214
220
|
// override normal content in preview mode
|
|
@@ -2,20 +2,50 @@ import type { CanTrack } from '../types/can-track.js';
|
|
|
2
2
|
interface Event {
|
|
3
3
|
type: 'click' | 'impression';
|
|
4
4
|
data: {
|
|
5
|
+
/**
|
|
6
|
+
* (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
|
|
7
|
+
*/
|
|
5
8
|
contentId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* This is the ID of the space that the content belongs to.
|
|
11
|
+
*/
|
|
6
12
|
ownerId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Stringified JSON object containing any additional metadata you want to track.
|
|
15
|
+
*/
|
|
7
16
|
metadata?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Session ID of the user. This is provided by the SDK by checking session storage.
|
|
19
|
+
*/
|
|
8
20
|
sessionId: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Visitor ID of the user. This is provided by the SDK by checking cookies.
|
|
23
|
+
*/
|
|
9
24
|
visitorId: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* (Optional) If running an A/B test, the ID of the variation that the user is in.
|
|
27
|
+
*/
|
|
28
|
+
variationId?: string;
|
|
10
29
|
[index: string]: any;
|
|
11
30
|
};
|
|
12
31
|
}
|
|
13
|
-
declare type EventProperties = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
declare type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | 'variationId'> & {
|
|
33
|
+
/**
|
|
34
|
+
* Your organization's API key.
|
|
35
|
+
*/
|
|
36
|
+
apiKey: Event['data']['ownerId'];
|
|
37
|
+
/**
|
|
38
|
+
* (Optional) metadata that you want to provide with your event.
|
|
39
|
+
*/
|
|
40
|
+
metadata?: {
|
|
41
|
+
[index: string]: any;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
45
|
+
*/
|
|
17
46
|
[index: string]: any;
|
|
18
47
|
};
|
|
19
48
|
export declare type EventProps = EventProperties & CanTrack;
|
|
20
|
-
export declare function
|
|
49
|
+
export declare function _track(eventProps: EventProps): Promise<void | Response>;
|
|
50
|
+
export declare const track: (args: EventProperties) => Promise<void | Response>;
|
|
21
51
|
export {};
|
|
@@ -14,16 +14,16 @@ const getTrackingEventData = async ({ canTrack, }) => {
|
|
|
14
14
|
visitorId,
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
const createEvent = async ({ type: eventType, canTrack,
|
|
17
|
+
const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...properties }) => ({
|
|
18
18
|
type: eventType,
|
|
19
19
|
data: {
|
|
20
20
|
...properties,
|
|
21
|
+
metadata: JSON.stringify(metadata),
|
|
21
22
|
...(await getTrackingEventData({ canTrack })),
|
|
22
|
-
ownerId:
|
|
23
|
-
contentId,
|
|
23
|
+
ownerId: apiKey,
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
|
-
export async function
|
|
26
|
+
export async function _track(eventProps) {
|
|
27
27
|
if (!eventProps.canTrack) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
@@ -46,3 +46,4 @@ export async function track(eventProps) {
|
|
|
46
46
|
console.error('Failed to track: ', err);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
+
export const track = (args) => _track({ ...args, canTrack: true });
|
package/package/index.d.ts
CHANGED
package/package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
-
"package"
|
|
7
|
+
"package",
|
|
8
|
+
"src"
|
|
8
9
|
],
|
|
9
10
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
|
|
10
11
|
"repository": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface BaseTextProps {
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { getContext, setContext } from "svelte";
|
|
9
|
+
|
|
10
|
+
import BuilderContext from "../context/builder.context.js";
|
|
11
|
+
|
|
12
|
+
export let text: BaseTextProps["text"];
|
|
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
|
+
|
|
24
|
+
let builderContext = getContext(BuilderContext.key);
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<span use:mitosis_styling={builderContext.inheritedStyles}>{text}</span>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface ButtonProps {
|
|
3
|
+
attributes?: any;
|
|
4
|
+
text?: string;
|
|
5
|
+
link?: string;
|
|
6
|
+
openLinkInNewTab?: boolean;
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
export let attributes: ButtonProps["attributes"];
|
|
12
|
+
export let text: ButtonProps["text"];
|
|
13
|
+
export let link: ButtonProps["link"];
|
|
14
|
+
export let openLinkInNewTab: ButtonProps["openLinkInNewTab"];
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
{#if link}
|
|
18
|
+
<a
|
|
19
|
+
{...attributes}
|
|
20
|
+
role="button"
|
|
21
|
+
href={link}
|
|
22
|
+
target={openLinkInNewTab ? "_blank" : undefined}
|
|
23
|
+
>
|
|
24
|
+
{text}
|
|
25
|
+
</a>
|
|
26
|
+
{:else}
|
|
27
|
+
<button {...attributes} class="button">
|
|
28
|
+
{text}
|
|
29
|
+
</button>
|
|
30
|
+
{/if}
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.button {
|
|
34
|
+
all: unset;
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
|
|
3
|
+
export const componentInfo: ComponentInfo = {
|
|
4
|
+
name: 'Core:Button',
|
|
5
|
+
builtIn: true,
|
|
6
|
+
image:
|
|
7
|
+
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',
|
|
8
|
+
defaultStyles: {
|
|
9
|
+
// TODO: make min width more intuitive and set one
|
|
10
|
+
appearance: 'none',
|
|
11
|
+
paddingTop: '15px',
|
|
12
|
+
paddingBottom: '15px',
|
|
13
|
+
paddingLeft: '25px',
|
|
14
|
+
paddingRight: '25px',
|
|
15
|
+
backgroundColor: '#000000',
|
|
16
|
+
color: 'white',
|
|
17
|
+
borderRadius: '4px',
|
|
18
|
+
textAlign: 'center',
|
|
19
|
+
cursor: 'pointer',
|
|
20
|
+
},
|
|
21
|
+
inputs: [
|
|
22
|
+
{
|
|
23
|
+
name: 'text',
|
|
24
|
+
type: 'text',
|
|
25
|
+
defaultValue: 'Click me!',
|
|
26
|
+
bubble: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'link',
|
|
30
|
+
type: 'url',
|
|
31
|
+
bubble: true,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'openLinkInNewTab',
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
defaultValue: false,
|
|
37
|
+
friendlyName: 'Open link in new tab',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
static: true,
|
|
41
|
+
noWrap: true,
|
|
42
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
3
|
+
|
|
4
|
+
type CSS = {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type Column = {
|
|
9
|
+
blocks: any;
|
|
10
|
+
// TODO: Implement this when support for dynamic CSS lands
|
|
11
|
+
width?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type StackColumnsAt = "tablet" | "mobile" | "never";
|
|
15
|
+
|
|
16
|
+
export interface ColumnProps {
|
|
17
|
+
columns?: Column[];
|
|
18
|
+
builderBlock: BuilderBlock;
|
|
19
|
+
|
|
20
|
+
// TODO: Implement this when support for dynamic CSS lands
|
|
21
|
+
space?: number;
|
|
22
|
+
// TODO: Implement this when support for dynamic CSS lands
|
|
23
|
+
stackColumnsAt?: StackColumnsAt;
|
|
24
|
+
// TODO: Implement this when support for dynamic CSS lands
|
|
25
|
+
reverseColumnsWhenStacked?: boolean;
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script lang="ts">
|
|
30
|
+
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
31
|
+
import { markMutable } from "../../functions/mark-mutable";
|
|
32
|
+
|
|
33
|
+
export let space: ColumnProps["space"];
|
|
34
|
+
export let columns: ColumnProps["columns"];
|
|
35
|
+
export let stackColumnsAt: ColumnProps["stackColumnsAt"];
|
|
36
|
+
export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
|
|
37
|
+
export let builderBlock: ColumnProps["builderBlock"];
|
|
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
|
+
function getGutterSize() {
|
|
50
|
+
return typeof space === "number" ? space || 0 : 20;
|
|
51
|
+
}
|
|
52
|
+
function getColumns() {
|
|
53
|
+
return columns || [];
|
|
54
|
+
}
|
|
55
|
+
function getWidth(index) {
|
|
56
|
+
const columns = getColumns();
|
|
57
|
+
return columns[index]?.width || 100 / columns.length;
|
|
58
|
+
}
|
|
59
|
+
function getColumnCssWidth(index) {
|
|
60
|
+
const columns = getColumns();
|
|
61
|
+
const gutterSize = getGutterSize();
|
|
62
|
+
const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
|
|
63
|
+
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
64
|
+
}
|
|
65
|
+
function maybeApplyForTablet(prop) {
|
|
66
|
+
const _stackColumnsAt = stackColumnsAt || "tablet";
|
|
67
|
+
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
68
|
+
}
|
|
69
|
+
$: columnsCssVars = () => {
|
|
70
|
+
const flexDir =
|
|
71
|
+
stackColumnsAt === "never"
|
|
72
|
+
? "inherit"
|
|
73
|
+
: reverseColumnsWhenStacked
|
|
74
|
+
? "column-reverse"
|
|
75
|
+
: "column";
|
|
76
|
+
return {
|
|
77
|
+
"--flex-dir": flexDir,
|
|
78
|
+
"--flex-dir-tablet": maybeApplyForTablet(flexDir),
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
$: columnCssVars = () => {
|
|
82
|
+
const width = "100%";
|
|
83
|
+
const marginLeft = "0";
|
|
84
|
+
return {
|
|
85
|
+
"--column-width": width,
|
|
86
|
+
"--column-margin-left": marginLeft,
|
|
87
|
+
"--column-width-tablet": maybeApplyForTablet(width),
|
|
88
|
+
"--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
|
|
94
|
+
{#each columns as column, index (index)}
|
|
95
|
+
<div
|
|
96
|
+
use:mitosis_styling={{
|
|
97
|
+
width: getColumnCssWidth(index),
|
|
98
|
+
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
99
|
+
...columnCssVars(),
|
|
100
|
+
}}
|
|
101
|
+
class="builder-column div-2"
|
|
102
|
+
>
|
|
103
|
+
<RenderBlocks
|
|
104
|
+
blocks={markMutable(column.blocks)}
|
|
105
|
+
path={`component.options.columns.${index}.blocks`}
|
|
106
|
+
parent={builderBlock.id}
|
|
107
|
+
styleProp={{
|
|
108
|
+
flexGrow: "1",
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
{/each}
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<style>
|
|
116
|
+
.div {
|
|
117
|
+
display: flex;
|
|
118
|
+
align-items: stretch;
|
|
119
|
+
line-height: normal;
|
|
120
|
+
}
|
|
121
|
+
@media (max-width: 991px) {
|
|
122
|
+
.div {
|
|
123
|
+
flex-direction: var(--flex-dir-tablet);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
@media (max-width: 639px) {
|
|
127
|
+
.div {
|
|
128
|
+
flex-direction: var(--flex-dir);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
.div-2 {
|
|
132
|
+
display: flex;
|
|
133
|
+
flex-direction: column;
|
|
134
|
+
align-items: stretch;
|
|
135
|
+
}
|
|
136
|
+
@media (max-width: 991px) {
|
|
137
|
+
.div-2 {
|
|
138
|
+
width: var(--column-width-tablet) !important;
|
|
139
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
@media (max-width: 639px) {
|
|
143
|
+
.div-2 {
|
|
144
|
+
width: var(--column-width) !important;
|
|
145
|
+
margin-left: var(--column-margin-left) !important;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
</style>
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
import { markSerializable } from '../util.js';
|
|
3
|
+
|
|
4
|
+
export const componentInfo: ComponentInfo = {
|
|
5
|
+
// TODO: ways to statically preprocess JSON for references, functions, etc
|
|
6
|
+
name: 'Columns',
|
|
7
|
+
builtIn: true,
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 'columns',
|
|
11
|
+
type: 'array',
|
|
12
|
+
broadcast: true,
|
|
13
|
+
subFields: [
|
|
14
|
+
{
|
|
15
|
+
name: 'blocks',
|
|
16
|
+
type: 'array',
|
|
17
|
+
hideFromUI: true,
|
|
18
|
+
defaultValue: [
|
|
19
|
+
{
|
|
20
|
+
'@type': '@builder.io/sdk:Element',
|
|
21
|
+
responsiveStyles: {
|
|
22
|
+
large: {
|
|
23
|
+
display: 'flex',
|
|
24
|
+
flexDirection: 'column',
|
|
25
|
+
alignItems: 'stretch',
|
|
26
|
+
flexShrink: '0',
|
|
27
|
+
position: 'relative',
|
|
28
|
+
marginTop: '30px',
|
|
29
|
+
textAlign: 'center',
|
|
30
|
+
lineHeight: 'normal',
|
|
31
|
+
height: 'auto',
|
|
32
|
+
minHeight: '20px',
|
|
33
|
+
minWidth: '20px',
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
component: {
|
|
38
|
+
name: 'Image',
|
|
39
|
+
options: {
|
|
40
|
+
image:
|
|
41
|
+
'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
42
|
+
backgroundPosition: 'center',
|
|
43
|
+
backgroundSize: 'cover',
|
|
44
|
+
aspectRatio: 0.7004048582995948,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
'@type': '@builder.io/sdk:Element',
|
|
50
|
+
responsiveStyles: {
|
|
51
|
+
large: {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
flexDirection: 'column',
|
|
54
|
+
alignItems: 'stretch',
|
|
55
|
+
flexShrink: '0',
|
|
56
|
+
position: 'relative',
|
|
57
|
+
marginTop: '30px',
|
|
58
|
+
textAlign: 'center',
|
|
59
|
+
lineHeight: 'normal',
|
|
60
|
+
height: 'auto',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
component: {
|
|
64
|
+
name: 'Text',
|
|
65
|
+
options: {
|
|
66
|
+
text: '<p>Enter some text...</p>',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'width',
|
|
74
|
+
type: 'number',
|
|
75
|
+
hideFromUI: true,
|
|
76
|
+
helperText: 'Width %, e.g. set to 50 to fill half of the space',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'link',
|
|
80
|
+
type: 'url',
|
|
81
|
+
helperText:
|
|
82
|
+
'Optionally set a url that clicking this column will link to',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
defaultValue: [
|
|
86
|
+
{
|
|
87
|
+
blocks: [
|
|
88
|
+
{
|
|
89
|
+
'@type': '@builder.io/sdk:Element',
|
|
90
|
+
responsiveStyles: {
|
|
91
|
+
large: {
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flexDirection: 'column',
|
|
94
|
+
alignItems: 'stretch',
|
|
95
|
+
flexShrink: '0',
|
|
96
|
+
position: 'relative',
|
|
97
|
+
marginTop: '30px',
|
|
98
|
+
textAlign: 'center',
|
|
99
|
+
lineHeight: 'normal',
|
|
100
|
+
height: 'auto',
|
|
101
|
+
minHeight: '20px',
|
|
102
|
+
minWidth: '20px',
|
|
103
|
+
overflow: 'hidden',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
component: {
|
|
107
|
+
name: 'Image',
|
|
108
|
+
options: {
|
|
109
|
+
image:
|
|
110
|
+
'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
111
|
+
backgroundPosition: 'center',
|
|
112
|
+
backgroundSize: 'cover',
|
|
113
|
+
aspectRatio: 0.7004048582995948,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
'@type': '@builder.io/sdk:Element',
|
|
119
|
+
responsiveStyles: {
|
|
120
|
+
large: {
|
|
121
|
+
display: 'flex',
|
|
122
|
+
flexDirection: 'column',
|
|
123
|
+
alignItems: 'stretch',
|
|
124
|
+
flexShrink: '0',
|
|
125
|
+
position: 'relative',
|
|
126
|
+
marginTop: '30px',
|
|
127
|
+
textAlign: 'center',
|
|
128
|
+
lineHeight: 'normal',
|
|
129
|
+
height: 'auto',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
component: {
|
|
133
|
+
name: 'Text',
|
|
134
|
+
options: {
|
|
135
|
+
text: '<p>Enter some text...</p>',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
blocks: [
|
|
143
|
+
{
|
|
144
|
+
'@type': '@builder.io/sdk:Element',
|
|
145
|
+
responsiveStyles: {
|
|
146
|
+
large: {
|
|
147
|
+
display: 'flex',
|
|
148
|
+
flexDirection: 'column',
|
|
149
|
+
alignItems: 'stretch',
|
|
150
|
+
flexShrink: '0',
|
|
151
|
+
position: 'relative',
|
|
152
|
+
marginTop: '30px',
|
|
153
|
+
textAlign: 'center',
|
|
154
|
+
lineHeight: 'normal',
|
|
155
|
+
height: 'auto',
|
|
156
|
+
minHeight: '20px',
|
|
157
|
+
minWidth: '20px',
|
|
158
|
+
overflow: 'hidden',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
component: {
|
|
162
|
+
name: 'Image',
|
|
163
|
+
options: {
|
|
164
|
+
image:
|
|
165
|
+
'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
166
|
+
backgroundPosition: 'center',
|
|
167
|
+
backgroundSize: 'cover',
|
|
168
|
+
aspectRatio: 0.7004048582995948,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
'@type': '@builder.io/sdk:Element',
|
|
174
|
+
responsiveStyles: {
|
|
175
|
+
large: {
|
|
176
|
+
display: 'flex',
|
|
177
|
+
flexDirection: 'column',
|
|
178
|
+
alignItems: 'stretch',
|
|
179
|
+
flexShrink: '0',
|
|
180
|
+
position: 'relative',
|
|
181
|
+
marginTop: '30px',
|
|
182
|
+
textAlign: 'center',
|
|
183
|
+
lineHeight: 'normal',
|
|
184
|
+
height: 'auto',
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
component: {
|
|
188
|
+
name: 'Text',
|
|
189
|
+
options: {
|
|
190
|
+
text: '<p>Enter some text...</p>',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
onChange: markSerializable((options: Map<string, any>) => {
|
|
198
|
+
function clearWidths() {
|
|
199
|
+
columns.forEach((col) => {
|
|
200
|
+
col.delete('width');
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const columns: Array<Map<string, any>> = options.get('columns');
|
|
205
|
+
|
|
206
|
+
if (Array.isArray(columns)) {
|
|
207
|
+
const containsColumnWithWidth = !!columns.find((col) =>
|
|
208
|
+
col.get('width')
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
if (containsColumnWithWidth) {
|
|
212
|
+
const containsColumnWithoutWidth = !!columns.find(
|
|
213
|
+
(col) => !col.get('width')
|
|
214
|
+
);
|
|
215
|
+
if (containsColumnWithoutWidth) {
|
|
216
|
+
clearWidths();
|
|
217
|
+
} else {
|
|
218
|
+
const sumWidths = columns.reduce((memo, col) => {
|
|
219
|
+
return memo + col.get('width');
|
|
220
|
+
}, 0);
|
|
221
|
+
const widthsDontAddUp = sumWidths !== 100;
|
|
222
|
+
if (widthsDontAddUp) {
|
|
223
|
+
clearWidths();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: 'space',
|
|
232
|
+
type: 'number',
|
|
233
|
+
defaultValue: 20,
|
|
234
|
+
helperText: 'Size of gap between columns',
|
|
235
|
+
advanced: true,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: 'stackColumnsAt',
|
|
239
|
+
type: 'string',
|
|
240
|
+
defaultValue: 'tablet',
|
|
241
|
+
helperText: 'Convert horizontal columns to vertical at what device size',
|
|
242
|
+
enum: ['tablet', 'mobile', 'never'],
|
|
243
|
+
advanced: true,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: 'reverseColumnsWhenStacked',
|
|
247
|
+
type: 'boolean',
|
|
248
|
+
defaultValue: false,
|
|
249
|
+
helperText:
|
|
250
|
+
'When stacking columns for mobile devices, reverse the ordering',
|
|
251
|
+
advanced: true,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
};
|