@webstudio-is/sdk 0.205.0 → 0.206.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.
@@ -19,18 +19,18 @@ import {
19
19
  // src/__generated__/normalize.css.ts
20
20
  var html = [
21
21
  { property: "display", value: { type: "keyword", value: "grid" } },
22
- { property: "minHeight", value: { type: "unit", unit: "%", value: 100 } },
22
+ { property: "min-height", value: { type: "unit", unit: "%", value: 100 } },
23
23
  {
24
- property: "fontFamily",
24
+ property: "font-family",
25
25
  value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
26
26
  },
27
- { property: "fontSize", value: { type: "unit", unit: "px", value: 16 } },
27
+ { property: "font-size", value: { type: "unit", unit: "px", value: 16 } },
28
28
  {
29
- property: "lineHeight",
29
+ property: "line-height",
30
30
  value: { type: "unit", unit: "number", value: 1.2 }
31
31
  },
32
32
  {
33
- property: "whiteSpaceCollapse",
33
+ property: "white-space-collapse",
34
34
  value: { type: "keyword", value: "preserve" }
35
35
  }
36
36
  ];
package/lib/index.js CHANGED
@@ -897,6 +897,13 @@ var WsEmbedTemplate = z15.lazy(
897
897
 
898
898
  // src/schema/component-meta.ts
899
899
  import { z as z16 } from "zod";
900
+ import { StyleValue as StyleValue4 } from "@webstudio-is/css-engine";
901
+ var PresetStyleDecl = z16.object({
902
+ // State selector, e.g. :hover
903
+ state: z16.optional(z16.string()),
904
+ property: z16.string(),
905
+ value: StyleValue4
906
+ });
900
907
  var WsComponentPropsMeta = z16.object({
901
908
  props: z16.record(PropMeta),
902
909
  // Props that will be always visible in properties panel.
@@ -948,9 +955,7 @@ var WsComponentMeta = z16.object({
948
955
  label: z16.optional(z16.string()),
949
956
  description: z16.string().optional(),
950
957
  icon: z16.string(),
951
- presetStyle: z16.optional(
952
- z16.record(z16.string(), z16.array(EmbedTemplateStyleDecl))
953
- ),
958
+ presetStyle: z16.optional(z16.record(z16.string(), z16.array(PresetStyleDecl))),
954
959
  states: z16.optional(z16.array(ComponentState)),
955
960
  template: z16.optional(WsEmbedTemplate),
956
961
  order: z16.number().optional()
@@ -968,18 +973,18 @@ import {
968
973
  // src/__generated__/normalize.css.ts
969
974
  var html = [
970
975
  { property: "display", value: { type: "keyword", value: "grid" } },
971
- { property: "minHeight", value: { type: "unit", unit: "%", value: 100 } },
976
+ { property: "min-height", value: { type: "unit", unit: "%", value: 100 } },
972
977
  {
973
- property: "fontFamily",
978
+ property: "font-family",
974
979
  value: { type: "fontFamily", value: ["Arial", "Roboto", "sans-serif"] }
975
980
  },
976
- { property: "fontSize", value: { type: "unit", unit: "px", value: 16 } },
981
+ { property: "font-size", value: { type: "unit", unit: "px", value: 16 } },
977
982
  {
978
- property: "lineHeight",
983
+ property: "line-height",
979
984
  value: { type: "unit", unit: "number", value: 1.2 }
980
985
  },
981
986
  {
982
- property: "whiteSpaceCollapse",
987
+ property: "white-space-collapse",
983
988
  value: { type: "keyword", value: "preserve" }
984
989
  }
985
990
  ];
@@ -1146,6 +1151,51 @@ var parseComponentName = (componentName) => {
1146
1151
  }
1147
1152
  return [namespace, name];
1148
1153
  };
1154
+ var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1155
+ const ancestors = /* @__PURE__ */ new Set();
1156
+ for (const meta of metas.values()) {
1157
+ if (meta.indexWithinAncestor !== void 0) {
1158
+ ancestors.add(meta.indexWithinAncestor);
1159
+ }
1160
+ }
1161
+ const indexes = /* @__PURE__ */ new Map();
1162
+ const traverseInstances2 = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
1163
+ const instance = instances2.get(instanceId);
1164
+ if (instance === void 0) {
1165
+ return;
1166
+ }
1167
+ const meta = metas.get(instance.component);
1168
+ if (ancestors.has(instance.component)) {
1169
+ latestIndexes2 = new Map(latestIndexes2);
1170
+ latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
1171
+ }
1172
+ if (instance.component === blockTemplateComponent) {
1173
+ latestIndexes2 = new Map(latestIndexes2);
1174
+ for (const key of latestIndexes2.keys()) {
1175
+ latestIndexes2.set(key, /* @__PURE__ */ new Map());
1176
+ }
1177
+ }
1178
+ if (meta?.indexWithinAncestor !== void 0) {
1179
+ const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
1180
+ if (ancestorIndexes) {
1181
+ let index = ancestorIndexes.get(instance.component) ?? -1;
1182
+ index += 1;
1183
+ ancestorIndexes.set(instance.component, index);
1184
+ indexes.set(instance.id, index);
1185
+ }
1186
+ }
1187
+ for (const child of instance.children) {
1188
+ if (child.type === "id") {
1189
+ traverseInstances2(instances2, child.value, latestIndexes2);
1190
+ }
1191
+ }
1192
+ };
1193
+ const latestIndexes = /* @__PURE__ */ new Map();
1194
+ for (const instanceId of rootIds) {
1195
+ traverseInstances2(instances, instanceId, latestIndexes);
1196
+ }
1197
+ return indexes;
1198
+ };
1149
1199
 
1150
1200
  // src/expression.ts
1151
1201
  import {
@@ -2090,6 +2140,7 @@ export {
2090
2140
  PageRedirect,
2091
2141
  PageTitle,
2092
2142
  Pages,
2143
+ PresetStyleDecl,
2093
2144
  ProjectNewRedirectPath,
2094
2145
  Prop,
2095
2146
  PropMeta,
@@ -2142,6 +2193,7 @@ export {
2142
2193
  generatePageMeta,
2143
2194
  generateResources,
2144
2195
  getExpressionIdentifiers,
2196
+ getIndexesWithinAncestors,
2145
2197
  getPagePath,
2146
2198
  getStaticSiteMapXml,
2147
2199
  getStyleDeclKey,
@@ -1,7 +1,7 @@
1
- import type { StyleProperty, StyleValue } from "@webstudio-is/css-engine";
1
+ import type { CssProperty, StyleValue } from "@webstudio-is/css-engine";
2
2
  type StyleDecl = {
3
3
  state?: string;
4
- property: StyleProperty;
4
+ property: CssProperty;
5
5
  value: StyleValue;
6
6
  };
7
7
  export declare const div: StyleDecl[];
@@ -1,5 +1,8 @@
1
+ import type { WsComponentMeta } from "./schema/component-meta";
1
2
  import type { Instance, Instances } from "./schema/instances";
2
3
  export declare const ROOT_INSTANCE_ID = ":root";
3
4
  export declare const findTreeInstanceIds: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
4
5
  export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Instances, rootInstanceId: Instance["id"]) => Set<string>;
5
6
  export declare const parseComponentName: (componentName: string) => readonly [string | undefined, string];
7
+ export type IndexesWithinAncestors = Map<Instance["id"], number>;
8
+ export declare const getIndexesWithinAncestors: (metas: Map<Instance["component"], WsComponentMeta>, instances: Instances, rootIds: Instance["id"][]) => IndexesWithinAncestors;