@builder.io/sdk-svelte 0.0.3 → 0.0.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 (142) hide show
  1. package/package/--package.json +159 -0
  2. package/package/blocks/BaseText.svelte +19 -0
  3. package/package/blocks/BaseText.svelte.d.ts +19 -0
  4. package/package/blocks/columns/columns.svelte +13 -4
  5. package/package/blocks/columns/columns.svelte.d.ts +1 -1
  6. package/package/blocks/custom-code/custom-code.svelte +1 -1
  7. package/package/blocks/embed/embed.svelte +2 -0
  8. package/package/blocks/form/form.svelte +7 -5
  9. package/package/blocks/image/image.svelte +48 -46
  10. package/package/blocks/image/image.svelte.d.ts +1 -1
  11. package/package/blocks/img/img.svelte +7 -2
  12. package/package/blocks/section/section.svelte +7 -2
  13. package/package/blocks/symbol/symbol.svelte +13 -13
  14. package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
  15. package/package/blocks/video/video.svelte +14 -3
  16. package/package/components/render-block/block-styles.svelte +24 -19
  17. package/package/components/render-block/block-styles.svelte.d.ts +2 -2
  18. package/package/components/render-block/render-block.svelte +81 -58
  19. package/package/components/render-block/render-block.svelte.d.ts +2 -2
  20. package/package/components/render-block/render-component-with-context.svelte +32 -0
  21. package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
  22. package/package/components/render-block/render-component.svelte +1 -3
  23. package/package/components/render-block/render-component.svelte.d.ts +2 -2
  24. package/package/components/render-block/render-repeated-block.svelte +3 -0
  25. package/package/components/render-block/types.d.ts +2 -2
  26. package/package/components/render-block/types.js +1 -2
  27. package/package/components/render-blocks.svelte +12 -1
  28. package/package/components/render-blocks.svelte.d.ts +3 -1
  29. package/package/components/render-content/components/render-styles.svelte +2 -1
  30. package/package/components/render-content/render-content.svelte +24 -8
  31. package/package/components/render-content/render-content.svelte.d.ts +2 -2
  32. package/package/constants/builder-registered-components.js +3 -0
  33. package/package/context/builder.context.d.ts +1 -0
  34. package/package/context/builder.context.js +1 -0
  35. package/package/context/types.d.ts +4 -3
  36. package/package/context/types.js +1 -3
  37. package/package/functions/extract-text-styles.d.ts +4 -0
  38. package/package/functions/extract-text-styles.js +34 -0
  39. package/package/functions/fast-clone.d.ts +4 -0
  40. package/package/functions/fast-clone.js +4 -0
  41. package/package/functions/get-block-actions-handler.d.ts +5 -0
  42. package/package/functions/get-block-actions-handler.js +9 -0
  43. package/package/functions/get-block-actions.d.ts +1 -1
  44. package/package/functions/get-block-actions.js +2 -8
  45. package/package/functions/get-block-component-options.d.ts +1 -1
  46. package/package/functions/get-block-component-options.js +0 -1
  47. package/package/functions/get-block-properties.d.ts +1 -1
  48. package/package/functions/get-block-properties.js +0 -1
  49. package/package/functions/get-block-tag.d.ts +1 -1
  50. package/package/functions/get-block-tag.js +0 -1
  51. package/package/functions/get-content/ab-testing.d.ts +5 -3
  52. package/package/functions/get-content/ab-testing.js +75 -37
  53. package/package/functions/get-content/index.d.ts +1 -1
  54. package/package/functions/get-content/index.js +4 -5
  55. package/package/functions/get-content/types.d.ts +7 -2
  56. package/package/functions/get-processed-block.d.ts +1 -1
  57. package/package/functions/get-processed-block.js +5 -4
  58. package/package/functions/get-processed-block.test.js +0 -1
  59. package/package/functions/get-react-native-block-styles.d.ts +6 -0
  60. package/package/functions/get-react-native-block-styles.js +16 -0
  61. package/package/functions/register-component.d.ts +2 -2
  62. package/package/functions/register-component.js +1 -5
  63. package/package/functions/register.d.ts +2 -2
  64. package/package/functions/register.js +0 -2
  65. package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
  66. package/package/functions/sanitize-react-native-block-styles.js +53 -0
  67. package/package/functions/track.d.ts +1 -1
  68. package/package/functions/track.js +5 -6
  69. package/package/functions/transform-block.d.ts +1 -1
  70. package/package/functions/transform-block.js +0 -1
  71. package/package/helpers/ab-tests.d.ts +8 -0
  72. package/package/helpers/ab-tests.js +5 -0
  73. package/package/helpers/cookie.d.ts +9 -3
  74. package/package/helpers/cookie.js +8 -3
  75. package/package/helpers/css.d.ts +5 -1
  76. package/package/helpers/css.js +14 -1
  77. package/package/helpers/localStorage.d.ts +3 -4
  78. package/package/helpers/sessionId.d.ts +3 -4
  79. package/package/helpers/sessionId.js +5 -3
  80. package/package/helpers/visitorId.d.ts +3 -5
  81. package/package/scripts/init-editing.js +42 -38
  82. package/package/types/builder-content.d.ts +1 -1
  83. package/package/types/builder-content.js +1 -1
  84. package/package/types/targets.d.ts +1 -1
  85. package/package/types/typescript.d.ts +1 -0
  86. package/package.json +8 -3
  87. package/package/blocks/button/button.lite.d.ts +0 -0
  88. package/package/blocks/button/button.lite.tsx +0 -36
  89. package/package/blocks/columns/columns.lite.d.ts +0 -0
  90. package/package/blocks/columns/columns.lite.tsx +0 -139
  91. package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
  92. package/package/blocks/custom-code/custom-code.lite.tsx +0 -70
  93. package/package/blocks/embed/embed.lite.d.ts +0 -0
  94. package/package/blocks/embed/embed.lite.tsx +0 -52
  95. package/package/blocks/form/form.lite.d.ts +0 -0
  96. package/package/blocks/form/form.lite.tsx +0 -351
  97. package/package/blocks/fragment/fragment.lite.d.ts +0 -0
  98. package/package/blocks/fragment/fragment.lite.tsx +0 -12
  99. package/package/blocks/image/image.lite.d.ts +0 -0
  100. package/package/blocks/image/image.lite.tsx +0 -148
  101. package/package/blocks/img/img.lite.d.ts +0 -0
  102. package/package/blocks/img/img.lite.tsx +0 -48
  103. package/package/blocks/input/input.lite.d.ts +0 -0
  104. package/package/blocks/input/input.lite.tsx +0 -34
  105. package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
  106. package/package/blocks/raw-text/raw-text.lite.tsx +0 -15
  107. package/package/blocks/section/section.lite.d.ts +0 -0
  108. package/package/blocks/section/section.lite.tsx +0 -30
  109. package/package/blocks/select/select.lite.d.ts +0 -0
  110. package/package/blocks/select/select.lite.tsx +0 -34
  111. package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
  112. package/package/blocks/submit-button/submit-button.lite.tsx +0 -15
  113. package/package/blocks/symbol/symbol.lite.d.ts +0 -0
  114. package/package/blocks/symbol/symbol.lite.tsx +0 -92
  115. package/package/blocks/text/text.lite.d.ts +0 -0
  116. package/package/blocks/text/text.lite.tsx +0 -11
  117. package/package/blocks/textarea/textarea.lite.d.ts +0 -0
  118. package/package/blocks/textarea/textarea.lite.tsx +0 -19
  119. package/package/blocks/video/video.lite.d.ts +0 -0
  120. package/package/blocks/video/video.lite.tsx +0 -92
  121. package/package/components/render-block/block-styles.lite.d.ts +0 -0
  122. package/package/components/render-block/block-styles.lite.tsx +0 -60
  123. package/package/components/render-block/render-block.lite.d.ts +0 -0
  124. package/package/components/render-block/render-block.lite.tsx +0 -216
  125. package/package/components/render-block/render-component.lite.d.ts +0 -0
  126. package/package/components/render-block/render-component.lite.tsx +0 -33
  127. package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
  128. package/package/components/render-block/render-repeated-block.lite.tsx +0 -49
  129. package/package/components/render-blocks.lite.d.ts +0 -0
  130. package/package/components/render-blocks.lite.tsx +0 -91
  131. package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
  132. package/package/components/render-content/components/render-styles.lite.tsx +0 -86
  133. package/package/components/render-content/render-content.lite.d.ts +0 -0
  134. package/package/components/render-content/render-content.lite.tsx +0 -356
  135. package/package/components/render-inlined-styles.lite.d.ts +0 -0
  136. package/package/components/render-inlined-styles.lite.tsx +0 -27
  137. package/package/functions/convert-style-object.d.ts +0 -1
  138. package/package/functions/convert-style-object.js +0 -3
  139. package/package/functions/get-block-styles.d.ts +0 -2
  140. package/package/functions/get-block-styles.js +0 -21
  141. package/package/functions/sanitize-styles.d.ts +0 -4
  142. package/package/functions/sanitize-styles.js +0 -6
