@builder.io/sdk-svelte 0.0.1-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/package.json +12 -0
  2. package/src/blocks/button.svelte +38 -0
  3. package/src/blocks/columns.svelte +95 -0
  4. package/src/blocks/custom-code.svelte +63 -0
  5. package/src/blocks/embed.svelte +62 -0
  6. package/src/blocks/form.svelte +300 -0
  7. package/src/blocks/fragment.svelte +25 -0
  8. package/src/blocks/image.svelte +99 -0
  9. package/src/blocks/img.svelte +33 -0
  10. package/src/blocks/input.svelte +32 -0
  11. package/src/blocks/raw-text.svelte +26 -0
  12. package/src/blocks/section.svelte +33 -0
  13. package/src/blocks/select.svelte +34 -0
  14. package/src/blocks/submit-button.svelte +30 -0
  15. package/src/blocks/symbol.svelte +55 -0
  16. package/src/blocks/text.svelte +25 -0
  17. package/src/blocks/textarea.svelte +29 -0
  18. package/src/blocks/video.svelte +42 -0
  19. package/src/components/block-styles.svelte +23 -0
  20. package/src/components/error-boundary.svelte +23 -0
  21. package/src/components/render-block.svelte +121 -0
  22. package/src/components/render-blocks.svelte +70 -0
  23. package/src/components/render-content/components/render-styles.svelte +95 -0
  24. package/src/components/render-content/render-content.svelte +216 -0
  25. package/src/constants/device-sizes.js +46 -0
  26. package/src/constants/target.js +11 -0
  27. package/src/context/builder.context.js +33 -0
  28. package/src/functions/evaluate.js +51 -0
  29. package/src/functions/event-handler-name.js +14 -0
  30. package/src/functions/get-block-actions.js +46 -0
  31. package/src/functions/get-block-component-options.js +29 -0
  32. package/src/functions/get-block-properties.js +35 -0
  33. package/src/functions/get-block-styles.js +52 -0
  34. package/src/functions/get-block-tag.js +13 -0
  35. package/src/functions/get-builder-search-params/fn.test.js +31 -0
  36. package/src/functions/get-builder-search-params/index.js +29 -0
  37. package/src/functions/get-content/fn.test.js +49 -0
  38. package/src/functions/get-content/index.js +158 -0
  39. package/src/functions/get-fetch.js +35 -0
  40. package/src/functions/get-global-this.js +25 -0
  41. package/src/functions/get-processed-block.js +67 -0
  42. package/src/functions/get-processed-block.test.js +49 -0
  43. package/src/functions/if-target.js +38 -0
  44. package/src/functions/is-browser.js +13 -0
  45. package/src/functions/is-editing.js +30 -0
  46. package/src/functions/is-iframe.js +30 -0
  47. package/src/functions/is-previewing.js +37 -0
  48. package/src/functions/macro-eval.js +12 -0
  49. package/src/functions/on-change.js +34 -0
  50. package/src/functions/on-change.test.js +37 -0
  51. package/src/functions/previewing-model-name.js +34 -0
  52. package/src/functions/register-component.js +74 -0
  53. package/src/functions/register.js +52 -0
  54. package/src/functions/set-editor-settings.js +38 -0
  55. package/src/functions/set.js +18 -0
  56. package/src/functions/set.test.js +34 -0
  57. package/src/functions/track.js +45 -0
  58. package/src/functions/transform-block.js +13 -0
  59. package/src/index-helpers/blocks-exports.js +43 -0
  60. package/src/index-helpers/top-of-file.js +11 -0
  61. package/src/index.js +32 -0
  62. package/src/scripts/init-editing.js +89 -0
  63. package/src/types/builder-block.js +3 -0
  64. package/src/types/builder-content.js +3 -0
  65. package/src/types/deep-partial.js +3 -0
  66. package/src/types/targets.js +3 -0
  67. package/src/types/typescript.js +3 -0
