@builder.io/sdk-svelte 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/--package.json +3 -3
- package/package/blocks/button/button.svelte +35 -3
- package/package/blocks/columns/columns.svelte +1 -2
- package/package/blocks/columns/component-info.js +2 -2
- package/package/blocks/embed/component-info.js +2 -2
- package/package/blocks/form/form.svelte +29 -1
- package/package/blocks/image/component-info.js +2 -2
- package/package/blocks/img/img.svelte +29 -1
- package/package/blocks/input/input.svelte +29 -1
- package/package/blocks/section/section.svelte +30 -2
- package/package/blocks/select/select.svelte +29 -1
- package/package/blocks/submit-button/submit-button.svelte +33 -2
- package/package/blocks/symbol/symbol.svelte +33 -8
- package/package/blocks/textarea/textarea.svelte +36 -2
- package/package/blocks/util.d.ts +4 -1
- package/package/blocks/util.js +13 -4
- package/package/blocks/video/video.svelte +30 -2
- package/package/components/render-block/block-styles.svelte +5 -3
- package/package/components/render-block/render-block.svelte +36 -15
- package/package/components/render-block/render-component.svelte +1 -2
- package/package/components/render-content/builder-editing.svelte +4 -0
- package/package/components/render-content/builder-editing.svelte.d.ts +14 -0
- package/package/components/render-content/render-content.svelte +6 -5
- package/package/components/render-inlined-styles.svelte +3 -3
- package/package/constants/device-sizes.d.ts +12 -1
- package/package/constants/device-sizes.js +27 -1
- package/package/functions/evaluate.d.ts +2 -1
- package/package/functions/evaluate.js +8 -5
- package/package/functions/event-handler-name.js +1 -4
- package/package/functions/get-block-actions-handler.d.ts +5 -2
- package/package/functions/get-block-actions-handler.js +7 -8
- package/package/functions/get-block-actions.js +2 -2
- package/package/functions/get-builder-search-params/index.d.ts +1 -1
- package/package/functions/get-content/index.js +5 -2
- package/package/functions/get-content/types.d.ts +4 -0
- package/package/functions/register-component.js +1 -13
- package/package/functions/track.d.ts +6 -1
- package/package/functions/track.js +4 -0
- package/package/index.d.ts +3 -1
- package/package/index.js +1 -1
- package/package/scripts/init-editing.js +6 -0
- package/package/types/builder-content.d.ts +7 -0
- package/package.json +2 -2
- package/src/blocks/button/button.svelte +41 -2
- package/src/blocks/columns/columns.svelte +1 -2
- package/src/blocks/columns/component-info.ts +2 -2
- package/src/blocks/embed/component-info.ts +2 -2
- package/src/blocks/form/form.svelte +36 -1
- package/src/blocks/image/component-info.ts +2 -2
- package/src/blocks/img/img.svelte +36 -1
- package/src/blocks/input/input.svelte +36 -1
- package/src/blocks/section/section.svelte +36 -1
- package/src/blocks/select/select.svelte +36 -1
- package/src/blocks/submit-button/submit-button.svelte +39 -1
- package/src/blocks/symbol/symbol.svelte +40 -8
- package/src/blocks/textarea/textarea.svelte +42 -1
- package/src/blocks/util.ts +18 -6
- package/src/blocks/video/video.svelte +36 -1
- package/src/components/render-block/block-styles.svelte +16 -3
- package/src/components/render-block/render-block.svelte +41 -15
- package/src/components/render-block/render-component.svelte +1 -2
- package/src/components/render-content/builder-editing.svelte +4 -0
- package/src/components/render-content/render-content.svelte +8 -5
- package/src/components/render-inlined-styles.svelte +3 -3
- package/src/constants/device-sizes.ts +39 -2
- package/src/functions/evaluate.ts +11 -6
- package/src/functions/event-handler-name.ts +1 -6
- package/src/functions/get-block-actions-handler.ts +10 -9
- package/src/functions/get-block-actions.ts +2 -2
- package/src/functions/get-builder-search-params/index.ts +1 -1
- package/src/functions/get-content/index.ts +6 -1
- package/src/functions/get-content/types.ts +5 -0
- package/src/functions/register-component.ts +1 -18
- package/src/functions/track.ts +13 -1
- package/src/index.ts +3 -1
- package/src/scripts/init-editing.ts +6 -0
- package/src/types/builder-content.ts +7 -0
- package/package/functions/mark-mutable.d.ts +0 -2
- package/package/functions/mark-mutable.js +0 -6
- package/src/functions/mark-mutable.ts +0 -7
package/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.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "./package/index.js",
|
|
17
17
|
"module": "./package/index.js",
|
|
18
|
-
"svelte": "./
|
|
18
|
+
"svelte": "./package/index.js",
|
|
19
19
|
"exports": {
|
|
20
20
|
"./package.json": "./package.json",
|
|
21
21
|
"./src": {
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"./components/render-block/render-repeated-block.svelte": "./components/render-block/render-repeated-block.svelte",
|
|
73
73
|
"./components/render-block/types": "./components/render-block/types.js",
|
|
74
74
|
"./components/render-blocks.svelte": "./components/render-blocks.svelte",
|
|
75
|
+
"./components/render-content/builder-editing.svelte": "./components/render-content/builder-editing.svelte",
|
|
75
76
|
"./components/render-content/components/render-styles.svelte": "./components/render-content/components/render-styles.svelte",
|
|
76
77
|
"./components/render-content": "./components/render-content/index.js",
|
|
77
78
|
"./components/render-content/render-content.svelte": "./components/render-content/render-content.svelte",
|
|
@@ -107,7 +108,6 @@
|
|
|
107
108
|
"./functions/is-editing": "./functions/is-editing.js",
|
|
108
109
|
"./functions/is-iframe": "./functions/is-iframe.js",
|
|
109
110
|
"./functions/is-previewing": "./functions/is-previewing.js",
|
|
110
|
-
"./functions/mark-mutable": "./functions/mark-mutable.js",
|
|
111
111
|
"./functions/on-change.test": "./functions/on-change.test.js",
|
|
112
112
|
"./functions/on-change": "./functions/on-change.js",
|
|
113
113
|
"./functions/register-component": "./functions/register-component.js",
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>
|
|
3
|
+
<script>const isEvent = (attr) => attr.startsWith("on:");
|
|
4
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
5
|
+
const filterAttrs = (attrs, filter) => {
|
|
6
|
+
const validAttr = {};
|
|
7
|
+
Object.keys(attrs).forEach((attr) => {
|
|
8
|
+
if (filter(attr)) {
|
|
9
|
+
validAttr[attr] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return validAttr;
|
|
13
|
+
};
|
|
14
|
+
const setAttrs = (node, attrs) => {
|
|
15
|
+
const attrKeys = Object.keys(attrs);
|
|
16
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
17
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
attrKeys.map(setup);
|
|
19
|
+
return {
|
|
20
|
+
update(attrs) {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
attrKeys.map(teardown);
|
|
23
|
+
attrKeys.map(setup);
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export let attributes;
|
|
4
31
|
export let text;
|
|
5
32
|
export let link;
|
|
6
33
|
export let openLinkInNewTab;
|
|
@@ -8,15 +35,20 @@ export let openLinkInNewTab;
|
|
|
8
35
|
|
|
9
36
|
{#if link}
|
|
10
37
|
<a
|
|
11
|
-
{...attributes}
|
|
12
38
|
role="button"
|
|
39
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
13
40
|
href={link}
|
|
14
41
|
target={openLinkInNewTab ? "_blank" : undefined}
|
|
42
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
15
43
|
>
|
|
16
44
|
{text}
|
|
17
45
|
</a>
|
|
18
46
|
{:else}
|
|
19
|
-
<button
|
|
47
|
+
<button
|
|
48
|
+
class="button"
|
|
49
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
50
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
51
|
+
>
|
|
20
52
|
{text}
|
|
21
53
|
</button>
|
|
22
54
|
{/if}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import RenderBlocks from "../../components/render-blocks.svelte";
|
|
4
|
-
import { markMutable } from "../../functions/mark-mutable";
|
|
5
4
|
export let space;
|
|
6
5
|
export let columns;
|
|
7
6
|
export let stackColumnsAt;
|
|
@@ -71,7 +70,7 @@ $: columnCssVars = () => {
|
|
|
71
70
|
class="builder-column div-2"
|
|
72
71
|
>
|
|
73
72
|
<RenderBlocks
|
|
74
|
-
blocks={
|
|
73
|
+
blocks={column.blocks}
|
|
75
74
|
path={`component.options.columns.${index}.blocks`}
|
|
76
75
|
parent={builderBlock.id}
|
|
77
76
|
styleProp={{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { serializeFn } from '../util.js';
|
|
2
2
|
export const componentInfo = {
|
|
3
3
|
// TODO: ways to statically preprocess JSON for references, functions, etc
|
|
4
4
|
name: 'Columns',
|
|
@@ -188,7 +188,7 @@ export const componentInfo = {
|
|
|
188
188
|
],
|
|
189
189
|
},
|
|
190
190
|
],
|
|
191
|
-
onChange:
|
|
191
|
+
onChange: serializeFn((options) => {
|
|
192
192
|
function clearWidths() {
|
|
193
193
|
columns.forEach((col) => {
|
|
194
194
|
col.delete('width');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { serializeFn } from '../util.js';
|
|
2
2
|
export const componentInfo = {
|
|
3
3
|
name: 'Embed',
|
|
4
4
|
static: true,
|
|
@@ -10,7 +10,7 @@ export const componentInfo = {
|
|
|
10
10
|
required: true,
|
|
11
11
|
defaultValue: '',
|
|
12
12
|
helperText: 'e.g. enter a youtube url, google map, etc',
|
|
13
|
-
onChange:
|
|
13
|
+
onChange: serializeFn((options) => {
|
|
14
14
|
const url = options.get('url');
|
|
15
15
|
if (url) {
|
|
16
16
|
options.set('content', 'Loading...');
|
|
@@ -6,6 +6,33 @@
|
|
|
6
6
|
import RenderBlock from "../../components/render-block/render-block.svelte";
|
|
7
7
|
import BuilderBlocks from "../../components/render-blocks.svelte";
|
|
8
8
|
import { isEditing } from "../../functions/is-editing.js";
|
|
9
|
+
const isEvent = (attr) => attr.startsWith("on:");
|
|
10
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
11
|
+
const filterAttrs = (attrs, filter) => {
|
|
12
|
+
const validAttr = {};
|
|
13
|
+
Object.keys(attrs).forEach((attr) => {
|
|
14
|
+
if (filter(attr)) {
|
|
15
|
+
validAttr[attr] = attrs[attr];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return validAttr;
|
|
19
|
+
};
|
|
20
|
+
const setAttrs = (node, attrs) => {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
23
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
24
|
+
attrKeys.map(setup);
|
|
25
|
+
return {
|
|
26
|
+
update(attrs) {
|
|
27
|
+
const attrKeys = Object.keys(attrs);
|
|
28
|
+
attrKeys.map(teardown);
|
|
29
|
+
attrKeys.map(setup);
|
|
30
|
+
},
|
|
31
|
+
destroy() {
|
|
32
|
+
attrKeys.map(teardown);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
9
36
|
export let previewState;
|
|
10
37
|
export let sendWithJs;
|
|
11
38
|
export let sendSubmissionsTo;
|
|
@@ -217,7 +244,6 @@ let formErrorMessage = "";
|
|
|
217
244
|
</script>
|
|
218
245
|
|
|
219
246
|
<form
|
|
220
|
-
{...attributes}
|
|
221
247
|
{validate}
|
|
222
248
|
bind:this={formRef}
|
|
223
249
|
action={!sendWithJs && action}
|
|
@@ -226,6 +252,8 @@ let formErrorMessage = "";
|
|
|
226
252
|
on:submit={(event) => {
|
|
227
253
|
onSubmit(event);
|
|
228
254
|
}}
|
|
255
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
256
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
229
257
|
>
|
|
230
258
|
{#if builderBlock && builderBlock.children}
|
|
231
259
|
{#each builderBlock?.children as block}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { serializeFn } from '../util.js';
|
|
2
2
|
export const componentInfo = {
|
|
3
3
|
name: 'Image',
|
|
4
4
|
static: true,
|
|
@@ -19,7 +19,7 @@ export const componentInfo = {
|
|
|
19
19
|
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg'],
|
|
20
20
|
required: true,
|
|
21
21
|
defaultValue: 'https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
|
|
22
|
-
onChange:
|
|
22
|
+
onChange: serializeFn((options) => {
|
|
23
23
|
const DEFAULT_ASPECT_RATIO = 0.7041;
|
|
24
24
|
options.delete('srcset');
|
|
25
25
|
options.delete('noWebp');
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { isEditing } from "../../functions/is-editing.js";
|
|
4
|
+
const isEvent = (attr) => attr.startsWith("on:");
|
|
5
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
6
|
+
const filterAttrs = (attrs, filter) => {
|
|
7
|
+
const validAttr = {};
|
|
8
|
+
Object.keys(attrs).forEach((attr) => {
|
|
9
|
+
if (filter(attr)) {
|
|
10
|
+
validAttr[attr] = attrs[attr];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return validAttr;
|
|
14
|
+
};
|
|
15
|
+
const setAttrs = (node, attrs) => {
|
|
16
|
+
const attrKeys = Object.keys(attrs);
|
|
17
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
19
|
+
attrKeys.map(setup);
|
|
20
|
+
return {
|
|
21
|
+
update(attrs) {
|
|
22
|
+
const attrKeys = Object.keys(attrs);
|
|
23
|
+
attrKeys.map(teardown);
|
|
24
|
+
attrKeys.map(setup);
|
|
25
|
+
},
|
|
26
|
+
destroy() {
|
|
27
|
+
attrKeys.map(teardown);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
4
31
|
export let backgroundSize;
|
|
5
32
|
export let backgroundPosition;
|
|
6
33
|
export let imgSrc;
|
|
@@ -20,7 +47,6 @@ function mitosis_styling(node, vars) {
|
|
|
20
47
|
</script>
|
|
21
48
|
|
|
22
49
|
<img
|
|
23
|
-
{...attributes}
|
|
24
50
|
use:mitosis_styling={{
|
|
25
51
|
objectFit: backgroundSize || "cover",
|
|
26
52
|
objectPosition: backgroundPosition || "center",
|
|
@@ -28,4 +54,6 @@ function mitosis_styling(node, vars) {
|
|
|
28
54
|
key={(isEditing() && imgSrc) || "default-key"}
|
|
29
55
|
alt={altText}
|
|
30
56
|
src={imgSrc || image}
|
|
57
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
58
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
31
59
|
/>
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { isEditing } from "../../functions/is-editing.js";
|
|
4
|
+
const isEvent = (attr) => attr.startsWith("on:");
|
|
5
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
6
|
+
const filterAttrs = (attrs, filter) => {
|
|
7
|
+
const validAttr = {};
|
|
8
|
+
Object.keys(attrs).forEach((attr) => {
|
|
9
|
+
if (filter(attr)) {
|
|
10
|
+
validAttr[attr] = attrs[attr];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return validAttr;
|
|
14
|
+
};
|
|
15
|
+
const setAttrs = (node, attrs) => {
|
|
16
|
+
const attrKeys = Object.keys(attrs);
|
|
17
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
19
|
+
attrKeys.map(setup);
|
|
20
|
+
return {
|
|
21
|
+
update(attrs) {
|
|
22
|
+
const attrKeys = Object.keys(attrs);
|
|
23
|
+
attrKeys.map(teardown);
|
|
24
|
+
attrKeys.map(setup);
|
|
25
|
+
},
|
|
26
|
+
destroy() {
|
|
27
|
+
attrKeys.map(teardown);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
4
31
|
export let attributes;
|
|
5
32
|
export let defaultValue;
|
|
6
33
|
export let placeholder;
|
|
@@ -11,7 +38,7 @@ export let required;
|
|
|
11
38
|
</script>
|
|
12
39
|
|
|
13
40
|
<input
|
|
14
|
-
{...attributes}
|
|
41
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
15
42
|
key={isEditing() && defaultValue ? defaultValue : "default-key"}
|
|
16
43
|
{placeholder}
|
|
17
44
|
{type}
|
|
@@ -19,4 +46,5 @@ export let required;
|
|
|
19
46
|
{value}
|
|
20
47
|
{defaultValue}
|
|
21
48
|
{required}
|
|
49
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
22
50
|
/>
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>
|
|
3
|
+
<script>const isEvent = (attr) => attr.startsWith("on:");
|
|
4
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
5
|
+
const filterAttrs = (attrs, filter) => {
|
|
6
|
+
const validAttr = {};
|
|
7
|
+
Object.keys(attrs).forEach((attr) => {
|
|
8
|
+
if (filter(attr)) {
|
|
9
|
+
validAttr[attr] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return validAttr;
|
|
13
|
+
};
|
|
14
|
+
const setAttrs = (node, attrs) => {
|
|
15
|
+
const attrKeys = Object.keys(attrs);
|
|
16
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
17
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
attrKeys.map(setup);
|
|
19
|
+
return {
|
|
20
|
+
update(attrs) {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
attrKeys.map(teardown);
|
|
23
|
+
attrKeys.map(setup);
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export let attributes;
|
|
4
31
|
export let maxWidth;
|
|
5
32
|
function mitosis_styling(node, vars) {
|
|
6
33
|
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
@@ -15,12 +42,13 @@ function mitosis_styling(node, vars) {
|
|
|
15
42
|
</script>
|
|
16
43
|
|
|
17
44
|
<section
|
|
18
|
-
{...attributes}
|
|
19
45
|
use:mitosis_styling={maxWidth && typeof maxWidth === "number"
|
|
20
46
|
? {
|
|
21
47
|
maxWidth: maxWidth,
|
|
22
48
|
}
|
|
23
49
|
: undefined}
|
|
50
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
51
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
24
52
|
>
|
|
25
53
|
<slot />
|
|
26
54
|
</section>
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { isEditing } from "../../functions/is-editing.js";
|
|
4
|
+
const isEvent = (attr) => attr.startsWith("on:");
|
|
5
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
6
|
+
const filterAttrs = (attrs, filter) => {
|
|
7
|
+
const validAttr = {};
|
|
8
|
+
Object.keys(attrs).forEach((attr) => {
|
|
9
|
+
if (filter(attr)) {
|
|
10
|
+
validAttr[attr] = attrs[attr];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return validAttr;
|
|
14
|
+
};
|
|
15
|
+
const setAttrs = (node, attrs) => {
|
|
16
|
+
const attrKeys = Object.keys(attrs);
|
|
17
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
19
|
+
attrKeys.map(setup);
|
|
20
|
+
return {
|
|
21
|
+
update(attrs) {
|
|
22
|
+
const attrKeys = Object.keys(attrs);
|
|
23
|
+
attrKeys.map(teardown);
|
|
24
|
+
attrKeys.map(setup);
|
|
25
|
+
},
|
|
26
|
+
destroy() {
|
|
27
|
+
attrKeys.map(teardown);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
4
31
|
export let attributes;
|
|
5
32
|
export let value;
|
|
6
33
|
export let defaultValue;
|
|
@@ -9,11 +36,12 @@ export let options;
|
|
|
9
36
|
</script>
|
|
10
37
|
|
|
11
38
|
<select
|
|
12
|
-
{...attributes}
|
|
39
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
13
40
|
{value}
|
|
14
41
|
key={isEditing() && defaultValue ? defaultValue : "default-key"}
|
|
15
42
|
{defaultValue}
|
|
16
43
|
{name}
|
|
44
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
17
45
|
>
|
|
18
46
|
{#each options as option}
|
|
19
47
|
<option value={option.value}>{option.name || option.value}</option>
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>
|
|
3
|
+
<script>const isEvent = (attr) => attr.startsWith("on:");
|
|
4
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
5
|
+
const filterAttrs = (attrs, filter) => {
|
|
6
|
+
const validAttr = {};
|
|
7
|
+
Object.keys(attrs).forEach((attr) => {
|
|
8
|
+
if (filter(attr)) {
|
|
9
|
+
validAttr[attr] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return validAttr;
|
|
13
|
+
};
|
|
14
|
+
const setAttrs = (node, attrs) => {
|
|
15
|
+
const attrKeys = Object.keys(attrs);
|
|
16
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
17
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
attrKeys.map(setup);
|
|
19
|
+
return {
|
|
20
|
+
update(attrs) {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
attrKeys.map(teardown);
|
|
23
|
+
attrKeys.map(setup);
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export let attributes;
|
|
4
31
|
export let text;
|
|
5
32
|
</script>
|
|
6
33
|
|
|
7
|
-
<button
|
|
34
|
+
<button
|
|
35
|
+
type="submit"
|
|
36
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
37
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
38
|
+
>
|
|
8
39
|
{text}
|
|
9
40
|
</button>
|
|
@@ -4,7 +4,33 @@
|
|
|
4
4
|
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
5
5
|
import BuilderContext from "../../context/builder.context.js";
|
|
6
6
|
import { getContent } from "../../functions/get-content/index.js";
|
|
7
|
-
|
|
7
|
+
const isEvent = (attr) => attr.startsWith("on:");
|
|
8
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
9
|
+
const filterAttrs = (attrs, filter) => {
|
|
10
|
+
const validAttr = {};
|
|
11
|
+
Object.keys(attrs).forEach((attr) => {
|
|
12
|
+
if (filter(attr)) {
|
|
13
|
+
validAttr[attr] = attrs[attr];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return validAttr;
|
|
17
|
+
};
|
|
18
|
+
const setAttrs = (node, attrs) => {
|
|
19
|
+
const attrKeys = Object.keys(attrs);
|
|
20
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
21
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
22
|
+
attrKeys.map(setup);
|
|
23
|
+
return {
|
|
24
|
+
update(attrs) {
|
|
25
|
+
const attrKeys = Object.keys(attrs);
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
attrKeys.map(setup);
|
|
28
|
+
},
|
|
29
|
+
destroy() {
|
|
30
|
+
attrKeys.map(teardown);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
8
34
|
export let symbol;
|
|
9
35
|
export let attributes;
|
|
10
36
|
let builderContext = getContext(BuilderContext.key);
|
|
@@ -43,24 +69,23 @@ $: onUpdateFn_0(...[symbol, fetchedContent]);
|
|
|
43
69
|
</script>
|
|
44
70
|
|
|
45
71
|
<div
|
|
46
|
-
{...attributes}
|
|
72
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
47
73
|
dataSet={{
|
|
48
74
|
class: className,
|
|
49
75
|
}}
|
|
50
76
|
class={className}
|
|
77
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
51
78
|
>
|
|
52
79
|
<RenderContent
|
|
53
80
|
apiKey={builderContext.apiKey}
|
|
54
81
|
context={builderContext.context}
|
|
55
|
-
customComponents={
|
|
56
|
-
|
|
57
|
-
)}
|
|
58
|
-
data={markMutable({
|
|
82
|
+
customComponents={Object.values(builderContext.registeredComponents)}
|
|
83
|
+
data={{
|
|
59
84
|
...symbol?.data,
|
|
60
85
|
...builderContext.state,
|
|
61
86
|
...symbol?.content?.data?.state,
|
|
62
|
-
}
|
|
87
|
+
}}
|
|
63
88
|
model={symbol?.model}
|
|
64
|
-
content={
|
|
89
|
+
content={contentToUse()}
|
|
65
90
|
/>
|
|
66
91
|
</div>
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>
|
|
3
|
+
<script>const isEvent = (attr) => attr.startsWith("on:");
|
|
4
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
5
|
+
const filterAttrs = (attrs, filter) => {
|
|
6
|
+
const validAttr = {};
|
|
7
|
+
Object.keys(attrs).forEach((attr) => {
|
|
8
|
+
if (filter(attr)) {
|
|
9
|
+
validAttr[attr] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return validAttr;
|
|
13
|
+
};
|
|
14
|
+
const setAttrs = (node, attrs) => {
|
|
15
|
+
const attrKeys = Object.keys(attrs);
|
|
16
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
17
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
attrKeys.map(setup);
|
|
19
|
+
return {
|
|
20
|
+
update(attrs) {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
attrKeys.map(teardown);
|
|
23
|
+
attrKeys.map(setup);
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export let attributes;
|
|
4
31
|
export let placeholder;
|
|
5
32
|
export let name;
|
|
6
33
|
export let value;
|
|
7
34
|
export let defaultValue;
|
|
8
35
|
</script>
|
|
9
36
|
|
|
10
|
-
<textarea
|
|
37
|
+
<textarea
|
|
38
|
+
{...filterAttrs(attributes, isNonEvent)}
|
|
39
|
+
{placeholder}
|
|
40
|
+
{name}
|
|
41
|
+
{value}
|
|
42
|
+
{defaultValue}
|
|
43
|
+
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
44
|
+
/>
|
package/package/blocks/util.d.ts
CHANGED
package/package/blocks/util.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Input attributes that are functions must be converted to strings before being serialized to JSON.
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
+
export const serializeFn = (fnValue) => {
|
|
6
|
+
const fnStr = fnValue.toString().trim();
|
|
7
|
+
// we need to account for a few different fn syntaxes:
|
|
8
|
+
// 1. `function name(args) => {code}`
|
|
9
|
+
// 2. `name(args) => {code}`
|
|
10
|
+
// 3. `(args) => {}`
|
|
11
|
+
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
12
|
+
return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
|
|
13
|
+
};
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>
|
|
3
|
+
<script>const isEvent = (attr) => attr.startsWith("on:");
|
|
4
|
+
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
5
|
+
const filterAttrs = (attrs, filter) => {
|
|
6
|
+
const validAttr = {};
|
|
7
|
+
Object.keys(attrs).forEach((attr) => {
|
|
8
|
+
if (filter(attr)) {
|
|
9
|
+
validAttr[attr] = attrs[attr];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return validAttr;
|
|
13
|
+
};
|
|
14
|
+
const setAttrs = (node, attrs) => {
|
|
15
|
+
const attrKeys = Object.keys(attrs);
|
|
16
|
+
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
17
|
+
const teardown = (attr) => node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
18
|
+
attrKeys.map(setup);
|
|
19
|
+
return {
|
|
20
|
+
update(attrs) {
|
|
21
|
+
const attrKeys = Object.keys(attrs);
|
|
22
|
+
attrKeys.map(teardown);
|
|
23
|
+
attrKeys.map(setup);
|
|
24
|
+
},
|
|
25
|
+
destroy() {
|
|
26
|
+
attrKeys.map(teardown);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export let autoPlay;
|
|
4
31
|
export let muted;
|
|
5
32
|
export let controls;
|
|
6
33
|
export let loop;
|
|
@@ -58,7 +85,6 @@ $: spreadProps = () => {
|
|
|
58
85
|
</script>
|
|
59
86
|
|
|
60
87
|
<video
|
|
61
|
-
{...spreadProps()}
|
|
62
88
|
use:mitosis_styling={{
|
|
63
89
|
width: "100%",
|
|
64
90
|
height: "100%",
|
|
@@ -69,6 +95,8 @@ $: spreadProps = () => {
|
|
|
69
95
|
// not have the video overflow
|
|
70
96
|
borderRadius: 1,
|
|
71
97
|
}}
|
|
98
|
+
{...filterAttrs(spreadProps(), isNonEvent)}
|
|
72
99
|
src={video || "no-src"}
|
|
73
100
|
poster={posterImage}
|
|
101
|
+
use:setAttrs={filterAttrs(spreadProps(), isEvent)}
|
|
74
102
|
/>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
3
|
+
<script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../constants/device-sizes.js";
|
|
4
4
|
import { TARGET } from "../../constants/target.js";
|
|
5
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
6
6
|
import { createCssClass } from "../../helpers/css.js";
|
|
@@ -17,6 +17,8 @@ $: useBlock = () => {
|
|
|
17
17
|
};
|
|
18
18
|
$: css = () => {
|
|
19
19
|
const styles = useBlock().responsiveStyles;
|
|
20
|
+
const content = context.content;
|
|
21
|
+
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
|
|
20
22
|
const largeStyles = styles?.large;
|
|
21
23
|
const mediumStyles = styles?.medium;
|
|
22
24
|
const smallStyles = styles?.small;
|
|
@@ -31,14 +33,14 @@ $: css = () => {
|
|
|
31
33
|
? createCssClass({
|
|
32
34
|
className,
|
|
33
35
|
styles: mediumStyles,
|
|
34
|
-
mediaQuery: getMaxWidthQueryForSize("medium"),
|
|
36
|
+
mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints),
|
|
35
37
|
})
|
|
36
38
|
: "";
|
|
37
39
|
const smallStylesClass = smallStyles
|
|
38
40
|
? createCssClass({
|
|
39
41
|
className,
|
|
40
42
|
styles: smallStyles,
|
|
41
|
-
mediaQuery: getMaxWidthQueryForSize("small"),
|
|
43
|
+
mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
|
|
42
44
|
})
|
|
43
45
|
: "";
|
|
44
46
|
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|