@@ -1,9 +1,8 @@
1
+ import type { CanTrack } from '../types/can-track.js';
1
2
  export declare const getLocalStorageItem: ({ key, canTrack, }: {
2
3
  key: string;
3
- canTrack: boolean;
4
- }) => string | null | undefined;
4
+ } & CanTrack) => string | null | undefined;
5
5
  export declare const setLocalStorageItem: ({ key, canTrack, value, }: {
6
6
  key: string;
7
7
  value: string;
8
- canTrack: boolean;
9
- }) => void;
8
+ } & CanTrack) => void;
@@ -1,7 +1,6 @@
1
- import { CanTrack } from '../types/can-track.js';
2
- export declare const getSessionId: ({ canTrack }: CanTrack) => string | undefined;
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ export declare const getSessionId: ({ canTrack }: CanTrack) => Promise<string | undefined>;
3
3
  export declare const createSessionId: () => string;
4
4
  export declare const setSessionId: ({ id, canTrack, }: {
5
5
  id: string;
6
- canTrack: boolean;
7
- }) => undefined;
6
+ } & CanTrack) => Promise<undefined>;
@@ -1,13 +1,15 @@
1
- import '../types/can-track.js';
2
1
  import { getCookie, setCookie } from './cookie.js';
3
2
  import { checkIsDefined } from './nullable.js';
