@builder.io/sdk-svelte 0.0.7 → 0.0.8

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 (44) hide show
  1. package/package/--package.json +2 -3
  2. package/package/blocks/button/button.svelte +35 -3
  3. package/package/blocks/form/form.svelte +29 -1
  4. package/package/blocks/img/img.svelte +29 -1
  5. package/package/blocks/input/input.svelte +29 -1
  6. package/package/blocks/section/section.svelte +30 -2
  7. package/package/blocks/select/select.svelte +29 -1
  8. package/package/blocks/submit-button/submit-button.svelte +33 -2
  9. package/package/blocks/symbol/symbol.svelte +29 -1
  10. package/package/blocks/textarea/textarea.svelte +36 -2
  11. package/package/blocks/video/video.svelte +30 -2
  12. package/package/components/render-block/render-block.svelte +29 -8
  13. package/package/components/render-content/render-content.svelte +5 -2
  14. package/package/functions/evaluate.d.ts +2 -1
  15. package/package/functions/evaluate.js +8 -5
  16. package/package/functions/event-handler-name.js +1 -4
  17. package/package/functions/get-block-actions-handler.d.ts +5 -2
  18. package/package/functions/get-block-actions-handler.js +7 -8
  19. package/package/functions/get-block-actions.js +2 -2
  20. package/package/functions/get-builder-search-params/index.d.ts +1 -1
  21. package/package/functions/track.d.ts +6 -1
  22. package/package/functions/track.js +4 -0
  23. package/package.json +2 -2
  24. package/src/blocks/button/button.svelte +41 -2
  25. package/src/blocks/form/form.svelte +36 -1
  26. package/src/blocks/img/img.svelte +36 -1
  27. package/src/blocks/input/input.svelte +36 -1
  28. package/src/blocks/section/section.svelte +36 -1
  29. package/src/blocks/select/select.svelte +36 -1
  30. package/src/blocks/submit-button/submit-button.svelte +39 -1
  31. package/src/blocks/symbol/symbol.svelte +36 -1
  32. package/src/blocks/textarea/textarea.svelte +42 -1
  33. package/src/blocks/video/video.svelte +36 -1
  34. package/src/components/render-block/render-block.svelte +34 -8
  35. package/src/components/render-content/render-content.svelte +7 -2
  36. package/src/functions/evaluate.ts +11 -6
  37. package/src/functions/event-handler-name.ts +1 -6
  38. package/src/functions/get-block-actions-handler.ts +10 -9
  39. package/src/functions/get-block-actions.ts +2 -2
  40. package/src/functions/get-builder-search-params/index.ts +1 -1
  41. package/src/functions/track.ts +13 -1
  42. package/package/functions/mark-mutable.d.ts +0 -2
  43. package/package/functions/mark-mutable.js +0 -6
  44. package/src/functions/mark-mutable.ts +0 -7
@@ -46,7 +46,6 @@
46
46
 
47
47
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
48
48
  import { TARGET } from "../../constants/target.js";
49
- import BuilderContext from "../../context/builder.context.js";
50
49
  import { evaluate } from "../../functions/evaluate.js";
51
50
  import { getContent } from "../../functions/get-content/index.js";
52
51
  import { getFetch } from "../../functions/get-fetch.js";
@@ -60,6 +59,7 @@
60
59
  import { _track } from "../../functions/track.js";
61
60
  import RenderBlocks from "../render-blocks.svelte";
62
61
  import RenderContentStyles from "./components/render-styles.svelte";
