@builder.io/sdk-svelte 0.0.1-0 → 0.0.1-11

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 (97) hide show
  1. package/README.md +15 -0
  2. package/package.json +16 -4
  3. package/src/blocks/{button.svelte → button/button.svelte} +29 -18
  4. package/src/blocks/button/component-info.js +41 -0
  5. package/src/blocks/{columns.svelte → columns/columns.svelte} +22 -14
  6. package/src/blocks/columns/component-info.js +217 -0
  7. package/src/blocks/custom-code/component-info.js +31 -0
  8. package/src/blocks/custom-code/custom-code.svelte +64 -0
  9. package/src/blocks/embed/component-info.js +24 -0
  10. package/src/blocks/embed/embed.svelte +63 -0
  11. package/src/blocks/form/component-info.js +262 -0
  12. package/src/blocks/{form.svelte → form/form.svelte} +49 -16
  13. package/src/blocks/fragment/component-info.js +11 -0
  14. package/src/blocks/{fragment.svelte → fragment/fragment.svelte} +5 -2
  15. package/src/blocks/image/component-info.js +104 -0
  16. package/src/blocks/{image.svelte → image/image.svelte} +27 -9
  17. package/src/blocks/img/component-info.js +20 -0
  18. package/src/blocks/{img.svelte → img/img.svelte} +5 -2
  19. package/src/blocks/input/component-info.js +74 -0
  20. package/src/blocks/{input.svelte → input/input.svelte} +5 -2
  21. package/src/blocks/raw-text/component-info.js +16 -0
  22. package/src/blocks/{raw-text.svelte → raw-text/raw-text.svelte} +4 -1
  23. package/src/blocks/section/component-info.js +49 -0
  24. package/src/blocks/{section.svelte → section/section.svelte} +4 -1
  25. package/src/blocks/select/component-info.js +59 -0
  26. package/src/blocks/{select.svelte → select/select.svelte} +10 -3
  27. package/src/blocks/submit-button/component-info.js +28 -0
  28. package/src/blocks/{submit-button.svelte → submit-button/submit-button.svelte} +4 -1
  29. package/src/blocks/symbol/component-info.js +43 -0
  30. package/src/blocks/symbol/symbol.svelte +54 -0
  31. package/src/blocks/text/component-info.js +24 -0
  32. package/src/blocks/{text.svelte → text/text.svelte} +4 -1
  33. package/src/blocks/textarea/component-info.js +47 -0
  34. package/src/blocks/{textarea.svelte → textarea/textarea.svelte} +4 -1
  35. package/src/blocks/video/component-info.js +106 -0
  36. package/src/blocks/{video.svelte → video/video.svelte} +4 -1
  37. package/src/components/error-boundary.svelte +4 -1
  38. package/src/components/render-block/block-styles.svelte +51 -0
  39. package/src/components/render-block/render-block.helpers.js +23 -0
  40. package/src/components/render-block/render-block.svelte +182 -0
  41. package/src/components/render-blocks.svelte +18 -6
  42. package/src/components/render-content/components/render-styles.svelte +8 -13
  43. package/src/components/render-content/index.js +4 -0
  44. package/src/components/render-content/render-content.svelte +210 -174
  45. package/src/components/render-inlined-styles.svelte +51 -0
  46. package/src/constants/builder-registered-components.js +45 -0
  47. package/src/constants/device-sizes.js +4 -11
  48. package/src/constants/target.js +3 -10
  49. package/src/context/builder.context.js +6 -31
  50. package/src/functions/evaluate.js +8 -31
  51. package/src/functions/event-handler-name.js +3 -10
  52. package/src/functions/fast-clone.js +4 -0
  53. package/src/functions/get-block-actions.js +6 -29
  54. package/src/functions/get-block-component-options.js +3 -9
  55. package/src/functions/get-block-properties.js +3 -9
  56. package/src/functions/get-block-styles.js +6 -27
  57. package/src/functions/get-block-tag.js +3 -10
  58. package/src/functions/get-builder-search-params/fn.test.js +3 -21
  59. package/src/functions/get-builder-search-params/index.js +4 -11
  60. package/src/functions/get-content/fn.test.js +3 -21
  61. package/src/functions/get-content/index.js +8 -28
  62. package/src/functions/get-fetch.js +31 -32
  63. package/src/functions/get-global-this.js +3 -10
  64. package/src/functions/get-processed-block.js +9 -30
  65. package/src/functions/get-processed-block.test.js +2 -20
  66. package/src/functions/if-target.js +5 -28
  67. package/src/functions/is-browser.js +3 -10
  68. package/src/functions/is-editing.js +5 -28
  69. package/src/functions/is-iframe.js +5 -28
  70. package/src/functions/is-previewing.js +7 -30
  71. package/src/functions/on-change.js +4 -11
  72. package/src/functions/on-change.test.js +4 -22
  73. package/src/functions/previewing-model-name.js +5 -28
  74. package/src/functions/register-component.js +32 -36
  75. package/src/functions/register.js +5 -28
  76. package/src/functions/set-editor-settings.js +5 -28
  77. package/src/functions/set.js +3 -10
  78. package/src/functions/set.test.js +4 -22
  79. package/src/functions/track.js +8 -31
  80. package/src/functions/transform-block.js +3 -10
  81. package/src/index-helpers/blocks-exports.js +19 -42
  82. package/src/index-helpers/top-of-file.js +3 -10
  83. package/src/index.js +10 -32
  84. package/src/scripts/init-editing.js +72 -81
  85. package/src/types/builder-block.js +0 -3
  86. package/src/types/builder-content.js +0 -3
  87. package/src/types/components.js +0 -0
  88. package/src/types/deep-partial.js +0 -3
  89. package/src/types/element.js +0 -0
  90. package/src/types/targets.js +0 -3
  91. package/src/types/typescript.js +0 -3
  92. package/src/blocks/custom-code.svelte +0 -63
  93. package/src/blocks/embed.svelte +0 -62
  94. package/src/blocks/symbol.svelte +0 -55
  95. package/src/components/block-styles.svelte +0 -23
  96. package/src/components/render-block.svelte +0 -121
  97. package/src/functions/macro-eval.js +0 -12