4
3
  import { uuid } from './uuid.js';
5
4
  const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
6
- export const getSessionId = ({ canTrack }) => {
5
+ export const getSessionId = async ({ canTrack }) => {
7
6
  if (!canTrack) {
8
7
  return undefined;
9
8
  }
10
- const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
9
+ const sessionId = await getCookie({
10
+ name: SESSION_LOCAL_STORAGE_KEY,
11
+ canTrack,
12
+ });
11
13
  if (checkIsDefined(sessionId)) {
12
14
  return sessionId;
13
15
  }
@@ -1,8 +1,6 @@
1
- export declare const getVisitorId: ({ canTrack }: {
2
- canTrack: boolean;
3
- }) => string | undefined;
1
+ import type { CanTrack } from '../types/can-track.js';
2
+ export declare const getVisitorId: ({ canTrack }: CanTrack) => string | undefined;
4
3
  export declare const createVisitorId: () => string;
5
4
  export declare const setVisitorId: ({ id, canTrack, }: {
6
5
  id: string;
7
- canTrack: boolean;
8
- }) => void;
6
+ } & CanTrack) => void;
@@ -31,52 +31,56 @@ export const setupBrowserForEditing = () => {
31
31
  // type: process.env.SDK_TYPE,
32
32
  // version: process.env.SDK_VERSION,
33
33
  supportsPatchUpdates: false,
34
+ // Supports builder-model="..." attribute which is needed to
35
+ // scope our '+ add block' button styling
36
+ supportsAddBlockScoping: true,
34
37
  },
35
38
  }, '*');
