@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-32

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 (91) hide show
  1. package/README.md +19 -0
  2. package/package.json +8 -1
  3. package/src/blocks/button/button.svelte +35 -48
  4. package/src/blocks/columns/columns.svelte +137 -103
  5. package/src/blocks/columns/component-info.js +26 -1
  6. package/src/blocks/custom-code/custom-code.svelte +58 -53
  7. package/src/blocks/embed/component-info.js +21 -1
  8. package/src/blocks/embed/embed.svelte +45 -57
  9. package/src/blocks/embed/helpers.js +9 -0
  10. package/src/blocks/form/form.svelte +313 -296
  11. package/src/blocks/fragment/fragment.svelte +9 -25
  12. package/src/blocks/image/component-info.js +48 -1
  13. package/src/blocks/image/image.helpers.js +48 -0
  14. package/src/blocks/image/image.svelte +146 -117
  15. package/src/blocks/img/img.svelte +48 -36
  16. package/src/blocks/input/input.svelte +30 -31
  17. package/src/blocks/raw-text/raw-text.svelte +12 -26
  18. package/src/blocks/section/section.svelte +30 -36
  19. package/src/blocks/select/select.svelte +30 -37
  20. package/src/blocks/submit-button/submit-button.svelte +12 -30
  21. package/src/blocks/symbol/component-info.js +1 -0
  22. package/src/blocks/symbol/symbol.svelte +88 -53
  23. package/src/blocks/text/text.svelte +8 -25
  24. package/src/blocks/textarea/textarea.svelte +16 -29
  25. package/src/blocks/util.js +7 -0
  26. package/src/blocks/video/video.svelte +88 -41
  27. package/src/components/render-block/block-styles.svelte +58 -51
  28. package/src/components/render-block/render-block.helpers.js +23 -0
  29. package/src/components/render-block/render-block.svelte +204 -160
  30. package/src/components/render-block/render-component.svelte +30 -0
  31. package/src/components/render-block/render-repeated-block.svelte +45 -0
  32. package/src/components/render-block/types.js +0 -0
  33. package/src/components/render-blocks.svelte +88 -80
  34. package/src/components/render-content/components/render-styles.svelte +59 -63
  35. package/src/components/render-content/index.js +4 -0
  36. package/src/components/render-content/render-content.svelte +316 -207
  37. package/src/components/render-inlined-styles.svelte +26 -48
  38. package/src/constants/builder-registered-components.js +51 -0
  39. package/src/constants/device-sizes.js +3 -21
  40. package/src/context/builder.context.js +7 -1
  41. package/src/functions/camel-to-kebab-case.js +4 -0
  42. package/src/functions/convert-style-object.js +6 -0
  43. package/src/functions/get-block-component-options.js +6 -1
  44. package/src/functions/get-block-styles.js +7 -4
  45. package/src/functions/get-builder-search-params/index.js +12 -1
  46. package/src/functions/get-content/ab-testing.js +38 -0
  47. package/src/functions/get-content/fn.test.js +1 -1
  48. package/src/functions/get-content/index.js +16 -58
  49. package/src/functions/get-content/types.js +0 -0
  50. package/src/functions/get-fetch.js +2 -2
  51. package/src/functions/get-processed-block.js +19 -8
  52. package/src/functions/get-processed-block.test.js +2 -1
  53. package/src/functions/register-component.js +45 -26
  54. package/src/functions/sanitize-styles.js +5 -0
  55. package/src/functions/track.js +71 -2
  56. package/src/helpers/cookie.js +59 -0
  57. package/src/helpers/css.js +12 -0
  58. package/src/helpers/flatten.js +34 -0
  59. package/src/helpers/localStorage.js +34 -0
  60. package/src/helpers/nullable.js +4 -0
  61. package/src/helpers/sessionId.js +26 -0
  62. package/src/helpers/time.js +5 -0
  63. package/src/helpers/url.js +10 -0
  64. package/src/helpers/url.test.js +15 -0
  65. package/src/helpers/uuid.js +13 -0
  66. package/src/helpers/visitorId.js +33 -0
  67. package/src/index-helpers/blocks-exports.js +10 -8
  68. package/src/scripts/init-editing.js +4 -5
  69. package/src/types/can-track.js +0 -0
  70. package/src/types/components.js +0 -0
  71. package/src/types/element.js +0 -0
  72. package/src/blocks/button/index.js +0 -7
  73. package/src/blocks/columns/index.js +0 -7
  74. package/src/blocks/custom-code/index.js +0 -7
  75. package/src/blocks/embed/index.js +0 -7
  76. package/src/blocks/form/index.js +0 -7
  77. package/src/blocks/fragment/index.js +0 -7
  78. package/src/blocks/image/index.js +0 -7
  79. package/src/blocks/img/index.js +0 -7
  80. package/src/blocks/input/index.js +0 -7
  81. package/src/blocks/raw-text/index.js +0 -7
  82. package/src/blocks/section/index.js +0 -7
  83. package/src/blocks/select/index.js +0 -7
  84. package/src/blocks/submit-button/index.js +0 -7
  85. package/src/blocks/symbol/index.js +0 -7
  86. package/src/blocks/text/index.js +0 -7
  87. package/src/blocks/textarea/index.js +0 -7
  88. package/src/blocks/video/index.js +0 -7
  89. package/src/components/error-boundary.svelte +0 -26
  90. package/src/functions/macro-eval.js +0 -5
  91. package/src/functions/previewing-model-name.js +0 -11
