@builder.io/sdk-svelte 0.0.1-8 → 0.0.1
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.
- package/README.md +4 -0
- package/package/CHANGELOG.md +19 -0
- package/package/README.md +19 -0
- package/{src/types/builder-block.js → package/blocks/button/button.lite.d.ts} +0 -0
- package/package/blocks/button/button.lite.tsx +36 -0
- package/package/blocks/button/button.svelte +28 -0
- package/package/blocks/button/button.svelte.d.ts +25 -0
- package/package/blocks/button/component-info.d.ts +2 -0
- package/package/blocks/button/component-info.js +39 -0
- package/{src/types/builder-content.js → package/blocks/columns/columns.lite.d.ts} +0 -0
- package/package/blocks/columns/columns.lite.tsx +139 -0
- package/package/blocks/columns/columns.svelte +109 -0
- package/package/blocks/columns/columns.svelte.d.ts +33 -0
- package/package/blocks/columns/component-info.d.ts +2 -0
- package/package/blocks/columns/component-info.js +241 -0
- package/package/blocks/custom-code/component-info.d.ts +2 -0
- package/package/blocks/custom-code/component-info.js +28 -0
- package/{src/types/components.js → package/blocks/custom-code/custom-code.lite.d.ts} +0 -0
- package/package/blocks/custom-code/custom-code.lite.tsx +70 -0
- package/package/blocks/custom-code/custom-code.svelte +55 -0
- package/package/blocks/custom-code/custom-code.svelte.d.ts +21 -0
- package/package/blocks/embed/component-info.d.ts +2 -0
- package/package/blocks/embed/component-info.js +47 -0
- package/{src/types/deep-partial.js → package/blocks/embed/embed.lite.d.ts} +0 -0
- package/package/blocks/embed/embed.lite.tsx +52 -0
- package/package/blocks/embed/embed.svelte +41 -0
- package/package/blocks/embed/embed.svelte.d.ts +19 -0
- package/package/blocks/embed/helpers.d.ts +1 -0
- package/package/blocks/embed/helpers.js +6 -0
- package/package/blocks/form/component-info.d.ts +2 -0
- package/package/blocks/form/component-info.js +268 -0
- package/{src/types/element.js → package/blocks/form/form.lite.d.ts} +0 -0
- package/package/blocks/form/form.lite.tsx +351 -0
- package/package/blocks/form/form.svelte +259 -0
- package/package/blocks/form/form.svelte.d.ts +70 -0
- package/package/blocks/fragment/component-info.d.ts +2 -0
- package/package/blocks/fragment/component-info.js +8 -0
- package/{src/types/targets.js → package/blocks/fragment/fragment.lite.d.ts} +0 -0
- package/package/blocks/fragment/fragment.lite.tsx +12 -0
- package/package/blocks/fragment/fragment.svelte +5 -0
- package/package/blocks/fragment/fragment.svelte.d.ts +21 -0
- package/package/blocks/image/component-info.d.ts +2 -0
- package/package/blocks/image/component-info.js +153 -0
- package/package/blocks/image/image.helpers.d.ts +1 -0
- package/package/blocks/image/image.helpers.js +56 -0
- package/{src/types/typescript.js → package/blocks/image/image.lite.d.ts} +0 -0
- package/package/blocks/image/image.lite.tsx +148 -0
- package/package/blocks/image/image.svelte +119 -0
- package/package/blocks/image/image.svelte.d.ts +48 -0
- package/package/blocks/img/component-info.d.ts +2 -0
- package/package/blocks/img/component-info.js +18 -0
- package/package/blocks/img/img.lite.d.ts +0 -0
- package/package/blocks/img/img.lite.tsx +48 -0
- package/package/blocks/img/img.svelte +26 -0
- package/package/blocks/img/img.svelte.d.ts +29 -0
- package/package/blocks/input/component-info.d.ts +2 -0
- package/package/blocks/input/component-info.js +72 -0
- package/package/blocks/input/input.lite.d.ts +0 -0
- package/package/blocks/input/input.lite.tsx +34 -0
- package/package/blocks/input/input.svelte +22 -0
- package/package/blocks/input/input.svelte.d.ts +31 -0
- package/package/blocks/raw-text/component-info.d.ts +2 -0
- package/package/blocks/raw-text/component-info.js +13 -0
- package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
- package/package/blocks/raw-text/raw-text.lite.tsx +15 -0
- package/package/blocks/raw-text/raw-text.svelte +9 -0
- package/package/blocks/raw-text/raw-text.svelte.d.ts +21 -0
- package/package/blocks/section/component-info.d.ts +2 -0
- package/package/blocks/section/component-info.js +46 -0
- package/package/blocks/section/section.lite.d.ts +0 -0
- package/package/blocks/section/section.lite.tsx +30 -0
- package/package/blocks/section/section.svelte +21 -0
- package/package/blocks/section/section.svelte.d.ts +25 -0
- package/package/blocks/select/component-info.d.ts +2 -0
- package/package/blocks/select/component-info.js +56 -0
- package/package/blocks/select/select.lite.d.ts +0 -0
- package/package/blocks/select/select.lite.tsx +34 -0
- package/package/blocks/select/select.svelte +21 -0
- package/package/blocks/select/select.svelte.d.ts +30 -0
- package/package/blocks/submit-button/component-info.d.ts +2 -0
- package/package/blocks/submit-button/component-info.js +29 -0
- package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
- package/package/blocks/submit-button/submit-button.lite.tsx +15 -0
- package/package/blocks/submit-button/submit-button.svelte +9 -0
- package/package/blocks/submit-button/submit-button.svelte.d.ts +21 -0
- package/package/blocks/symbol/component-info.d.ts +2 -0
- package/package/blocks/symbol/component-info.js +40 -0
- package/package/blocks/symbol/symbol.lite.d.ts +0 -0
- package/package/blocks/symbol/symbol.lite.tsx +92 -0
- package/package/blocks/symbol/symbol.svelte +66 -0
- package/package/blocks/symbol/symbol.svelte.d.ts +35 -0
- package/package/blocks/text/component-info.d.ts +2 -0
- package/package/blocks/text/component-info.js +21 -0
- package/package/blocks/text/text.lite.d.ts +0 -0
- package/package/blocks/text/text.lite.tsx +11 -0
- package/package/blocks/text/text.svelte +6 -0
- package/package/blocks/text/text.svelte.d.ts +19 -0
- package/package/blocks/textarea/component-info.d.ts +2 -0
- package/package/blocks/textarea/component-info.js +44 -0
- package/package/blocks/textarea/textarea.lite.d.ts +0 -0
- package/package/blocks/textarea/textarea.lite.tsx +19 -0
- package/package/blocks/textarea/textarea.svelte +10 -0
- package/package/blocks/textarea/textarea.svelte.d.ts +27 -0
- package/package/blocks/util.d.ts +1 -0
- package/package/blocks/util.js +4 -0
- package/package/blocks/video/component-info.d.ts +2 -0
- package/package/blocks/video/component-info.js +103 -0
- package/package/blocks/video/video.lite.d.ts +0 -0
- package/package/blocks/video/video.lite.tsx +92 -0
- package/package/blocks/video/video.svelte +63 -0
- package/package/blocks/video/video.svelte.d.ts +41 -0
- package/package/components/render-block/block-styles.lite.d.ts +0 -0
- package/package/components/render-block/block-styles.lite.tsx +60 -0
- package/package/components/render-block/block-styles.svelte +45 -0
- package/package/components/render-block/block-styles.svelte.d.ts +23 -0
- package/package/components/render-block/render-block.helpers.d.ts +1 -0
- package/package/components/render-block/render-block.helpers.js +24 -0
- package/package/components/render-block/render-block.lite.d.ts +0 -0
- package/package/components/render-block/render-block.lite.tsx +216 -0
- package/package/components/render-block/render-block.svelte +185 -0
- package/package/components/render-block/render-block.svelte.d.ts +23 -0
- package/package/components/render-block/render-component.lite.d.ts +0 -0
- package/package/components/render-block/render-component.lite.tsx +33 -0
- package/package/components/render-block/render-component.svelte +24 -0
- package/package/components/render-block/render-component.svelte.d.ts +27 -0
- package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
- package/package/components/render-block/render-repeated-block.lite.tsx +49 -0
- package/package/components/render-block/render-repeated-block.svelte +36 -0
- package/package/components/render-block/render-repeated-block.svelte.d.ts +23 -0
- package/package/components/render-block/types.d.ts +6 -0
- package/package/components/render-block/types.js +2 -0
- package/package/components/render-blocks.lite.d.ts +0 -0
- package/package/components/render-blocks.lite.tsx +91 -0
- package/package/components/render-blocks.svelte +73 -0
- package/package/components/render-blocks.svelte.d.ts +24 -0
- package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
- package/package/components/render-content/components/render-styles.lite.tsx +86 -0
- package/package/components/render-content/components/render-styles.svelte +61 -0
- package/package/components/render-content/components/render-styles.svelte.d.ts +29 -0
- package/package/components/render-content/index.d.ts +1 -0
- package/package/components/render-content/index.js +1 -0
- package/package/components/render-content/render-content.lite.d.ts +0 -0
- package/package/components/render-content/render-content.lite.tsx +356 -0
- package/package/components/render-content/render-content.svelte +260 -0
- package/package/components/render-content/render-content.svelte.d.ts +36 -0
- package/package/components/render-inlined-styles.lite.d.ts +0 -0
- package/package/components/render-inlined-styles.lite.tsx +27 -0
- package/package/components/render-inlined-styles.svelte +19 -0
- package/package/components/render-inlined-styles.svelte.d.ts +19 -0
- package/package/constants/builder-registered-components.d.ts +6 -0
- package/package/constants/builder-registered-components.js +36 -0
- package/package/constants/device-sizes.d.ts +2 -0
- package/package/constants/device-sizes.js +18 -0
- package/package/constants/target.d.ts +2 -0
- package/package/constants/target.js +2 -0
- package/package/context/builder.context.d.ts +11 -0
- package/package/context/builder.context.js +11 -0
- package/package/context/types.d.ts +16 -0
- package/package/context/types.js +3 -0
- package/package/functions/camel-to-kebab-case.d.ts +1 -0
- package/package/functions/camel-to-kebab-case.js +1 -0
- package/package/functions/convert-style-object.d.ts +1 -0
- package/package/functions/convert-style-object.js +3 -0
- package/package/functions/evaluate.d.ts +5 -0
- package/package/functions/evaluate.js +25 -0
- package/package/functions/event-handler-name.d.ts +1 -0
- package/package/functions/event-handler-name.js +4 -0
- package/package/functions/get-block-actions.d.ts +9 -0
- package/package/functions/get-block-actions.js +21 -0
- package/package/functions/get-block-component-options.d.ts +2 -0
- package/package/functions/get-block-component-options.js +11 -0
- package/package/functions/get-block-properties.d.ts +5 -0
- package/package/functions/get-block-properties.js +10 -0
- package/package/functions/get-block-styles.d.ts +2 -0
- package/package/functions/get-block-styles.js +21 -0
- package/package/functions/get-block-tag.d.ts +10 -0
- package/package/functions/get-block-tag.js +9 -0
- package/package/functions/get-builder-search-params/fn.test.d.ts +1 -0
- package/package/functions/get-builder-search-params/fn.test.js +13 -0
- package/package/functions/get-builder-search-params/index.d.ts +6 -0
- package/package/functions/get-builder-search-params/index.js +29 -0
- package/package/functions/get-content/ab-testing.d.ts +3 -0
- package/package/functions/get-content/ab-testing.js +40 -0
- package/package/functions/get-content/fn.test.d.ts +1 -0
- package/package/functions/get-content/fn.test.js +31 -0
- package/package/functions/get-content/index.d.ts +9 -0
- package/package/functions/get-content/index.js +42 -0
- package/package/functions/get-content/types.d.ts +26 -0
- package/package/functions/get-content/types.js +1 -0
- package/package/functions/get-fetch.d.ts +1 -0
- package/package/functions/get-fetch.js +9 -0
- package/package/functions/get-global-this.d.ts +1 -0
- package/package/functions/get-global-this.js +15 -0
- package/package/functions/get-processed-block.d.ts +10 -0
- package/package/functions/get-processed-block.js +29 -0
- package/package/functions/get-processed-block.test.d.ts +1 -0
- package/package/functions/get-processed-block.test.js +32 -0
- package/package/functions/if-target.d.ts +7 -0
- package/package/functions/if-target.js +10 -0
- package/package/functions/is-browser.d.ts +1 -0
- package/package/functions/is-browser.js +3 -0
- package/package/functions/is-editing.d.ts +1 -0
- package/package/functions/is-editing.js +4 -0
- package/package/functions/is-iframe.d.ts +1 -0
- package/package/functions/is-iframe.js +4 -0
- package/package/functions/is-previewing.d.ts +1 -0
- package/package/functions/is-previewing.js +11 -0
- package/package/functions/mark-mutable.d.ts +2 -0
- package/package/functions/mark-mutable.js +6 -0
- package/package/functions/on-change.d.ts +7 -0
- package/package/functions/on-change.js +28 -0
- package/package/functions/on-change.test.d.ts +1 -0
- package/package/functions/on-change.test.js +20 -0
- package/package/functions/register-component.d.ts +14 -0
- package/package/functions/register-component.js +42 -0
- package/package/functions/register.d.ts +16 -0
- package/package/functions/register.js +29 -0
- package/package/functions/sanitize-styles.d.ts +4 -0
- package/package/functions/sanitize-styles.js +6 -0
- package/package/functions/set-editor-settings.d.ts +4 -0
- package/package/functions/set-editor-settings.js +12 -0
- package/package/functions/set.d.ts +7 -0
- package/package/functions/set.js +21 -0
- package/package/functions/set.test.d.ts +1 -0
- package/package/functions/set.test.js +16 -0
- package/package/functions/track.d.ts +21 -0
- package/package/functions/track.js +49 -0
- package/package/functions/transform-block.d.ts +2 -0
- package/package/functions/transform-block.js +5 -0
- package/package/helpers/cookie.d.ts +9 -0
- package/package/helpers/cookie.js +55 -0
- package/package/helpers/css.d.ts +1 -0
- package/package/helpers/css.js +9 -0
- package/package/helpers/flatten.d.ts +6 -0
- package/package/helpers/flatten.js +19 -0
- package/package/helpers/localStorage.d.ts +9 -0
- package/package/helpers/localStorage.js +23 -0
- package/package/helpers/nullable.d.ts +2 -0
- package/package/helpers/nullable.js +1 -0
- package/package/helpers/sessionId.d.ts +7 -0
- package/package/helpers/sessionId.js +20 -0
- package/package/helpers/time.d.ts +1 -0
- package/package/helpers/time.js +2 -0
- package/package/helpers/url.d.ts +6 -0
- package/package/helpers/url.js +12 -0
- package/package/helpers/url.test.d.ts +1 -0
- package/package/helpers/url.test.js +15 -0
- package/package/helpers/uuid.d.ts +8 -0
- package/package/helpers/uuid.js +15 -0
- package/package/helpers/visitorId.d.ts +8 -0
- package/package/helpers/visitorId.js +26 -0
- package/package/index-helpers/blocks-exports.d.ts +10 -0
- package/package/index-helpers/blocks-exports.js +10 -0
- package/package/index-helpers/top-of-file.d.ts +1 -0
- package/package/index-helpers/top-of-file.js +4 -0
- package/package/index.d.ts +10 -0
- package/package/index.js +10 -0
- package/package/scripts/init-editing.d.ts +2 -0
- package/package/scripts/init-editing.js +84 -0
- package/package/types/builder-block.d.ts +57 -0
- package/package/types/builder-block.js +1 -0
- package/package/types/builder-content.d.ts +38 -0
- package/package/types/builder-content.js +1 -0
- package/package/types/can-track.d.ts +3 -0
- package/package/types/can-track.js +1 -0
- package/package/types/components.d.ts +177 -0
- package/package/types/components.js +1 -0
- package/package/types/deep-partial.d.ts +3 -0
- package/package/types/deep-partial.js +1 -0
- package/package/types/element.d.ts +59 -0
- package/package/types/element.js +1 -0
- package/package/types/targets.d.ts +3 -0
- package/package/types/targets.js +1 -0
- package/package/types/typescript.d.ts +4 -0
- package/package/types/typescript.js +1 -0
- package/package.json +31 -8
- package/src/blocks/button/button.svelte +0 -49
- package/src/blocks/button/component-info.js +0 -41
- package/src/blocks/columns/columns.svelte +0 -103
- package/src/blocks/columns/component-info.js +0 -217
- package/src/blocks/custom-code/component-info.js +0 -31
- package/src/blocks/custom-code/custom-code.svelte +0 -64
- package/src/blocks/embed/component-info.js +0 -24
- package/src/blocks/embed/embed.svelte +0 -63
- package/src/blocks/form/component-info.js +0 -262
- package/src/blocks/form/form.svelte +0 -333
- package/src/blocks/fragment/component-info.js +0 -11
- package/src/blocks/fragment/fragment.svelte +0 -28
- package/src/blocks/image/component-info.js +0 -104
- package/src/blocks/image/image.svelte +0 -117
- package/src/blocks/img/component-info.js +0 -20
- package/src/blocks/img/img.svelte +0 -36
- package/src/blocks/input/component-info.js +0 -74
- package/src/blocks/input/input.svelte +0 -35
- package/src/blocks/raw-text/component-info.js +0 -16
- package/src/blocks/raw-text/raw-text.svelte +0 -29
- package/src/blocks/section/component-info.js +0 -49
- package/src/blocks/section/section.svelte +0 -36
- package/src/blocks/select/component-info.js +0 -59
- package/src/blocks/select/select.svelte +0 -41
- package/src/blocks/submit-button/component-info.js +0 -28
- package/src/blocks/submit-button/submit-button.svelte +0 -33
- package/src/blocks/symbol/component-info.js +0 -42
- package/src/blocks/symbol/symbol.svelte +0 -54
- package/src/blocks/text/component-info.js +0 -24
- package/src/blocks/text/text.svelte +0 -28
- package/src/blocks/textarea/component-info.js +0 -47
- package/src/blocks/textarea/textarea.svelte +0 -32
- package/src/blocks/video/component-info.js +0 -106
- package/src/blocks/video/video.svelte +0 -45
- package/src/components/error-boundary.svelte +0 -26
- package/src/components/render-block/block-styles.svelte +0 -51
- package/src/components/render-block/render-block.helpers.js +0 -23
- package/src/components/render-block/render-block.svelte +0 -174
- package/src/components/render-blocks.svelte +0 -82
- package/src/components/render-content/components/render-styles.svelte +0 -90
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/render-content.svelte +0 -252
- package/src/components/render-inlined-styles.svelte +0 -51
- package/src/constants/builder-registered-components.js +0 -45
- package/src/constants/device-sizes.js +0 -39
- package/src/constants/target.js +0 -4
- package/src/context/builder.context.js +0 -8
- package/src/functions/evaluate.js +0 -28
- package/src/functions/event-handler-name.js +0 -7
- package/src/functions/fast-clone.js +0 -4
- package/src/functions/get-block-actions.js +0 -23
- package/src/functions/get-block-component-options.js +0 -23
- package/src/functions/get-block-properties.js +0 -29
- package/src/functions/get-block-styles.js +0 -31
- package/src/functions/get-block-tag.js +0 -6
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-builder-search-params/index.js +0 -22
- package/src/functions/get-content/fn.test.js +0 -31
- package/src/functions/get-content/index.js +0 -138
- package/src/functions/get-fetch.js +0 -34
- package/src/functions/get-global-this.js +0 -18
- package/src/functions/get-processed-block.js +0 -46
- package/src/functions/get-processed-block.test.js +0 -31
- package/src/functions/if-target.js +0 -15
- package/src/functions/is-browser.js +0 -6
- package/src/functions/is-editing.js +0 -7
- package/src/functions/is-iframe.js +0 -7
- package/src/functions/is-previewing.js +0 -14
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/on-change.js +0 -27
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/previewing-model-name.js +0 -11
- package/src/functions/register-component.js +0 -70
- package/src/functions/register.js +0 -29
- package/src/functions/set-editor-settings.js +0 -15
- package/src/functions/set.js +0 -11
- package/src/functions/set.test.js +0 -16
- package/src/functions/track.js +0 -22
- package/src/functions/transform-block.js +0 -6
- package/src/index-helpers/blocks-exports.js +0 -20
- package/src/index-helpers/top-of-file.js +0 -4
- package/src/index.js +0 -10
- package/src/scripts/init-editing.js +0 -80
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import '../types/builder-block.js';
|
|
2
|
+
import { getProcessedBlock } from './get-processed-block.js';
|
|
3
|
+
test('Can process bindings', () => {
|
|
4
|
+
const block = {
|
|
5
|
+
'@type': '@builder.io/sdk:Element',
|
|
6
|
+
properties: {
|
|
7
|
+
foo: 'bar',
|
|
8
|
+
},
|
|
9
|
+
bindings: {
|
|
10
|
+
'properties.foo': '"baz"',
|
|
11
|
+
'responsiveStyles.large.zIndex': '1 + 1',
|
|
12
|
+
'properties.test': 'state.test',
|
|
13
|
+
'properties.block': `
|
|
14
|
+
const foo = 'bar';
|
|
15
|
+
return foo;
|
|
16
|
+
`,
|
|
17
|
+
'properties.isEditing': 'builder.isEditing',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const processed = getProcessedBlock({
|
|
21
|
+
block,
|
|
22
|
+
context: {},
|
|
23
|
+
state: { test: 'hello' },
|
|
24
|
+
shouldEvaluateBindings: true,
|
|
25
|
+
});
|
|
26
|
+
expect(processed).not.toEqual(block);
|
|
27
|
+
expect(processed.properties?.foo).toEqual('baz');
|
|
28
|
+
expect(processed.properties?.test).toEqual('hello');
|
|
29
|
+
expect(processed.properties?.block).toEqual('bar');
|
|
30
|
+
expect(processed.properties?.isEditing).toEqual(false);
|
|
31
|
+
expect(processed.responsiveStyles?.large?.zIndex).toEqual(2);
|
|
32
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target.js';
|
|
2
|
+
// TODO: babel compile to include certain code only if the target matches
|
|
3
|
+
export function ifTarget({ targets, doThing, elseThing, }) {
|
|
4
|
+
if (TARGET && targets.includes(TARGET)) {
|
|
5
|
+
return doThing();
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return elseThing?.();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEditing(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isIframe(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isPreviewing(): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isBrowser } from './is-browser.js';
|
|
2
|
+
import { isEditing } from './is-editing.js';
|
|
3
|
+
export function isPreviewing() {
|
|
4
|
+
if (!isBrowser()) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (isEditing()) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return Boolean(location.search.indexOf('builder.preview=') !== -1);
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const onChangeProxySymbol = Symbol('onChangeProxySymbol');
|
|
2
|
+
/**
|
|
3
|
+
* Deeply observe an object and run a callback when it changes
|
|
4
|
+
*
|
|
5
|
+
* See ./on-change.test.ts for more info
|
|
6
|
+
*/
|
|
7
|
+
export function onChange(obj, cb) {
|
|
8
|
+
return new Proxy(obj, {
|
|
9
|
+
get(target, key) {
|
|
10
|
+
if (key === onChangeProxySymbol) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const value = Reflect.get(target, key);
|
|
14
|
+
if (value && typeof value === 'object') {
|
|
15
|
+
if (value[onChangeProxySymbol]) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return onChange(value, cb);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
},
|
|
22
|
+
set(target, key, value) {
|
|
23
|
+
const returnValue = Reflect.set(target, key, value);
|
|
24
|
+
cb();
|
|
25
|
+
return returnValue;
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { onChange } from './on-change.js';
|
|
2
|
+
test('onChange can observe a shallow change', () => {
|
|
3
|
+
let changeHappend = false;
|
|
4
|
+
const obj = onChange({ foo: 'hi' }, () => (changeHappend = true));
|
|
5
|
+
obj.foo = 'yo';
|
|
6
|
+
expect(changeHappend).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
test('onChange can observe a deep change', () => {
|
|
9
|
+
let changeHappend = false;
|
|
10
|
+
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
11
|
+
obj.foo.bar = 'yo';
|
|
12
|
+
expect(changeHappend).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
test('Smoke test: callback is not fired if no properties updated', () => {
|
|
15
|
+
let changeHappend = false;
|
|
16
|
+
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
17
|
+
// Access some properties
|
|
18
|
+
obj.foo.bar;
|
|
19
|
+
expect(changeHappend).toBe(false);
|
|
20
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RegisteredComponent } from '../context/types.js';
|
|
2
|
+
import type { ComponentInfo } from '../types/components.js';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
5
|
+
*/
|
|
6
|
+
export declare const components: RegisteredComponent[];
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerComponent(component: any, info: ComponentInfo): void;
|
|
11
|
+
export declare const createRegisterComponentMessage: ({ component, ...info }: RegisteredComponent) => {
|
|
12
|
+
type: string;
|
|
13
|
+
data: ComponentInfo;
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import '../context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
4
|
+
*/
|
|
5
|
+
export const components = [];
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
8
|
+
*/
|
|
9
|
+
export function registerComponent(component, info) {
|
|
10
|
+
components.push({ component, ...info });
|
|
11
|
+
console.warn('registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.');
|
|
12
|
+
return component;
|
|
13
|
+
}
|
|
14
|
+
export const createRegisterComponentMessage = ({ component: _, ...info }) => ({
|
|
15
|
+
type: 'builder.registerComponent',
|
|
16
|
+
data: prepareComponentInfoToSend(info),
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* We need to serialize values to a string in case there are Proxy values, as is the case with SolidJS etc.
|
|
20
|
+
*/
|
|
21
|
+
const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
22
|
+
const serializeValue = (value) => typeof value === 'function' ? serializeFn(value) : fastClone(value);
|
|
23
|
+
/**
|
|
24
|
+
* Input attributes that are functions must be converted to strings before being serialized to JSON.
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
27
|
+
const serializeFn = (fnValue) => {
|
|
28
|
+
const fnStr = fnValue.toString().trim();
|
|
29
|
+
// we need to account for a few different fn syntaxes:
|
|
30
|
+
// 1. `function name(args) => {code}`
|
|
31
|
+
// 2. `name(args) => {code}`
|
|
32
|
+
// 3. `(args) => {}`
|
|
33
|
+
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
34
|
+
return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
|
|
35
|
+
};
|
|
36
|
+
const prepareComponentInfoToSend = ({ inputs, ...info }) => ({
|
|
37
|
+
...fastClone(info),
|
|
38
|
+
inputs: inputs?.map((input) => Object.entries(input).reduce((acc, [key, value]) => ({
|
|
39
|
+
...acc,
|
|
40
|
+
[key]: serializeValue(value),
|
|
41
|
+
}), {})),
|
|
42
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BuilderBlock } from '../types/builder-block.js';
|
|
2
|
+
import { DeepPartial } from '../types/deep-partial.js';
|
|
3
|
+
export interface InsertMenuItem {
|
|
4
|
+
name: string;
|
|
5
|
+
icon?: string;
|
|
6
|
+
item: DeepPartial<BuilderBlock>;
|
|
7
|
+
}
|
|
8
|
+
export interface InsertMenuConfig {
|
|
9
|
+
name: string;
|
|
10
|
+
priority?: number;
|
|
11
|
+
persist?: boolean;
|
|
12
|
+
advanced?: boolean;
|
|
13
|
+
items: InsertMenuItem[];
|
|
14
|
+
}
|
|
15
|
+
export declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
|
|
16
|
+
export declare function register(type: string, info: any): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '../types/builder-block.js';
|
|
2
|
+
import '../types/deep-partial.js';
|
|
3
|
+
import { isBrowser } from './is-browser.js';
|
|
4
|
+
const registry = {};
|
|
5
|
+
export function register(type, info) {
|
|
6
|
+
let typeList = registry[type];
|
|
7
|
+
if (!typeList) {
|
|
8
|
+
typeList = registry[type] = [];
|
|
9
|
+
}
|
|
10
|
+
typeList.push(info);
|
|
11
|
+
if (isBrowser()) {
|
|
12
|
+
const message = {
|
|
13
|
+
type: 'builder.register',
|
|
14
|
+
data: {
|
|
15
|
+
type,
|
|
16
|
+
info,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
parent.postMessage(message, '*');
|
|
21
|
+
if (parent !== window) {
|
|
22
|
+
window.postMessage(message, '*');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.debug('Could not postmessage', err);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isBrowser } from './is-browser.js';
|
|
2
|
+
const settings = {};
|
|
3
|
+
export function setEditorSettings(newSettings) {
|
|
4
|
+
if (isBrowser()) {
|
|
5
|
+
Object.assign(settings, newSettings);
|
|
6
|
+
const message = {
|
|
7
|
+
type: 'builder.settingsChange',
|
|
8
|
+
data: settings,
|
|
9
|
+
};
|
|
10
|
+
parent.postMessage(message, '*');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal implementation of lodash's _.set
|
|
3
|
+
* https://lodash.com/docs/4.17.15#set
|
|
4
|
+
*
|
|
5
|
+
* See ./set.test.ts for usage examples
|
|
6
|
+
*/
|
|
7
|
+
export const set = (obj, _path, value) => {
|
|
8
|
+
if (Object(obj) !== obj) {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
const path = Array.isArray(_path)
|
|
12
|
+
? _path
|
|
13
|
+
: _path.toString().match(/[^.[\]]+/g);
|
|
14
|
+
path
|
|
15
|
+
.slice(0, -1)
|
|
16
|
+
.reduce((a, c, i) => Object(a[c]) === a[c]
|
|
17
|
+
? a[c]
|
|
18
|
+
: (a[c] =
|
|
19
|
+
Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}), obj)[path[path.length - 1]] = value;
|
|
20
|
+
return obj;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { set } from './set.js';
|
|
2
|
+
test('can shallow set a property', () => {
|
|
3
|
+
const obj = { foo: 'bar' };
|
|
4
|
+
set(obj, 'foo', 'baz');
|
|
5
|
+
expect(obj.foo).toBe('baz');
|
|
6
|
+
});
|
|
7
|
+
test('can deeply set a property', () => {
|
|
8
|
+
const obj = { foo: 'bar' };
|
|
9
|
+
set(obj, 'foo.bar', 'baz');
|
|
10
|
+
expect(obj.foo.bar).toBe('baz');
|
|
11
|
+
});
|
|
12
|
+
test('can deeply create arrays', () => {
|
|
13
|
+
const obj = { foo: 'bar' };
|
|
14
|
+
set(obj, 'foo.bar.0', 'hi');
|
|
15
|
+
expect(obj.foo.bar).toEqual(['hi']);
|
|
16
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CanTrack } from '../types/can-track.js';
|
|
2
|
+
interface Event {
|
|
3
|
+
type: 'click' | 'impression';
|
|
4
|
+
data: {
|
|
5
|
+
contentId?: string;
|
|
6
|
+
ownerId: string;
|
|
7
|
+
metadata?: string;
|
|
8
|
+
sessionId: string | undefined;
|
|
9
|
+
visitorId: string | undefined;
|
|
10
|
+
[index: string]: any;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare type EventProperties = {
|
|
14
|
+
type: Event['type'];
|
|
15
|
+
orgId: Event['data']['ownerId'];
|
|
16
|
+
contentId: Event['data']['contentId'];
|
|
17
|
+
[index: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export declare type EventProps = EventProperties & CanTrack;
|
|
20
|
+
export declare function track(eventProps: EventProps): Promise<void | Response>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target.js';
|
|
2
|
+
import { getSessionId } from '../helpers/sessionId.js';
|
|
3
|
+
import { getVisitorId } from '../helpers/visitorId.js';
|
|
4
|
+
import '../types/can-track.js';
|
|
5
|
+
import { isBrowser } from './is-browser.js';
|
|
6
|
+
import { isEditing } from './is-editing.js';
|
|
7
|
+
const getTrackingEventData = ({ canTrack }) => {
|
|
8
|
+
if (!canTrack) {
|
|
9
|
+
return { visitorId: undefined, sessionId: undefined };
|
|
10
|
+
}
|
|
11
|
+
const sessionId = getSessionId({ canTrack });
|
|
12
|
+
const visitorId = getVisitorId({ canTrack });
|
|
13
|
+
return {
|
|
14
|
+
sessionId,
|
|
15
|
+
visitorId,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const createEvent = ({ type: eventType, canTrack, orgId, contentId, ...properties }) => ({
|
|
19
|
+
type: eventType,
|
|
20
|
+
data: {
|
|
21
|
+
...properties,
|
|
22
|
+
...getTrackingEventData({ canTrack }),
|
|
23
|
+
ownerId: orgId,
|
|
24
|
+
contentId,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
export async function track(eventProps) {
|
|
28
|
+
if (!eventProps.canTrack) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (isEditing()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return fetch(`https://builder.io/api/v1/track`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
events: [createEvent(eventProps)],
|
|
41
|
+
}),
|
|
42
|
+
headers: {
|
|
43
|
+
'content-type': 'application/json',
|
|
44
|
+
},
|
|
45
|
+
mode: 'cors',
|
|
46
|
+
}).catch((err) => {
|
|
47
|
+
console.error('Failed to track: ', err);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CanTrack } from '../types/can-track.js';
|
|
2
|
+
export declare const getCookie: ({ name, canTrack, }: {
|
|
3
|
+
name: string;
|
|
4
|
+
} & CanTrack) => string | undefined;
|
|
5
|
+
export declare const setCookie: ({ name, value, expires, canTrack, }: {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
expires?: Date | undefined;
|
|
9
|
+
} & CanTrack) => undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import '../types/can-track.js';
|
|
3
|
+
import { getTopLevelDomain } from './url.js';
|
|
4
|
+
export const getCookie = ({ name, canTrack, }) => {
|
|
5
|
+
try {
|
|
6
|
+
if (!canTrack) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Extracted from MDN docs
|
|
11
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
|
|
12
|
+
*/
|
|
13
|
+
return document.cookie
|
|
14
|
+
.split('; ')
|
|
15
|
+
.find((row) => row.startsWith(`${name}=`))
|
|
16
|
+
?.split('=')[1];
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.debug('[COOKIE] GET error: ', err);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const stringifyCookie = (cookie) => cookie.map(([key, value]) => (value ? `${key}=${value}` : key)).join('; ');
|
|
23
|
+
const SECURE_CONFIG = [
|
|
24
|
+
['secure', ''],
|
|
25
|
+
['SameSite', 'None'],
|
|
26
|
+
];
|
|
27
|
+
const createCookieString = ({ name, value, expires, }) => {
|
|
28
|
+
const secure = isBrowser() ? location.protocol === 'https:' : true;
|
|
29
|
+
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
30
|
+
// TODO: need to know if secure server side
|
|
31
|
+
const expiresObj = expires
|
|
32
|
+
? [['expires', expires.toUTCString()]]
|
|
33
|
+
: [[]];
|
|
34
|
+
const cookieValue = [
|
|
35
|
+
[name, value],
|
|
36
|
+
...expiresObj,
|
|
37
|
+
['path', '/'],
|
|
38
|
+
['domain', getTopLevelDomain(window.location.hostname)],
|
|
39
|
+
...secureObj,
|
|
40
|
+
];
|
|
41
|
+
const cookie = stringifyCookie(cookieValue);
|
|
42
|
+
return cookie;
|
|
43
|
+
};
|
|
44
|
+
export const setCookie = ({ name, value, expires, canTrack, }) => {
|
|
45
|
+
try {
|
|
46
|
+
if (!canTrack) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const cookie = createCookieString({ name, value, expires });
|
|
50
|
+
document.cookie = cookie;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.warn('[COOKIE] SET error: ', err);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertStyleMaptoCSS: (style: Partial<CSSStyleDeclaration>) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
|
|
2
|
+
export const convertStyleMaptoCSS = (style) => {
|
|
3
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
|
+
if (typeof value === 'string') {
|
|
5
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return cssProps.join('\n');
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert deep object to a flat object with dots
|
|
3
|
+
*
|
|
4
|
+
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
5
|
+
*/
|
|
6
|
+
export function flatten(object, path = null, separator = '.') {
|
|
7
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
8
|
+
const value = object[key];
|
|
9
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
10
|
+
const isObject = [
|
|
11
|
+
typeof value === 'object',
|
|
12
|
+
value !== null,
|
|
13
|
+
!(Array.isArray(value) && value.length === 0),
|
|
14
|
+
].every(Boolean);
|
|
15
|
+
return isObject
|
|
16
|
+
? { ...acc, ...flatten(value, newPath, separator) }
|
|
17
|
+
: { ...acc, [newPath]: value };
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const getLocalStorageItem: ({ key, canTrack, }: {
|
|
2
|
+
key: string;
|
|
3
|
+
canTrack: boolean;
|
|
4
|
+
}) => string | null | undefined;
|
|
5
|
+
export declare const setLocalStorageItem: ({ key, canTrack, value, }: {
|
|
6
|
+
key: string;
|
|
7
|
+
value: string;
|
|
8
|
+
canTrack: boolean;
|
|
9
|
+
}) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
const getLocalStorage = () => isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
|
|
3
|
+
export const getLocalStorageItem = ({ key, canTrack, }) => {
|
|
4
|
+
try {
|
|
5
|
+
if (canTrack) {
|
|
6
|
+
return getLocalStorage()?.getItem(key);
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.debug('[LocalStorage] GET error: ', err);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const setLocalStorageItem = ({ key, canTrack, value, }) => {
|
|
15
|
+
try {
|
|
16
|
+
if (canTrack) {
|
|
17
|
+
getLocalStorage()?.setItem(key, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.debug('[LocalStorage] SET error: ', err);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanTrack } from '../types/can-track.js';
|
|
2
|
+
export declare const getSessionId: ({ canTrack }: CanTrack) => string | undefined;
|
|
3
|
+
export declare const createSessionId: () => string;
|
|
4
|
+
export declare const setSessionId: ({ id, canTrack, }: {
|
|
5
|
+
id: string;
|
|
6
|
+
canTrack: boolean;
|
|
7
|
+
}) => undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import '../types/can-track.js';
|
|
2
|
+
import { getCookie, setCookie } from './cookie.js';
|
|
3
|
+
import { checkIsDefined } from './nullable.js';
|
|
4
|
+
import { uuid } from './uuid.js';
|
|
5
|
+
const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
|
|
6
|
+
export const getSessionId = ({ canTrack }) => {
|
|
7
|
+
if (!canTrack) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
|
|
11
|
+
if (checkIsDefined(sessionId)) {
|
|
12
|
+
return sessionId;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const newSessionId = createSessionId();
|
|
16
|
+
setSessionId({ id: newSessionId, canTrack });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const createSessionId = () => uuid();
|
|
20
|
+
export const setSessionId = ({ id, canTrack, }) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCurrentDatePlusMinutes: (minutes?: number) => Date;
|