@webstudio-is/sdk 0.182.0 → 0.185.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.
@@ -43,28 +43,16 @@ var ol = div;
43
43
  var p = div;
44
44
  var span = div;
45
45
  var html = [
46
+ { property: "display", value: { type: "keyword", value: "grid" } },
47
+ { property: "minHeight", value: { type: "unit", unit: "%", value: 100 } },
46
48
  {
47
- property: "lineHeight",
48
- value: { type: "unit", unit: "number", value: 1.15 }
49
- },
50
- {
51
- property: "textSizeAdjust",
52
- value: { type: "unit", unit: "%", value: 100 }
53
- },
54
- { property: "tabSize", value: { type: "unit", unit: "number", value: 4 } },
55
- { property: "boxSizing", value: { type: "keyword", value: "border-box" } },
56
- { property: "borderTopWidth", value: { type: "unit", unit: "px", value: 1 } },
57
- {
58
- property: "borderRightWidth",
59
- value: { type: "unit", unit: "px", value: 1 }
60
- },
61
- {
62
- property: "borderBottomWidth",
63
- value: { type: "unit", unit: "px", value: 1 }
49
+ property: "fontFamily",
50
+ value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
64
51
  },
52
+ { property: "fontSize", value: { type: "unit", unit: "px", value: 16 } },
65
53
  {
66
- property: "borderLeftWidth",
67
- value: { type: "unit", unit: "px", value: 1 }
54
+ property: "lineHeight",
55
+ value: { type: "unit", unit: "number", value: 1.2 }
68
56
  }
69
57
  ];