@@ -1,41 +1,34 @@
1
- <script>
2
-
3
-
4
-
5
-
6
- import { isEditing } from '../../functions/is-editing.js';
7
-
8
-
9
-
10
-
11
-
12
-
13
- export let attributes;
14
- export let value;
15
- export let defaultValue;
16
- export let name;
17
- export let options;
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
1
+ <script context="module" lang="ts">
2
+ export interface FormSelectProps {
3
+ options?: {
4
+ name?: string;
5
+ value: string;
6
+ }[];
7
+ attributes?: any;
8
+ name?: string;
9
+ value?: string;
10
+ defaultValue?: string;
11
+ }
31
12
  </script>
32
13
 
33
- <select {...attributes} value={value} key={isEditing() && defaultValue ? defaultValue : 'default-key'} defaultValue={defaultValue} name={name} >
34
-
35
-
36
- {#each options as option, index }
37
- <option value={option.value} >{option.name || option.value}</option>
38
- {/each}
14
+ <script lang="ts">
15
+ import { isEditing } from "../../functions/is-editing.js";
39
16
 
17
+ export let attributes: FormSelectProps["attributes"];
18
+ export let value: FormSelectProps["value"];
19
+ export let defaultValue: FormSelectProps["defaultValue"];
20
+ export let name: FormSelectProps["name"];
21
+ export let options: FormSelectProps["options"];
22
+ </script>
40
23
 
41
- </select>
24
+ <select
25
+ {...attributes}
26
+ {value}
27
+ key={isEditing() && defaultValue ? defaultValue : "default-key"}
28
+ {defaultValue}
29
+ {name}
30
+ >
31
+ {#each options as option}
32
+ <option value={option.value}>{option.name || option.value}</option>
33
+ {/each}
34
+ </select>
@@ -1,33 +1,15 @@
1
- <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- export let attributes;
13
- export let text;
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
1
+ <script context="module" lang="ts">
2
+ export interface ButtonProps {
3
+ attributes?: any;
4
+ text?: string;
5
+ }
27
6
  </script>
28
7
 
29
- <button {...attributes} type="submit" >
30
-
31
- {text}
8
+ <script lang="ts">
9
+ export let attributes: ButtonProps["attributes"];
10
+ export let text: ButtonProps["text"];
11
+ </script>
32
12
 
33
- </button>
13
+ <button {...attributes} type="submit">
14
+ {text}
15
+ </button>
@@ -2,6 +2,7 @@ const componentInfo = {
2
2
  name: "Symbol",
3
3
  noWrap: true,
4
4
  static: true,
5
+ builtIn: true,
5
6
  inputs: [
6
7
  {
7
8
  name: "symbol",
@@ -1,54 +1,89 @@
1
- <script>
2
- import { onMount } from 'svelte'
3
- import { afterUpdate } from 'svelte'
4
-
5
-
6
- import RenderContent, { } from '../../components/render-content/render-content.svelte';
7
- import BuilderContext, { } from '../../context/builder.context';
8
- import { getContent } from '../../functions/get-content/index.js';
9
-
10
-
11
-
12
- import { getContext, setContext } from "svelte";
13
-
14
-
15
- export let attributes;
16
- export let symbol;
17
-
18
-
19
-
20
-
21
- let builderContext = getContext(BuilderContext.key);
22
-
23
- let className = 'builder-symbol';
24
- let content = null;
25
-
26
- onMount(() => { content = symbol?.content; });
27
-
28
- afterUpdate(() => { const symbolToUse = symbol;
29
-
30
- if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
31
- getContent({
32
- model: symbolToUse.model,
33
- apiKey: builderContext.apiKey,
34
- options: {
35
- entry: symbolToUse.entry
1
+ <script context="module" lang="ts">
2
+ export interface SymbolInfo {
3
+ model?: string;
4
+ entry?: string;
5
+ data?: any;
6
+ content?: BuilderContent;
7
+ inline?: boolean;
8
+ dynamic?: boolean;
36
9
  }
37
- }).then(response => {
38
- content = response;
39
- });
40
- } })
41
-
42
-
43
- </script>
44
-
45
- <div {...attributes} dataSet={{
46
- class: className
47
- }} class={className} >
48
-
49
- <RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...symbol?.data,
50
- ...builderContext.state,
51
- ...symbol?.content?.data?.state
52
- }} model={symbol?.model} content={content} ></RenderContent>
53
-
54
- </div>
10
+
11
+ export interface SymbolProps {
12
+ symbol?: SymbolInfo;
13
+ dataOnly?: boolean;
14
+ dynamic?: boolean;
15
+ builderBlock?: BuilderBlock;
16
+ attributes?: any;
17
+ inheritState?: boolean;
18
+ }
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { onMount } from "svelte";
23
+ import { afterUpdate } from "svelte";
24
+
25
+ import RenderContent from "../../components/render-content/render-content.svelte";
26
+ import BuilderContext from "../../context/builder.context";
27
+ import { getContent } from "../../functions/get-content/index.js";
28
+
29
+ import { getContext, setContext } from "svelte";
30
+
31
+ export let attributes: SymbolProps["attributes"];
32
+ export let symbol: SymbolProps["symbol"];
33
+
34
+ let builderContext = getContext(BuilderContext.key);
35
+
36
+ let className = "builder-symbol";
37
+ let content = null;
38
+
39
+ onMount(() => {
40
+ content = symbol?.content;
41
+ });
42
+
43
+ function onUpdateFn_0() {
44
+ const symbolToUse = symbol;
45
+ /**
46
+ * If:
47
+ * - we have a symbol prop
48
+ * - yet it does not have any content
49
+ * - and we have not already stored content from before
50
+ * - and it has a model name
51
+ *
52
+ * then we want to re-fetch the symbol content.
53
+ */
54
+
55
+ if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
56
+ getContent({
57
+ model: symbolToUse.model,
58
+ apiKey: builderContext.apiKey,
59
+ query: {
60
+ id: symbolToUse.entry,
61
+ },
62
+ }).then((response) => {
63
+ content = response;
64
+ });
65
+ }
66
+ }
67
+ $: onUpdateFn_0(...[symbol?.content, symbol?.model, symbol?.entry, content]);
68
+ </script>
69
+
70
+ <div
71
+ {...attributes}
72
+ dataSet={{
73
+ class: className,
74
+ }}
75
+ class={className}
76
+ >
77
+ <RenderContent
78
+ apiKey={builderContext.apiKey}
79
+ context={builderContext.context}
80
+ customComponents={Object.values(builderContext.registeredComponents)}
81
+ data={{
82
+ ...symbol?.data,
83
+ ...builderContext.state,
84
+ ...symbol?.content?.data?.state,
85
+ }}
86
+ model={symbol?.model}
87
+ {content}
88
+ />
89
+ </div>
@@ -1,28 +1,11 @@
1
- <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- export let text;
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
1
+ <script context="module" lang="ts">
2
+ export interface TextProps {
3
+ text: string;
4
+ }
5
+ </script>
24
6
 
25
-
7
+ <script lang="ts">
8
+ export let text: TextProps["text"];
26
9
  </script>
27
10
 
28
- <div class="builder-text" >{@html text}</div>
11
+ <div class="builder-text">{@html text}</div>
@@ -1,32 +1,19 @@
1
- <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- export let attributes;
13
- export let placeholder;
14
- export let name;
15
- export let value;
16
- export let defaultValue;
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
1
+ <script context="module" lang="ts">
2
+ export interface TextareaProps {
3
+ attributes?: any;
4
+ name?: string;
5
+ value?: string;
6
+ defaultValue?: string;
7
+ placeholder?: string;
8
+ }
9
+ </script>
28
10
 
29
-
11
+ <script lang="ts">
12
+ export let attributes: TextareaProps["attributes"];
13
+ export let placeholder: TextareaProps["placeholder"];
14
+ export let name: TextareaProps["name"];
15
+ export let value: TextareaProps["value"];
16
+ export let defaultValue: TextareaProps["defaultValue"];
30
17
  </script>
31
18
 
32
- <textarea {...attributes} placeholder={placeholder} name={name} value={value} defaultValue={defaultValue} ></textarea>
19
+ <textarea {...attributes} {placeholder} {name} {value} {defaultValue} />
@@ -0,0 +1,7 @@
1
+ function markSerializable(fn) {
2
+ fn.__qwik_serializable__ = true;
3
+ return fn;
4
+ }
5
+ export {
6
+ markSerializable
7
+ };
@@ -1,45 +1,92 @@
1
- <script>
2
-
3
-
4
-
5
-
6
-
7
-
1
+ <script context="module" lang="ts">
2
+ export interface VideoProps {
3
+ attributes?: any;
4
+ video?: string;
5
+ autoPlay?: boolean;
6
+ controls?: boolean;
7
+ muted?: boolean;
8
+ loop?: boolean;
9
+ playsInline?: boolean;
10
+ aspectRatio?: number;
11
+ width?: number;
12
+ height?: number;
13
+ fit?: "contain" | "cover" | "fill";
14
+ position?:
15
+ | "center"
16
+ | "top"
17
+ | "left"
18
+ | "right"
19
+ | "bottom"
20
+ | "top left"
21
+ | "top right"
22
+ | "bottom left"
23
+ | "bottom right";
24
+ posterImage?: string;
25
+ lazyLoad?: boolean;
26
+ }
27
+ </script>
8
28
 
9
-
29
+ <script lang="ts">
30
+ export let autoPlay: VideoProps["autoPlay"];
31
+ export let muted: VideoProps["muted"];
32
+ export let controls: VideoProps["controls"];
33
+ export let loop: VideoProps["loop"];
34
+ export let playsInline: VideoProps["playsInline"];
35
+ export let attributes: VideoProps["attributes"];
36
+ export let fit: VideoProps["fit"];
37
+ export let position: VideoProps["position"];
38
+ export let video: VideoProps["video"];
39
+ export let posterImage: VideoProps["posterImage"];
10
40
 
11
-
12
- export let attributes;
13
- export let fit;
14
- export let position;
15
- export let video;
16
- export let posterImage;
17
- export let autoPlay;
18
- export let muted;
19
- export let controls;
20
- export let loop;
21
-
22
-
23
-
41
+ function mitosis_styling(node, vars) {
42
+ Object.entries(vars).forEach(([p, v]) => {
43
+ node.style[p] = v;
44
+ });
45
+ }
24
46
 
25
-
26
-
27
-
47
+ $: videoProps = () => {
48
+ return {
49
+ ...(autoPlay === true
50
+ ? {
51
+ autoPlay: true,
52
+ }
53
+ : {}),
54
+ ...(muted === true
55
+ ? {
56
+ muted: true,
57
+ }
58
+ : {}),
59
+ ...(controls === true
60
+ ? {
61
+ controls: true,
62
+ }
63
+ : {}),
64
+ ...(loop === true
65
+ ? {
66
+ loop: true,
67
+ }
68
+ : {}),
69
+ ...(playsInline === true
70
+ ? {
71
+ playsInline: true,
72
+ }
73
+ : {}),
74
+ };
75
+ };
76
+ </script>
28
77
 
29
-
30
-
31
-
32
-
33
-
34
- </script>
35
-
36
- <video {...attributes} preload="none" style={{
37
- width: '100%',
38
- height: '100%',
39
- ...attributes?.style,
40
- objectFit: fit,
41
- objectPosition: position,
42
- // Hack to get object fit to work as expected and
43
- // not have the video overflow
44
- borderRadius: 1
45
- }} key={video || 'no-src'} poster={posterImage} autoPlay={autoPlay} muted={muted} controls={controls} loop={loop} ></video>
78
+ <video
79
+ {...videoProps()}
80
+ use:mitosis_styling={{
81
+ width: "100%",
82
+ height: "100%",
83
+ ...attributes?.style,
84
+ objectFit: fit,
85
+ objectPosition: position,
86
+ // Hack to get object fit to work as expected and
87
+ // not have the video overflow
88
+ borderRadius: 1,
89
+ }}
90
+ src={video || "no-src"}
91
+ poster={posterImage}
92
+ />
@@ -1,51 +1,58 @@
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>
1
+ <script context="module" lang="ts">
2
+ export type BlockStylesProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ };
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
10
+ import { TARGET } from "../../constants/target.js";
11
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
+ import { convertStyleMaptoCSS } from "../../helpers/css.js";
13
+ import RenderInlinedStyles from "../render-inlined-styles.svelte";
14
+
15
+ export let block: BlockStylesProps["block"];
16
+ export let context: BlockStylesProps["context"];
17
+
18
+ $: useBlock = () => {
19
+ return getProcessedBlock({
20
+ block: block,
21
+ state: context.state,
22
+ context: context.context,
23
+ shouldEvaluateBindings: true,
24
+ });
25
+ };
26
+
27
+ $: css = () => {
28
+ const styles = useBlock().responsiveStyles;
29
+ const largeStyles = styles?.large;
30
+ const mediumStyles = styles?.medium;
31
+ const smallStyles = styles?.small;
32
+ return `
33
+ ${
34
+ largeStyles
35
+ ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}`
36
+ : ""
37
+ }
38
+ ${
39
+ mediumStyles
40
+ ? `${getMaxWidthQueryForSize("medium")} {
41
+ .${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
42
+ }`
43
+ : ""
44
+ }
45
+ ${
46
+ smallStyles
47
+ ? `${getMaxWidthQueryForSize("small")} {
48
+ .${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
49
+ }`
50
+ : ""
51
+ }
52
+ }`;
53
+ };
54
+ </script>
55
+
56
+ {#if TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}
57
+ <RenderInlinedStyles styles={css()} />
58
+ {/if}
@@ -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
+ };