@webstudio-is/sdk 0.124.0 → 0.125.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.
package/lib/index.js CHANGED
@@ -32,13 +32,26 @@ var Assets = z.map(AssetId, Asset);
32
32
  // src/schema/pages.ts
33
33
  import { z as z2 } from "zod";
34
34
  var MIN_TITLE_LENGTH = 2;
35
+ var PageId = z2.string();
36
+ var FolderId = z2.string();
37
+ var FolderName = z2.string().refine((value) => value.trim() !== "", "Can't be empty");
38
+ var FolderSlug = z2.string().refine((slug) => slug !== "", "Can't be empty").refine((slug) => slug.includes("/") === false, "Can't contain a /").refine(
39
+ (path) => /^[-a-z0-9]*$/.test(path),
40
+ "Only a-z, 0-9 and - are allowed"
41
+ );
42
+ var Folder = z2.object({
43
+ id: FolderId,
44
+ name: FolderName,
45
+ slug: z2.string(),
46
+ children: z2.array(z2.union([FolderId, PageId]))
47
+ });
35
48
  var PageName = z2.string().refine((value) => value.trim() !== "", "Can't be empty");
36
49
  var PageTitle = z2.string().refine(
37
50
  (val) => val.length >= MIN_TITLE_LENGTH,
38
51
  `Minimum ${MIN_TITLE_LENGTH} characters required`
39
52
  );
