@builder.io/sdk-svelte 0.0.1-15 → 0.0.1-18

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.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.1-15",
4
+ "version": "0.0.1-18",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src"
8
8
  ],
9
+ "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/BuilderIO/builder.git",
13
+ "directory": "packages/sdks/output/svelte"
14
+ },
9
15
  "main": "./src/index.js",
10
16
  "module": "./src/index.js",
11
17
  "svelte": "./src/index.js",
@@ -39,10 +39,10 @@ export let builderBlock;
39
39
 
40
40
  <picture >
41
41
 
42
- <img loading="lazy" class="img" alt={altText} role={altText ? 'presentation' : undefined} style={{
42
+ <img loading="lazy" alt={altText} role={altText ? 'presentation' : undefined} style={{
43
43
  objectPosition: backgroundSize || 'center',
44
44
  objectFit: backgroundSize || 'cover'
45
- }} class={'builder-image' + (className ? ' ' + className : '')} src={image} srcset={srcset} sizes={sizes} />
45
+ }} class={'builder-image' + (className ? ' ' + className : '') + 'img'} src={image} srcset={srcset} sizes={sizes} />
46
46
 
47
47
 
48
48
  <source srcset={srcset} />
@@ -52,13 +52,13 @@ objectFit: backgroundSize || 'cover'
52
52
 
53
53
 
54
54
  {#if aspectRatio && !(fitContent && builderBlock?.children?.length) }
55
+
56
+
55
57
  <div class="builder-image-sizer div-2" style={{
56
58
  paddingTop: aspectRatio * 100 + '%'
57
- }} >
58
-
59
- {' '}
59
+ }} ></div>
60
60
 
61
- </div>
61
+
62
62
 
63
63
 
64
64
  {/if}
@@ -7,6 +7,8 @@
7
7
  import BuilderContext from '../../context/builder.context';
8
8
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
9
9
  import RenderInlinedStyles from '../render-inlined-styles.svelte';
10
+ import { convertStyleMaptoCSS } from '../../helpers/css.js';
11
+ import { getMaxWidthQueryForSize } from '../../constants/device-sizes.js';
10
12
 
11
13
 
12
14
 
@@ -15,9 +17,7 @@ import RenderInlinedStyles from '../render-inlined-styles.svelte';
15
17
 
16
18
  export let block;
17
19
 
18
- function camelToKebabCase(string) {
19
- return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
20
- }
20
+
21
21
  $: useBlock = () => {
22
22
  return getProcessedBlock({
23
23
  block: block,
@@ -27,25 +27,19 @@ return getProcessedBlock({
27
27
  };
28
28
 
29
29
  $: css = () => {
30
- // TODO: media queries
31
- const styleObject = useBlock().responsiveStyles?.large;
32
-
33
- if (!styleObject) {
34
- return '';
35
- }
36
-
37
- let str = `.${useBlock().id} {`;
38
-
39
- for (const key in styleObject) {
40
- const value = styleObject[key];
41
-
42
- if (typeof value === 'string') {
43
- str += `${camelToKebabCase(key)}: ${value};`;
44
- }
45
- }
46
-
47
- str += '}';
48
- return str;
30
+ const styles = useBlock().responsiveStyles;
31
+ const largeStyles = styles?.large;
32
+ const mediumStyles = styles?.medium;
33
+ const smallStyles = styles?.small;
34
+ return `
35
+ ${largeStyles ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}` : ''}
36
+ ${mediumStyles ? `${getMaxWidthQueryForSize('medium')} {
37
+ .${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
38
+ }` : ''}
39
+ ${smallStyles ? `${getMaxWidthQueryForSize('small')} {
40
+ .${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
41
+ }` : ''}
42
+ }`;
49
43
  };
50
44
 
51
45
  let builderContext = getContext(BuilderContext.key);
@@ -60,7 +54,7 @@ return str;
60
54
  </script>
61
55
 
62
56
 
63
- {#if TARGET === 'vue' || TARGET === 'svelte' }
57
+ {#if TARGET === 'vue2' || TARGET === 'vue3' || TARGET === 'svelte' }
64
58
 
65
59
 
66
60
  <RenderInlinedStyles styles={css()} ></RenderInlinedStyles>
@@ -54,7 +54,7 @@ return 'builder-blocks' + (!blocks?.length ? ' no-blocks' : '');
54
54
 
55
55
  </script>
56
56
 
57
- <div class="div" class={className()} builder-path={path} builder-parent-id={parent} dataSet={{
57
+ <div class={className() + 'div'} builder-path={path} builder-parent-id={parent} dataSet={{
58
58
  class: className()
59
59
  }} on:click="{event => onClick()}" on:mouseenter="{event => onMouseEnter()}" >
60
60
 
@@ -1,10 +1,4 @@
1
- const sizeNames = ["xsmall", "small", "medium", "large"];
2
- const sizes = {
3
- xsmall: {
4
- min: 0,
5
- default: 0,
6
- max: 0
7
- },
1
+ const SIZES = {
8
2
  small: {
9
3
  min: 320,
10
4
  default: 321,
@@ -19,21 +13,9 @@ const sizes = {
19
13
  min: 990,
20
14
  default: 991,
21
15
  max: 1200
22
- },
23
- getWidthForSize(size) {
24
- return this[size].default;
25
- },
26
- getSizeForWidth(width) {
27
- for (const size of sizeNames) {
28
- const value = this[size];
29
- if (width <= value.max) {
30
- return size;
31
- }
32
- }
33
- return "large";
34
16
  }
35
17
  };
18
+ const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
36
19
  export {
37
- sizeNames,
38
- sizes
20
+ getMaxWidthQueryForSize
39
21
  };
@@ -0,0 +1,4 @@
1
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
2
+ export {
3
+ camelToKebabCase
4
+ };
@@ -14,15 +14,15 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { sizes } from "../constants/device-sizes.js";
17
+ import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
18
  function getBlockStyles(block) {
19
19
  var _a, _b, _c, _d, _e;
20
20
  const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
21
21
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
22
- styles[`@media (max-width: ${sizes.medium})`] = (_c = block.responsiveStyles) == null ? void 0 : _c.medium;
22
+ styles[getMaxWidthQueryForSize("medium")] = (_c = block.responsiveStyles) == null ? void 0 : _c.medium;
23
23
  }
24
24
  if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
25
- styles[`@media (max-width: ${sizes.small})`] = (_e = block.responsiveStyles) == null ? void 0 : _e.small;
25
+ styles[getMaxWidthQueryForSize("small")] = (_e = block.responsiveStyles) == null ? void 0 : _e.small;
26
26
  }
27
27
  return styles;
28
28
  }
@@ -0,0 +1,12 @@
1
+ import { camelToKebabCase } from "../functions/camel-to-kebab-case";
2
+ 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
+ };
10
+ export {
11
+ convertStyleMaptoCSS
12
+ };