@@ -0,0 +1,33 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { isEditing } from '../functions/is-editing';
7
+
8
+
9
+
10
+
11
+
12
+ export let backgroundSize;
13
+ export let backgroundPosition;
14
+ export let attributes;
15
+ export let imgSrc;
16
+ export let altText;
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ </script>
29
+
30
+ <img {...attributes} style={{
31
+ objectFit: backgroundSize || 'cover',
32
+ objectPosition: backgroundPosition || 'center'
33
+ }} key={isEditing() && imgSrc || 'default-key'} alt={altText} src={imgSrc} />
@@ -0,0 +1,32 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { isEditing } from '../functions/is-editing';
7
+
8
+
9
+
10
+
11
+
12
+ export let attributes;
13
+ export let defaultValue;
14
+ export let placeholder;
15
+ export let type;
16
+ export let name;
17
+ export let value;
18
+ export let required;
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ </script>
31
+
32
+ <input {...attributes} key={isEditing() && defaultValue ? defaultValue : 'default-key'} placeholder={placeholder} type={type} name={name} value={value} defaultValue={defaultValue} required={required} />
@@ -0,0 +1,26 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let attributes;
12
+ export let text;
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ </script>
25
+
26
+ <span class={attributes?.class || attributes?.className} >{@html text || ''}</span>
@@ -0,0 +1,33 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let attributes;
12
+ export let maxWidth;
13
+ export let children;
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ </script>
26
+
27
+ <section {...attributes} style={maxWidth && typeof maxWidth === 'number' ? {
28
+ maxWidth: maxWidth
29
+ } : undefined} >
30
+
31
+ <slot></slot>
32
+
33
+ </section>
@@ -0,0 +1,34 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { isEditing } from '../functions/is-editing';
7
+
8
+
9
+
10
+
11
+
12
+ export let attributes;
13
+ export let value;
14
+ export let defaultValue;
15
+ export let name;
16
+ export let options;
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ </script>
29
+
30
+ <select {...attributes} value={value} key={isEditing() && defaultValue ? defaultValue : 'default-key'} defaultValue={defaultValue} name={name} >
31
+
32
+ {#each options as option }<option value={option.value} >{option.name || option.value}</option>{/each}
33
+
34
+ </select>
@@ -0,0 +1,30 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let attributes;
12
+ export let text;
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ </script>
25
+
26
+ <button {...attributes} type="submit" >
27
+
28
+ {text}
29
+
30
+ </button>
@@ -0,0 +1,55 @@
1
+ <script>
2
+ import { onMount } from 'svelte'
3
+ import { afterUpdate } from 'svelte'
4
+
5
+
6
+ import RenderContent, { } from '../components/render-content/render-content.lite';
7
+ import BuilderContext, { } from '../context/builder.context.lite';
8
+ import { getContent } from '../functions/get-content';
9
+
10
+
11
+
12
+
13
+
14
+ export let attributes;
15
+ export let symbol;
16
+
17
+
18
+
19
+
20
+ let className = 'builder-symbol';
21
+ let content = null;
22
+
23
+ onMount(() => {
24
+ content = symbol?.content;
25
+ });
26
+
27
+ afterUpdate(() => {
28
+ const symbol = symbol;
29
+
30
+ if (symbol && !symbol.content && !content && symbol.model) {
31
+ getContent({
32
+ model: symbol.model,
33
+ apiKey: builderContext.apiKey!,
34
+ options: {
35
+ entry: symbol.entry
36
+ }
37
+ }).then(response => {
38
+ content = response;
39
+ });
40
+ }
41
+ })
42
+
43
+
44
+ </script>
45
+
46
+ <div {...attributes} dataSet={{
47
+ class: className
48
+ }} class={className} >
49
+
50
+ <RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...symbol?.data,
51
+ ...builderContext.state,
52
+ ...symbol?.content?.data?.state
53
+ }} model={symbol?.model} content={content} ></RenderContent>
54
+
55
+ </div>
@@ -0,0 +1,25 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let text;
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ </script>
24
+
25
+ <div class="builder-text" >{@html text}</div>
@@ -0,0 +1,29 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let attributes;
12
+ export let placeholder;
13
+ export let name;
14
+ export let value;
15
+ export let defaultValue;
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ </script>
28
+
29
+ <textarea {...attributes} placeholder={placeholder} name={name} value={value} defaultValue={defaultValue} ></textarea>
@@ -0,0 +1,42 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export let attributes;
12
+ export let fit;
13
+ export let position;
14
+ export let video;
15
+ export let posterImage;
16
+ export let autoPlay;
17
+ export let muted;
18
+ export let controls;
19
+ export let loop;
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ </script>
32
+
33
+ <video {...attributes} preload="none" style={{
34
+ width: '100%',
35
+ height: '100%',
36
+ ...attributes?.style,
37
+ objectFit: fit,
38
+ objectPosition: position,
39
+ // Hack to get object fit to work as expected and
40
+ // not have the video overflow
41
+ borderRadius: 1
42
+ }} key={video || 'no-src'} poster={posterImage} autoPlay={autoPlay} muted={muted} controls={controls} loop={loop} ></video>
@@ -0,0 +1,121 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { getBlockComponentOptions } from '../functions/get-block-component-options';
7
+ import { getBlockProperties } from '../functions/get-block-properties';
8
+ import { getBlockStyles } from '../functions/get-block-styles';
9
+ import { getBlockTag } from '../functions/get-block-tag';
10
+ import { components } from '../functions/register-component';
11
+ import BuilderContext, { } from '../context/builder.context.lite';
12
+ import { getBlockActions } from '../functions/get-block-actions';
13
+ import { getProcessedBlock } from '../functions/get-processed-block';
14
+ import BlockStyles, { } from './block-styles.lite';
15
+
16
+
17
+
18
+
19
+
20
+ export let block;
21
+
22
+
23
+ $: component = () => {
24
+ const componentName = useBlock().component?.name;
25
+
26
+ if (!componentName) {
27
+ return null;
28
+ }
29
+
30
+ const ref = components[useBlock().component?.name];
31
+
32
+ if (componentName && !ref) {
33
+ // TODO: Public doc page with more info about this message
34
+ console.warn(`
35
+ Could not find a registered component named "${componentName}".
36
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
37
+ }
38
+
39
+ return ref;
40
+ };
41
+
42
+ $: componentInfo = () => {
43
+ return component?.()?.info;
44
+ };
45
+
46
+ $: componentRef = () => {
47
+ return component?.()?.component;
48
+ };
49
+
50
+ $: tagName = () => {
51
+ return getBlockTag(useBlock());
52
+ };
53
+
54
+ $: useBlock = () => {
55
+ return getProcessedBlock({
56
+ block: block,
57
+ state: builderContext.state,
58
+ context: builderContext.context
59
+ });
60
+ };
61
+
62
+ $: propertiesAndActions = () => {
63
+ return { ...getBlockProperties(useBlock()),
64
+ ...getBlockActions({
65
+ block: useBlock(),
66
+ state: builderContext.state,
67
+ context: builderContext.context
68
+ })
69
+ };
70
+ };
71
+
72
+ $: css = () => {
73
+ return getBlockStyles(useBlock());
74
+ };
75
+
76
+ $: componentOptions = () => {
77
+ return getBlockComponentOptions(useBlock());
78
+ };
79
+
80
+ $: children = () => {
81
+ // TO-DO: When should `canHaveChildren` dictate rendering?
82
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
83
+ // but still receive and need to render children.
84
+ // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
85
+ return useBlock().children ?? [];
86
+ };
87
+
88
+ $: noCompRefChildren = () => {
89
+ return componentRef() ? [] : children();
90
+ };
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ </script>
100
+
101
+
102
+
103
+ {#if !componentInfo?.()?.noWrap }
104
+
105
+ <tagName() {...propertiesAndActions()} style={css()} >
106
+
107
+ <BlockStyles block={useBlock()} ></BlockStyles>
108
+
109
+
110
+ {#if componentRef() }<componentRef() {...componentOptions()} builderBlock={useBlock()} >
111
+
112
+ {#each children() as child }<RenderBlock block={child} ></RenderBlock>{/each}
113
+
114
+ </componentRef()>{/if}
115
+
116
+
117
+ {#each noCompRefChildren() as child }<RenderBlock block={child} ></RenderBlock>{/each}
118
+
119
+ </tagName()>
120
+
121
+ {/if}
@@ -0,0 +1,70 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { isEditing } from '../functions/is-editing';
7
+ import RenderBlock, { } from './render-block.lite';
8
+
9
+
10
+
11
+
12
+
13
+ export let blocks;
14
+ export let parent;
15
+ export let path;
16
+
17
+ function onClick() {
18
+ if (isEditing() && !blocks?.length) {
19
+ window.parent?.postMessage({
20
+ type: 'builder.clickEmptyBlocks',
21
+ data: {
22
+ parentElementId: parent,
23
+ dataPath: path
24
+ }
25
+ }, '*');
26
+ }
27
+ }
28
+
29
+ function onMouseEnter() {
30
+ if (isEditing() && !blocks?.length) {
31
+ window.parent?.postMessage({
32
+ type: 'builder.hoverEmptyBlocks',
33
+ data: {
34
+ parentElementId: parent,
35
+ dataPath: path
36
+ }
37
+ }, '*');
38
+ }
39
+ }
40
+ $: className = () => {
41
+ return 'builder-blocks' + (!blocks?.length ? ' no-blocks' : '');
42
+ };
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+ </script>
52
+
53
+ <div class="div" builder-path={path} builder-parent-id={parent} dataSet={{
54
+ class: className()
55
+ }} on:click="{event => onClick()}" on:mouseenter="{event => onMouseEnter()}" class={className()} >
56
+
57
+ {#if blocks }
58
+
59
+ {#each blocks as block }<RenderBlock key={block.id} block={block} ></RenderBlock>{/each}
60
+
61
+ {/if}
62
+
63
+ </div>
64
+
65
+ <style>
66
+ .div {
67
+ display: flex;
68
+ flex-direction: column;
69
+ align-items: stretch; }
70
+ </style>
@@ -0,0 +1,95 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { TARGET } from '../../../constants/target';
7
+
8
+
9
+
10
+
11
+
12
+ export let cssCode;
13
+ export let customFonts;
14
+
15
+ function getCssFromFont(font) {
16
+ // TODO: compute what font sizes are used and only load those.......
17
+ const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
18
+ const name = family.split(',')[0];
19
+ const url = font.fileUrl ?? font?.files?.regular;
20
+ let str = '';
21
+
22
+ if (url && family && name) {
23
+ str += `
24
+ @font-face {
25
+ font-family: "${family}";
26
+ src: local("${name}"), url('${url}') format('woff2');
27
+ font-display: fallback;
28
+ font-weight: 400;
29
+ }
30
+ `.trim();
31
+ }
32
+
33
+ if (font.files) {
34
+ for (const weight in font.files) {
35
+ const isNumber = String(Number(weight)) === weight;
36
+
37
+ if (!isNumber) {
38
+ continue;
39
+ } // TODO: maybe limit number loaded
40
+
41
+
42
+ const weightUrl = font.files[weight];
43
+
44
+ if (weightUrl && weightUrl !== url) {
45
+ str += `
46
+ @font-face {
47
+ font-family: "${family}";
48
+ src: url('${weightUrl}') format('woff2');
49
+ font-display: fallback;
50
+ font-weight: ${weight};
51
+ }
52
+ `.trim();
53
+ }
54
+ }
55
+ }
56
+
57
+ return str;
58
+ }
59
+
60
+ function getFontCss({
61
+ customFonts
62
+ }) {
63
+ // TODO: flag for this
64
+ // if (!this.builder.allowCustomFonts) {
65
+ // return '';
66
+ // }
67
+ // TODO: separate internal data from external
68
+ return customFonts?.map(font => this.getCssFromFont(font))?.join(' ') || '';
69
+ }
70
+ $: injectedStyles = () => {
71
+ return `
72
+ ${cssCode || ''}
73
+ ${getFontCss({
74
+ customFonts: customFonts
75
+ })}`;
76
+ };
77
+
78
+ $: injectedStyleScript = () => {
79
+ return `<style>${injectedStyles()}</style>`;
80
+ };
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ </script>
90
+
91
+ {#if TARGET === 'svelte' }
92
+
93
+ {@html injectedStyleScript()}
94
+
95
+ {/if}