@builder.io/sdk-svelte 4.2.1 → 4.2.4

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 (125) hide show
  1. package/lib/browser/blocks/form/form/form.svelte +4 -5
  2. package/lib/browser/blocks/img/component-info.js +33 -3
  3. package/lib/browser/blocks/img/img.svelte +18 -6
  4. package/lib/browser/blocks/symbol/symbol.svelte +5 -2
  5. package/lib/browser/blocks/symbol/symbol.svelte.d.ts +1 -1
  6. package/lib/browser/blocks/symbol/symbol.types.d.ts +1 -2
  7. package/lib/browser/blocks/tabs/tabs.svelte +5 -4
  8. package/lib/browser/blocks/tabs/tabs.svelte.d.ts +1 -1
  9. package/lib/browser/blocks/text/component-info.js +0 -1
  10. package/lib/browser/components/awaiter.types.d.ts +7 -0
  11. package/lib/browser/components/awaiter.types.js +1 -0
  12. package/lib/browser/components/block/block.svelte +2 -2
  13. package/lib/browser/components/block/components/component-ref/component-ref.svelte +8 -8
  14. package/lib/browser/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  15. package/lib/browser/components/block/components/interactive-element.svelte +8 -1
  16. package/lib/browser/components/block/components/live-edit-block-styles.svelte +114 -0
  17. package/lib/browser/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  18. package/lib/browser/components/block/components/style-wrapper.svelte +25 -0
  19. package/lib/browser/components/block/components/style-wrapper.svelte.d.ts +23 -0
  20. package/lib/browser/components/content/components/enable-editor.svelte +30 -9
  21. package/lib/browser/components/live-edit.svelte +20 -0
  22. package/lib/browser/components/live-edit.svelte.d.ts +26 -0
  23. package/lib/browser/constants/sdk-version.d.ts +1 -1
  24. package/lib/browser/constants/sdk-version.js +1 -1
  25. package/lib/browser/functions/get-builder-search-params/index.d.ts +8 -2
  26. package/lib/browser/functions/get-builder-search-params/index.js +8 -2
  27. package/lib/browser/functions/get-content/generate-content-url.js +3 -8
  28. package/lib/browser/functions/get-content/index.js +8 -0
  29. package/lib/browser/functions/is-previewing.d.ts +11 -1
  30. package/lib/browser/functions/is-previewing.js +14 -4
  31. package/lib/browser/helpers/find-block.d.ts +18 -0
  32. package/lib/browser/helpers/find-block.js +41 -0
  33. package/lib/browser/helpers/subscribe-to-editor.d.ts +3 -2
  34. package/lib/browser/helpers/subscribe-to-editor.js +4 -2
  35. package/lib/edge/blocks/form/form/form.svelte +4 -5
  36. package/lib/edge/blocks/img/component-info.js +33 -3
  37. package/lib/edge/blocks/img/img.svelte +18 -6
  38. package/lib/edge/blocks/symbol/symbol.svelte +5 -2
  39. package/lib/edge/blocks/symbol/symbol.svelte.d.ts +1 -1
  40. package/lib/edge/blocks/symbol/symbol.types.d.ts +1 -2
  41. package/lib/edge/blocks/tabs/tabs.svelte +5 -4
  42. package/lib/edge/blocks/tabs/tabs.svelte.d.ts +1 -1
  43. package/lib/edge/blocks/text/component-info.js +0 -1
  44. package/lib/edge/components/awaiter.types.d.ts +7 -0
  45. package/lib/edge/components/awaiter.types.js +1 -0
  46. package/lib/edge/components/block/block.svelte +2 -2
  47. package/lib/edge/components/block/components/component-ref/component-ref.svelte +8 -8
  48. package/lib/edge/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  49. package/lib/edge/components/block/components/interactive-element.svelte +8 -1
  50. package/lib/edge/components/block/components/live-edit-block-styles.svelte +114 -0
  51. package/lib/edge/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  52. package/lib/edge/components/block/components/style-wrapper.svelte +25 -0
  53. package/lib/edge/components/block/components/style-wrapper.svelte.d.ts +23 -0
  54. package/lib/edge/components/content/components/enable-editor.svelte +30 -9
  55. package/lib/edge/components/live-edit.svelte +20 -0
  56. package/lib/edge/components/live-edit.svelte.d.ts +26 -0
  57. package/lib/edge/constants/sdk-version.d.ts +1 -1
  58. package/lib/edge/constants/sdk-version.js +1 -1
  59. package/lib/edge/functions/get-builder-search-params/index.d.ts +8 -2
  60. package/lib/edge/functions/get-builder-search-params/index.js +8 -2
  61. package/lib/edge/functions/get-content/generate-content-url.js +3 -8
  62. package/lib/edge/functions/get-content/index.js +8 -0
  63. package/lib/edge/functions/is-previewing.d.ts +11 -1
  64. package/lib/edge/functions/is-previewing.js +14 -4
  65. package/lib/edge/helpers/find-block.d.ts +18 -0
  66. package/lib/edge/helpers/find-block.js +41 -0
  67. package/lib/edge/helpers/subscribe-to-editor.d.ts +3 -2
  68. package/lib/edge/helpers/subscribe-to-editor.js +4 -2
  69. package/lib/node/blocks/form/form/form.svelte +4 -5
  70. package/lib/node/blocks/img/component-info.js +33 -3
  71. package/lib/node/blocks/img/img.svelte +18 -6
  72. package/lib/node/blocks/symbol/symbol.svelte +5 -2
  73. package/lib/node/blocks/symbol/symbol.svelte.d.ts +1 -1
  74. package/lib/node/blocks/symbol/symbol.types.d.ts +1 -2
  75. package/lib/node/blocks/tabs/tabs.svelte +5 -4
  76. package/lib/node/blocks/tabs/tabs.svelte.d.ts +1 -1
  77. package/lib/node/blocks/text/component-info.js +0 -1
  78. package/lib/node/components/awaiter.types.d.ts +7 -0
  79. package/lib/node/components/awaiter.types.js +1 -0
  80. package/lib/node/components/block/block.svelte +2 -2
  81. package/lib/node/components/block/components/component-ref/component-ref.svelte +8 -8
  82. package/lib/node/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
  83. package/lib/node/components/block/components/interactive-element.svelte +8 -1
  84. package/lib/node/components/block/components/live-edit-block-styles.svelte +114 -0
  85. package/lib/node/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
  86. package/lib/node/components/block/components/style-wrapper.svelte +25 -0
  87. package/lib/node/components/block/components/style-wrapper.svelte.d.ts +23 -0
  88. package/lib/node/components/content/components/enable-editor.svelte +30 -9
  89. package/lib/node/components/live-edit.svelte +20 -0
  90. package/lib/node/components/live-edit.svelte.d.ts +26 -0
  91. package/lib/node/constants/sdk-version.d.ts +1 -1
  92. package/lib/node/constants/sdk-version.js +1 -1
  93. package/lib/node/functions/get-builder-search-params/index.d.ts +8 -2
  94. package/lib/node/functions/get-builder-search-params/index.js +8 -2
  95. package/lib/node/functions/get-content/generate-content-url.js +3 -8
  96. package/lib/node/functions/get-content/index.js +8 -0
  97. package/lib/node/functions/is-previewing.d.ts +11 -1
  98. package/lib/node/functions/is-previewing.js +14 -4
  99. package/lib/node/helpers/find-block.d.ts +18 -0
  100. package/lib/node/helpers/find-block.js +41 -0
  101. package/lib/node/helpers/subscribe-to-editor.d.ts +3 -2
  102. package/lib/node/helpers/subscribe-to-editor.js +4 -2
  103. package/package.json +1 -1
  104. package/src/blocks/form/form/form.svelte +4 -5
  105. package/src/blocks/img/component-info.ts +33 -3
  106. package/src/blocks/img/img.svelte +22 -6
  107. package/src/blocks/symbol/symbol.svelte +5 -2
  108. package/src/blocks/symbol/symbol.types.ts +1 -1
  109. package/src/blocks/tabs/tabs.svelte +5 -4
  110. package/src/blocks/text/component-info.ts +0 -1
  111. package/src/components/awaiter.types.ts +7 -0
  112. package/src/components/block/block.svelte +2 -2
  113. package/src/components/block/components/component-ref/component-ref.svelte +8 -10
  114. package/src/components/block/components/interactive-element.svelte +7 -0
  115. package/src/components/block/components/live-edit-block-styles.svelte +146 -0
  116. package/src/components/block/components/style-wrapper.svelte +41 -0
  117. package/src/components/content/components/enable-editor.svelte +32 -9
  118. package/src/components/live-edit.svelte +32 -0
  119. package/src/constants/sdk-version.ts +1 -1
  120. package/src/functions/get-builder-search-params/index.ts +8 -2
  121. package/src/functions/get-content/generate-content-url.ts +3 -8
  122. package/src/functions/get-content/index.ts +8 -0
  123. package/src/functions/is-previewing.ts +15 -4
  124. package/src/helpers/find-block.ts +40 -0
  125. package/src/helpers/subscribe-to-editor.ts +7 -4