70
58
  var body = [
@@ -78,15 +66,6 @@ var body = [
78
66
  value: { type: "unit", unit: "number", value: 0 }
79
67
  },
80
68
  { property: "marginLeft", value: { type: "unit", unit: "number", value: 0 } },
81
- {
82
- property: "fontFamily",
83
- value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
84
- },
85
- { property: "fontSize", value: { type: "unit", unit: "px", value: 16 } },
86
- {
87
- property: "lineHeight",
88
- value: { type: "unit", unit: "number", value: 1.2 }
89
- },
90
69
  { property: "boxSizing", value: { type: "keyword", value: "border-box" } },
91
70
  { property: "borderTopWidth", value: { type: "unit", unit: "px", value: 1 } },
92
71
  {
package/lib/index.js CHANGED
@@ -461,6 +461,7 @@ var WebstudioFragment = z12.object({
461
461
  });
462
462
 
463
463
  // src/instances-utils.ts
464
+ var ROOT_INSTANCE_ID = ":root";
464
465
  var traverseInstances = (instances, instanceId, callback) => {
465
466
  const instance = instances.get(instanceId);
466
467
  if (instance === void 0) {
@@ -477,14 +478,14 @@ var traverseInstances = (instances, instanceId, callback) => {
477
478
  }
478
479
  };
479
480
  var findTreeInstanceIds = (instances, rootInstanceId) => {
480
- const ids = /* @__PURE__ */ new Set();
481
+ const ids = /* @__PURE__ */ new Set([rootInstanceId]);
481
482
  traverseInstances(instances, rootInstanceId, (instance) => {
482
483
  ids.add(instance.id);
483
484
  });
484
485
  return ids;
485
486
  };
486
487
  var findTreeInstanceIdsExcludingSlotDescendants = (instances, rootInstanceId) => {
487
- const ids = /* @__PURE__ */ new Set();
488
+ const ids = /* @__PURE__ */ new Set([rootInstanceId]);
488
489
  traverseInstances(instances, rootInstanceId, (instance) => {
489
490
  ids.add(instance.id);
490
491
  if (instance.component === "Slot") {
@@ -543,7 +544,7 @@ var lintExpression = ({
543
544
  simple(root, {
544
545
  Identifier(node) {
545
546
  if (availableVariables.has(node.name) === false) {
546
- addError(`"${node.name}" is not available in the scope`)(node);
547
+ addError(`"${node.name}" is not defined in the scope`)(node);
547
548
  }
548
549
  },
549
550
  Literal() {
@@ -576,7 +577,7 @@ var lintExpression = ({
576
577
  simple(node.left, {
577
578
  Identifier(node2) {
578
579
  if (availableVariables.has(node2.name) === false) {
579
- addError(`"${node2.name}" is not available in the scope`)(node2);
580
+ addError(`"${node2.name}" is not defined in the scope`)(node2);
580
581
  }
581
582
  }
582
583
  });
@@ -645,20 +646,20 @@ var isLiteralExpression = (expression) => {
645
646
  }
646
647
  };
647
648
  var getExpressionIdentifiers = (expression) => {
648
- const identifiers = /* @__PURE__ */ new Set();
649
+ const identifiers2 = /* @__PURE__ */ new Set();
649
650
  try {
650
651
  const root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
651
652
  simple(root, {
652
- Identifier: (node) => identifiers.add(node.name),
653
+ Identifier: (node) => identifiers2.add(node.name),
653
654
  AssignmentExpression(node) {
654
655
  simple(node.left, {
655
- Identifier: (node2) => identifiers.add(node2.name)
656
+ Identifier: (node2) => identifiers2.add(node2.name)
656
657
  });
657
658
  }
658
659
  });
659
660
  } catch {
660
661
  }
661
- return identifiers;
662
+ return identifiers2;
662
663
  };
663
664
  var transpileExpression = ({
664
665
  expression,
@@ -857,6 +858,9 @@ var getStaticSiteMapXml = (pages, updatedAt) => {
857
858
  };
858
859
 
859
860
  // src/scope.ts
861
+ import reservedIdentifiers from "reserved-identifiers";
862
+ var identifiers = reservedIdentifiers({ includeGlobalProperties: true });
863
+ var isReserved = (identifier) => identifiers.has(identifier);
860
864
  var normalizeJsName = (name) => {
861
865
  name = name.replaceAll(/[^\w$]/g, "");
862
866
  if (name.length === 0) {
@@ -865,6 +869,9 @@ var normalizeJsName = (name) => {
865
869
  if (/[A-Za-z_$]/.test(name[0]) === false) {
866
870
  name = `_${name}`;
867
871
  }
872
+ if (isReserved(name)) {
873
+ return `${name}_`;
874
+ }
868
875
  return name;
869
876
  };
870
877
  var createScope = (occupiedIdentifiers = [], normalizeName = normalizeJsName, separator = "_") => {
@@ -914,12 +921,15 @@ var loadResource = async (customFetch, resourceRequest) => {
914
921
  }
915
922
  try {
916
923
  const response = await customFetch(url.trim(), requestInit);
917
- let data;
918
- if (response.ok && // accept json by default and when specified explicitly
919
- (response.headers.has("content-type") === false || response.headers.get("content-type")?.includes("application/json"))) {
920
- data = await response.json();
921
- } else {
922
- data = await response.text();
924
+ let data = await response.text();
925
+ try {
926
+ data = JSON.parse(data);
927
+ } catch {
928
+ }
929
+ if (!response.ok) {
930
+ console.error(
931
+ `Failed to load resource: ${url} - ${response.status}: ${JSON.stringify(data).slice(0, 300)}`
932
+ );
923
933
  }
924
934
  return {
925
935
  ok: response.ok,
@@ -928,6 +938,7 @@ var loadResource = async (customFetch, resourceRequest) => {
928
938
  statusText: response.statusText
929
939
  };
930
940
  } catch (error) {
941
+ console.error(error);
931
942
  const message = error.message;
932
943
  return {
933
944
  ok: false,
@@ -1315,6 +1326,7 @@ export {
1315
1326
  Prop,
1316
1327
  Props,
1317
1328
  ROOT_FOLDER_ID,
1329
+ ROOT_INSTANCE_ID,
1318
1330
  Resource,
1319
1331
  ResourceRequest,
1320
1332
  Resources,
@@ -1,4 +1,5 @@
1
1
  import type { Instance, Instances } from "./schema/instances";
2
+ export declare const ROOT_INSTANCE_ID = ":root";
2
3
  export declare const findTreeInstanceIds: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
3
4
  export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
4
5
  export declare const parseComponentName: (componentName: string) => readonly [string | undefined, string];
@@ -1,14 +1,24 @@
1
1
  import type { ResourceRequest } from "./schema/resources";
2
2
  export declare const loadResource: (customFetch: typeof fetch, resourceRequest: ResourceRequest) => Promise<{
3
3
  ok: boolean;
4
- data: any;
4
+ data: string;
5
+ status: number;
6
+ statusText: string;
7
+ } | {
8
+ ok: boolean;
9
+ data: undefined;
5
10
  status: number;
6
11
  statusText: string;
7
12
  }>;
8
13
  export declare const loadResources: (customFetch: typeof fetch, requests: Map<string, ResourceRequest>) => Promise<{
9
14
  [k: string]: {
10
15
  ok: boolean;
11
- data: any;
16
+ data: string;
17
+ status: number;
18
+ statusText: string;
19
+ } | {
20
+ ok: boolean;
21
+ data: undefined;
12
22
  status: number;
13
23
  statusText: string;
14
24
  };
@@ -0,0 +1 @@
1
+ export {};