@builder.io/sdk-svelte 0.8.1 → 0.9.0

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 (81) hide show
  1. package/lib/browser/components/blocks/blocks-wrapper.svelte +8 -4
  2. package/lib/browser/components/blocks/blocks.svelte +8 -1
  3. package/lib/browser/components/content/components/enable-editor.svelte +7 -2
  4. package/lib/browser/components/content/components/enable-editor.svelte.d.ts +3 -1
  5. package/lib/browser/components/content/content.svelte +8 -0
  6. package/lib/browser/components/content/content.svelte.d.ts +4 -0
  7. package/lib/browser/components/content-variants/content-variants.svelte +12 -0
  8. package/lib/browser/components/content-variants/content-variants.svelte.d.ts +4 -0
  9. package/lib/browser/components/content-variants/content-variants.types.d.ts +16 -0
  10. package/lib/browser/constants/sdk-version.d.ts +1 -1
  11. package/lib/browser/constants/sdk-version.js +1 -1
  12. package/lib/browser/context/builder.context.d.ts +2 -0
  13. package/lib/browser/context/builder.context.js +2 -0
  14. package/lib/browser/context/types.d.ts +2 -1
  15. package/lib/browser/functions/get-block-properties.js +5 -9
  16. package/lib/browser/functions/transform-block-properties.d.ts +7 -1
  17. package/lib/browser/functions/transform-block-properties.js +1 -1
  18. package/lib/browser/types/enforced-partials.d.ts +7 -2
  19. package/lib/edge/components/blocks/blocks-wrapper.svelte +8 -4
  20. package/lib/edge/components/blocks/blocks.svelte +8 -1
  21. package/lib/edge/components/content/components/enable-editor.svelte +7 -2
  22. package/lib/edge/components/content/components/enable-editor.svelte.d.ts +3 -1
  23. package/lib/edge/components/content/content.svelte +8 -0
  24. package/lib/edge/components/content/content.svelte.d.ts +4 -0
  25. package/lib/edge/components/content-variants/content-variants.svelte +12 -0
  26. package/lib/edge/components/content-variants/content-variants.svelte.d.ts +4 -0
  27. package/lib/edge/components/content-variants/content-variants.types.d.ts +16 -0
  28. package/lib/edge/constants/sdk-version.d.ts +1 -1
  29. package/lib/edge/constants/sdk-version.js +1 -1
  30. package/lib/edge/context/builder.context.d.ts +2 -0
  31. package/lib/edge/context/builder.context.js +2 -0
  32. package/lib/edge/context/types.d.ts +2 -1
  33. package/lib/edge/functions/get-block-properties.js +5 -9
  34. package/lib/edge/functions/transform-block-properties.d.ts +7 -1
  35. package/lib/edge/functions/transform-block-properties.js +1 -1
  36. package/lib/edge/types/enforced-partials.d.ts +7 -2
  37. package/lib/node/components/blocks/blocks-wrapper.svelte +8 -4
  38. package/lib/node/components/blocks/blocks.svelte +8 -1
  39. package/lib/node/components/content/components/enable-editor.svelte +7 -2
  40. package/lib/node/components/content/components/enable-editor.svelte.d.ts +3 -1
  41. package/lib/node/components/content/content.svelte +8 -0
  42. package/lib/node/components/content/content.svelte.d.ts +4 -0
  43. package/lib/node/components/content-variants/content-variants.svelte +12 -0
  44. package/lib/node/components/content-variants/content-variants.svelte.d.ts +4 -0
  45. package/lib/node/components/content-variants/content-variants.types.d.ts +16 -0
  46. package/lib/node/constants/sdk-version.d.ts +1 -1
  47. package/lib/node/constants/sdk-version.js +1 -1
  48. package/lib/node/context/builder.context.d.ts +2 -0
  49. package/lib/node/context/builder.context.js +2 -0
  50. package/lib/node/context/types.d.ts +2 -1
  51. package/lib/node/functions/get-block-properties.js +5 -9
  52. package/lib/node/functions/transform-block-properties.d.ts +7 -1
  53. package/lib/node/functions/transform-block-properties.js +1 -1
  54. package/lib/node/types/enforced-partials.d.ts +7 -2
  55. package/package.json +1 -1
  56. package/src/components/blocks/blocks-wrapper.svelte +16 -4
  57. package/src/components/blocks/blocks.svelte +11 -2
  58. package/src/components/content/components/enable-editor.svelte +14 -3
  59. package/src/components/content/content.svelte +9 -0
  60. package/src/components/content-variants/content-variants.svelte +15 -0
  61. package/src/components/content-variants/content-variants.types.ts +16 -0
  62. package/src/constants/sdk-version.ts +1 -1
  63. package/src/context/builder.context.ts +2 -0
  64. package/src/context/types.ts +2 -1
  65. package/src/functions/get-block-properties.ts +5 -9
  66. package/src/functions/transform-block-properties.ts +9 -1
  67. package/src/types/enforced-partials.ts +8 -2
  68. package/lib/browser/functions/get-react-native-block-styles.d.ts +0 -7
  69. package/lib/browser/functions/get-react-native-block-styles.js +0 -17
  70. package/lib/browser/functions/sanitize-react-native-block-styles.d.ts +0 -3
  71. package/lib/browser/functions/sanitize-react-native-block-styles.js +0 -61
  72. package/lib/edge/functions/get-react-native-block-styles.d.ts +0 -7
  73. package/lib/edge/functions/get-react-native-block-styles.js +0 -17
  74. package/lib/edge/functions/sanitize-react-native-block-styles.d.ts +0 -3
  75. package/lib/edge/functions/sanitize-react-native-block-styles.js +0 -61
  76. package/lib/node/functions/get-react-native-block-styles.d.ts +0 -7
  77. package/lib/node/functions/get-react-native-block-styles.js +0 -17
  78. package/lib/node/functions/sanitize-react-native-block-styles.d.ts +0 -3
  79. package/lib/node/functions/sanitize-react-native-block-styles.js +0 -61
  80. package/src/functions/get-react-native-block-styles.ts +0 -27
  81. package/src/functions/sanitize-react-native-block-styles.ts +0 -58