@@ -0,0 +1,51 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import RenderInlinedStyles, { } from '../render-inlined-styles.svelte';
7
+
8
+
9
+
10
+
11
+
12
+
13
+ export let block;
14
+
15
+ function camelToKebabCase(string) {
16
+ return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
17
+ }
18
+ $: css = () => {
19
+ // TODO: media queries
20
+ const styleObject = block.responsiveStyles?.large;
21
+
22
+ if (!styleObject) {
23
+ return '';
24
+ }
25
+
26
+ let str = `.${block.id} {`;
27
+
28
+ for (const key in styleObject) {
29
+ const value = styleObject[key];
30
+
31
+ if (typeof value === 'string') {
32
+ str += `${camelToKebabCase(key)}: ${value};`;
33
+ }
34
+ }
35
+
36
+ str += '}';
37
+ return str;
38
+ };
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ </script>
50
+
51
+ <RenderInlinedStyles styles={css()} ></RenderInlinedStyles>
@@ -0,0 +1,23 @@
1
+ const EMPTY_HTML_ELEMENTS = [
2
+ "area",
3
+ "base",
4
+ "br",
5
+ "col",
6
+ "embed",
7
+ "hr",
8
+ "img",
9
+ "input",
10
+ "keygen",
11
+ "link",
12
+ "meta",
13
+ "param",
14
+ "source",
15
+ "track",
16
+ "wbr"
17
+ ];
18
+ const isEmptyHtmlElement = (tagName) => {
19
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
20
+ };
21
+ export {
22
+ isEmptyHtmlElement
23
+ };
@@ -0,0 +1,182 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { TARGET } from '../../constants/target.js';
7
+ import BuilderContext, { } from '../../context/builder.context';
8
+ import { getBlockActions } from '../../functions/get-block-actions.js';
9
+ import { getBlockComponentOptions } from '../../functions/get-block-component-options.js';
10
+ import { getBlockProperties } from '../../functions/get-block-properties.js';
11
+ import { getBlockStyles } from '../../functions/get-block-styles.js';
12
+ import { getBlockTag } from '../../functions/get-block-tag.js';
13
+ import { getProcessedBlock } from '../../functions/get-processed-block.js';
14
+ import BlockStyles, { } from './block-styles.svelte';
15
+ import { isEmptyHtmlElement } from './render-block.helpers.js';
16
+
17
+
18
+
19
+ import { getContext, setContext } from "svelte";
20
+
21
+
22
+ export let block;
23
+
24
+
25
+ $: component = () => {
26
+ const componentName = useBlock().component?.name;
27
+
28
+ if (!componentName) {
29
+ return null;
30
+ }
31
+
32
+ const ref = builderContext.registeredComponents[componentName];
33
+
34
+ if (!ref) {
35
+ // TODO: Public doc page with more info about this message
36
+ console.warn(`
37
+ Could not find a registered component named "${componentName}".
38
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
39
+ return undefined;
40
+ } else {
41
+ return ref;
42
+ }
43
+ };
44
+
45
+ $: componentInfo = () => {
46
+ if (component()) {
47
+ const {
48
+ component: _,
49
+ ...info
50
+ } = component();
51
+ return info;
52
+ } else {
53
+ return undefined;
54
+ }
55
+ };
56
+
57
+ $: componentRef = () => {
58
+ return component?.()?.component;
59
+ };
60
+
61
+ $: tagName = () => {
62
+ return getBlockTag(useBlock());
63
+ };
64
+
65
+ $: useBlock = () => {
66
+ return getProcessedBlock({
67
+ block: block,
68
+ state: builderContext.state,
69
+ context: builderContext.context
70
+ });
71
+ };
72
+
73
+ $: propertiesAndActions = () => {
74
+ return { ...getBlockProperties(useBlock()),
75
+ ...getBlockActions({
76
+ block: useBlock(),
77
+ state: builderContext.state,
78
+ context: builderContext.context
79
+ })
80
+ };
81
+ };
82
+
83
+ $: css = () => {
84
+ return getBlockStyles(useBlock());
85
+ };
86
+
87
+ $: componentOptions = () => {
88
+ return getBlockComponentOptions(useBlock());
89
+ };
90
+
91
+ $: children = () => {
92
+ // TO-DO: When should `canHaveChildren` dictate rendering?
93
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
94
+ // but still receive and need to render children.
95
+ // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
96
+ return useBlock().children ?? [];
97
+ };
98
+
99
+ $: noCompRefChildren = () => {
100
+ return componentRef() ? [] : children();
101
+ };
102
+
103
+ let builderContext = getContext(BuilderContext.key);
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ </script>
113
+
114
+
115
+ {#if !componentInfo?.()?.noWrap }
116
+
117
+
118
+
119
+ {#if !isEmptyHtmlElement(tagName()) }
120
+
121
+
122
+ <svelte:element {...propertiesAndActions()} style={css()} this={tagName()} >
123
+
124
+
125
+ {#if TARGET === 'vue' || TARGET === 'svelte' }
126
+
127
+
128
+ <BlockStyles block={useBlock()} ></BlockStyles>
129
+
130
+
131
+
132
+
133
+ {/if}
134
+
135
+
136
+
137
+ {#if componentRef() }
138
+ <svelte:component {...componentOptions()} builderBlock={useBlock()} this={componentRef()} >
139
+
140
+
141
+ {#each children() as child, index }
142
+ <svelte:self key={child.id} block={child} ></svelte:self>
143
+ {/each}
144
+
145
+
146
+ </svelte:component>
147
+
148
+
149
+ {/if}
150
+
151
+
152
+
153
+ {#each noCompRefChildren() as child, index }
154
+ <svelte:self key={child.id} block={child} ></svelte:self>
155
+ {/each}
156
+
157
+
158
+ </svelte:element>
159
+
160
+
161
+
162
+
163
+ {:else}
164
+ <svelte:element {...propertiesAndActions()} style={css()} this={tagName()} ></svelte:element>
165
+
166
+ {/if}
167
+
168
+
169
+
170
+
171
+ {:else}
172
+ <svelte:component {...componentOptions()} attributes={propertiesAndActions()} builderBlock={useBlock()} style={css()} this={componentRef()} >
173
+
174
+
175
+ {#each children() as child, index }
176
+ <svelte:self key={child.id} block={child} ></svelte:self>
177
+ {/each}
178
+
179
+
180
+ </svelte:component>
181
+
182
+ {/if}
@@ -3,17 +3,18 @@
3
3
 
4
4
 
5
5
 
6
- import { isEditing } from '../functions/is-editing';
7
- import RenderBlock, { } from './render-block.lite';
6
+ import { isEditing } from '../functions/is-editing.js';
7
+ import RenderBlock, { } from './render-block/render-block.svelte';
8
8
 
9
9
 
10
10
 
11
+
11
12
 
12
13
 
13
14
  export let blocks;
14
15
  export let parent;
15
16
  export let path;
16
-
17
+
17
18
  function onClick() {
18
19
  if (isEditing() && !blocks?.length) {
19
20
  window.parent?.postMessage({
@@ -42,6 +43,8 @@ return 'builder-blocks' + (!blocks?.length ? ' no-blocks' : '');
42
43
  };
43
44
 
44
45
 
46
+
47
+
45
48
 
46
49
 
47
50
 
@@ -50,15 +53,24 @@ return 'builder-blocks' + (!blocks?.length ? ' no-blocks' : '');
50
53
 
51
54
  </script>
52
55
 
53
- <div class="div" builder-path={path} builder-parent-id={parent} dataSet={{
56
+ <div builder-path={path} builder-parent-id={parent} dataSet={{
54
57
  class: className()
55
58
  }} on:click="{event => onClick()}" on:mouseenter="{event => onMouseEnter()}" class={className()} >
56
59
 
60
+
57
61
  {#if blocks }
62
+
58
63
 
59
- {#each blocks as block }<RenderBlock key={block.id} block={block} ></RenderBlock>{/each}
60
64
 
61
- {/if}
65
+ {#each blocks as block, index }
66
+ <RenderBlock key={block.id} block={block} ></RenderBlock>
67
+ {/each}
68
+
69
+
70
+
71
+
72
+
73
+ {/if}
62
74
 
63
75
  </div>
64
76
 
@@ -3,15 +3,16 @@
3
3
 
4
4
 
5
5
 
6
- import { TARGET } from '../../../constants/target';
6
+ import RenderInlinedStyles, { } from '../../render-inlined-styles.svelte';
7
7
 
8
8
 
9
9
 
10
+
10
11
 
11
12
 
12
13
  export let cssCode;
13
14
  export let customFonts;
14
-
15
+
15
16
  function getCssFromFont(font) {
16
17
  // TODO: compute what font sizes are used and only load those.......
17
18
  const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
@@ -61,11 +62,11 @@ function getFontCss({
61
62
  customFonts
62
63
  }) {
63
64
  // TODO: flag for this
64
- // if (!this.builder.allowCustomFonts) {
65
+ // if (!builder.allowCustomFonts) {
65
66
  // return '';
66
67
  // }
67
68
  // TODO: separate internal data from external
68
- return customFonts?.map(font => this.getCssFromFont(font))?.join(' ') || '';
69
+ return customFonts?.map(font => getCssFromFont(font))?.join(' ') || '';
69
70
  }
70
71
  $: injectedStyles = () => {
71
72
  return `
@@ -75,21 +76,15 @@ ${getFontCss({
75
76
  })}`;
76
77
  };
77
78
 
78
- $: injectedStyleScript = () => {
79
- return `<style>${injectedStyles()}</style>`;
80
- };
81
-
82
79
 
83
-
80
+
84
81
 
85
82
 
86
83
 
87
84
 
88
85
 
89
- </script>
90
86
 
91
- {#if TARGET === 'svelte' }
92
87
 
93
- {@html injectedStyleScript()}
88
+ </script>
94
89
 
95
- {/if}
90
+ <RenderInlinedStyles styles={injectedStyles()} ></RenderInlinedStyles>
@@ -0,0 +1,4 @@
1
+ import { default as default2 } from "./render-content.svelte";
2
+ export {
3
+ default2 as default
4
+ };