36
39
  window.addEventListener('message', ({ data }) => {
37
- if (data) {
38
- switch (data.type) {
39
- case 'builder.evaluate': {
40
- const text = data.data.text;
41
- const args = data.data.arguments || [];
42
- const id = data.data.id;
43
- // tslint:disable-next-line:no-function-constructor-with-string-args
44
- const fn = new Function(text);
45
- let result;
46
- let error = null;
47
- try {
48
- // eslint-disable-next-line prefer-spread
49
- result = fn.apply(null, args);
50
- }
51
- catch (err) {
52
- error = err;
53
- }
54
- if (error) {
55
- window.parent?.postMessage({
56
- type: 'builder.evaluateError',
57
- data: { id, error: error.message },
58
- }, '*');
59
- }
60
- else {
61
- if (result && typeof result.then === 'function') {
62
- result
63
- .then((finalResult) => {
64
- window.parent?.postMessage({
65
- type: 'builder.evaluateResult',
66
- data: { id, result: finalResult },
67
- }, '*');
68
- })
69
- .catch(console.error);
70
- }
71
- else {
40
+ if (!data?.type) {
41
+ return;
42
+ }
43
+ switch (data.type) {
44
+ case 'builder.evaluate': {
45
+ const text = data.data.text;
46
+ const args = data.data.arguments || [];
47
+ const id = data.data.id;
48
+ // tslint:disable-next-line:no-function-constructor-with-string-args
49
+ const fn = new Function(text);
50
+ let result;
51
+ let error = null;
52
+ try {
53
+ // eslint-disable-next-line prefer-spread
54
+ result = fn.apply(null, args);
55
+ }
56
+ catch (err) {
57
+ error = err;
58
+ }
59
+ if (error) {
60
+ window.parent?.postMessage({
61
+ type: 'builder.evaluateError',
62
+ data: { id, error: error.message },
63
+ }, '*');
64
+ }
65
+ else {
66
+ if (result && typeof result.then === 'function') {
67
+ result
68
+ .then((finalResult) => {
72
69
  window.parent?.postMessage({
73
70
  type: 'builder.evaluateResult',
74
- data: { result, id },
71
+ data: { id, result: finalResult },
75
72
  }, '*');
76
- }
73
+ })
74
+ .catch(console.error);
75
+ }
76
+ else {
77
+ window.parent?.postMessage({
78
+ type: 'builder.evaluateResult',
79
+ data: { result, id },
80
+ }, '*');
77
81
  }
78
- break;
79
82
  }
83
+ break;
80
84
  }
81
85
  }
82
86
  });
@@ -1,4 +1,4 @@
1
- import { BuilderBlock } from './builder-block.js';
1
+ import type { BuilderBlock } from './builder-block.js';
2
2
  declare type Input = any;
3
3
  export interface BuilderContentVariation {
4
4
  data?: {
@@ -1 +1 @@
1
- import './builder-block.js';
1
+ export {};
@@ -1,3 +1,3 @@
1
1
  declare type MitosisTargets = import('@builder.io/mitosis').Target;
2
- export declare type Target = Extract<MitosisTargets, 'vue3' | 'vue2' | 'reactNative' | 'svelte'>;
2
+ export declare type Target = Extract<MitosisTargets, 'vue3' | 'vue2' | 'reactNative' | 'svelte' | 'qwik'>;
3
3
  export {};
@@ -2,3 +2,4 @@ export declare type Nullable<T> = T | null | undefined;
2
2
  export declare type Dictionary<T> = {
3
3
  [key: string]: T;
4
4
  };
5
+ export declare type Overwrite<T, U> = keyof U extends keyof T ? Pick<T, Exclude<keyof T, keyof U>> & U : never;
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": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package"
@@ -14,8 +14,12 @@
14
14
  },
15
15
  "main": "./package/index.js",
16
16
  "module": "./package/index.js",
17
- "svelte": "./package/index.js",
17
+ "svelte": "./src/index.ts",
18
18
  "exports": {
19
+ "./src": {
20
+ "import": "./src/index.js",
21
+ "require": "./src/index.js"
22
+ },
19
23
  ".": {
20
24
  "import": "./package/index.js",
21
25
  "require": "./package/index.js"
@@ -26,7 +30,8 @@
26
30
  "release:patch": "yarn run build && npm version patch --no-git-tag-version && npm publish --access public",
27
31
  "release:dev": "yarn run build && npm version prerelease --no-git-tag-version && npm publish --tag dev --access public",
28
32
  "dev": "vite dev",
29
- "build": "svelte-kit sync && svelte-package && rm package/package.json",
33
+ "build": "svelte-kit sync && svelte-package",
34
+ "build:watch": "svelte-kit sync && svelte-package --watch",
30
35
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
31
36
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
32
37
  },
File without changes
@@ -1,36 +0,0 @@
1
- <script context="module" lang="ts">
2
- export interface ButtonProps {
3
- attributes?: any;
4
- text?: string;
5
- link?: string;
6
- openLinkInNewTab?: boolean;
7
- }
8
- </script>
9
-
10
- <script lang="ts">
11
- export let attributes: ButtonProps["attributes"];
12
- export let text: ButtonProps["text"];
13
- export let link: ButtonProps["link"];
14
- export let openLinkInNewTab: ButtonProps["openLinkInNewTab"];
15
- </script>
16
-
17
- {#if link}
18
- <a
19
- {...attributes}
20
- role="button"
21
- href={link}
22
- target={openLinkInNewTab ? "_blank" : undefined}
23
- >
24
- {text}
25
- </a>
26
- {:else}
27
- <button {...attributes} class="button">
28
- {text}
29
- </button>
30
- {/if}
31
-
32
- <style>
33
- .button {
34
- all: unset;
35
- }
36
- </style>
File without changes
@@ -1,139 +0,0 @@
1
- <script context="module" lang="ts">
2
- type Column = {
3
- blocks: any; // TODO: Implement this when support for dynamic CSS lands
4
-
5
- width?: number;
6
- };
7
-
8
- type StackColumnsAt = "tablet" | "mobile" | "never";
9
-
10
- export interface ColumnProps {
11
- columns?: Column[];
12
- builderBlock: BuilderBlock; // TODO: Implement this when support for dynamic CSS lands
13
-
14
- space?: number; // TODO: Implement this when support for dynamic CSS lands
15
-
16
- stackColumnsAt?: StackColumnsAt; // TODO: Implement this when support for dynamic CSS lands
17
-
18
- reverseColumnsWhenStacked?: boolean;
19
- }
20
- </script>
21
-
22
- <script lang="ts">
23
- import RenderBlocks from "../../components/render-blocks.svelte";
24
- import { BuilderBlock } from "../../types/builder-block";
25
- import { markMutable } from "../../functions/mark-mutable";
26
-
27
- export let space: ColumnProps["space"];
28
- export let columns: ColumnProps["columns"];
29
- export let stackColumnsAt: ColumnProps["stackColumnsAt"];
30
- export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
31
- export let builderBlock: ColumnProps["builderBlock"];
32
-
33
- function mitosis_styling(node, vars) {
34
- Object.entries(vars).forEach(([p, v]) => {
35
- node.style[p] = v;
36
- });
37
- }
38
-
39
- function getGutterSize() {
40
- return typeof space === "number" ? space || 0 : 20;
41
- }
42
-
43
- function getColumns() {
44
- return columns || [];
45
- }
46
-
47
- function getWidth(index) {
48
- const columns = getColumns();
49
- return columns[index]?.width || 100 / columns.length;
50
- }
51
-
52
- function getColumnCssWidth(index) {
53
- const columns = getColumns();
54
- const gutterSize = getGutterSize();
55
- const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
56
- return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
57
- }
58
-
59
- function maybeApplyForTablet(prop) {
60
- const _stackColumnsAt = stackColumnsAt || "tablet";
61
-
62
- return _stackColumnsAt === "tablet" ? prop : "inherit";
63
- }
64
- $: columnsCssVars = () => {
65
- const flexDir =
66
- stackColumnsAt === "never"
67
- ? "inherit"
68
- : reverseColumnsWhenStacked
69
- ? "column-reverse"
70
- : "column";
71
- return {
72
- "--flex-dir": flexDir,
73
- "--flex-dir-tablet": maybeApplyForTablet(flexDir),
74
- };
75
- };
76
-
77
- $: columnCssVars = () => {
78
- const width = "100%";
79
- const marginLeft = "0";
80
- return {
81
- "--column-width": width,
82
- "--column-margin-left": marginLeft,
83
- "--column-width-tablet": maybeApplyForTablet(width),
84
- "--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
85
- };
86
- };
87
- </script>
88
-
89
- <div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
90
- {#each columns as column, index (index)}
91
- <div
92
- use:mitosis_styling={{
93
- width: getColumnCssWidth(index),
94
- marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
95
- ...columnCssVars(),
96
- }}
97
- class="builder-column div-2"
98
- >
99
- <RenderBlocks
100
- blocks={markMutable(column.blocks)}
101
- path={`component.options.columns.${index}.blocks`}
102
- parent={builderBlock.id}
103
- />
104
- </div>
105
- {/each}
106
- </div>
107
-
108
- <style>
109
- .div {
110
- display: flex;
111
- align-items: stretch;
112
- line-height: normal;
113
- }
114
- @media (max-width: 991px) {
115
- .div {
116
- flex-direction: var(--flex-dir-tablet);
117
- }
118
- }
119
- @media (max-width: 639px) {
120
- .div {
121
- flex-direction: var(--flex-dir);
122
- }
123
- }
124
- .div-2 {
125
- flex-grow: 1;
126
- }
127
- @media (max-width: 991px) {
128
- .div-2 {
129
- width: var(--column-width-tablet) !important;
130
- margin-left: var(--column-margin-left-tablet) !important;
131
- }
132
- }
133
- @media (max-width: 639px) {
134
- .div-2 {
135
- width: var(--column-width) !important;
136
- margin-left: var(--column-margin-left) !important;
137
- }
138
- }
139
- </style>
File without changes
@@ -1,70 +0,0 @@
1
- <script context="module" lang="ts">
2
- export interface CustomCodeProps {
3
- code: string;
4
- replaceNodes?: boolean;
5
- }
6
- </script>
7
-
8
- <script lang="ts">
9
- import { onMount } from "svelte";
10
-
11
- export let replaceNodes: CustomCodeProps["replaceNodes"];
12
- export let code: CustomCodeProps["code"];
13
-
14
- function findAndRunScripts() {
15
- // TODO: Move this function to standalone one in '@builder.io/utils'
16
- if (elem && typeof window !== "undefined") {
17
- const scripts = elem.getElementsByTagName("script");
18
-
19
- for (let i = 0; i < scripts.length; i++) {
20
- const script = scripts[i];
21
-
22
- if (script.src) {
23
- if (scriptsInserted.includes(script.src)) {
24
- continue;
25
- }
26
-
27
- scriptsInserted.push(script.src);
28
- const newScript = document.createElement("script");
29
- newScript.async = true;
30
- newScript.src = script.src;
31
- document.head.appendChild(newScript);
32
- } else if (
33
- !script.type ||
34
- [
35
- "text/javascript",
36
- "application/javascript",
37
- "application/ecmascript",
38
- ].includes(script.type)
39
- ) {
40
- if (scriptsRun.includes(script.innerText)) {
41
- continue;
42
- }
43
-
44
- try {
45
- scriptsRun.push(script.innerText);
46
- new Function(script.innerText)();
47
- } catch (error) {
48
- console.warn("`CustomCode`: Error running script:", error);
49
- }
50
- }
51
- }
52
- }
53
- }
54
-
55
- let elem;
56
-
57
- let scriptsInserted = [];
58
- let scriptsRun = [];
59
-
60
- onMount(() => {
61
- findAndRunScripts();
62
- });
63
- </script>
64
-
65
- <div
66
- bind:this={elem}
67
- class={"builder-custom-code" + (replaceNodes ? " replace-nodes" : "")}
68
- >
69
- {@html code}
70
- </div>
File without changes
@@ -1,52 +0,0 @@
1
- <script context="module" lang="ts">
2
- export interface EmbedProps {
3
- content: string;
4
- }
5
- </script>
6
-
7
- <script lang="ts">
8
- import { afterUpdate } from "svelte";
9
-
10
- import { isJsScript } from "./helpers.js";
11
-
12
- export let content: EmbedProps["content"];
13
-
14
- function findAndRunScripts() {
15
- const scripts = elem.getElementsByTagName("script");
16
-
17
- for (let i = 0; i < scripts.length; i++) {
18
- const script = scripts[i];
19
-
20
- if (script.src && !scriptsInserted.includes(script.src)) {
21
- scriptsInserted.push(script.src);
22
- const newScript = document.createElement("script");
23
- newScript.async = true;
24
- newScript.src = script.src;
25
- document.head.appendChild(newScript);
26
- } else if (isJsScript(script) && !scriptsRun.includes(script.innerText)) {
27
- try {
28
- scriptsRun.push(script.innerText);
29
- new Function(script.innerText)();
30
- } catch (error) {
31
- console.warn("`Embed`: Error running script:", error);
32
- }
33
- }
34
- }
35
- }
36
-
37
- let elem;
38
-
39
- let scriptsInserted = [];
40
- let scriptsRun = [];
41
- let ranInitFn = false;
42
-
43
- function onUpdateFn_0() {
44
- if (elem && !ranInitFn) {
45
- ranInitFn = true;
46
- findAndRunScripts();
47
- }
48
- }
49
- $: onUpdateFn_0(...[elem, ranInitFn]);
50
- </script>
51
-
52
- <div class="builder-embed" bind:this={elem}>{@html content}</div>
File without changes