@@ -12,6 +12,8 @@ export default {
12
12
  apiVersion: undefined,
13
13
  componentInfos: {},
14
14
  inheritedStyles: {},
15
+ BlocksWrapper: "div",
16
+ BlocksWrapperProps: {},
15
17
  }),
16
18
  key,
17
19
  };
@@ -1,3 +1,4 @@
1
+ import type { BlocksWrapperProps } from '../components/blocks/blocks-wrapper.svelte';
1
2
  import type { ApiVersion } from '../types/api-version.js';
2
3
  import type { BuilderContent } from '../types/builder-content.js';
3
4
  import type { ComponentInfo } from '../types/components.js';
@@ -8,7 +9,7 @@ export type RegisteredComponent = ComponentInfo & {
8
9
  export type RegisteredComponents = Dictionary<RegisteredComponent>;
9
10
  export type BuilderRenderState = Record<string, unknown>;
10
11
  export type BuilderRenderContext = Record<string, unknown>;
11
- export interface BuilderContextInterface {
12
+ export interface BuilderContextInterface extends Pick<BlocksWrapperProps, 'BlocksWrapper' | 'BlocksWrapperProps'> {
12
13
  content: Nullable<BuilderContent>;
13
14
  context: BuilderRenderContext;
14
15
  /**
@@ -2,7 +2,6 @@ import { TARGET } from '../constants/target.js';
2
2
  import type { BuilderContextInterface } from '../context/types.js';
3
3
  import { convertStyleMapToCSSArray } from '../helpers/css.js';
4
4
  import type { BuilderBlock } from '../types/builder-block.js';
5
- import { getReactNativeBlockStyles } from './get-react-native-block-styles.js';
6
5
  import { transformBlockProperties } from './transform-block-properties.js';
7
6
  const extractRelevantRootBlockProperties = (block: BuilderBlock) => {
8
7
  // currently we are only spreading the `href` property
@@ -52,14 +51,11 @@ export function getBlockProperties({
52
51
  style: block.style ? getStyleAttribute(block.style) : undefined,
53
52
  class: [block.id, 'builder-block', block.class, block.properties?.class].filter(Boolean).join(' ')
54
53
  };
55
- if (TARGET === 'reactNative') {
56
- properties.style = getReactNativeBlockStyles({
57
- block,
58
- context,
59
- blockStyles: properties.style
60
- });
61
- }
62
- return transformBlockProperties(properties);
54
+ return transformBlockProperties({
55
+ properties,
56
+ context,
57
+ block
58
+ });
63
59
  }
64
60
  /**
65
61
  * Svelte does not support style attribute as an object so we need to flatten it.
@@ -1,3 +1,11 @@
1
- export function transformBlockProperties<T>(properties: T) {
1
+ import type { BuilderContextInterface } from '../context/types';
2
+ import type { BuilderBlock } from '../types/builder-block';
3
+ export function transformBlockProperties<T>({
4
+ properties
5
+ }: {
6
+ properties: T;
7
+ context: BuilderContextInterface;
8
+ block: BuilderBlock;
9
+ }) {
2
10
  return properties;
3
11
  }
@@ -1,6 +1,12 @@
1
1
  import type { Prettify } from './typescript.js';
2
- type OptionalFieldsOnly<T> = { [K in keyof T as T[K] extends Required<T>[K] ? never : K]: T[K] };
3
- type RequiredFieldsOnly<T> = { [K in keyof T as T[K] extends Required<T>[K] ? K : never]: T[K] };
2
+
3
+ /**
4
+ * Lol Typescript
5
+ * https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
6
+ */
7
+ type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
8
+ type OptionalFieldsOnly<T> = { [K in keyof T as T[K] extends Required<T>[K] ? IfAny<T[K], K, never> : K]: T[K] };
9
+ type RequiredFieldsOnly<T> = { [K in keyof T as T[K] extends Required<T>[K] ? IfAny<T[K], never, K> : never]: T[K] };
4
10
  type Enforced<T> = { [K in keyof T]-?: T[K] };
5
11
  type AndUndefined<T> = { [K in keyof T]: T[K] | undefined };
6
12
 
@@ -1,7 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function getReactNativeBlockStyles({ block, context, blockStyles }: {
4
- block: BuilderBlock;
5
- context: BuilderContextInterface;
6
- blockStyles: any;
7
- }): CSSStyleDeclaration | Record<string, string | undefined>;
@@ -1,17 +0,0 @@
1
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
2
- export function getReactNativeBlockStyles({ block, context, blockStyles }) {
3
- const responsiveStyles = block.responsiveStyles;
4
- if (!responsiveStyles) {
5
- return {};
6
- }
7
- const styles = {
8
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
9
- ...context.inheritedStyles,
10
- ...(responsiveStyles.large || {}),
11
- ...(responsiveStyles.medium || {}),
12
- ...(responsiveStyles.small || {}),
13
- ...blockStyles
14
- };
15
- const newStyles = sanitizeReactNativeBlockStyles(styles);
16
- return newStyles;
17
- }
@@ -1,3 +0,0 @@
1
- type Styles = Record<string, string | number>;
2
- export declare const sanitizeReactNativeBlockStyles: (styles: Styles) => Styles;
3
- export {};
@@ -1,61 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
- const SHOW_WARNINGS = false;
4
- const normalizeNumber = (value) => {
5
- if (Number.isNaN(value)) {
6
- return undefined;
7
- }
8
- else if (value < 0) {
9
- // TODO: why are negative values not allowed?
10
- return 0;
11
- }
12
- else {
13
- return value;
14
- }
15
- };
16
- export const sanitizeReactNativeBlockStyles = (styles) => {
17
- return Object.keys(styles).reduce((acc, key) => {
18
- const propertyValue = styles[key];
19
- if (key === 'display' && !displayValues.has(propertyValue)) {
20
- if (SHOW_WARNINGS) {
21
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
22
- }
23
- return acc;
24
- }
25
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
26
- if (SHOW_WARNINGS) {
27
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
28
- }
29
- return acc;
30
- }
31
- if (typeof propertyValue === 'string') {
32
- // `px` units need to be stripped and replaced with numbers
33
- // https://regexr.com/6ualn
34
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
35
- if (isPixelUnit) {
36
- const newValue = parseFloat(propertyValue);
37
- const normalizedValue = normalizeNumber(newValue);
38
- if (normalizedValue) {
39
- return {
40
- ...acc,
41
- [key]: normalizedValue
42
- };
43
- }
44
- else {
45
- return acc;
46
- }
47
- }
48
- else if (propertyValue === '0') {
49
- // 0 edge case needs to be handled
50
- return {
51
- ...acc,
52
- [key]: 0
53
- };
54
- }
55
- }
56
- return {
57
- ...acc,
58
- [key]: propertyValue
59
- };
60
- }, {});
61
- };
@@ -1,7 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function getReactNativeBlockStyles({ block, context, blockStyles }: {
4
- block: BuilderBlock;
5
- context: BuilderContextInterface;
6
- blockStyles: any;
7
- }): CSSStyleDeclaration | Record<string, string | undefined>;
@@ -1,17 +0,0 @@
1
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
2
- export function getReactNativeBlockStyles({ block, context, blockStyles }) {
3
- const responsiveStyles = block.responsiveStyles;
4
- if (!responsiveStyles) {
5
- return {};
6
- }
7
- const styles = {
8
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
9
- ...context.inheritedStyles,
10
- ...(responsiveStyles.large || {}),
11
- ...(responsiveStyles.medium || {}),
12
- ...(responsiveStyles.small || {}),
13
- ...blockStyles
14
- };
15
- const newStyles = sanitizeReactNativeBlockStyles(styles);
16
- return newStyles;
17
- }
@@ -1,3 +0,0 @@
1
- type Styles = Record<string, string | number>;
2
- export declare const sanitizeReactNativeBlockStyles: (styles: Styles) => Styles;
3
- export {};
@@ -1,61 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
- const SHOW_WARNINGS = false;
4
- const normalizeNumber = (value) => {
5
- if (Number.isNaN(value)) {
6
- return undefined;
7
- }
8
- else if (value < 0) {
9
- // TODO: why are negative values not allowed?
10
- return 0;
11
- }
12
- else {
13
- return value;
14
- }
15
- };
16
- export const sanitizeReactNativeBlockStyles = (styles) => {
17
- return Object.keys(styles).reduce((acc, key) => {
18
- const propertyValue = styles[key];
19
- if (key === 'display' && !displayValues.has(propertyValue)) {
20
- if (SHOW_WARNINGS) {
21
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
22
- }
23
- return acc;
24
- }
25
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
26
- if (SHOW_WARNINGS) {
27
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
28
- }
29
- return acc;
30
- }
31
- if (typeof propertyValue === 'string') {
32
- // `px` units need to be stripped and replaced with numbers
33
- // https://regexr.com/6ualn
34
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
35
- if (isPixelUnit) {
36
- const newValue = parseFloat(propertyValue);
37
- const normalizedValue = normalizeNumber(newValue);
38
- if (normalizedValue) {
39
- return {
40
- ...acc,
41
- [key]: normalizedValue
42
- };
43
- }
44
- else {
45
- return acc;
46
- }
47
- }
48
- else if (propertyValue === '0') {
49
- // 0 edge case needs to be handled
50
- return {
51
- ...acc,
52
- [key]: 0
53
- };
54
- }
55
- }
56
- return {
57
- ...acc,
58
- [key]: propertyValue
59
- };
60
- }, {});
61
- };
@@ -1,7 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- export declare function getReactNativeBlockStyles({ block, context, blockStyles }: {
4
- block: BuilderBlock;
5
- context: BuilderContextInterface;
6
- blockStyles: any;
7
- }): CSSStyleDeclaration | Record<string, string | undefined>;
@@ -1,17 +0,0 @@
1
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
2
- export function getReactNativeBlockStyles({ block, context, blockStyles }) {
3
- const responsiveStyles = block.responsiveStyles;
4
- if (!responsiveStyles) {
5
- return {};
6
- }
7
- const styles = {
8
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
9
- ...context.inheritedStyles,
10
- ...(responsiveStyles.large || {}),
11
- ...(responsiveStyles.medium || {}),
12
- ...(responsiveStyles.small || {}),
13
- ...blockStyles
14
- };
15
- const newStyles = sanitizeReactNativeBlockStyles(styles);
16
- return newStyles;
17
- }
@@ -1,3 +0,0 @@
1
- type Styles = Record<string, string | number>;
2
- export declare const sanitizeReactNativeBlockStyles: (styles: Styles) => Styles;
3
- export {};
@@ -1,61 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
- const SHOW_WARNINGS = false;
4
- const normalizeNumber = (value) => {
5
- if (Number.isNaN(value)) {
6
- return undefined;
7
- }
8
- else if (value < 0) {
9
- // TODO: why are negative values not allowed?
10
- return 0;
11
- }
12
- else {
13
- return value;
14
- }
15
- };
16
- export const sanitizeReactNativeBlockStyles = (styles) => {
17
- return Object.keys(styles).reduce((acc, key) => {
18
- const propertyValue = styles[key];
19
- if (key === 'display' && !displayValues.has(propertyValue)) {
20
- if (SHOW_WARNINGS) {
21
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
22
- }
23
- return acc;
24
- }
25
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
26
- if (SHOW_WARNINGS) {
27
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
28
- }
29
- return acc;
30
- }
31
- if (typeof propertyValue === 'string') {
32
- // `px` units need to be stripped and replaced with numbers
33
- // https://regexr.com/6ualn
34
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
35
- if (isPixelUnit) {
36
- const newValue = parseFloat(propertyValue);
37
- const normalizedValue = normalizeNumber(newValue);
38
- if (normalizedValue) {
39
- return {
40
- ...acc,
41
- [key]: normalizedValue
42
- };
43
- }
44
- else {
45
- return acc;
46
- }
47
- }
48
- else if (propertyValue === '0') {
49
- // 0 edge case needs to be handled
50
- return {
51
- ...acc,
52
- [key]: 0
53
- };
54
- }
55
- }
56
- return {
57
- ...acc,
58
- [key]: propertyValue
59
- };
60
- }, {});
61
- };
@@ -1,27 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
4
- export function getReactNativeBlockStyles({
5
- block,
6
- context,
7
- blockStyles
8
- }: {
9
- block: BuilderBlock;
10
- context: BuilderContextInterface;
11
- blockStyles: any;
12
- }): CSSStyleDeclaration | Record<string, string | undefined> {
13
- const responsiveStyles = block.responsiveStyles;
14
- if (!responsiveStyles) {
15
- return {};
16
- }
17
- const styles = ({
18
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
19
- ...context.inheritedStyles,
20
- ...(responsiveStyles.large || {}),
21
- ...(responsiveStyles.medium || {}),
22
- ...(responsiveStyles.small || {}),
23
- ...blockStyles
24
- } as Record<string, string | number>);
25
- const newStyles = ((sanitizeReactNativeBlockStyles(styles) as any) as CSSStyleDeclaration);
26
- return newStyles;
27
- }
@@ -1,58 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
- const SHOW_WARNINGS = false;
4
- type Styles = Record<string, string | number>;
5
- const normalizeNumber = (value: number): number | undefined => {
6
- if (Number.isNaN(value)) {
7
- return undefined;
8
- } else if (value < 0) {
9
- // TODO: why are negative values not allowed?
10
- return 0;
11
- } else {
12
- return value;
13
- }
14
- };
15
- export const sanitizeReactNativeBlockStyles = (styles: Styles): Styles => {
16
- return Object.keys(styles).reduce<Styles>((acc, key): Styles => {
17
- const propertyValue = styles[key];
18
- if (key === 'display' && !displayValues.has((propertyValue as string))) {
19
- if (SHOW_WARNINGS) {
20
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
21
- }
22
- return acc;
23
- }
24
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
25
- if (SHOW_WARNINGS) {
26
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
27
- }
28
- return acc;
29
- }
30
- if (typeof propertyValue === 'string') {
31
- // `px` units need to be stripped and replaced with numbers
32
- // https://regexr.com/6ualn
33
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
34
- if (isPixelUnit) {
35
- const newValue = parseFloat(propertyValue);
36
- const normalizedValue = normalizeNumber(newValue);
37
- if (normalizedValue) {
38
- return {
39
- ...acc,
40
- [key]: normalizedValue
41
- };
42
- } else {
43
- return acc;
44
- }
45
- } else if (propertyValue === '0') {
46
- // 0 edge case needs to be handled
47
- return {
48
- ...acc,
49
- [key]: 0
50
- };
51
- }
52
- }
53
- return {
54
- ...acc,
55
- [key]: propertyValue
56
- };
57
- }, {});
58
- }