62
+ import BuilderContext from "../../context/builder.context.js";
63
63
  import {
64
64
  registerInsertMenu,
65
65
  setupBrowserForEditing,
@@ -258,6 +258,11 @@
258
258
  let overrideState = {};
259
259
 
260
260
  onMount(() => {
261
+ if (!apiKey) {
262
+ console.error(
263
+ "[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
264
+ );
265
+ }
261
266
  if (isBrowser()) {
262
267
  if (isEditing()) {
263
268
  forceReRenderCount = forceReRenderCount + 1;
@@ -314,7 +319,7 @@
314
319
  function onUpdateFn_0() {
315
320
  evaluateJsCode();
316
321
  }
317
- $: onUpdateFn_0(...[useContent?.()?.data?.jsCode]);
322
+ $: onUpdateFn_0(...[useContent?.()?.data?.jsCode, contentState()]);
318
323
  function onUpdateFn_1() {
319
324
  runHttpRequests();
320
325
  }
@@ -7,9 +7,11 @@ export function evaluate({
7
7
  context,
8
8
  state,
9
9
  event,
10
+ isExpression = true,
10
11
  }: {
11
12
  code: string;
12
13
  event?: Event;
14
+ isExpression?: boolean;
13
15
  } & Pick<BuilderContextInterface, 'state' | 'context'>): any {
14
16
  if (code === '') {
15
17
  console.warn('Skipping evaluation of empty code block.');
@@ -24,11 +26,14 @@ export function evaluate({
24
26
 
25
27
  // Be able to handle simple expressions like "state.foo" or "1 + 1"
26
28
  // as well as full blocks like "var foo = "bar"; return foo"
27
- const useReturn = !(
28
- code.includes(';') ||
29
- code.includes(' return ') ||
30
- code.trim().startsWith('return ')
31
- );
29
+ const useReturn =
30
+ // we disable this for cases where we definitely don't want a return
31
+ isExpression &&
32
+ !(
33
+ code.includes(';') ||
34
+ code.includes(' return ') ||
35
+ code.trim().startsWith('return ')
36
+ );
32
37
 
33
38
  const useCode = useReturn ? `return (${code});` : code;
34
39
 
@@ -46,7 +51,7 @@ export function evaluate({
46
51
  'Builder custom code error: \n While Evaluating: \n ',
47
52
  useCode,
48
53
  '\n',
49
- (e as any).message || e
54
+ e
50
55
  );
51
56
  }
52
57
  }
@@ -1,6 +1 @@
1
- function capitalizeFirstLetter(string: string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
4
-
5
- export const getEventHandlerName = (key: string) =>
6
- `on${capitalizeFirstLetter(key)}`;
1
+ export const getEventHandlerName = (key: string) => `on:${key.toLowerCase()}`;
@@ -2,18 +2,19 @@ import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
3
  import { evaluate } from './evaluate.js';
4
4
 
5
- export function crateEventHandler(
6
- value: string,
7
- options: { block: BuilderBlock } & Pick<
8
- BuilderContextInterface,
9
- 'state' | 'context'
10
- >
11
- ): (event: Event) => any {
12
- return (event: Event) =>
5
+ type Options = {
6
+ block: BuilderBlock;
7
+ } & Pick<BuilderContextInterface, 'state' | 'context'>;
8
+
9
+ type EventHandler = (event: Event) => any;
10
+
11
+ export const createEventHandler =
12
+ (value: string, options: Options): EventHandler =>
13
+ (event) =>
13
14
  evaluate({
14
15
  code: value,
15
16
  context: options.context,
16
17
  state: options.state,
17
18
  event,
19
+ isExpression: false,
18
20
  });
19
- }
@@ -1,7 +1,7 @@
1
1
  import type { BuilderContextInterface } from '../context/types.js';
2
2
  import type { BuilderBlock } from '../types/builder-block.js';
3
3
  import { getEventHandlerName } from './event-handler-name.js';
4
- import { crateEventHandler } from './get-block-actions-handler.js';
4
+ import { createEventHandler } from './get-block-actions-handler.js';
5
5
 
6
6
  type Actions = { [index: string]: (event: Event) => any };
7
7
 
@@ -19,7 +19,7 @@ export function getBlockActions(
19
19
  continue;
20
20
  }
21
21
  const value = optionActions[key];
22
- obj[getEventHandlerName(key)] = crateEventHandler(value, options);
22
+ obj[getEventHandlerName(key)] = createEventHandler(value, options);
23
23
  }
24
24
  return obj;
25
25
  }
@@ -2,7 +2,7 @@ import { isBrowser } from '../is-browser.js';
2
2
 
3
3
  const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
4
4
 
5
- type QueryObject = Record<string, string>;
5
+ type QueryObject = Record<string, string | string[]>;
6
6
 
7
7
  export const convertSearchParamsToQueryObject = (
8
8
  searchParams: URLSearchParams
@@ -6,7 +6,12 @@ import { isBrowser } from './is-browser.js';
6
6
  import { isEditing } from './is-editing.js';
7
7
 
8
8
  interface Event {
9
- type: 'click' | 'impression';
9
+ /**
10
+ * The type of your event.
11
+ *
12
+ * Examples: `click`, `conversion`, `pageview`, `impression`
13
+ */
14
+ type: string;
10
15
  data: {
11
16
  /**
12
17
  * (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
@@ -95,6 +100,13 @@ const createEvent = async ({
95
100
  });
96
101
 
97
102
  export async function _track(eventProps: EventProps) {
103
+ if (!eventProps.apiKey) {
104
+ console.error(
105
+ '[Builder.io]: Missing API key for track call. Please provide your API key.'
106
+ );
107
+ return;
108
+ }
109
+
98
110
  if (!eventProps.canTrack) {
99
111
  return;
100
112
  }
@@ -1,2 +0,0 @@
1
- export declare function markMutable<T = any>(value: T): T;
2
- export declare function markPropsMutable<T = any>(props: T): T;
@@ -1,6 +0,0 @@
1
- export function markMutable(value) {
2
- return value;
3
- }
4
- export function markPropsMutable(props) {
5
- return props;
6
- }
@@ -1,7 +0,0 @@
1
- export function markMutable<T = any>(value: T): T {
2
- return value;
3
- }
4
-
5
- export function markPropsMutable<T = any>(props: T): T {
6
- return props;
7
- }