@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
@@ -0,0 +1,4 @@
1
+ const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
2
+ export {
3
+ checkIsDefined
4
+ };
@@ -0,0 +1,26 @@
1
+ import { getCookie, setCookie } from "./cookie";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
5
+ const getSessionId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
10
+ if (checkIsDefined(sessionId)) {
11
+ return sessionId;
12
+ } else {
13
+ const newSessionId = createSessionId();
14
+ setSessionId({ id: newSessionId, canTrack });
15
+ }
16
+ };
17
+ const createSessionId = () => uuid();
18
+ const setSessionId = ({
19
+ id,
20
+ canTrack
21
+ }) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
22
+ export {
23
+ createSessionId,
24
+ getSessionId,
25
+ setSessionId
26
+ };
@@ -0,0 +1,5 @@
1
+ const MINUTE_TO_MILLESECONDS_MULTIPLIER = 6e4;
2
+ const getCurrentDatePlusMinutes = (minutes = 30) => new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER);
3
+ export {
4
+ getCurrentDatePlusMinutes
5
+ };
@@ -0,0 +1,10 @@
1
+ const getTopLevelDomain = (host) => {
2
+ const parts = host.split(".");
3
+ if (parts.length > 2) {
4
+ return parts.slice(1).join(".");
5
+ }
6
+ return host;
7
+ };
8
+ export {
9
+ getTopLevelDomain
10
+ };
@@ -0,0 +1,15 @@
1
+ import { getTopLevelDomain } from "./url.js";
2
+ describe("getTopLevelDomain", () => {
3
+ test("handles root domain", () => {
4
+ const output = getTopLevelDomain("example.com");
5
+ expect(output).toBe("example.com");
6
+ });
7
+ test("handles subdomain", () => {
8
+ const output = getTopLevelDomain("wwww.example.com");
9
+ expect(output).toBe("example.com");
10
+ });
11
+ test("handles subdomain with long suffix", () => {
12
+ const output = getTopLevelDomain("www.example.co.uk");
13
+ expect(output).toBe("example.co.uk");
14
+ });
15
+ });
@@ -0,0 +1,13 @@
1
+ function uuidv4() {
2
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
3
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
4
+ return v.toString(16);
5
+ });
6
+ }
7
+ function uuid() {
8
+ return uuidv4().replace(/-/g, "");
9
+ }
10
+ export {
11
+ uuid,
12
+ uuidv4
13
+ };
@@ -0,0 +1,33 @@
1
+ import { getLocalStorageItem, setLocalStorageItem } from "./localStorage";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
5
+ const getVisitorId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const visitorId = getLocalStorageItem({
10
+ key: VISITOR_LOCAL_STORAGE_KEY,
11
+ canTrack
12
+ });
13
+ if (checkIsDefined(visitorId)) {
14
+ return visitorId;
15
+ } else {
16
+ const newVisitorId = createVisitorId();
17
+ setVisitorId({ id: newVisitorId, canTrack });
18
+ }
19
+ };
20
+ const createVisitorId = () => uuid();
21
+ const setVisitorId = ({
22
+ id,
23
+ canTrack
24
+ }) => setLocalStorageItem({
25
+ key: VISITOR_LOCAL_STORAGE_KEY,
26
+ value: id,
27
+ canTrack
28
+ });
29
+ export {
30
+ createVisitorId,
31
+ getVisitorId,
32
+ setVisitorId
33
+ };
@@ -1,17 +1,19 @@
1
- import { default as default2 } from "../blocks/columns";
2
- import { default as default3 } from "../blocks/image";
3
- import { default as default4 } from "../blocks/text";
4
- import { default as default5 } from "../blocks/video";
5
- import { default as default6 } from "../blocks/symbol";
6
- import { default as default7 } from "../blocks/button";
7
- import { default as default8 } from "../blocks/section";
8
- import { default as default9 } from "../blocks/fragment";
1
+ import { default as default2 } from "../blocks/columns/columns.svelte";
2
+ import { default as default3 } from "../blocks/image/image.svelte";
3
+ import { default as default4 } from "../blocks/text/text.svelte";
4
+ import { default as default5 } from "../blocks/video/video.svelte";
5
+ import { default as default6 } from "../blocks/symbol/symbol.svelte";
6
+ import { default as default7 } from "../blocks/button/button.svelte";
7
+ import { default as default8 } from "../blocks/section/section.svelte";
8
+ import { default as default9 } from "../blocks/fragment/fragment.svelte";
9
9
  import { default as default10 } from "../components/render-content/render-content.svelte";
10
+ import { default as default11 } from "../components/render-blocks.svelte";
10
11
  export {
11
12
  default7 as Button,
12
13
  default2 as Columns,
13
14
  default9 as Fragment,
14
15
  default3 as Image,
16
+ default11 as RenderBlocks,
15
17
  default10 as RenderContent,
16
18
  default8 as Section,
17
19
  default6 as Symbol,
@@ -1,6 +1,5 @@
1
1
  import { TARGET } from "../constants/target.js";
2
2
  import { isBrowser } from "../functions/is-browser.js";
3
- import { isEditing } from "../functions/is-editing.js";
4
3
  import { register } from "../functions/register.js";
5
4
  const registerInsertMenu = () => {
6
5
  register("insertMenu", {
@@ -74,7 +73,7 @@ const setupBrowserForEditing = () => {
74
73
  });
75
74
  }
76
75
  };
77
- if (isEditing()) {
78
- registerInsertMenu();
79
- setupBrowserForEditing();
80
- }
76
+ export {
77
+ registerInsertMenu,
78
+ setupBrowserForEditing
79
+ };
File without changes
File without changes
File without changes
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./button.svelte";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./columns.svelte";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./custom-code.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./embed.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./form.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./fragment.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./image.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./img.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./input.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./raw-text.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./section.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./select.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./submit-button.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./symbol.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./text.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./textarea.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./video.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,5 +0,0 @@
1
- function macroEval(items, string) {
2
- }
3
- export {
4
- macroEval
5
- };
@@ -1,11 +0,0 @@
1
- import { isPreviewing } from "./is-previewing.js";
2
- function previewingModelName() {
3
- if (!isPreviewing()) {
4
- return null;
5
- }
6
- const url = new URL(location.href);
7
- return url.searchParams.get("builder.preview");
8
- }
9
- export {
10
- previewingModelName
11
- };