@webstudio-is/react-sdk 0.10.0 → 0.10.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.
@@ -15,10 +15,12 @@ const Image = forwardRef(
15
15
  const asset = useUserPropsAsset(componentId, "src");
16
16
  const params = getParams();
17
17
  const loader = useMemo(() => {
18
- if (asset == null)
18
+ if (asset == null) {
19
19
  return null;
20
- if (asset.location === "REMOTE")
20
+ }
21
+ if (asset.location === "REMOTE") {
21
22
  return loaders.cloudflareImageLoader(params);
23
+ }
22
24
  return loaders.localImageLoader();
23
25
  }, [asset, params]);
24
26
  let src = props.src;
@@ -35,10 +35,12 @@ const Image = (0, import_react.forwardRef)(
35
35
  const asset = (0, import_use_user_props_asset.useUserPropsAsset)(componentId, "src");
36
36
  const params = (0, import_params.getParams)();
37
37
  const loader = (0, import_react.useMemo)(() => {
38
- if (asset == null)
38
+ if (asset == null) {
39
39
  return null;
40
- if (asset.location === "REMOTE")
40
+ }
41
+ if (asset.location === "REMOTE") {
41
42
  return import_image.loaders.cloudflareImageLoader(params);
43
+ }
42
44
  return import_image.loaders.localImageLoader();
43
45
  }, [asset, params]);
44
46
  let src = props.src;
@@ -27,8 +27,9 @@ const unitRegex = new RegExp(`${import_css_data.units.join("|")}`);
27
27
  const parseValue = (property, value) => {
28
28
  const number = parseFloat(value);
29
29
  const parsedUnit = unitRegex.exec(value);
30
- if (value === "rgba(0, 0, 0, 0)")
30
+ if (value === "rgba(0, 0, 0, 0)") {
31
31
  value = "transparent";
32
+ }
32
33
  if (isNaN(number) || parsedUnit === null) {
33
34
  return {
34
35
  type: "keyword",
@@ -46,13 +47,15 @@ const parseValue = (property, value) => {
46
47
  };
47
48
  const getBrowserStyle = (element) => {
48
49
  const browserStyle = {};
49
- if (element === void 0)
50
+ if (element === void 0) {
50
51
  return browserStyle;
52
+ }
51
53
  let knownProperty;
52
54
  const computedStyle = getComputedStyle(element);
53
55
  for (knownProperty in import_css_data.properties) {
54
- if (knownProperty in computedStyle === false)
56
+ if (knownProperty in computedStyle === false) {
55
57
  continue;
58
+ }
56
59
  const computedValue = computedStyle[knownProperty];
57
60
  browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
58
61
  }
@@ -52,8 +52,9 @@ const createPubsub = () => {
52
52
  const publishCallback = (0, import_react.useCallback)(
53
53
  (action) => {
54
54
  const element = iframeRef.current;
55
- if (element?.contentWindow == null)
55
+ if (element?.contentWindow == null) {
56
56
  return;
57
+ }
57
58
  element.contentWindow.postMessage(action, "*");
58
59
  window.postMessage(action, "*");
59
60
  },
@@ -37,8 +37,9 @@ const renderText = (text) => {
37
37
  }, index));
38
38
  };
39
39
  const renderWrapperComponentChildren = (children) => {
40
- if (children === void 0 || children.length === 0)
40
+ if (children === void 0 || children.length === 0) {
41
41
  return;
42
+ }
42
43
  return children.map((child) => {
43
44
  return typeof child === "string" ? renderText(child) : child;
44
45
  });
@@ -27,11 +27,13 @@ const useUserPropsAsset = (instanceId, propName) => {
27
27
  const [allUserProps] = (0, import_all_user_props.useAllUserProps)();
28
28
  const propsData = allUserProps[instanceId];
29
29
  const asset = (0, import_react.useMemo)(() => {
30
- if (propsData == null)
30
+ if (propsData == null) {
31
31
  return void 0;
32
+ }
32
33
  const prop = propsData.props.find((prop2) => prop2.prop === propName);
33
- if (prop == null)
34
+ if (prop == null) {
34
35
  return void 0;
36
+ }
35
37
  if (prop.type === "asset") {
36
38
  return prop.value;
37
39
  }
@@ -27,8 +27,9 @@ const useUserProps = (instanceId) => {
27
27
  const [allUserProps] = (0, import_all_user_props.useAllUserProps)();
28
28
  const propsData = allUserProps[instanceId];
29
29
  const props = (0, import_react.useMemo)(() => {
30
- if (propsData == null)
30
+ if (propsData == null) {
31
31
  return {};
32
+ }
32
33
  const result = {};
33
34
  for (const userProp of propsData.props) {
34
35
  if (userProp.type !== "asset") {
@@ -4,8 +4,9 @@ const unitRegex = new RegExp(`${units.join("|")}`);
4
4
  const parseValue = (property, value) => {
5
5
  const number = parseFloat(value);
6
6
  const parsedUnit = unitRegex.exec(value);
7
- if (value === "rgba(0, 0, 0, 0)")
7
+ if (value === "rgba(0, 0, 0, 0)") {
8
8
  value = "transparent";
9
+ }
9
10
  if (isNaN(number) || parsedUnit === null) {
10
11
  return {
11
12
  type: "keyword",
@@ -23,13 +24,15 @@ const parseValue = (property, value) => {
23
24
  };
24
25
  const getBrowserStyle = (element) => {
25
26
  const browserStyle = {};
26
- if (element === void 0)
27
+ if (element === void 0) {
27
28
  return browserStyle;
29
+ }
28
30
  let knownProperty;
29
31
  const computedStyle = getComputedStyle(element);
30
32
  for (knownProperty in properties) {
31
- if (knownProperty in computedStyle === false)
33
+ if (knownProperty in computedStyle === false) {
32
34
  continue;
35
+ }
33
36
  const computedValue = computedStyle[knownProperty];
34
37
  browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
35
38
  }
@@ -23,8 +23,9 @@ const createPubsub = () => {
23
23
  const publishCallback = useCallback(
24
24
  (action) => {
25
25
  const element = iframeRef.current;
26
- if (element?.contentWindow == null)
26
+ if (element?.contentWindow == null) {
27
27
  return;
28
+ }
28
29
  element.contentWindow.postMessage(action, "*");
29
30
  window.postMessage(action, "*");
30
31
  },
@@ -12,8 +12,9 @@ const renderText = (text) => {
12
12
  }, index));
13
13
  };
14
14
  const renderWrapperComponentChildren = (children) => {
15
- if (children === void 0 || children.length === 0)
15
+ if (children === void 0 || children.length === 0) {
16
16
  return;
17
+ }
17
18
  return children.map((child) => {
18
19
  return typeof child === "string" ? renderText(child) : child;
19
20
  });
@@ -4,11 +4,13 @@ const useUserPropsAsset = (instanceId, propName) => {
4
4
  const [allUserProps] = useAllUserProps();
5
5
  const propsData = allUserProps[instanceId];
6
6
  const asset = useMemo(() => {
7
- if (propsData == null)
7
+ if (propsData == null) {
8
8
  return void 0;
9
+ }
9
10
  const prop = propsData.props.find((prop2) => prop2.prop === propName);
10
- if (prop == null)
11
+ if (prop == null) {
11
12
  return void 0;
13
+ }
12
14
  if (prop.type === "asset") {
13
15
  return prop.value;
14
16
  }
@@ -4,8 +4,9 @@ const useUserProps = (instanceId) => {
4
4
  const [allUserProps] = useAllUserProps();
5
5
  const propsData = allUserProps[instanceId];
6
6
  const props = useMemo(() => {
7
- if (propsData == null)
7
+ if (propsData == null) {
8
8
  return {};
9
+ }
9
10
  const result = {};
10
11
  for (const userProp of propsData.props) {
11
12
  if (userProp.type !== "asset") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -22,9 +22,12 @@ export const Image = forwardRef<ElementRef<typeof defaultTag>, Props>(
22
22
  const params = getParams();
23
23
 
24
24
  const loader = useMemo(() => {
25
- if (asset == null) return null;
26
- if (asset.location === "REMOTE")
25
+ if (asset == null) {
26
+ return null;
27
+ }
28
+ if (asset.location === "REMOTE") {
27
29
  return loaders.cloudflareImageLoader(params);
30
+ }
28
31
  return loaders.localImageLoader();
29
32
  }, [asset, params]);
30
33
 
@@ -11,7 +11,9 @@ const parseValue = (
11
11
  ): StyleValue => {
12
12
  const number = parseFloat(value);
13
13
  const parsedUnit = unitRegex.exec(value);
14
- if (value === "rgba(0, 0, 0, 0)") value = "transparent";
14
+ if (value === "rgba(0, 0, 0, 0)") {
15
+ value = "transparent";
16
+ }
15
17
  if (isNaN(number) || parsedUnit === null) {
16
18
  return {
17
19
  type: "keyword",
@@ -32,11 +34,15 @@ const parseValue = (
32
34
 
33
35
  export const getBrowserStyle = (element?: Element): Style => {
34
36
  const browserStyle: Style = {};
35
- if (element === undefined) return browserStyle;
37
+ if (element === undefined) {
38
+ return browserStyle;
39
+ }
36
40
  let knownProperty: keyof typeof properties;
37
41
  const computedStyle = getComputedStyle(element);
38
42
  for (knownProperty in properties) {
39
- if (knownProperty in computedStyle === false) continue;
43
+ if (knownProperty in computedStyle === false) {
44
+ continue;
45
+ }
40
46
  // Typescript doesn't know we can access CSSStyleDeclaration properties by keys
41
47
  const computedValue = computedStyle[knownProperty as unknown as number];
42
48
  browserStyle[knownProperty] = parseValue(knownProperty, computedValue);
@@ -43,7 +43,9 @@ export const createPubsub = <PublishMap>() => {
43
43
  const publishCallback = useCallback(
44
44
  <Type extends keyof PublishMap>(action: Action<Type>) => {
45
45
  const element = iframeRef.current;
46
- if (element?.contentWindow == null) return;
46
+ if (element?.contentWindow == null) {
47
+ return;
48
+ }
47
49
  element.contentWindow.postMessage(action, "*");
48
50
  window.postMessage(action, "*");
49
51
  },
@@ -19,7 +19,9 @@ export const renderWrapperComponentChildren = (
19
19
  ): Array<JSX.Element | string | Array<JSX.Element | string>> | undefined => {
20
20
  // Some elements like input can't have children
21
21
  // @todo needs to be made impossible to drag element into input
22
- if (children === undefined || children.length === 0) return;
22
+ if (children === undefined || children.length === 0) {
23
+ return;
24
+ }
23
25
  return children.map((child) => {
24
26
  return typeof child === "string" ? renderText(child) : child;
25
27
  });
@@ -15,10 +15,14 @@ export const useUserPropsAsset = (
15
15
 
16
16
  const propsData = allUserProps[instanceId];
17
17
  const asset = useMemo(() => {
18
- if (propsData == null) return undefined;
18
+ if (propsData == null) {
19
+ return undefined;
20
+ }
19
21
  const prop = propsData.props.find((prop) => prop.prop === propName);
20
22
 
21
- if (prop == null) return undefined;
23
+ if (prop == null) {
24
+ return undefined;
25
+ }
22
26
 
23
27
  if (prop.type === "asset") {
24
28
  return prop.value;
@@ -14,7 +14,9 @@ export const useUserProps = (instanceId: Instance["id"]) => {
14
14
 
15
15
  const propsData = allUserProps[instanceId];
16
16
  const props = useMemo(() => {
17
- if (propsData == null) return {};
17
+ if (propsData == null) {
18
+ return {};
19
+ }
18
20
  const result: UserProps = {};
19
21
 
20
22
  for (const userProp of propsData.props) {