@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
@@ -1,89 +1,80 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __reExport = (target, module2, desc) => {
9
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
10
- for (let key of __getOwnPropNames(module2))
11
- if (!__hasOwnProp.call(target, key) && key !== "default")
12
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
13
- }
14
- return target;
15
- };
16
- var __toModule = (module2) => {
17
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
18
- };
19
- var import_target = __toModule(require("../constants/target"));
20
- var import_is_browser = __toModule(require("../functions/is-browser"));
21
- var import_register = __toModule(require("../functions/register"));
22
- var _a;
23
- (0, import_register.register)("insertMenu", {
24
- name: "_default",
25
- default: true,
26
- items: [
27
- { name: "Box" },
28
- { name: "Text" },
29
- { name: "Image" },
30
- { name: "Columns" },
31
- ...import_target.TARGET === "reactNative" ? [] : [
32
- { name: "Core:Section" },
33
- { name: "Core:Button" },
34
- { name: "Embed" },
35
- { name: "Custom Code" }
1
+ import { TARGET } from "../constants/target.js";
2
+ import { isBrowser } from "../functions/is-browser.js";
3
+ import { isEditing } from "../functions/is-editing.js";
4
+ import { register } from "../functions/register.js";
5
+ const registerInsertMenu = () => {
6
+ register("insertMenu", {
7
+ name: "_default",
8
+ default: true,
9
+ items: [
10
+ { name: "Box" },
11
+ { name: "Text" },
12
+ { name: "Image" },
13
+ { name: "Columns" },
14
+ ...TARGET === "reactNative" ? [] : [
15
+ { name: "Core:Section" },
16
+ { name: "Core:Button" },
17
+ { name: "Embed" },
18
+ { name: "Custom Code" }
19
+ ]
36
20
  ]
37
- ]
38
- });
39
- if ((0, import_is_browser.isBrowser)()) {
40
- (_a = window.parent) == null ? void 0 : _a.postMessage({
41
- type: "builder.sdkInfo",
42
- data: {
43
- target: import_target.TARGET,
44
- supportsPatchUpdates: false
45
- }
46
- }, "*");
47
- window.addEventListener("message", ({ data }) => {
48
- var _a2, _b;
49
- if (data) {
50
- switch (data.type) {
51
- case "builder.evaluate": {
52
- const text = data.data.text;
53
- const args = data.data.arguments || [];
54
- const id = data.data.id;
55
- const fn = new Function(text);
56
- let result;
57
- let error = null;
58
- try {
59
- result = fn.apply(null, args);
60
- } catch (err) {
61
- error = err;
62
- }
63
- if (error) {
64
- (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
65
- type: "builder.evaluateError",
66
- data: { id, error: error.message }
67
- }, "*");
68
- } else {
69
- if (result && typeof result.then === "function") {
70
- result.then((finalResult) => {
71
- var _a3;
72
- (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
21
+ });
22
+ };
23
+ const setupBrowserForEditing = () => {
24
+ var _a;
25
+ if (isBrowser()) {
26
+ (_a = window.parent) == null ? void 0 : _a.postMessage({
27
+ type: "builder.sdkInfo",
28
+ data: {
29
+ target: TARGET,
30
+ supportsPatchUpdates: false
31
+ }
32
+ }, "*");
33
+ window.addEventListener("message", ({ data }) => {
34
+ var _a2, _b;
35
+ if (data) {
36
+ switch (data.type) {
37
+ case "builder.evaluate": {
38
+ const text = data.data.text;
39
+ const args = data.data.arguments || [];
40
+ const id = data.data.id;
41
+ const fn = new Function(text);
42
+ let result;
43
+ let error = null;
44
+ try {
45
+ result = fn.apply(null, args);
46
+ } catch (err) {
47
+ error = err;
48
+ }
49
+ if (error) {
50
+ (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
51
+ type: "builder.evaluateError",
52
+ data: { id, error: error.message }
53
+ }, "*");
54
+ } else {
55
+ if (result && typeof result.then === "function") {
56
+ result.then((finalResult) => {
57
+ var _a3;
58
+ (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
59
+ type: "builder.evaluateResult",
60
+ data: { id, result: finalResult }
61
+ }, "*");
62
+ }).catch(console.error);
63
+ } else {
64
+ (_b = window.parent) == null ? void 0 : _b.postMessage({
73
65
  type: "builder.evaluateResult",
74
- data: { id, result: finalResult }
66
+ data: { result, id }
75
67
  }, "*");
76
- }).catch(console.error);
77
- } else {
78
- (_b = window.parent) == null ? void 0 : _b.postMessage({
79
- type: "builder.evaluateResult",
80
- data: { result, id }
81
- }, "*");
68
+ }
82
69
  }
70
+ break;
83
71
  }
84
- break;
85
72
  }
86
73
  }
87
- }
88
- });
74
+ });
75
+ }
76
+ };
77
+ if (isEditing()) {
78
+ registerInsertMenu();
79
+ setupBrowserForEditing();
89
80
  }
@@ -1,3 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- __markAsModule(exports);
@@ -1,3 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- __markAsModule(exports);
File without changes
@@ -1,3 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- __markAsModule(exports);
File without changes
@@ -1,3 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- __markAsModule(exports);
@@ -1,3 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- __markAsModule(exports);
@@ -1,63 +0,0 @@
1
- <script>
2
- import { onMount } from 'svelte'
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
- export let elem;
12
- export let replaceNodes;
13
- export let code;
14
-
15
- function findAndRunScripts() {
16
- // TODO: Move this function to standalone one in '@builder.io/utils'
17
- if (elem && typeof window !== 'undefined') {
18
- /** @type {HTMLScriptElement[]} */
19
- const scripts = elem.getElementsByTagName('script');
20
-
21
- for (let i = 0; i < scripts.length; i++) {
22
- const script = scripts[i];
23
-
24
- if (script.src) {
25
- if (scriptsInserted.includes(script.src)) {
26
- continue;
27
- }
28
-
29
- scriptsInserted.push(script.src);
30
- const newScript = document.createElement('script');
31
- newScript.async = true;
32
- newScript.src = script.src;
33
- document.head.appendChild(newScript);
34
- } else if (!script.type || ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(script.type)) {
35
- if (scriptsRun.includes(script.innerText)) {
36
- continue;
37
- }
38
-
39
- try {
40
- scriptsRun.push(script.innerText);
41
- new Function(script.innerText)();
42
- } catch (error) {
43
- console.warn('`CustomCode`: Error running script:', error);
44
- }
45
- }
46
- }
47
- }
48
- }
49
-
50
-
51
- let scriptsInserted = [];
52
- let scriptsRun = [];
53
-
54
- onMount(() => {
55
- findAndRunScripts();
56
- });
57
-
58
-
59
-
60
-
61
- </script>
62
-
63
- <div bind:this={elem} class={'builder-custom-code' + (replaceNodes ? ' replace-nodes' : '')} >{@html code}</div>
@@ -1,62 +0,0 @@
1
- <script>
2
- import { onMount } from 'svelte'
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
- export let elem;
12
- export let content;
13
-
14
- function findAndRunScripts() {
15
- // TODO: Move this function to standalone one in '@builder.io/utils'
16
- if (elem && typeof window !== 'undefined') {
17
- /** @type {HTMLScriptElement[]} */
18
- const scripts = elem.getElementsByTagName('script');
19
-
20
- for (let i = 0; i < scripts.length; i++) {
21
- const script = scripts[i];
22
-
23
- if (script.src) {
24
- if (scriptsInserted.includes(script.src)) {
25
- continue;
26
- }
27
-
28
- scriptsInserted.push(script.src);
29
- const newScript = document.createElement('script');
30
- newScript.async = true;
31
- newScript.src = script.src;
32
- document.head.appendChild(newScript);
33
- } else if (!script.type || ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(script.type)) {
34
- if (scriptsRun.includes(script.innerText)) {
35
- continue;
36
- }
37
-
38
- try {
39
- scriptsRun.push(script.innerText);
40
- new Function(script.innerText)();
41
- } catch (error) {
42
- console.warn('`Embed`: Error running script:', error);
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
-
50
- let scriptsInserted = [];
51
- let scriptsRun = [];
52
-
53
- onMount(() => {
54
- findAndRunScripts();
55
- });
56
-
57
-
58
-
59
-
60
- </script>
61
-
62
- <div class="builder-embed" bind:this={elem} >{@html content}</div>
@@ -1,55 +0,0 @@
1
- <script>
2
- import { onMount } from 'svelte'
3
- import { afterUpdate } from 'svelte'
4
-
5
-
6
- import RenderContent, { } from '../components/render-content/render-content.lite';
7
- import BuilderContext, { } from '../context/builder.context.lite';
8
- import { getContent } from '../functions/get-content';
9
-
10
-
11
-
12
-
13
-
14
- export let attributes;
15
- export let symbol;
16
-
17
-
18
-
19
-
20
- let className = 'builder-symbol';
21
- let content = null;
22
-
23
- onMount(() => {
24
- content = symbol?.content;
25
- });
26
-
27
- afterUpdate(() => {
28
- const symbol = symbol;
29
-
30
- if (symbol && !symbol.content && !content && symbol.model) {
31
- getContent({
32
- model: symbol.model,
33
- apiKey: builderContext.apiKey!,
34
- options: {
35
- entry: symbol.entry
36
- }
37
- }).then(response => {
38
- content = response;
39
- });
40
- }
41
- })
42
-
43
-
44
- </script>
45
-
46
- <div {...attributes} dataSet={{
47
- class: className
48
- }} class={className} >
49
-
50
- <RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...symbol?.data,
51
- ...builderContext.state,
52
- ...symbol?.content?.data?.state
53
- }} model={symbol?.model} content={content} ></RenderContent>
54
-
55
- </div>
@@ -1,121 +0,0 @@
1
- <script>
2
-
3
-
4
-
5
-
6
- import { getBlockComponentOptions } from '../functions/get-block-component-options';
7
- import { getBlockProperties } from '../functions/get-block-properties';
8
- import { getBlockStyles } from '../functions/get-block-styles';
9
- import { getBlockTag } from '../functions/get-block-tag';
10
- import { components } from '../functions/register-component';
11
- import BuilderContext, { } from '../context/builder.context.lite';
12
- import { getBlockActions } from '../functions/get-block-actions';
13
- import { getProcessedBlock } from '../functions/get-processed-block';
14
- import BlockStyles, { } from './block-styles.lite';
15
-
16
-
17
-
18
-
19
-
20
- export let block;
21
-
22
-
23
- $: component = () => {
24
- const componentName = useBlock().component?.name;
25
-
26
- if (!componentName) {
27
- return null;
28
- }
29
-
30
- const ref = components[useBlock().component?.name];
31
-
32
- if (componentName && !ref) {
33
- // TODO: Public doc page with more info about this message
34
- console.warn(`
35
- Could not find a registered component named "${componentName}".
36
- If you registered it, is the file that registered it imported by the file that needs to render it?`);
37
- }
38
-
39
- return ref;
40
- };
41
-
42
- $: componentInfo = () => {
43
- return component?.()?.info;
44
- };
45
-
46
- $: componentRef = () => {
47
- return component?.()?.component;
48
- };
49
-
50
- $: tagName = () => {
51
- return getBlockTag(useBlock());
52
- };
53
-
54
- $: useBlock = () => {
55
- return getProcessedBlock({
56
- block: block,
57
- state: builderContext.state,
58
- context: builderContext.context
59
- });
60
- };
61
-
62
- $: propertiesAndActions = () => {
63
- return { ...getBlockProperties(useBlock()),
64
- ...getBlockActions({
65
- block: useBlock(),
66
- state: builderContext.state,
67
- context: builderContext.context
68
- })
69
- };
70
- };
71
-
72
- $: css = () => {
73
- return getBlockStyles(useBlock());
74
- };
75
-
76
- $: componentOptions = () => {
77
- return getBlockComponentOptions(useBlock());
78
- };
79
-
80
- $: children = () => {
81
- // TO-DO: When should `canHaveChildren` dictate rendering?
82
- // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
83
- // but still receive and need to render children.
84
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
85
- return useBlock().children ?? [];
86
- };
87
-
88
- $: noCompRefChildren = () => {
89
- return componentRef() ? [] : children();
90
- };
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- </script>
100
-
101
-
102
-
103
- {#if !componentInfo?.()?.noWrap }
104
-
105
- <tagName() {...propertiesAndActions()} style={css()} >
106
-
107
- <BlockStyles block={useBlock()} ></BlockStyles>
108
-
109
-
110
- {#if componentRef() }<componentRef() {...componentOptions()} builderBlock={useBlock()} >
111
-
112
- {#each children() as child }<RenderBlock block={child} ></RenderBlock>{/each}
113
-
114
- </componentRef()>{/if}
115
-
116
-
117
- {#each noCompRefChildren() as child }<RenderBlock block={child} ></RenderBlock>{/each}
118
-
119
- </tagName()>
120
-
121
- {/if}
@@ -1,12 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
3
- var __export = (target, all) => {
4
- __markAsModule(target);
5
- for (var name in all)
6
- __defProp(target, name, { get: all[name], enumerable: true });
7
- };
8
- __export(exports, {
9
- macroEval: () => macroEval
10
- });
11
- function macroEval(items, string) {
12
- }