@webstudio-is/sdk 0.189.0 → 0.191.4
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/package.json +13 -9
- package/lib/__generated__/normalize.css.js +0 -505
- package/lib/index.js +0 -1377
- package/lib/types/__generated__/normalize.css.d.ts +0 -57
- package/lib/types/expression.d.ts +0 -53
- package/lib/types/expression.test.d.ts +0 -1
- package/lib/types/form-fields.d.ts +0 -8
- package/lib/types/index.d.ts +0 -22
- package/lib/types/instances-utils.d.ts +0 -5
- package/lib/types/instances-utils.test.d.ts +0 -1
- package/lib/types/jsx.d.ts +0 -151
- package/lib/types/jsx.test.d.ts +0 -1
- package/lib/types/page-meta-generator.d.ts +0 -24
- package/lib/types/page-meta-generator.test.d.ts +0 -1
- package/lib/types/page-utils.d.ts +0 -24
- package/lib/types/page-utils.test.d.ts +0 -1
- package/lib/types/resource-loader.d.ts +0 -25
- package/lib/types/resource-loader.test.d.ts +0 -1
- package/lib/types/resources-generator.d.ts +0 -22
- package/lib/types/resources-generator.test.d.ts +0 -1
- package/lib/types/schema/assets.d.ts +0 -527
- package/lib/types/schema/breakpoints.d.ts +0 -56
- package/lib/types/schema/data-sources.d.ts +0 -303
- package/lib/types/schema/deployment.d.ts +0 -41
- package/lib/types/schema/instances.d.ts +0 -208
- package/lib/types/schema/pages.d.ts +0 -675
- package/lib/types/schema/props.d.ts +0 -549
- package/lib/types/schema/resources.d.ts +0 -126
- package/lib/types/schema/style-source-selections.d.ts +0 -23
- package/lib/types/schema/style-sources.d.ts +0 -62
- package/lib/types/schema/styles.d.ts +0 -2629
- package/lib/types/schema/webstudio.d.ts +0 -2374
- package/lib/types/scope.d.ts +0 -16
- package/lib/types/scope.test.d.ts +0 -1
- package/lib/types/testing.d.ts +0 -1
- package/lib/types/to-string.d.ts +0 -2
- package/lib/types/url-pattern.d.ts +0 -2
- package/lib/types/url-pattern.test.d.ts +0 -1
package/lib/index.js
DELETED
|
@@ -1,1377 +0,0 @@
|
|
|
1
|
-
// src/schema/assets.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { FontFormat, FontMeta } from "@webstudio-is/fonts";
|
|
4
|
-
var AssetId = z.string();
|
|
5
|
-
var baseAsset = {
|
|
6
|
-
id: AssetId,
|
|
7
|
-
projectId: z.string(),
|
|
8
|
-
size: z.number(),
|
|
9
|
-
name: z.string(),
|
|
10
|
-
description: z.union([z.string(), z.null()]),
|
|
11
|
-
createdAt: z.string()
|
|
12
|
-
};
|
|
13
|
-
var FontAsset = z.object({
|
|
14
|
-
...baseAsset,
|
|
15
|
-
format: FontFormat,
|
|
16
|
-
meta: FontMeta,
|
|
17
|
-
type: z.literal("font")
|
|
18
|
-
});
|
|
19
|
-
var ImageMeta = z.object({
|
|
20
|
-
width: z.number(),
|
|
21
|
-
height: z.number()
|
|
22
|
-
});
|
|
23
|
-
var ImageAsset = z.object({
|
|
24
|
-
...baseAsset,
|
|
25
|
-
format: z.string(),
|
|
26
|
-
meta: ImageMeta,
|
|
27
|
-
type: z.literal("image")
|
|
28
|
-
});
|
|
29
|
-
var Asset = z.union([FontAsset, ImageAsset]);
|
|
30
|
-
var Assets = z.map(AssetId, Asset);
|
|
31
|
-
|
|
32
|
-
// src/schema/pages.ts
|
|
33
|
-
import { z as z2 } from "zod";
|
|
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 Slug = z2.string().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: Slug,
|
|
46
|
-
children: z2.array(z2.union([FolderId, PageId]))
|
|
47
|
-
});
|
|
48
|
-
var PageName = z2.string().refine((value) => value.trim() !== "", "Can't be empty");
|
|
49
|
-
var PageTitle = z2.string().refine(
|
|
50
|
-
(val) => val.length >= MIN_TITLE_LENGTH,
|
|
51
|
-
`Minimum ${MIN_TITLE_LENGTH} characters required`
|
|
52
|
-
);
|
|
53
|
-
var documentTypes = ["html", "xml"];
|
|
54
|
-
var commonPageFields = {
|
|
55
|
-
id: PageId,
|
|
56
|
-
name: PageName,
|
|
57
|
-
title: PageTitle,
|
|
58
|
-
history: z2.optional(z2.array(z2.string())),
|
|
59
|
-
rootInstanceId: z2.string(),
|
|
60
|
-
systemDataSourceId: z2.string(),
|
|
61
|
-
meta: z2.object({
|
|
62
|
-
description: z2.string().optional(),
|
|
63
|
-
title: z2.string().optional(),
|
|
64
|
-
excludePageFromSearch: z2.string().optional(),
|
|
65
|
-
language: z2.string().optional(),
|
|
66
|
-
socialImageAssetId: z2.string().optional(),
|
|
67
|
-
socialImageUrl: z2.string().optional(),
|
|
68
|
-
status: z2.string().optional(),
|
|
69
|
-
redirect: z2.string().optional(),
|
|
70
|
-
documentType: z2.optional(z2.enum(documentTypes)),
|
|
71
|
-
custom: z2.array(
|
|
72
|
-
z2.object({
|
|
73
|
-
property: z2.string(),
|
|
74
|
-
content: z2.string()
|
|
75
|
-
})
|
|
76
|
-
).optional()
|
|
77
|
-
}),
|
|
78
|
-
marketplace: z2.optional(
|
|
79
|
-
z2.object({
|
|
80
|
-
include: z2.optional(z2.boolean()),
|
|
81
|
-
category: z2.optional(z2.string()),
|
|
82
|
-
thumbnailAssetId: z2.optional(z2.string())
|
|
83
|
-
})
|
|
84
|
-
)
|
|
85
|
-
};
|
|
86
|
-
var HomePagePath = z2.string().refine((path) => path === "", "Home page path must be empty");
|
|
87
|
-
var HomePage = z2.object({
|
|
88
|
-
...commonPageFields,
|
|
89
|
-
path: HomePagePath
|
|
90
|
-
});
|
|
91
|
-
var PagePath = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine((path) => path === "" || path.startsWith("/"), "Must start with a /").refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
|
|
92
|
-
(path) => /^[-_a-z0-9*:?\\/.]*$/.test(path),
|
|
93
|
-
"Only a-z, 0-9, -, _, /, :, ?, . and * are allowed"
|
|
94
|
-
).refine(
|
|
95
|
-
// We use /s for our system stuff like /s/css or /s/uploads
|
|
96
|
-
(path) => path !== "/s" && path.startsWith("/s/") === false,
|
|
97
|
-
"/s prefix is reserved for the system"
|
|
98
|
-
).refine(
|
|
99
|
-
// Remix serves build artefacts like JS bundles from /build
|
|
100
|
-
// And we cannot customize it due to bug in Remix: https://github.com/remix-run/remix/issues/2933
|
|
101
|
-
(path) => path !== "/build" && path.startsWith("/build/") === false,
|
|
102
|
-
"/build prefix is reserved for the system"
|
|
103
|
-
);
|
|
104
|
-
var Page = z2.object({
|
|
105
|
-
...commonPageFields,
|
|
106
|
-
path: PagePath
|
|
107
|
-
});
|
|
108
|
-
var ProjectMeta = z2.object({
|
|
109
|
-
// All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
|
|
110
|
-
siteName: z2.string().optional(),
|
|
111
|
-
contactEmail: z2.string().optional(),
|
|
112
|
-
faviconAssetId: z2.string().optional(),
|
|
113
|
-
code: z2.string().optional()
|
|
114
|
-
});
|
|
115
|
-
var ProjectNewRedirectPath = PagePath.or(
|
|
116
|
-
z2.string().refine((data) => {
|
|
117
|
-
if (data === "/") {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
new URL(data);
|
|
122
|
-
return true;
|
|
123
|
-
} catch {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
}, "Must be a valid URL")
|
|
127
|
-
);
|
|
128
|
-
var PageRedirect = z2.object({
|
|
129
|
-
old: PagePath,
|
|
130
|
-
new: ProjectNewRedirectPath,
|
|
131
|
-
status: z2.enum(["301", "302"]).optional()
|
|
132
|
-
});
|
|
133
|
-
var CompilerSettings = z2.object({
|
|
134
|
-
// All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
|
|
135
|
-
atomicStyles: z2.boolean().optional()
|
|
136
|
-
});
|
|
137
|
-
var Pages = z2.object({
|
|
138
|
-
meta: ProjectMeta.optional(),
|
|
139
|
-
compiler: CompilerSettings.optional(),
|
|
140
|
-
redirects: z2.array(PageRedirect).optional(),
|
|
141
|
-
homePage: HomePage,
|
|
142
|
-
pages: z2.array(Page),
|
|
143
|
-
folders: z2.array(Folder).refine((folders) => folders.length > 0, "Folders can't be empty")
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// src/schema/instances.ts
|
|
147
|
-
import { z as z3 } from "zod";
|
|
148
|
-
var TextChild = z3.object({
|
|
149
|
-
type: z3.literal("text"),
|
|
150
|
-
value: z3.string(),
|
|
151
|
-
placeholder: z3.boolean().optional()
|
|
152
|
-
});
|
|
153
|
-
var InstanceId = z3.string();
|
|
154
|
-
var IdChild = z3.object({
|
|
155
|
-
type: z3.literal("id"),
|
|
156
|
-
value: InstanceId
|
|
157
|
-
});
|
|
158
|
-
var ExpressionChild = z3.object({
|
|
159
|
-
type: z3.literal("expression"),
|
|
160
|
-
value: z3.string()
|
|
161
|
-
});
|
|
162
|
-
var InstanceChild = z3.union([IdChild, TextChild, ExpressionChild]);
|
|
163
|
-
var Instance = z3.object({
|
|
164
|
-
type: z3.literal("instance"),
|
|
165
|
-
id: InstanceId,
|
|
166
|
-
component: z3.string(),
|
|
167
|
-
label: z3.string().optional(),
|
|
168
|
-
children: z3.array(InstanceChild)
|
|
169
|
-
});
|
|
170
|
-
var Instances = z3.map(InstanceId, Instance);
|
|
171
|
-
|
|
172
|
-
// src/schema/data-sources.ts
|
|
173
|
-
import { z as z4 } from "zod";
|
|
174
|
-
var DataSourceId = z4.string();
|
|
175
|
-
var DataSourceVariableValue = z4.union([
|
|
176
|
-
z4.object({
|
|
177
|
-
type: z4.literal("number"),
|
|
178
|
-
// initial value of variable store
|
|
179
|
-
value: z4.number()
|
|
180
|
-
}),
|
|
181
|
-
z4.object({
|
|
182
|
-
type: z4.literal("string"),
|
|
183
|
-
value: z4.string()
|
|
184
|
-
}),
|
|
185
|
-
z4.object({
|
|
186
|
-
type: z4.literal("boolean"),
|
|
187
|
-
value: z4.boolean()
|
|
188
|
-
}),
|
|
189
|
-
z4.object({
|
|
190
|
-
type: z4.literal("string[]"),
|
|
191
|
-
value: z4.array(z4.string())
|
|
192
|
-
}),
|
|
193
|
-
z4.object({
|
|
194
|
-
type: z4.literal("json"),
|
|
195
|
-
value: z4.unknown()
|
|
196
|
-
})
|
|
197
|
-
]);
|
|
198
|
-
var DataSource = z4.union([
|
|
199
|
-
z4.object({
|
|
200
|
-
type: z4.literal("variable"),
|
|
201
|
-
id: DataSourceId,
|
|
202
|
-
scopeInstanceId: z4.optional(z4.string()),
|
|
203
|
-
name: z4.string(),
|
|
204
|
-
value: DataSourceVariableValue
|
|
205
|
-
}),
|
|
206
|
-
z4.object({
|
|
207
|
-
type: z4.literal("parameter"),
|
|
208
|
-
id: DataSourceId,
|
|
209
|
-
scopeInstanceId: z4.optional(z4.string()),
|
|
210
|
-
name: z4.string()
|
|
211
|
-
}),
|
|
212
|
-
z4.object({
|
|
213
|
-
type: z4.literal("resource"),
|
|
214
|
-
id: DataSourceId,
|
|
215
|
-
scopeInstanceId: z4.optional(z4.string()),
|
|
216
|
-
name: z4.string(),
|
|
217
|
-
resourceId: z4.string()
|
|
218
|
-
})
|
|
219
|
-
]);
|
|
220
|
-
var DataSources = z4.map(DataSourceId, DataSource);
|
|
221
|
-
|
|
222
|
-
// src/schema/resources.ts
|
|
223
|
-
import { z as z5 } from "zod";
|
|
224
|
-
var ResourceId = z5.string();
|
|
225
|
-
var Method = z5.union([
|
|
226
|
-
z5.literal("get"),
|
|
227
|
-
z5.literal("post"),
|
|
228
|
-
z5.literal("put"),
|
|
229
|
-
z5.literal("delete")
|
|
230
|
-
]);
|
|
231
|
-
var Header = z5.object({
|
|
232
|
-
name: z5.string(),
|
|
233
|
-
// expression
|
|
234
|
-
value: z5.string()
|
|
235
|
-
});
|
|
236
|
-
var Resource = z5.object({
|
|
237
|
-
id: ResourceId,
|
|
238
|
-
name: z5.string(),
|
|
239
|
-
control: z5.optional(z5.union([z5.literal("system"), z5.literal("graphql")])),
|
|
240
|
-
method: Method,
|
|
241
|
-
// expression
|
|
242
|
-
url: z5.string(),
|
|
243
|
-
headers: z5.array(Header),
|
|
244
|
-
// expression
|
|
245
|
-
body: z5.optional(z5.string())
|
|
246
|
-
});
|
|
247
|
-
var ResourceRequest = z5.object({
|
|
248
|
-
id: ResourceId,
|
|
249
|
-
name: z5.string(),
|
|
250
|
-
method: Method,
|
|
251
|
-
url: z5.string(),
|
|
252
|
-
headers: z5.array(Header),
|
|
253
|
-
body: z5.optional(z5.unknown())
|
|
254
|
-
});
|
|
255
|
-
var Resources = z5.map(ResourceId, Resource);
|
|
256
|
-
var LOCAL_RESOURCE_PREFIX = "$resources";
|
|
257
|
-
var isLocalResource = (pathname, resourceName) => {
|
|
258
|
-
const segments = pathname.split("/").filter(Boolean);
|
|
259
|
-
if (resourceName === void 0) {
|
|
260
|
-
return segments[0] === LOCAL_RESOURCE_PREFIX;
|
|
261
|
-
}
|
|
262
|
-
return segments.join("/") === `${LOCAL_RESOURCE_PREFIX}/${resourceName}`;
|
|
263
|
-
};
|
|
264
|
-
var sitemapResourceUrl = `/${LOCAL_RESOURCE_PREFIX}/sitemap.xml`;
|
|
265
|
-
|
|
266
|
-
// src/schema/props.ts
|
|
267
|
-
import { z as z6 } from "zod";
|
|
268
|
-
var PropId = z6.string();
|
|
269
|
-
var baseProp = {
|
|
270
|
-
id: PropId,
|
|
271
|
-
instanceId: z6.string(),
|
|
272
|
-
name: z6.string(),
|
|
273
|
-
required: z6.optional(z6.boolean())
|
|
274
|
-
};
|
|
275
|
-
var Prop = z6.union([
|
|
276
|
-
z6.object({
|
|
277
|
-
...baseProp,
|
|
278
|
-
type: z6.literal("number"),
|
|
279
|
-
value: z6.number()
|
|
280
|
-
}),
|
|
281
|
-
z6.object({
|
|
282
|
-
...baseProp,
|
|
283
|
-
type: z6.literal("string"),
|
|
284
|
-
value: z6.string()
|
|
285
|
-
}),
|
|
286
|
-
z6.object({
|
|
287
|
-
...baseProp,
|
|
288
|
-
type: z6.literal("boolean"),
|
|
289
|
-
value: z6.boolean()
|
|
290
|
-
}),
|
|
291
|
-
z6.object({
|
|
292
|
-
...baseProp,
|
|
293
|
-
type: z6.literal("json"),
|
|
294
|
-
value: z6.unknown()
|
|
295
|
-
}),
|
|
296
|
-
z6.object({
|
|
297
|
-
...baseProp,
|
|
298
|
-
type: z6.literal("asset"),
|
|
299
|
-
value: z6.string()
|
|
300
|
-
// asset id
|
|
301
|
-
}),
|
|
302
|
-
z6.object({
|
|
303
|
-
...baseProp,
|
|
304
|
-
type: z6.literal("page"),
|
|
305
|
-
value: z6.union([
|
|
306
|
-
z6.string(),
|
|
307
|
-
// page id
|
|
308
|
-
z6.object({
|
|
309
|
-
pageId: z6.string(),
|
|
310
|
-
instanceId: z6.string()
|
|
311
|
-
})
|
|
312
|
-
])
|
|
313
|
-
}),
|
|
314
|
-
z6.object({
|
|
315
|
-
...baseProp,
|
|
316
|
-
type: z6.literal("string[]"),
|
|
317
|
-
value: z6.array(z6.string())
|
|
318
|
-
}),
|
|
319
|
-
z6.object({
|
|
320
|
-
...baseProp,
|
|
321
|
-
type: z6.literal("parameter"),
|
|
322
|
-
// data source id
|
|
323
|
-
value: z6.string()
|
|
324
|
-
}),
|
|
325
|
-
z6.object({
|
|
326
|
-
...baseProp,
|
|
327
|
-
type: z6.literal("resource"),
|
|
328
|
-
// resource id
|
|
329
|
-
value: z6.string()
|
|
330
|
-
}),
|
|
331
|
-
z6.object({
|
|
332
|
-
...baseProp,
|
|
333
|
-
type: z6.literal("expression"),
|
|
334
|
-
// expression code
|
|
335
|
-
value: z6.string()
|
|
336
|
-
}),
|
|
337
|
-
z6.object({
|
|
338
|
-
...baseProp,
|
|
339
|
-
type: z6.literal("action"),
|
|
340
|
-
value: z6.array(
|
|
341
|
-
z6.object({
|
|
342
|
-
type: z6.literal("execute"),
|
|
343
|
-
args: z6.array(z6.string()),
|
|
344
|
-
code: z6.string()
|
|
345
|
-
})
|
|
346
|
-
)
|
|
347
|
-
})
|
|
348
|
-
]);
|
|
349
|
-
var Props = z6.map(PropId, Prop);
|
|
350
|
-
|
|
351
|
-
// src/schema/breakpoints.ts
|
|
352
|
-
import { z as z7 } from "zod";
|
|
353
|
-
var BreakpointId = z7.string();
|
|
354
|
-
var Breakpoint = z7.object({
|
|
355
|
-
id: BreakpointId,
|
|
356
|
-
label: z7.string(),
|
|
357
|
-
minWidth: z7.number().optional(),
|
|
358
|
-
maxWidth: z7.number().optional()
|
|
359
|
-
}).refine(({ minWidth, maxWidth }) => {
|
|
360
|
-
return (
|
|
361
|
-
// Either min or max width have to be defined
|
|
362
|
-
minWidth !== void 0 && maxWidth === void 0 || minWidth === void 0 && maxWidth !== void 0 || // This is a base breakpoint
|
|
363
|
-
minWidth === void 0 && maxWidth === void 0
|
|
364
|
-
);
|
|
365
|
-
}, "Either minWidth or maxWidth should be defined");
|
|
366
|
-
var Breakpoints = z7.map(BreakpointId, Breakpoint);
|
|
367
|
-
var initialBreakpoints = [
|
|
368
|
-
{ id: "placeholder", label: "Base" },
|
|
369
|
-
{ id: "placeholder", label: "Tablet", maxWidth: 991 },
|
|
370
|
-
{ id: "placeholder", label: "Mobile landscape", maxWidth: 767 },
|
|
371
|
-
{ id: "placeholder", label: "Mobile portrait", maxWidth: 479 }
|
|
372
|
-
];
|
|
373
|
-
|
|
374
|
-
// src/schema/style-sources.ts
|
|
375
|
-
import { z as z8 } from "zod";
|
|
376
|
-
var StyleSourceId = z8.string();
|
|
377
|
-
var StyleSourceToken = z8.object({
|
|
378
|
-
type: z8.literal("token"),
|
|
379
|
-
id: StyleSourceId,
|
|
380
|
-
name: z8.string()
|
|
381
|
-
});
|
|
382
|
-
var StyleSourceLocal = z8.object({
|
|
383
|
-
type: z8.literal("local"),
|
|
384
|
-
id: StyleSourceId
|
|
385
|
-
});
|
|
386
|
-
var StyleSource = z8.union([StyleSourceToken, StyleSourceLocal]);
|
|
387
|
-
var StyleSources = z8.map(StyleSourceId, StyleSource);
|
|
388
|
-
|
|
389
|
-
// src/schema/style-source-selections.ts
|
|
390
|
-
import { z as z9 } from "zod";
|
|
391
|
-
var InstanceId2 = z9.string();
|
|
392
|
-
var StyleSourceId2 = z9.string();
|
|
393
|
-
var StyleSourceSelection = z9.object({
|
|
394
|
-
instanceId: InstanceId2,
|
|
395
|
-
values: z9.array(StyleSourceId2)
|
|
396
|
-
});
|
|
397
|
-
var StyleSourceSelections = z9.map(InstanceId2, StyleSourceSelection);
|
|
398
|
-
|
|
399
|
-
// src/schema/styles.ts
|
|
400
|
-
import { z as z10 } from "zod";
|
|
401
|
-
import { StyleValue } from "@webstudio-is/css-engine";
|
|
402
|
-
var StyleDeclRaw = z10.object({
|
|
403
|
-
styleSourceId: z10.string(),
|
|
404
|
-
breakpointId: z10.string(),
|
|
405
|
-
state: z10.optional(z10.string()),
|
|
406
|
-
// @todo can't figure out how to make property to be enum
|
|
407
|
-
property: z10.string(),
|
|
408
|
-
value: StyleValue,
|
|
409
|
-
listed: z10.boolean().optional()
|
|
410
|
-
});
|
|
411
|
-
var StyleDecl = StyleDeclRaw;
|
|
412
|
-
var getStyleDeclKey = (styleDecl) => {
|
|
413
|
-
return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
|
|
414
|
-
};
|
|
415
|
-
var Styles = z10.map(z10.string(), StyleDecl);
|
|
416
|
-
|
|
417
|
-
// src/schema/deployment.ts
|
|
418
|
-
import { z as z11 } from "zod";
|
|
419
|
-
var Templates = z11.enum([
|
|
420
|
-
"vanilla",
|
|
421
|
-
"vercel",
|
|
422
|
-
"netlify-functions",
|
|
423
|
-
"netlify-edge-functions",
|
|
424
|
-
"ssg",
|
|
425
|
-
"ssg-netlify",
|
|
426
|
-
"ssg-vercel"
|
|
427
|
-
]);
|
|
428
|
-
var Deployment = z11.union([
|
|
429
|
-
z11.object({
|
|
430
|
-
destination: z11.literal("static"),
|
|
431
|
-
name: z11.string(),
|
|
432
|
-
assetsDomain: z11.string(),
|
|
433
|
-
// Must be validated very strictly
|
|
434
|
-
templates: z11.array(Templates)
|
|
435
|
-
}),
|
|
436
|
-
z11.object({
|
|
437
|
-
destination: z11.literal("saas").optional(),
|
|
438
|
-
domains: z11.array(z11.string()),
|
|
439
|
-
assetsDomain: z11.string().optional(),
|
|
440
|
-
/**
|
|
441
|
-
* @deprecated This field is deprecated, use `domains` instead.
|
|
442
|
-
*/
|
|
443
|
-
projectDomain: z11.string().optional(),
|
|
444
|
-
excludeWstdDomainFromSearch: z11.boolean().optional()
|
|
445
|
-
})
|
|
446
|
-
]);
|
|
447
|
-
|
|
448
|
-
// src/schema/webstudio.ts
|
|
449
|
-
import { z as z12 } from "zod";
|
|
450
|
-
var WebstudioFragment = z12.object({
|
|
451
|
-
children: z12.array(InstanceChild),
|
|
452
|
-
instances: z12.array(Instance),
|
|
453
|
-
assets: z12.array(Asset),
|
|
454
|
-
dataSources: z12.array(DataSource),
|
|
455
|
-
resources: z12.array(Resource),
|
|
456
|
-
props: z12.array(Prop),
|
|
457
|
-
breakpoints: z12.array(Breakpoint),
|
|
458
|
-
styleSourceSelections: z12.array(StyleSourceSelection),
|
|
459
|
-
styleSources: z12.array(StyleSource),
|
|
460
|
-
styles: z12.array(StyleDecl)
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
// src/instances-utils.ts
|
|
464
|
-
var ROOT_INSTANCE_ID = ":root";
|
|
465
|
-
var traverseInstances = (instances, instanceId, callback) => {
|
|
466
|
-
const instance = instances.get(instanceId);
|
|
467
|
-
if (instance === void 0) {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
const skipTraversingChildren = callback(instance);
|
|
471
|
-
if (skipTraversingChildren === false) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
for (const child of instance.children) {
|
|
475
|
-
if (child.type === "id") {
|
|
476
|
-
traverseInstances(instances, child.value, callback);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
var findTreeInstanceIds = (instances, rootInstanceId) => {
|
|
481
|
-
const ids = /* @__PURE__ */ new Set([rootInstanceId]);
|
|
482
|
-
traverseInstances(instances, rootInstanceId, (instance) => {
|
|
483
|
-
ids.add(instance.id);
|
|
484
|
-
});
|
|
485
|
-
return ids;
|
|
486
|
-
};
|
|
487
|
-
var findTreeInstanceIdsExcludingSlotDescendants = (instances, rootInstanceId) => {
|
|
488
|
-
const ids = /* @__PURE__ */ new Set([rootInstanceId]);
|
|
489
|
-
traverseInstances(instances, rootInstanceId, (instance) => {
|
|
490
|
-
ids.add(instance.id);
|
|
491
|
-
if (instance.component === "Slot") {
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
return ids;
|
|
496
|
-
};
|
|
497
|
-
var parseComponentName = (componentName) => {
|
|
498
|
-
const parts = componentName.split(":");
|
|
499
|
-
let namespace;
|
|
500
|
-
let name;
|
|
501
|
-
if (parts.length === 1) {
|
|
502
|
-
[name] = parts;
|
|
503
|
-
} else {
|
|
504
|
-
[namespace, name] = parts;
|
|
505
|
-
}
|
|
506
|
-
return [namespace, name];
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
// src/expression.ts
|
|
510
|
-
import { parseExpressionAt } from "acorn";
|
|
511
|
-
import { simple } from "acorn-walk";
|
|
512
|
-
var lintExpression = ({
|
|
513
|
-
expression,
|
|
514
|
-
availableVariables = /* @__PURE__ */ new Set(),
|
|
515
|
-
allowAssignment = false
|
|
516
|
-
}) => {
|
|
517
|
-
const diagnostics = [];
|
|
518
|
-
const addError = (message) => {
|
|
519
|
-
return (node) => {
|
|
520
|
-
diagnostics.push({
|
|
521
|
-
// tune error position after wrapping expression with parentheses
|
|
522
|
-
from: node.start - 1,
|
|
523
|
-
to: node.end - 1,
|
|
524
|
-
severity: "error",
|
|
525
|
-
message
|
|
526
|
-
});
|
|
527
|
-
};
|
|
528
|
-
};
|
|
529
|
-
if (expression.trim().length === 0) {
|
|
530
|
-
diagnostics.push({
|
|
531
|
-
from: 0,
|
|
532
|
-
to: 0,
|
|
533
|
-
severity: "error",
|
|
534
|
-
message: "Expression cannot be empty"
|
|
535
|
-
});
|
|
536
|
-
return diagnostics;
|
|
537
|
-
}
|
|
538
|
-
try {
|
|
539
|
-
const root = parseExpressionAt(`(${expression})`, 0, {
|
|
540
|
-
ecmaVersion: "latest",
|
|
541
|
-
// support parsing import to forbid explicitly
|
|
542
|
-
sourceType: "module"
|
|
543
|
-
});
|
|
544
|
-
simple(root, {
|
|
545
|
-
Identifier(node) {
|
|
546
|
-
if (availableVariables.has(node.name) === false) {
|
|
547
|
-
addError(`"${node.name}" is not defined in the scope`)(node);
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
Literal() {
|
|
551
|
-
},
|
|
552
|
-
ArrayExpression() {
|
|
553
|
-
},
|
|
554
|
-
ObjectExpression() {
|
|
555
|
-
},
|
|
556
|
-
UnaryExpression() {
|
|
557
|
-
},
|
|
558
|
-
BinaryExpression() {
|
|
559
|
-
},
|
|
560
|
-
LogicalExpression() {
|
|
561
|
-
},
|
|
562
|
-
MemberExpression() {
|
|
563
|
-
},
|
|
564
|
-
ConditionalExpression() {
|
|
565
|
-
},
|
|
566
|
-
TemplateLiteral() {
|
|
567
|
-
},
|
|
568
|
-
ChainExpression() {
|
|
569
|
-
},
|
|
570
|
-
ParenthesizedExpression() {
|
|
571
|
-
},
|
|
572
|
-
AssignmentExpression(node) {
|
|
573
|
-
if (allowAssignment === false) {
|
|
574
|
-
addError("Assignment is supported only inside actions")(node);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
simple(node.left, {
|
|
578
|
-
Identifier(node2) {
|
|
579
|
-
if (availableVariables.has(node2.name) === false) {
|
|
580
|
-
addError(`"${node2.name}" is not defined in the scope`)(node2);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
},
|
|
585
|
-
// parser forbids to yield inside module
|
|
586
|
-
YieldExpression() {
|
|
587
|
-
},
|
|
588
|
-
ThisExpression: addError(`"this" keyword is not supported`),
|
|
589
|
-
FunctionExpression: addError("Functions are not supported"),
|
|
590
|
-
UpdateExpression: addError("Increment and decrement are not supported"),
|
|
591
|
-
CallExpression: addError("Functions are not supported"),
|
|
592
|
-
NewExpression: addError("Classes are not supported"),
|
|
593
|
-
SequenceExpression: addError(`Only single expression is supported`),
|
|
594
|
-
ArrowFunctionExpression: addError("Functions are not supported"),
|
|
595
|
-
TaggedTemplateExpression: addError("Tagged template is not supported"),
|
|
596
|
-
ClassExpression: addError("Classes are not supported"),
|
|
597
|
-
MetaProperty: addError("Imports are not supported"),
|
|
598
|
-
AwaitExpression: addError(`"await" keyword is not supported`),
|
|
599
|
-
ImportExpression: addError("Imports are not supported")
|
|
600
|
-
});
|
|
601
|
-
} catch (error) {
|
|
602
|
-
const castedError = error;
|
|
603
|
-
diagnostics.push({
|
|
604
|
-
// tune error position after wrapping expression with parentheses
|
|
605
|
-
from: castedError.pos - 1,
|
|
606
|
-
to: castedError.pos - 1,
|
|
607
|
-
severity: "error",
|
|
608
|
-
// trim auto generated error location
|
|
609
|
-
// to not conflict with tuned position
|
|
610
|
-
message: castedError.message.replaceAll(/\s+\(\d+:\d+\)$/g, "")
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
return diagnostics;
|
|
614
|
-
};
|
|
615
|
-
var isLiteralNode = (node) => {
|
|
616
|
-
if (node.type === "Literal") {
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
if (node.type === "ArrayExpression") {
|
|
620
|
-
return node.elements.every((node2) => {
|
|
621
|
-
if (node2 === null || node2.type === "SpreadElement") {
|
|
622
|
-
return false;
|
|
623
|
-
}
|
|
624
|
-
return isLiteralNode(node2);
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
if (node.type === "ObjectExpression") {
|
|
628
|
-
return node.properties.every((property) => {
|
|
629
|
-
if (property.type === "SpreadElement") {
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
const key = property.key;
|
|
633
|
-
const isIdentifierKey = key.type === "Identifier" && property.computed === false;
|
|
634
|
-
const isLiteralKey = key.type === "Literal";
|
|
635
|
-
return (isLiteralKey || isIdentifierKey) && isLiteralNode(property.value);
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
return false;
|
|
639
|
-
};
|
|
640
|
-
var isLiteralExpression = (expression) => {
|
|
641
|
-
try {
|
|
642
|
-
const node = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
|
|
643
|
-
return isLiteralNode(node);
|
|
644
|
-
} catch {
|
|
645
|
-
return false;
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
var getExpressionIdentifiers = (expression) => {
|
|
649
|
-
const identifiers2 = /* @__PURE__ */ new Set();
|
|
650
|
-
try {
|
|
651
|
-
const root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
|
|
652
|
-
simple(root, {
|
|
653
|
-
Identifier: (node) => identifiers2.add(node.name),
|
|
654
|
-
AssignmentExpression(node) {
|
|
655
|
-
simple(node.left, {
|
|
656
|
-
Identifier: (node2) => identifiers2.add(node2.name)
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
} catch {
|
|
661
|
-
}
|
|
662
|
-
return identifiers2;
|
|
663
|
-
};
|
|
664
|
-
var transpileExpression = ({
|
|
665
|
-
expression,
|
|
666
|
-
executable = false,
|
|
667
|
-
replaceVariable
|
|
668
|
-
}) => {
|
|
669
|
-
let root;
|
|
670
|
-
try {
|
|
671
|
-
root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
|
|
672
|
-
} catch (error) {
|
|
673
|
-
const message = error.message;
|
|
674
|
-
throw Error(`${message} in ${JSON.stringify(expression)}`);
|
|
675
|
-
}
|
|
676
|
-
const replacements = [];
|
|
677
|
-
const replaceIdentifier = (node, assignee) => {
|
|
678
|
-
const newName = replaceVariable?.(node.name, assignee);
|
|
679
|
-
if (newName) {
|
|
680
|
-
replacements.push([node.start, node.end, newName]);
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
simple(root, {
|
|
684
|
-
Identifier: (node) => replaceIdentifier(node, false),
|
|
685
|
-
AssignmentExpression(node) {
|
|
686
|
-
simple(node.left, {
|
|
687
|
-
Identifier: (node2) => replaceIdentifier(node2, true)
|
|
688
|
-
});
|
|
689
|
-
},
|
|
690
|
-
MemberExpression(node) {
|
|
691
|
-
if (executable === false || node.optional) {
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
if (node.computed === false) {
|
|
695
|
-
const dotIndex = expression.indexOf(".", node.object.end);
|
|
696
|
-
replacements.push([dotIndex, dotIndex, "?"]);
|
|
697
|
-
}
|
|
698
|
-
if (node.computed === true) {
|
|
699
|
-
const dotIndex = expression.indexOf("[", node.object.end);
|
|
700
|
-
replacements.push([dotIndex, dotIndex, "?."]);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
replacements.sort(([leftStart], [rightStart]) => rightStart - leftStart);
|
|
705
|
-
for (const [start, end, fragment] of replacements) {
|
|
706
|
-
const before = expression.slice(0, start);
|
|
707
|
-
const after = expression.slice(end);
|
|
708
|
-
expression = before + fragment + after;
|
|
709
|
-
}
|
|
710
|
-
return expression;
|
|
711
|
-
};
|
|
712
|
-
var parseObjectExpression = (expression) => {
|
|
713
|
-
const map = /* @__PURE__ */ new Map();
|
|
714
|
-
let root;
|
|
715
|
-
try {
|
|
716
|
-
root = parseExpressionAt(expression, 0, { ecmaVersion: "latest" });
|
|
717
|
-
} catch (error) {
|
|
718
|
-
return map;
|
|
719
|
-
}
|
|
720
|
-
if (root.type !== "ObjectExpression") {
|
|
721
|
-
return map;
|
|
722
|
-
}
|
|
723
|
-
for (const property of root.properties) {
|
|
724
|
-
if (property.type === "SpreadElement") {
|
|
725
|
-
continue;
|
|
726
|
-
}
|
|
727
|
-
if (property.computed) {
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
let key;
|
|
731
|
-
if (property.key.type === "Identifier") {
|
|
732
|
-
key = property.key.name;
|
|
733
|
-
} else if (property.key.type === "Literal" && typeof property.key.value === "string") {
|
|
734
|
-
key = property.key.value;
|
|
735
|
-
} else {
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
const valueExpression = expression.slice(
|
|
739
|
-
property.value.start,
|
|
740
|
-
property.value.end
|
|
741
|
-
);
|
|
742
|
-
map.set(key, valueExpression);
|
|
743
|
-
}
|
|
744
|
-
return map;
|
|
745
|
-
};
|
|
746
|
-
var generateObjectExpression = (map) => {
|
|
747
|
-
let generated = "{\n";
|
|
748
|
-
for (const [key, valueExpression] of map) {
|
|
749
|
-
const keyExpression = JSON.stringify(key);
|
|
750
|
-
generated += ` ${keyExpression}: ${valueExpression},
|
|
751
|
-
`;
|
|
752
|
-
}
|
|
753
|
-
generated += `}`;
|
|
754
|
-
return generated;
|
|
755
|
-
};
|
|
756
|
-
var dataSourceVariablePrefix = "$ws$dataSource$";
|
|
757
|
-
var encodeDataSourceVariable = (id) => {
|
|
758
|
-
const encoded = id.replaceAll("-", "__DASH__");
|
|
759
|
-
return `${dataSourceVariablePrefix}${encoded}`;
|
|
760
|
-
};
|
|
761
|
-
var decodeDataSourceVariable = (name) => {
|
|
762
|
-
if (name.startsWith(dataSourceVariablePrefix)) {
|
|
763
|
-
const encoded = name.slice(dataSourceVariablePrefix.length);
|
|
764
|
-
return encoded.replaceAll("__DASH__", "-");
|
|
765
|
-
}
|
|
766
|
-
return;
|
|
767
|
-
};
|
|
768
|
-
var generateExpression = ({
|
|
769
|
-
expression,
|
|
770
|
-
dataSources,
|
|
771
|
-
usedDataSources,
|
|
772
|
-
scope
|
|
773
|
-
}) => {
|
|
774
|
-
return transpileExpression({
|
|
775
|
-
expression,
|
|
776
|
-
executable: true,
|
|
777
|
-
replaceVariable: (identifier) => {
|
|
778
|
-
const depId = decodeDataSourceVariable(identifier);
|
|
779
|
-
const dep = depId ? dataSources.get(depId) : void 0;
|
|
780
|
-
if (dep) {
|
|
781
|
-
usedDataSources?.set(dep.id, dep);
|
|
782
|
-
return scope.getName(dep.id, dep.name);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
};
|
|
787
|
-
var executeExpression = (expression) => {
|
|
788
|
-
try {
|
|
789
|
-
const fn = new Function(`return (${expression})`);
|
|
790
|
-
return fn();
|
|
791
|
-
} catch {
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
// src/url-pattern.ts
|
|
796
|
-
var tokenRegex = /:(?<name>\w+)(?<modifier>[?*]?)|(?<wildcard>(?<!:\w+)\*)/;
|
|
797
|
-
var isPathnamePattern = (pathname) => tokenRegex.test(pathname);
|
|
798
|
-
var tokenRegexGlobal = new RegExp(tokenRegex.source, "g");
|
|
799
|
-
var matchPathnameParams = (pathname) => {
|
|
800
|
-
return pathname.matchAll(tokenRegexGlobal);
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
// src/page-utils.ts
|
|
804
|
-
var ROOT_FOLDER_ID = "root";
|
|
805
|
-
var isRootFolder = ({ id }) => id === ROOT_FOLDER_ID;
|
|
806
|
-
var findPageByIdOrPath = (idOrPath, pages) => {
|
|
807
|
-
if (idOrPath === "" || idOrPath === "/" || idOrPath === pages.homePage.id) {
|
|
808
|
-
return pages.homePage;
|
|
809
|
-
}
|
|
810
|
-
return pages.pages.find(
|
|
811
|
-
(page) => page.id === idOrPath || getPagePath(page.id, pages) === idOrPath
|
|
812
|
-
);
|
|
813
|
-
};
|
|
814
|
-
var findParentFolderByChildId = (id, folders) => {
|
|
815
|
-
for (const folder of folders) {
|
|
816
|
-
if (folder.children.includes(id)) {
|
|
817
|
-
return folder;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
var getPagePath = (id, pages) => {
|
|
822
|
-
const foldersMap = /* @__PURE__ */ new Map();
|
|
823
|
-
const childParentMap = /* @__PURE__ */ new Map();
|
|
824
|
-
for (const folder of pages.folders) {
|
|
825
|
-
foldersMap.set(folder.id, folder);
|
|
826
|
-
for (const childId of folder.children) {
|
|
827
|
-
childParentMap.set(childId, folder.id);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
const paths = [];
|
|
831
|
-
let currentId = id;
|
|
832
|
-
const allPages = [pages.homePage, ...pages.pages];
|
|
833
|
-
for (const page of allPages) {
|
|
834
|
-
if (page.id === id) {
|
|
835
|
-
paths.push(page.path);
|
|
836
|
-
currentId = childParentMap.get(page.id);
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
while (currentId) {
|
|
841
|
-
const folder = foldersMap.get(currentId);
|
|
842
|
-
if (folder === void 0) {
|
|
843
|
-
break;
|
|
844
|
-
}
|
|
845
|
-
paths.push(folder.slug);
|
|
846
|
-
currentId = childParentMap.get(currentId);
|
|
847
|
-
}
|
|
848
|
-
return paths.reverse().join("/").replace(/\/+/g, "/");
|
|
849
|
-
};
|
|
850
|
-
var getStaticSiteMapXml = (pages, updatedAt) => {
|
|
851
|
-
const allPages = [pages.homePage, ...pages.pages];
|
|
852
|
-
return allPages.filter((page) => (page.meta.documentType ?? "html") === "html").filter(
|
|
853
|
-
(page) => executeExpression(page.meta.excludePageFromSearch) !== true
|
|
854
|
-
).filter((page) => false === isPathnamePattern(page.path)).map((page) => ({
|
|
855
|
-
path: getPagePath(page.id, pages),
|
|
856
|
-
lastModified: updatedAt.split("T")[0]
|
|
857
|
-
}));
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
// src/scope.ts
|
|
861
|
-
import reservedIdentifiers from "reserved-identifiers";
|
|
862
|
-
var identifiers = reservedIdentifiers({ includeGlobalProperties: true });
|
|
863
|
-
var isReserved = (identifier) => identifiers.has(identifier);
|
|
864
|
-
var normalizeJsName = (name) => {
|
|
865
|
-
name = name.replaceAll(/[^\w$]/g, "");
|
|
866
|
-
if (name.length === 0) {
|
|
867
|
-
return "_";
|
|
868
|
-
}
|
|
869
|
-
if (/[A-Za-z_$]/.test(name[0]) === false) {
|
|
870
|
-
name = `_${name}`;
|
|
871
|
-
}
|
|
872
|
-
if (isReserved(name)) {
|
|
873
|
-
return `${name}_`;
|
|
874
|
-
}
|
|
875
|
-
return name;
|
|
876
|
-
};
|
|
877
|
-
var createScope = (occupiedIdentifiers = [], normalizeName = normalizeJsName, separator = "_") => {
|
|
878
|
-
const nameById = /* @__PURE__ */ new Map();
|
|
879
|
-
const usedNames = /* @__PURE__ */ new Set();
|
|
880
|
-
for (const identifier of occupiedIdentifiers) {
|
|
881
|
-
usedNames.add(identifier);
|
|
882
|
-
}
|
|
883
|
-
const getName = (id, preferredName) => {
|
|
884
|
-
const cachedName = nameById.get(id);
|
|
885
|
-
if (cachedName !== void 0) {
|
|
886
|
-
return cachedName;
|
|
887
|
-
}
|
|
888
|
-
preferredName = normalizeName(preferredName);
|
|
889
|
-
let index = 0;
|
|
890
|
-
let scopedName = preferredName;
|
|
891
|
-
while (usedNames.has(scopedName)) {
|
|
892
|
-
index += 1;
|
|
893
|
-
scopedName = `${preferredName}${separator}${index}`;
|
|
894
|
-
}
|
|
895
|
-
nameById.set(id, scopedName);
|
|
896
|
-
usedNames.add(scopedName);
|
|
897
|
-
return scopedName;
|
|
898
|
-
};
|
|
899
|
-
return {
|
|
900
|
-
getName
|
|
901
|
-
};
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
// src/resource-loader.ts
|
|
905
|
-
var loadResource = async (customFetch, resourceRequest) => {
|
|
906
|
-
const { url, method, headers, body } = resourceRequest;
|
|
907
|
-
const requestHeaders = new Headers(
|
|
908
|
-
headers.map(({ name, value }) => [name, value])
|
|
909
|
-
);
|
|
910
|
-
const requestInit = {
|
|
911
|
-
method,
|
|
912
|
-
headers: requestHeaders
|
|
913
|
-
};
|
|
914
|
-
if (method !== "get" && body !== void 0) {
|
|
915
|
-
if (typeof body === "string") {
|
|
916
|
-
requestInit.body = body;
|
|
917
|
-
}
|
|
918
|
-
if (typeof body === "object") {
|
|
919
|
-
requestInit.body = JSON.stringify(body);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
try {
|
|
923
|
-
const response = await customFetch(url.trim(), requestInit);
|
|
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
|
-
);
|
|
933
|
-
}
|
|
934
|
-
return {
|
|
935
|
-
ok: response.ok,
|
|
936
|
-
data,
|
|
937
|
-
status: response.status,
|
|
938
|
-
statusText: response.statusText
|
|
939
|
-
};
|
|
940
|
-
} catch (error) {
|
|
941
|
-
console.error(error);
|
|
942
|
-
const message = error.message;
|
|
943
|
-
return {
|
|
944
|
-
ok: false,
|
|
945
|
-
data: void 0,
|
|
946
|
-
status: 500,
|
|
947
|
-
statusText: message
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
var loadResources = async (customFetch, requests) => {
|
|
952
|
-
return Object.fromEntries(
|
|
953
|
-
await Promise.all(
|
|
954
|
-
Array.from(
|
|
955
|
-
requests,
|
|
956
|
-
async ([name, request]) => [name, await loadResource(customFetch, request)]
|
|
957
|
-
)
|
|
958
|
-
)
|
|
959
|
-
);
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
// src/resources-generator.ts
|
|
963
|
-
var generateResources = ({
|
|
964
|
-
scope,
|
|
965
|
-
page,
|
|
966
|
-
dataSources,
|
|
967
|
-
props,
|
|
968
|
-
resources
|
|
969
|
-
}) => {
|
|
970
|
-
const usedDataSources = /* @__PURE__ */ new Map();
|
|
971
|
-
let generatedRequests = "";
|
|
972
|
-
for (const resource of resources.values()) {
|
|
973
|
-
let generatedRequest = "";
|
|
974
|
-
const resourceName = scope.getName(resource.id, resource.name);
|
|
975
|
-
generatedRequest += ` const ${resourceName}: ResourceRequest = {
|
|
976
|
-
`;
|
|
977
|
-
generatedRequest += ` id: "${resource.id}",
|
|
978
|
-
`;
|
|
979
|
-
generatedRequest += ` name: ${JSON.stringify(resource.name)},
|
|
980
|
-
`;
|
|
981
|
-
const url = generateExpression({
|
|
982
|
-
expression: resource.url,
|
|
983
|
-
dataSources,
|
|
984
|
-
usedDataSources,
|
|
985
|
-
scope
|
|
986
|
-
});
|
|
987
|
-
generatedRequest += ` url: ${url},
|
|
988
|
-
`;
|
|
989
|
-
generatedRequest += ` method: "${resource.method}",
|
|
990
|
-
`;
|
|
991
|
-
generatedRequest += ` headers: [
|
|
992
|
-
`;
|
|
993
|
-
for (const header of resource.headers) {
|
|
994
|
-
const value = generateExpression({
|
|
995
|
-
expression: header.value,
|
|
996
|
-
dataSources,
|
|
997
|
-
usedDataSources,
|
|
998
|
-
scope
|
|
999
|
-
});
|
|
1000
|
-
generatedRequest += ` { name: "${header.name}", value: ${value} },
|
|
1001
|
-
`;
|
|
1002
|
-
}
|
|
1003
|
-
generatedRequest += ` ],
|
|
1004
|
-
`;
|
|
1005
|
-
if (resource.body !== void 0 && resource.body.length > 0) {
|
|
1006
|
-
const body = generateExpression({
|
|
1007
|
-
expression: resource.body,
|
|
1008
|
-
dataSources,
|
|
1009
|
-
usedDataSources,
|
|
1010
|
-
scope
|
|
1011
|
-
});
|
|
1012
|
-
generatedRequest += ` body: ${body},
|
|
1013
|
-
`;
|
|
1014
|
-
}
|
|
1015
|
-
generatedRequest += ` }
|
|
1016
|
-
`;
|
|
1017
|
-
generatedRequests += generatedRequest;
|
|
1018
|
-
}
|
|
1019
|
-
let generatedVariables = "";
|
|
1020
|
-
for (const dataSource of usedDataSources.values()) {
|
|
1021
|
-
if (dataSource.type === "variable") {
|
|
1022
|
-
const name = scope.getName(dataSource.id, dataSource.name);
|
|
1023
|
-
const value = JSON.stringify(dataSource.value.value);
|
|
1024
|
-
generatedVariables += ` let ${name} = ${value}
|
|
1025
|
-
`;
|
|
1026
|
-
}
|
|
1027
|
-
if (dataSource.type === "parameter") {
|
|
1028
|
-
if (dataSource.id !== page.systemDataSourceId) {
|
|
1029
|
-
continue;
|
|
1030
|
-
}
|
|
1031
|
-
const name = scope.getName(dataSource.id, dataSource.name);
|
|
1032
|
-
generatedVariables += ` const ${name} = _props.system
|
|
1033
|
-
`;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
let generated = "";
|
|
1037
|
-
generated += `import type { System, ResourceRequest } from "@webstudio-is/sdk";
|
|
1038
|
-
`;
|
|
1039
|
-
generated += `export const getResources = (_props: { system: System }) => {
|
|
1040
|
-
`;
|
|
1041
|
-
generated += generatedVariables;
|
|
1042
|
-
generated += generatedRequests;
|
|
1043
|
-
generated += ` const _data = new Map<string, ResourceRequest>([
|
|
1044
|
-
`;
|
|
1045
|
-
for (const dataSource of dataSources.values()) {
|
|
1046
|
-
if (dataSource.type === "resource") {
|
|
1047
|
-
const name = scope.getName(dataSource.resourceId, dataSource.name);
|
|
1048
|
-
generated += ` ["${name}", ${name}],
|
|
1049
|
-
`;
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
generated += ` ])
|
|
1053
|
-
`;
|
|
1054
|
-
generated += ` const _action = new Map<string, ResourceRequest>([
|
|
1055
|
-
`;
|
|
1056
|
-
for (const prop of props.values()) {
|
|
1057
|
-
if (prop.type === "resource") {
|
|
1058
|
-
const name = scope.getName(prop.value, prop.name);
|
|
1059
|
-
generated += ` ["${name}", ${name}],
|
|
1060
|
-
`;
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
generated += ` ])
|
|
1064
|
-
`;
|
|
1065
|
-
generated += ` return { data: _data, action: _action }
|
|
1066
|
-
`;
|
|
1067
|
-
generated += `}
|
|
1068
|
-
`;
|
|
1069
|
-
return generated;
|
|
1070
|
-
};
|
|
1071
|
-
var getMethod = (value) => {
|
|
1072
|
-
switch (value?.toLowerCase()) {
|
|
1073
|
-
case "get":
|
|
1074
|
-
return "get";
|
|
1075
|
-
case "delete":
|
|
1076
|
-
return "delete";
|
|
1077
|
-
case "put":
|
|
1078
|
-
return "put";
|
|
1079
|
-
default:
|
|
1080
|
-
return "post";
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
var replaceFormActionsWithResources = ({
|
|
1084
|
-
props,
|
|
1085
|
-
instances,
|
|
1086
|
-
resources
|
|
1087
|
-
}) => {
|
|
1088
|
-
const formProps = /* @__PURE__ */ new Map();
|
|
1089
|
-
for (const prop of props.values()) {
|
|
1090
|
-
if (prop.name === "method" && prop.type === "string" && instances.get(prop.instanceId)?.component === "Form") {
|
|
1091
|
-
let data = formProps.get(prop.instanceId);
|
|
1092
|
-
if (data === void 0) {
|
|
1093
|
-
data = {};
|
|
1094
|
-
formProps.set(prop.instanceId, data);
|
|
1095
|
-
}
|
|
1096
|
-
data.method = prop.value;
|
|
1097
|
-
props.delete(prop.id);
|
|
1098
|
-
}
|
|
1099
|
-
if (prop.name === "action" && prop.type === "string" && prop.value && instances.get(prop.instanceId)?.component === "Form") {
|
|
1100
|
-
let data = formProps.get(prop.instanceId);
|
|
1101
|
-
if (data === void 0) {
|
|
1102
|
-
data = {};
|
|
1103
|
-
formProps.set(prop.instanceId, data);
|
|
1104
|
-
}
|
|
1105
|
-
data.action = prop.value;
|
|
1106
|
-
props.set(prop.id, {
|
|
1107
|
-
id: prop.id,
|
|
1108
|
-
instanceId: prop.instanceId,
|
|
1109
|
-
name: prop.name,
|
|
1110
|
-
type: "resource",
|
|
1111
|
-
value: prop.instanceId
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
for (const [instanceId, { action, method }] of formProps) {
|
|
1116
|
-
if (action) {
|
|
1117
|
-
resources.set(instanceId, {
|
|
1118
|
-
id: instanceId,
|
|
1119
|
-
name: "action",
|
|
1120
|
-
method: getMethod(method),
|
|
1121
|
-
url: JSON.stringify(action),
|
|
1122
|
-
headers: []
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
// src/page-meta-generator.ts
|
|
1129
|
-
var generatePageMeta = ({
|
|
1130
|
-
globalScope,
|
|
1131
|
-
page,
|
|
1132
|
-
dataSources,
|
|
1133
|
-
assets
|
|
1134
|
-
}) => {
|
|
1135
|
-
const localScope = createScope(["system", "resources"]);
|
|
1136
|
-
const usedDataSources = /* @__PURE__ */ new Map();
|
|
1137
|
-
const titleExpression = generateExpression({
|
|
1138
|
-
expression: page.title,
|
|
1139
|
-
dataSources,
|
|
1140
|
-
usedDataSources,
|
|
1141
|
-
scope: localScope
|
|
1142
|
-
});
|
|
1143
|
-
const descriptionExpression = generateExpression({
|
|
1144
|
-
expression: page.meta.description ?? "undefined",
|
|
1145
|
-
dataSources,
|
|
1146
|
-
usedDataSources,
|
|
1147
|
-
scope: localScope
|
|
1148
|
-
});
|
|
1149
|
-
const excludePageFromSearchExpression = generateExpression({
|
|
1150
|
-
expression: page.meta.excludePageFromSearch ?? "undefined",
|
|
1151
|
-
dataSources,
|
|
1152
|
-
usedDataSources,
|
|
1153
|
-
scope: localScope
|
|
1154
|
-
});
|
|
1155
|
-
const languageExpression = generateExpression({
|
|
1156
|
-
expression: page.meta.language ?? "undefined",
|
|
1157
|
-
dataSources,
|
|
1158
|
-
usedDataSources,
|
|
1159
|
-
scope: localScope
|
|
1160
|
-
});
|
|
1161
|
-
const socialImageAssetNameExpression = JSON.stringify(
|
|
1162
|
-
page.meta.socialImageAssetId ? assets.get(page.meta.socialImageAssetId)?.name : void 0
|
|
1163
|
-
);
|
|
1164
|
-
const socialImageUrlExpression = generateExpression({
|
|
1165
|
-
expression: page.meta.socialImageUrl ?? "undefined",
|
|
1166
|
-
dataSources,
|
|
1167
|
-
usedDataSources,
|
|
1168
|
-
scope: localScope
|
|
1169
|
-
});
|
|
1170
|
-
const statusExpression = generateExpression({
|
|
1171
|
-
expression: page.meta.status ?? "undefined",
|
|
1172
|
-
dataSources,
|
|
1173
|
-
usedDataSources,
|
|
1174
|
-
scope: localScope
|
|
1175
|
-
});
|
|
1176
|
-
const redirectExpression = generateExpression({
|
|
1177
|
-
expression: page.meta.redirect ?? "undefined",
|
|
1178
|
-
dataSources,
|
|
1179
|
-
usedDataSources,
|
|
1180
|
-
scope: localScope
|
|
1181
|
-
});
|
|
1182
|
-
let customExpression = "";
|
|
1183
|
-
customExpression += `[
|
|
1184
|
-
`;
|
|
1185
|
-
for (const customMeta of page.meta.custom ?? []) {
|
|
1186
|
-
if (customMeta.property.trim().length === 0) {
|
|
1187
|
-
continue;
|
|
1188
|
-
}
|
|
1189
|
-
const propertyExpression = JSON.stringify(customMeta.property);
|
|
1190
|
-
const contentExpression = generateExpression({
|
|
1191
|
-
expression: customMeta.content,
|
|
1192
|
-
dataSources,
|
|
1193
|
-
usedDataSources,
|
|
1194
|
-
scope: localScope
|
|
1195
|
-
});
|
|
1196
|
-
customExpression += ` {
|
|
1197
|
-
`;
|
|
1198
|
-
customExpression += ` property: ${propertyExpression},
|
|
1199
|
-
`;
|
|
1200
|
-
customExpression += ` content: ${contentExpression},
|
|
1201
|
-
`;
|
|
1202
|
-
customExpression += ` },
|
|
1203
|
-
`;
|
|
1204
|
-
}
|
|
1205
|
-
customExpression += ` ]`;
|
|
1206
|
-
let generated = "";
|
|
1207
|
-
generated += `export const getPageMeta = ({
|
|
1208
|
-
`;
|
|
1209
|
-
generated += ` system,
|
|
1210
|
-
`;
|
|
1211
|
-
generated += ` resources,
|
|
1212
|
-
`;
|
|
1213
|
-
generated += `}: {
|
|
1214
|
-
`;
|
|
1215
|
-
generated += ` system: System;
|
|
1216
|
-
`;
|
|
1217
|
-
generated += ` resources: Record<string, any>;
|
|
1218
|
-
`;
|
|
1219
|
-
generated += `}): PageMeta => {
|
|
1220
|
-
`;
|
|
1221
|
-
for (const dataSource of usedDataSources.values()) {
|
|
1222
|
-
if (dataSource.type === "variable") {
|
|
1223
|
-
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1224
|
-
const initialValueString = JSON.stringify(dataSource.value.value);
|
|
1225
|
-
generated += ` let ${valueName} = ${initialValueString}
|
|
1226
|
-
`;
|
|
1227
|
-
continue;
|
|
1228
|
-
}
|
|
1229
|
-
if (dataSource.type === "parameter") {
|
|
1230
|
-
if (dataSource.id === page.systemDataSourceId) {
|
|
1231
|
-
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1232
|
-
generated += ` let ${valueName} = system
|
|
1233
|
-
`;
|
|
1234
|
-
}
|
|
1235
|
-
continue;
|
|
1236
|
-
}
|
|
1237
|
-
if (dataSource.type === "resource") {
|
|
1238
|
-
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1239
|
-
const resourceName = globalScope.getName(
|
|
1240
|
-
dataSource.resourceId,
|
|
1241
|
-
dataSource.name
|
|
1242
|
-
);
|
|
1243
|
-
generated += ` let ${valueName} = resources.${resourceName}
|
|
1244
|
-
`;
|
|
1245
|
-
continue;
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
generated += ` return {
|
|
1249
|
-
`;
|
|
1250
|
-
generated += ` title: ${titleExpression},
|
|
1251
|
-
`;
|
|
1252
|
-
generated += ` description: ${descriptionExpression},
|
|
1253
|
-
`;
|
|
1254
|
-
generated += ` excludePageFromSearch: ${excludePageFromSearchExpression},
|
|
1255
|
-
`;
|
|
1256
|
-
generated += ` language: ${languageExpression},
|
|
1257
|
-
`;
|
|
1258
|
-
generated += ` socialImageAssetName: ${socialImageAssetNameExpression},
|
|
1259
|
-
`;
|
|
1260
|
-
generated += ` socialImageUrl: ${socialImageUrlExpression},
|
|
1261
|
-
`;
|
|
1262
|
-
generated += ` status: ${statusExpression},
|
|
1263
|
-
`;
|
|
1264
|
-
generated += ` redirect: ${redirectExpression},
|
|
1265
|
-
`;
|
|
1266
|
-
generated += ` custom: ${customExpression},
|
|
1267
|
-
`;
|
|
1268
|
-
generated += ` };
|
|
1269
|
-
`;
|
|
1270
|
-
generated += `};
|
|
1271
|
-
`;
|
|
1272
|
-
return generated;
|
|
1273
|
-
};
|
|
1274
|
-
|
|
1275
|
-
// src/form-fields.ts
|
|
1276
|
-
var formIdFieldName = `ws--form-id`;
|
|
1277
|
-
var formBotFieldName = `ws--form-bot`;
|
|
1278
|
-
|
|
1279
|
-
// src/to-string.ts
|
|
1280
|
-
var createJsonStringifyProxy = (target) => {
|
|
1281
|
-
return new Proxy(target, {
|
|
1282
|
-
get(target2, prop, receiver) {
|
|
1283
|
-
if (prop === "toString") {
|
|
1284
|
-
return function() {
|
|
1285
|
-
return JSON.stringify(target2);
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
const value = Reflect.get(target2, prop, receiver);
|
|
1289
|
-
if (typeof value === "object" && value !== null) {
|
|
1290
|
-
return createJsonStringifyProxy(value);
|
|
1291
|
-
}
|
|
1292
|
-
return value;
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
};
|
|
1296
|
-
var isPlainObject = (value) => {
|
|
1297
|
-
return Object.prototype.toString.call(value) === "[object Object]" && (Object.getPrototypeOf(value) === null || Object.getPrototypeOf(value) === Object.prototype);
|
|
1298
|
-
};
|
|
1299
|
-
export {
|
|
1300
|
-
Asset,
|
|
1301
|
-
Assets,
|
|
1302
|
-
Breakpoint,
|
|
1303
|
-
Breakpoints,
|
|
1304
|
-
CompilerSettings,
|
|
1305
|
-
DataSource,
|
|
1306
|
-
DataSourceVariableValue,
|
|
1307
|
-
DataSources,
|
|
1308
|
-
Deployment,
|
|
1309
|
-
ExpressionChild,
|
|
1310
|
-
Folder,
|
|
1311
|
-
FolderName,
|
|
1312
|
-
FontAsset,
|
|
1313
|
-
HomePagePath,
|
|
1314
|
-
IdChild,
|
|
1315
|
-
ImageAsset,
|
|
1316
|
-
ImageMeta,
|
|
1317
|
-
Instance,
|
|
1318
|
-
InstanceChild,
|
|
1319
|
-
Instances,
|
|
1320
|
-
PageName,
|
|
1321
|
-
PagePath,
|
|
1322
|
-
PageRedirect,
|
|
1323
|
-
PageTitle,
|
|
1324
|
-
Pages,
|
|
1325
|
-
ProjectNewRedirectPath,
|
|
1326
|
-
Prop,
|
|
1327
|
-
Props,
|
|
1328
|
-
ROOT_FOLDER_ID,
|
|
1329
|
-
ROOT_INSTANCE_ID,
|
|
1330
|
-
Resource,
|
|
1331
|
-
ResourceRequest,
|
|
1332
|
-
Resources,
|
|
1333
|
-
StyleDecl,
|
|
1334
|
-
StyleSource,
|
|
1335
|
-
StyleSourceSelection,
|
|
1336
|
-
StyleSourceSelections,
|
|
1337
|
-
StyleSources,
|
|
1338
|
-
Styles,
|
|
1339
|
-
Templates,
|
|
1340
|
-
TextChild,
|
|
1341
|
-
WebstudioFragment,
|
|
1342
|
-
createJsonStringifyProxy,
|
|
1343
|
-
createScope,
|
|
1344
|
-
decodeDataSourceVariable,
|
|
1345
|
-
documentTypes,
|
|
1346
|
-
encodeDataSourceVariable,
|
|
1347
|
-
executeExpression,
|
|
1348
|
-
findPageByIdOrPath,
|
|
1349
|
-
findParentFolderByChildId,
|
|
1350
|
-
findTreeInstanceIds,
|
|
1351
|
-
findTreeInstanceIdsExcludingSlotDescendants,
|
|
1352
|
-
formBotFieldName,
|
|
1353
|
-
formIdFieldName,
|
|
1354
|
-
generateExpression,
|
|
1355
|
-
generateObjectExpression,
|
|
1356
|
-
generatePageMeta,
|
|
1357
|
-
generateResources,
|
|
1358
|
-
getExpressionIdentifiers,
|
|
1359
|
-
getPagePath,
|
|
1360
|
-
getStaticSiteMapXml,
|
|
1361
|
-
getStyleDeclKey,
|
|
1362
|
-
initialBreakpoints,
|
|
1363
|
-
isLiteralExpression,
|
|
1364
|
-
isLocalResource,
|
|
1365
|
-
isPathnamePattern,
|
|
1366
|
-
isPlainObject,
|
|
1367
|
-
isRootFolder,
|
|
1368
|
-
lintExpression,
|
|
1369
|
-
loadResource,
|
|
1370
|
-
loadResources,
|
|
1371
|
-
matchPathnameParams,
|
|
1372
|
-
parseComponentName,
|
|
1373
|
-
parseObjectExpression,
|
|
1374
|
-
replaceFormActionsWithResources,
|
|
1375
|
-
sitemapResourceUrl,
|
|
1376
|
-
transpileExpression
|
|
1377
|
-
};
|