40
53
  var commonPageFields = {
41
- id: z2.string(),
54
+ id: PageId,
42
55
  name: PageName,
43
56
  title: PageTitle,
44
57
  meta: z2.object({
@@ -95,26 +108,31 @@ var Pages = z2.object({
95
108
  pages: z2.array(Page).refine(
96
109
  (array) => new Set(array.map((page) => page.path)).size === array.length,
97
110
  "All paths must be unique"
98
- )
111
+ ),
112
+ folders: z2.array(Folder).refine((folders) => folders.length > 0, "Folders can't be empty")
99
113
  });
100
114
 
101
115
  // src/schema/instances.ts
102
116
  import { z as z3 } from "zod";
103
- var Text = z3.object({
117
+ var TextChild = z3.object({
104
118
  type: z3.literal("text"),
105
119
  value: z3.string()
106
120
  });
107
121
  var InstanceId = z3.string();
108
- var Id = z3.object({
122
+ var IdChild = z3.object({
109
123
  type: z3.literal("id"),
110
124
  value: InstanceId
111
125
  });
126
+ var ExpressionChild = z3.object({
127
+ type: z3.literal("expression"),
128
+ value: z3.string()
129
+ });
112
130
  var Instance = z3.object({
113
131
  type: z3.literal("instance"),
114
132
  id: InstanceId,
115
133
  component: z3.string(),
116
134
  label: z3.string().optional(),
117
- children: z3.array(z3.union([Id, Text]))
135
+ children: z3.array(z3.union([IdChild, TextChild, ExpressionChild]))
118
136
  });
119
137
  var Instances = z3.map(InstanceId, Instance);
120
138
 
@@ -463,9 +481,13 @@ export {
463
481
  DataSourceVariableValue,
464
482
  DataSources,
465
483
  Deployment,
484
+ ExpressionChild,
485
+ Folder,
486
+ FolderName,
487
+ FolderSlug,
466
488
  FontAsset,
467
489
  HomePagePath,
468
- Id,
490
+ IdChild,
469
491
  ImageAsset,
470
492
  ImageMeta,
471
493
  Instance,
@@ -484,7 +506,7 @@ export {
484
506
  StyleSourceSelections,
485
507
  StyleSources,
486
508
  Styles,
487
- Text,
509
+ TextChild,
488
510
  createScope,
489
511
  findTreeInstanceIds,
490
512
  findTreeInstanceIdsExcludingSlotDescendants,
@@ -2,27 +2,33 @@ import type { Instance } from "./schema/instances";
2
2
  export declare const findTreeInstanceIds: (instances: Map<string, {
3
3
  type: "instance";
4
4
  id: string;
5
- component: string;
6
5
  children: ({
7
6
  value: string;
8
7
  type: "text";
9
8
  } | {
10
9
  value: string;
11
10
  type: "id";
11
+ } | {
12
+ value: string;
13
+ type: "expression";
12
14
  })[];
15
+ component: string;
13
16
  label?: string | undefined;
14
17
  }>, rootInstanceId: Instance["id"]) => Set<string>;
15
18
  export declare const findTreeInstanceIdsExcludingSlotDescendants: (instances: Map<string, {
16
19
  type: "instance";
17
20
  id: string;
18
- component: string;
19
21
  children: ({
20
22
  value: string;
21
23
  type: "text";
22
24
  } | {
23
25
  value: string;
24
26
  type: "id";
27
+ } | {
28
+ value: string;
29
+ type: "expression";
25
30
  })[];
31
+ component: string;
26
32
  label?: string | undefined;
27
33
  }>, rootInstanceId: Instance["id"]) => Set<string>;
28
34
  export declare const parseComponentName: (componentName: string) => readonly [string | undefined, string];
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- export declare const Text: z.ZodObject<{
2
+ export declare const TextChild: z.ZodObject<{
3
3
  type: z.ZodLiteral<"text">;
4
4
  value: z.ZodString;
5
5
  }, "strip", z.ZodTypeAny, {
@@ -9,8 +9,8 @@ export declare const Text: z.ZodObject<{
9
9
  value: string;
10
10
  type: "text";
11
11
  }>;
12
- export type Text = z.infer<typeof Text>;
13
- export declare const Id: z.ZodObject<{
12
+ export type TextChild = z.infer<typeof TextChild>;
13
+ export declare const IdChild: z.ZodObject<{
14
14
  type: z.ZodLiteral<"id">;
15
15
  value: z.ZodString;
16
16
  }, "strip", z.ZodTypeAny, {
@@ -20,7 +20,18 @@ export declare const Id: z.ZodObject<{
20
20
  value: string;
21
21
  type: "id";
22
22
  }>;
23
- export type Id = z.infer<typeof Id>;
23
+ export type IdChild = z.infer<typeof IdChild>;
24
+ export declare const ExpressionChild: z.ZodObject<{
25
+ type: z.ZodLiteral<"expression">;
26
+ value: z.ZodString;
27
+ }, "strip", z.ZodTypeAny, {
28
+ value: string;
29
+ type: "expression";
30
+ }, {
31
+ value: string;
32
+ type: "expression";
33
+ }>;
34
+ export type ExpressionChild = z.infer<typeof ExpressionChild>;
24
35
  export declare const Instance: z.ZodObject<{
25
36
  type: z.ZodLiteral<"instance">;
26
37
  id: z.ZodString;
@@ -44,30 +55,45 @@ export declare const Instance: z.ZodObject<{
44
55
  }, {
45
56
  value: string;
46
57
  type: "text";
58
+ }>, z.ZodObject<{
59
+ type: z.ZodLiteral<"expression">;
60
+ value: z.ZodString;
61
+ }, "strip", z.ZodTypeAny, {
62
+ value: string;
63
+ type: "expression";
64
+ }, {
65
+ value: string;
66
+ type: "expression";
47
67
  }>]>, "many">;
48
68
  }, "strip", z.ZodTypeAny, {
49
69
  type: "instance";
50
70
  id: string;
51
- component: string;
52
71
  children: ({
53
72
  value: string;
54
73
  type: "text";
55
74
  } | {
56
75
  value: string;
57
76
  type: "id";
77
+ } | {
78
+ value: string;
79
+ type: "expression";
58
80
  })[];
81
+ component: string;
59
82
  label?: string | undefined;
60
83
  }, {
61
84
  type: "instance";
62
85
  id: string;
63
- component: string;
64
86
  children: ({
65
87
  value: string;
66
88
  type: "text";
67
89
  } | {
68
90
  value: string;
69
91
  type: "id";
92
+ } | {
93
+ value: string;
94
+ type: "expression";
70
95
  })[];
96
+ component: string;
71
97
  label?: string | undefined;
72
98
  }>;
73
99
  export type Instance = z.infer<typeof Instance>;
@@ -94,30 +120,45 @@ export declare const Instances: z.ZodMap<z.ZodString, z.ZodObject<{
94
120
  }, {
95
121
  value: string;
96
122
  type: "text";
123
+ }>, z.ZodObject<{
124
+ type: z.ZodLiteral<"expression">;
125
+ value: z.ZodString;
126
+ }, "strip", z.ZodTypeAny, {
127
+ value: string;
128
+ type: "expression";
129
+ }, {
130
+ value: string;
131
+ type: "expression";
97
132
  }>]>, "many">;
98
133
  }, "strip", z.ZodTypeAny, {
99
134
  type: "instance";
100
135
  id: string;
101
- component: string;
102
136
  children: ({
103
137
  value: string;
104
138
  type: "text";
105
139
  } | {
106
140
  value: string;
107
141
  type: "id";
142
+ } | {
143
+ value: string;
144
+ type: "expression";
108
145
  })[];
146
+ component: string;
109
147
  label?: string | undefined;
110
148
  }, {
111
149
  type: "instance";
112
150
  id: string;
113
- component: string;
114
151
  children: ({
115
152
  value: string;
116
153
  type: "text";
117
154
  } | {
118
155
  value: string;
119
156
  type: "id";
157
+ } | {
158
+ value: string;
159
+ type: "expression";
120
160
  })[];
161
+ component: string;
121
162
  label?: string | undefined;
122
163
  }>>;
123
164
  export type Instances = z.infer<typeof Instances>;
@@ -1,4 +1,23 @@
1
1
  import { z } from "zod";
2
+ export declare const FolderName: z.ZodEffects<z.ZodString, string, string>;
3
+ export declare const FolderSlug: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, string, string>;
4
+ export declare const Folder: z.ZodObject<{
5
+ id: z.ZodString;
6
+ name: z.ZodEffects<z.ZodString, string, string>;
7
+ slug: z.ZodString;
8
+ children: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodString]>, "many">;
9
+ }, "strip", z.ZodTypeAny, {
10
+ name: string;
11
+ id: string;
12
+ slug: string;
13
+ children: string[];
14
+ }, {
15
+ name: string;
16
+ id: string;
17
+ slug: string;
18
+ children: string[];
19
+ }>;
20
+ export type Folder = z.infer<typeof Folder>;
2
21
  export declare const PageName: z.ZodEffects<z.ZodString, string, string>;
3
22
  export declare const PageTitle: z.ZodEffects<z.ZodString, string, string>;
4
23
  export declare const HomePagePath: z.ZodEffects<z.ZodString, string, string>;
@@ -301,6 +320,32 @@ export declare const Pages: z.ZodObject<{
301
320
  rootInstanceId: string;
302
321
  pathVariableId?: string | undefined;
303
322
  }[]>;
323
+ folders: z.ZodEffects<z.ZodArray<z.ZodObject<{
324
+ id: z.ZodString;
325
+ name: z.ZodEffects<z.ZodString, string, string>;
326
+ slug: z.ZodString;
327
+ children: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodString]>, "many">;
328
+ }, "strip", z.ZodTypeAny, {
329
+ name: string;
330
+ id: string;
331
+ slug: string;
332
+ children: string[];
333
+ }, {
334
+ name: string;
335
+ id: string;
336
+ slug: string;
337
+ children: string[];
338
+ }>, "many">, {
339
+ name: string;
340
+ id: string;
341
+ slug: string;
342
+ children: string[];
343
+ }[], {
344
+ name: string;
345
+ id: string;
346
+ slug: string;
347
+ children: string[];
348
+ }[]>;
304
349
  }, "strip", z.ZodTypeAny, {
305
350
  homePage: {
306
351
  path: string;
@@ -338,6 +383,12 @@ export declare const Pages: z.ZodObject<{
338
383
  rootInstanceId: string;
339
384
  pathVariableId?: string | undefined;
340
385
  }[];
386
+ folders: {
387
+ name: string;
388
+ id: string;
389
+ slug: string;
390
+ children: string[];
391
+ }[];
341
392
  meta?: {
342
393
  siteName?: string | undefined;
343
394
  faviconAssetId?: string | undefined;
@@ -383,6 +434,12 @@ export declare const Pages: z.ZodObject<{
383
434
  rootInstanceId: string;
384
435
  pathVariableId?: string | undefined;
385
436
  }[];
437
+ folders: {
438
+ name: string;
439
+ id: string;
440
+ slug: string;
441
+ children: string[];
442
+ }[];
386
443
  meta?: {
387
444
  siteName?: string | undefined;
388
445
  faviconAssetId?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/sdk",
3
- "version": "0.124.0",
3
+ "version": "0.125.0",
4
4
  "description": "Webstudio project data schema",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -19,8 +19,8 @@
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
21
  "zod": "^3.21.4",
22
- "@webstudio-is/css-engine": "0.124.0",
23
- "@webstudio-is/fonts": "0.124.0"
22
+ "@webstudio-is/css-engine": "0.125.0",
23
+ "@webstudio-is/fonts": "0.125.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@jest/globals": "^29.7.0",