@@ -20,15 +20,10 @@ export const generateContentUrl = (options) => {
20
20
  url.searchParams.set('limit', String(limit));
21
21
  url.searchParams.set('noTraverse', String(noTraverse));
22
22
  url.searchParams.set('includeRefs', String(true));
23
- const finalLocale = locale || userAttributes?.locale;
24
- let finalUserAttributes = userAttributes || {};
25
- if (finalLocale) {
26
- url.searchParams.set('locale', finalLocale);
27
- finalUserAttributes = {
28
- locale: finalLocale,
29
- ...finalUserAttributes
30
- };
23
+ if (locale) {
24
+ url.searchParams.set('locale', locale);
31
25
  }
26
+ let finalUserAttributes = userAttributes || {};
32
27
  if (enrich)
33
28
  url.searchParams.set('enrich', String(enrich));
34
29
  url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
@@ -12,6 +12,14 @@ const checkContentHasResults = (content) => 'results' in content;
12
12
  * Returns the first content entry that matches the given options.
13
13
  */
14
14
  export async function fetchOneEntry(options) {
15
+ const finalLocale = options.locale || options.userAttributes?.locale;
16
+ if (finalLocale) {
17
+ options.locale = finalLocale;
18
+ options.userAttributes = {
19
+ locale: finalLocale,
20
+ ...options.userAttributes
21
+ };
22
+ }
15
23
  const allContent = await fetchEntries({
16
24
  ...options,
17
25
  limit: 1
@@ -1,2 +1,12 @@
1
1
  import type { Search } from '../helpers/search/search';
2
- export declare function isPreviewing(_search?: Search): boolean;
2
+ /**
3
+ * Checks the current URL's search parameters to see if it is attempting to
4
+ * preview Builder Content.
5
+ *
6
+ * When called on the client, it uses `window.location.search`.
7
+ * When called on the server (SSR), it requires a `search` argument.
8
+ *
9
+ * @param search - The search parameters to check. Can be a URL string (containing the search parameters), `URLSearchParams`, or a key-value object containing the search parameters.
10
+ * @returns `true` if the current page is being previewed, `false` otherwise.
11
+ */
12
+ export declare function isPreviewing(search?: Search): boolean;
@@ -1,14 +1,24 @@
1
1
  import { getSearchString } from '../helpers/search/search';
2
2
  import { isBrowser } from './is-browser';
3
- export function isPreviewing(_search) {
4
- const search = _search || (isBrowser() ? window.location.search : undefined);
3
+ /**
4
+ * Checks the current URL's search parameters to see if it is attempting to
5
+ * preview Builder Content.
6
+ *
7
+ * When called on the client, it uses `window.location.search`.
8
+ * When called on the server (SSR), it requires a `search` argument.
9
+ *
10
+ * @param search - The search parameters to check. Can be a URL string (containing the search parameters), `URLSearchParams`, or a key-value object containing the search parameters.
11
+ * @returns `true` if the current page is being previewed, `false` otherwise.
12
+ */
13
+ export function isPreviewing(search) {
14
+ const searchToUse = search || (isBrowser() ? window.location.search : undefined);
5
15
  /**
6
16
  * If this function is called on the server without an explicit `search` argument,
7
17
  * then it can't check if the user is previewing, and will return `false`.
8
18
  */
9
- if (!search) {
19
+ if (!searchToUse) {
10
20
  return false;
11
21
  }
12
- const normalizedSearch = getSearchString(search);
22
+ const normalizedSearch = getSearchString(searchToUse);
13
23
  return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
14
24
  }
@@ -0,0 +1,18 @@
1
+ import type { BuilderBlock, BuilderContent } from '../server-index';
2
+ /**
3
+ * Recursively searches for a block by ID.
4
+ *
5
+ * @param content The Builder content to search through.
6
+ * @param id The ID of the block to search for.
7
+ * @returns The block if found, otherwise null.
8
+ */
9
+ export declare const findBlockById: (content: BuilderContent, id: string) => BuilderBlock | null;
10
+ /**
11
+ * Helper function to recursively search through block tree.
12
+ *
13
+ * @param blocks The blocks to search through.
14
+ * @param id The ID of the block to search for.
15
+ * @returns The block if found, otherwise null.
16
+ * @private This is an internal implementation detail.
17
+ */
18
+ export declare const findBlockInTree: (blocks: BuilderBlock[] | undefined, id: string) => BuilderBlock | null;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Recursively searches for a block by ID.
3
+ *
4
+ * @param content The Builder content to search through.
5
+ * @param id The ID of the block to search for.
6
+ * @returns The block if found, otherwise null.
7
+ */
8
+ export const findBlockById = (content, id) => {
9
+ return findBlockInTree(content.data?.blocks, id);
10
+ };
11
+ /**
12
+ * Helper function to recursively search through block tree.
13
+ *
14
+ * @param blocks The blocks to search through.
15
+ * @param id The ID of the block to search for.
16
+ * @returns The block if found, otherwise null.
17
+ * @private This is an internal implementation detail.
18
+ */
19
+ export const findBlockInTree = (blocks, id) => {
20
+ if (!blocks)
21
+ return null;
22
+ for (const block of blocks) {
23
+ if (block.id === id)
24
+ return block;
25
+ if (block.children) {
26
+ const child = findBlockInTree(block.children, id);
27
+ if (child)
28
+ return child;
29
+ }
30
+ if (block.component?.name === 'Columns' && block.component?.options?.columns) {
31
+ for (const column of block.component.options.columns) {
32
+ if (column.blocks) {
33
+ const child = findBlockInTree(column.blocks, id);
34
+ if (child)
35
+ return child;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ return null;
41
+ };
@@ -2,10 +2,11 @@ import type { ContentProps } from '../components/content/content.types';
2
2
  import type { BuilderAnimation } from '../types/builder-block';
3
3
  import type { BuilderContent } from '../types/builder-content';
4
4
  import type { Dictionary } from '../types/typescript';
5
+ export type EditType = 'client' | 'server' | undefined;
5
6
  type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
6
7
  callbacks: {
7
- contentUpdate: (updatedContent: BuilderContent) => void;
8
- stateUpdate: (newState: Dictionary<string>) => void;
8
+ contentUpdate: (updatedContent: BuilderContent, editType?: EditType) => void;
9
+ stateUpdate: (newState: Dictionary<string>, editType?: EditType) => void;
9
10
  animation: (updatedContent: BuilderAnimation) => void;
10
11
  configureSdk: (updatedContent: any) => void;
11
12
  };
@@ -25,8 +25,9 @@ export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
25
25
  const messageContent = data.data;
26
26
  const modelName = messageContent.model;
27
27
  const newState = messageContent?.state;
28
+ const editType = messageContent.editType;
28
29
  if (modelName === model && newState) {
29
- callbacks.stateUpdate(newState);
30
+ callbacks.stateUpdate(newState, editType);
30
31
  }
31
32
  break;
32
33
  }
@@ -35,8 +36,9 @@ export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
35
36
  const messageContent = data.data;
36
37
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
37
38
  const contentData = messageContent.data;
39
+ const editType = messageContent.editType;
38
40
  if (key === model) {
39
- callbacks.contentUpdate(contentData);
41
+ callbacks.contentUpdate(contentData, editType);
40
42
  }
41
43
  break;
42
44
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "4.2.1",
4
+ "version": "4.2.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -87,6 +87,9 @@
87
87
  function submissionState() {
88
88
  return (isEditing() && previewState) || formState;
89
89
  }
90
+ function errorResponse(response: any) {
91
+ return JSON.stringify(response, null, 2);
92
+ }
90
93
  function onSubmit(event: any) {
91
94
  const sendWithJsProp = sendWithJs || sendSubmissionsTo === "email";
92
95
  if (sendSubmissionsTo === "zapier") {
@@ -351,11 +354,7 @@
351
354
  />
352
355
  {/if}
353
356
  {#if submissionState() === "error" && responseData}
354
- <pre class="builder-form-error-text pre">{JSON.stringify(
355
- responseData,
356
- null,
357
- 2
358
- )}</pre>
357
+ <pre class="builder-form-error-text pre">{errorResponse(responseData)}</pre>
359
358
  {/if}
360
359
  {#if submissionState() === "success"}
361
360
  <Blocks
@@ -1,7 +1,6 @@
1
1
  import { IMAGE_FILE_TYPES } from '../../constants/file-types';
2
2
  import type { ComponentInfo } from '../../types/components';
3
3
  export const componentInfo: ComponentInfo = {
4
- // friendlyName?
5
4
  name: 'Raw:Img',
6
5
  hideFromInsertMenu: true,
7
6
  image: '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',
@@ -11,7 +10,38 @@ export const componentInfo: ComponentInfo = {
11
10
  type: 'file',
12
11
  allowedFileTypes: IMAGE_FILE_TYPES,
13
12
  required: true
13
+ }, {
14
+ name: 'backgroundSize',
15
+ type: 'text',
16
+ defaultValue: 'cover',
17
+ enum: [{
18
+ label: 'contain',
19
+ value: 'contain',
20
+ helperText: 'The image should never get cropped'
21
+ }, {
22
+ label: 'cover',
23
+ value: 'cover',
24
+ helperText: "The image should fill it's box, cropping when needed"
25
+ }]
26
+ }, {
27
+ name: 'backgroundPosition',
28
+ type: 'text',
29
+ defaultValue: 'center',
30
+ enum: ['center', 'top', 'left', 'right', 'bottom', 'top left', 'top right', 'bottom left', 'bottom right']
31
+ }, {
32
+ name: 'altText',
33
+ type: 'string',
34
+ helperText: 'Text to display when the user has images off'
35
+ }, {
36
+ name: 'title',
37
+ type: 'string',
38
+ helperText: 'Text to display when hovering over the asset'
39
+ }, {
40
+ name: 'aspectRatio',
41
+ type: 'number',
42
+ helperText: "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",
43
+ advanced: true,
44
+ defaultValue: 0.7041
14
45
  }],
15
- noWrap: true,
16
- static: true
46
+ noWrap: true
17
47
  }
@@ -19,6 +19,8 @@
19
19
  | "top right"
20
20
  | "bottom left"
21
21
  | "bottom right";
22
+ aspectRatio?: number;
23
+ title?: string;
22
24
  }
23
25
  </script>
24
26
 
@@ -26,14 +28,16 @@
26
28
  import { isEditing } from "../../functions/is-editing";
27
29
  import { filterAttrs } from "../helpers";
28
30
  import { getSrcSet } from "../image/image.helpers";
29
- import { setAttrs } from "../helpers";
31
+ import { getClassPropName } from "../../functions/get-class-prop-name";
30
32
 
31
33
  export let imgSrc: ImgProps["imgSrc"] = undefined;
32
34
  export let image: ImgProps["image"] = undefined;
35
+ export let attributes: ImgProps["attributes"] = undefined;
36
+ export let altText: ImgProps["altText"] = undefined;
37
+ export let title: ImgProps["title"] = undefined;
33
38
  export let backgroundSize: ImgProps["backgroundSize"] = undefined;
34
39
  export let backgroundPosition: ImgProps["backgroundPosition"] = undefined;
35
- export let altText: ImgProps["altText"] = undefined;
36
- export let attributes: ImgProps["attributes"] = undefined;
40
+ export let aspectRatio: ImgProps["aspectRatio"] = undefined;
37
41
  function stringifyStyles(stylesObj) {
38
42
  let styles = "";
39
43
  for (let key in stylesObj) {
@@ -57,6 +61,17 @@
57
61
  }
58
62
  return getSrcSet(url);
59
63
  };
64
+ $: imgAttrs = () => {
65
+ const attrs = {
66
+ ...filterAttrs(attributes, "on:", false),
67
+ ...filterAttrs(attributes, "on:", true),
68
+ [getClassPropName()]: `builder-raw-img ${
69
+ attributes[getClassPropName()] || ""
70
+ }`,
71
+ } as Record<string, any>;
72
+ delete attrs.style;
73
+ return attrs;
74
+ };
60
75
  </script>
61
76
 
62
77
  {#key (isEditing() && imgSrc) || "default-key"}
@@ -64,12 +79,13 @@
64
79
  style={stringifyStyles({
65
80
  objectFit: backgroundSize || "cover",
66
81
  objectPosition: backgroundPosition || "center",
82
+ aspectRatio: aspectRatio || undefined,
83
+ ...(attributes?.style || {}),
67
84
  })}
68
85
  loading="lazy"
69
86
  alt={altText}
87
+ {title}
70
88
  src={imgSrc || image}
71
- srcSet={srcSetToUse()}
72
- {...filterAttrs(attributes, "on:", false)}
73
- use:setAttrs={filterAttrs(attributes, "on:", true)}
89
+ {...imgAttrs()}
74
90
  />
75
91
  {/key}
@@ -12,11 +12,11 @@
12
12
  import type { SymbolProps } from "./symbol.types";
13
13
 
14
14
  export let symbol: SymbolProps["symbol"] = undefined;
15
+ export let builderComponents: SymbolProps["builderComponents"];
15
16
  export let attributes: SymbolProps["attributes"] = undefined;
16
17
  export let dynamic: SymbolProps["dynamic"] = undefined;
17
18
  export let builderContext: SymbolProps["builderContext"];
18
19
  export let builderBlock: SymbolProps["builderBlock"];
19
- export let builderComponents: SymbolProps["builderComponents"];
20
20
  export let builderLinkComponent: SymbolProps["builderLinkComponent"] =
21
21
  undefined;
22
22
 
@@ -38,6 +38,9 @@
38
38
  $: contentWrapper = () => {
39
39
  return "div";
40
40
  };
41
+ $: customComponents = () => {
42
+ return Object.values(builderComponents);
43
+ };
41
44
  $: className = () => {
42
45
  return [
43
46
  ...[attributes[getClassPropName()]],
@@ -78,7 +81,7 @@
78
81
  ...$builderContext.context,
79
82
  symbolId: builderBlock?.id,
80
83
  }}
81
- customComponents={Object.values(builderComponents)}
84
+ customComponents={customComponents()}
82
85
  data={{
83
86
  ...symbol?.data,
84
87
  ...$builderContext.localState,
@@ -1,6 +1,6 @@
1
1
  import type { BuilderContent } from '../../types/builder-content';
2
2
  import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
3
- interface SymbolInfo {
3
+ export interface SymbolInfo {
4
4
  model?: string;
5
5
  entry?: string;
6
6
  data?: any;
@@ -5,9 +5,9 @@
5
5
 
6
6
  export let defaultActiveTab: TabsProps["defaultActiveTab"] = undefined;
7
7
  export let tabs: TabsProps["tabs"];
8
+ export let activeTabStyle: TabsProps["activeTabStyle"] = undefined;
8
9
  export let collapsible: TabsProps["collapsible"] = undefined;
9
10
  export let tabHeaderLayout: TabsProps["tabHeaderLayout"] = undefined;
10
- export let activeTabStyle: TabsProps["activeTabStyle"] = undefined;
11
11
  export let builderBlock: TabsProps["builderBlock"];
12
12
  export let builderContext: TabsProps["builderContext"];
13
13
  export let builderComponents: TabsProps["builderComponents"];
@@ -27,6 +27,9 @@
27
27
  function activeTabContent(active: number) {
28
28
  return tabs && tabs[active].content;
29
29
  }
30
+ function getTabStyle(index: number) {
31
+ return index === activeTab ? activeTabStyle : {};
32
+ }
30
33
  function onClick(index: number) {
31
34
  if (index === activeTab && collapsible) {
32
35
  activeTab = -1;
@@ -50,9 +53,7 @@
50
53
  >
51
54
  {#each tabs as tab, index (index)}
52
55
  <span
53
- style={stringifyStyles({
54
- ...(activeTab === index ? activeTabStyle : {}),
55
- })}
56
+ style={stringifyStyles(getTabStyle(index))}
56
57
  class={`builder-tab-wrap ${
57
58
  activeTab === index ? "builder-tab-active" : ""
58
59
  }`}
@@ -7,7 +7,6 @@ export const componentInfo: ComponentInfo = {
7
7
  } : {},
8
8
  name: 'Text',
9
9
  static: true,
10
- isRSC: true,
11
10
  image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929',
12
11
  inputs: [{
13
12
  name: 'text',
@@ -0,0 +1,7 @@
1
+ export type AwaiterProps = {
2
+ load: () => Promise<any>;
3
+ props?: any;
4
+ attributes?: any;
5
+ fallback?: any;
6
+ children?: any;
7
+ }
@@ -31,11 +31,11 @@
31
31
  provideLinkComponent,
32
32
  provideRegisteredComponents,
33
33
  } from "./block.helpers";
34
- import BlockStyles from "./components/block-styles.svelte";
35
34
  import BlockWrapper from "./components/block-wrapper.svelte";
36
35
  import type { ComponentProps } from "./components/component-ref/component-ref.helpers";
37
36
  import ComponentRef from "./components/component-ref/component-ref.svelte";
38
37
  import RepeatedBlock from "./components/repeated-block.svelte";
38
+ import StyleWrapper from "./components/style-wrapper.svelte";
39
39
  import type { Writable } from "svelte/store";
40
40
 
41
41
  export let block: BlockProps["block"];
@@ -148,7 +148,7 @@
148
148
  </script>
149
149
 
150
150
  {#if canShowBlock()}
151
- <BlockStyles block={processedBlock()} context={$context} />
151
+ <StyleWrapper block={processedBlock()} context={$context} id={block.id} />
152
152
 
153
153
  {#if !blockComponent?.()?.noWrap}
154
154
  {#if !repeatItem()}
@@ -5,22 +5,18 @@
5
5
  import type { ComponentProps } from "./component-ref.helpers";
6
6
  import { getWrapperProps } from "./component-ref.helpers";
7
7
 
8
- export let componentOptions: ComponentProps["componentOptions"];
9
- export let blockChildren: ComponentProps["blockChildren"];
10
8
  export let isInteractive: ComponentProps["isInteractive"];
11
9
  export let componentRef: ComponentProps["componentRef"];
10
+ export let componentOptions: ComponentProps["componentOptions"];
12
11
  export let builderBlock: ComponentProps["builderBlock"];
13
12
  export let context: ComponentProps["context"];
14
13
  export let linkComponent: ComponentProps["linkComponent"];
15
14
  export let includeBlockProps: ComponentProps["includeBlockProps"];
15
+ export let blockChildren: ComponentProps["blockChildren"];
16
16
  export let registeredComponents: ComponentProps["registeredComponents"];
17
17
 
18
18
  let shouldUpdate = false;
19
19
  let Wrapper = isInteractive ? InteractiveElement : componentRef;
20
-
21
- function onUpdateFn_0(..._args: any[]) {}
22
-
23
- $: onUpdateFn_0(...[componentOptions, blockChildren]);
24
20
  </script>
25
21
 
26
22
  {#if componentRef}
@@ -37,8 +33,10 @@
37
33
  contextValue: $context,
38
34
  })}
39
35
  >
40
- {#each blockChildren as child (child.id)}
41
- <Block block={child} {context} {registeredComponents} {linkComponent} />
42
- {/each}
43
- </svelte:component>
36
+ {#if componentRef}
37
+ {#each blockChildren as child (child.id)}
38
+ <Block block={child} {context} {registeredComponents} {linkComponent} />
39
+ {/each}
40
+ {/if}</svelte:component
41
+ >
44
42
  {/if}
@@ -10,12 +10,15 @@
10
10
  </script>
11
11
 
12
12
  <script lang="ts">
13
+ import { TARGET } from "../../../constants/target";
13
14
  import type { BuilderContextInterface } from "../../../context/types";
14
15
  import { getBlockActions } from "../../../functions/get-block-actions";
15
16
  import { getBlockProperties } from "../../../functions/get-block-properties";
17
+ import { isEditing } from "../../../server-index";
16
18
  import type { BuilderBlock } from "../../../types/builder-block";
17
19
  import type { Dictionary } from "../../../types/typescript";
18
20
  import Awaiter from "../../awaiter.svelte";
21
+ import LiveEdit from "../../live-edit.svelte";
19
22
  import type { Writable } from "svelte/store";
20
23
 
21
24
  export let wrapperProps: InteractiveElementProps["wrapperProps"];
@@ -59,6 +62,10 @@
59
62
  props={wrapperProps}
60
63
  attributes={attributes()}><slot /></Awaiter
61
64
  >
65
+ {:else if TARGET === "rsc" && isEditing()}
66
+ <LiveEdit {Wrapper} id={block.id || ""} attributes={attributes()}
67
+ ><slot /></LiveEdit
68
+ >
62
69
  {:else}
63
70
  <svelte:component
64
71
  this={Wrapper}
@@ -0,0 +1,146 @@
1
+ <script context="module" lang="ts">
2
+ type LiveEditBlockStylesProps = {
3
+ id?: any;
4
+ contextProvider: BuilderContextInterface;
5
+ };
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import {
10
+ getMaxWidthQueryForSize,
11
+ getSizesForBreakpoints,
12
+ } from "../../../constants/device-sizes";
13
+ import { TARGET } from "../../../constants/target";
14
+ import { camelToKebabCase } from "../../../functions/camel-to-kebab-case";
15
+ import { getProcessedBlock } from "../../../functions/get-processed-block";
16
+ import { createCssClass } from "../../../helpers/css";
17
+ import { findBlockById } from "../../../helpers/find-block";
18
+ import { checkIsDefined } from "../../../helpers/nullable";
19
+ import type {
20
+ BuilderBlock,
21
+ BuilderContextInterface,
22
+ } from "../../../server-index";
23
+ import InlinedStyles from "../../inlined-styles.svelte";
24
+
25
+ export let contextProvider: LiveEditBlockStylesProps["contextProvider"];
26
+ export let id: LiveEditBlockStylesProps["id"] = undefined;
27
+
28
+ $: block = () => {
29
+ return findBlockById(contextProvider.content!, id);
30
+ };
31
+ $: processedBlock = () => {
32
+ const foundBlock = block();
33
+ if (!foundBlock) {
34
+ return null;
35
+ }
36
+ const blockToUse = foundBlock.repeat?.collection
37
+ ? foundBlock
38
+ : getProcessedBlock({
39
+ block: foundBlock,
40
+ localState: contextProvider.localState,
41
+ rootState: contextProvider.rootState,
42
+ rootSetState: contextProvider.rootSetState,
43
+ context: contextProvider.context,
44
+ });
45
+ return blockToUse;
46
+ };
47
+ $: canShowBlock = () => {
48
+ if (checkIsDefined(processedBlock?.()?.hide)) {
49
+ return !processedBlock?.()?.hide;
50
+ }
51
+ if (checkIsDefined(processedBlock?.()?.show)) {
52
+ return processedBlock?.()?.show;
53
+ }
54
+ return true;
55
+ };
56
+ $: css = () => {
57
+ const styles = processedBlock?.()?.responsiveStyles;
58
+ const content = contextProvider.content;
59
+ const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
60
+ content?.meta?.breakpoints || {}
61
+ );
62
+ const contentHasXSmallBreakpoint = Boolean(
63
+ content?.meta?.breakpoints?.xsmall
64
+ );
65
+ const largeStyles = styles?.large;
66
+ const mediumStyles = styles?.medium;
67
+ const smallStyles = styles?.small;
68
+ const xsmallStyles = styles?.xsmall;
69
+ const className = processedBlock?.()?.id;
70
+ if (!className) {
71
+ return "";
72
+ }
73
+ const largeStylesClass = largeStyles
74
+ ? createCssClass({
75
+ className,
76
+ styles: largeStyles,
77
+ })
78
+ : "";
79
+ const mediumStylesClass = mediumStyles
80
+ ? createCssClass({
81
+ className,
82
+ styles: mediumStyles,
83
+ mediaQuery: getMaxWidthQueryForSize(
84
+ "medium",
85
+ sizesWithUpdatedBreakpoints
86
+ ),
87
+ })
88
+ : "";
89
+ const smallStylesClass = smallStyles
90
+ ? createCssClass({
91
+ className,
92
+ styles: smallStyles,
93
+ mediaQuery: getMaxWidthQueryForSize(
94
+ "small",
95
+ sizesWithUpdatedBreakpoints
96
+ ),
97
+ })
98
+ : "";
99
+ const xsmallStylesClass =
100
+ xsmallStyles && contentHasXSmallBreakpoint
101
+ ? createCssClass({
102
+ className,
103
+ styles: xsmallStyles,
104
+ mediaQuery: getMaxWidthQueryForSize(
105
+ "xsmall",
106
+ sizesWithUpdatedBreakpoints
107
+ ),
108
+ })
109
+ : "";
110
+ const hoverAnimation =
111
+ processedBlock().animations &&
112
+ processedBlock().animations.find((item) => item.trigger === "hover");
113
+ let hoverStylesClass = "";
114
+ if (hoverAnimation) {
115
+ const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
116
+ hoverStylesClass =
117
+ createCssClass({
118
+ className: `${className}:hover`,
119
+ styles: {
120
+ ...hoverStyles,
121
+ transition: `all ${hoverAnimation.duration}s ${camelToKebabCase(
122
+ hoverAnimation.easing
123
+ )}`,
124
+ transitionDelay: hoverAnimation.delay
125
+ ? `${hoverAnimation.delay}s`
126
+ : "0s",
127
+ },
128
+ }) || "";
129
+ }
130
+ return [
131
+ largeStylesClass,
132
+ mediumStylesClass,
133
+ smallStylesClass,
134
+ xsmallStylesClass,
135
+ hoverStylesClass,
136
+ ].join(" ");
137
+ };
138
+ </script>
139
+
140
+ {#if TARGET === "rsc" && css() && canShowBlock()}
141
+ <InlinedStyles
142
+ id="builderio-block"
143
+ styles={css()}
144
+ nonce={contextProvider.nonce}
145
+ />
146
+ {/if}