@webstudio-is/sdk 0.204.0 → 0.205.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 +683 -301
- package/lib/types/core-metas.d.ts +35 -0
- package/lib/types/css.d.ts +31 -0
- package/lib/types/css.test.d.ts +1 -0
- package/lib/types/expression.d.ts +7 -5
- package/lib/types/index.d.ts +3 -0
- package/lib/types/schema/animation-schema.d.ts +22925 -0
- package/lib/types/schema/component-meta.d.ts +42 -0
- package/lib/types/schema/data-sources.d.ts +18 -18
- package/lib/types/schema/deployment.d.ts +4 -4
- package/lib/types/schema/pages.d.ts +13 -13
- package/lib/types/schema/prop-meta.d.ts +21 -0
- package/lib/types/schema/props.d.ts +16186 -0
- package/lib/types/schema/webstudio.d.ts +9386 -15
- package/package.json +8 -7
package/lib/index.js
CHANGED
|
@@ -57,7 +57,7 @@ var commonPageFields = {
|
|
|
57
57
|
title: PageTitle,
|
|
58
58
|
history: z2.optional(z2.array(z2.string())),
|
|
59
59
|
rootInstanceId: z2.string(),
|
|
60
|
-
systemDataSourceId: z2.string(),
|
|
60
|
+
systemDataSourceId: z2.string().optional(),
|
|
61
61
|
meta: z2.object({
|
|
62
62
|
description: z2.string().optional(),
|
|
63
63
|
title: z2.string().optional(),
|
|
@@ -221,20 +221,25 @@ var DataSource = z4.union([
|
|
|
221
221
|
z4.object({
|
|
222
222
|
type: z4.literal("variable"),
|
|
223
223
|
id: DataSourceId,
|
|
224
|
-
|
|
224
|
+
// The instance should always be specified for variables,
|
|
225
|
+
// however, there was a bug in the embed template
|
|
226
|
+
// which produced variables without an instance
|
|
227
|
+
// and these variables will fail validation
|
|
228
|
+
// if we make it required
|
|
229
|
+
scopeInstanceId: z4.string().optional(),
|
|
225
230
|
name: z4.string(),
|
|
226
231
|
value: DataSourceVariableValue
|
|
227
232
|
}),
|
|
228
233
|
z4.object({
|
|
229
234
|
type: z4.literal("parameter"),
|
|
230
235
|
id: DataSourceId,
|
|
231
|
-
scopeInstanceId: z4.string(),
|
|
236
|
+
scopeInstanceId: z4.string().optional(),
|
|
232
237
|
name: z4.string()
|
|
233
238
|
}),
|
|
234
239
|
z4.object({
|
|
235
240
|
type: z4.literal("resource"),
|
|
236
241
|
id: DataSourceId,
|
|
237
|
-
scopeInstanceId: z4.string(),
|
|
242
|
+
scopeInstanceId: z4.string().optional(),
|
|
238
243
|
name: z4.string(),
|
|
239
244
|
resourceId: z4.string()
|
|
240
245
|
})
|
|
@@ -277,98 +282,261 @@ var ResourceRequest = z5.object({
|
|
|
277
282
|
var Resources = z5.map(ResourceId, Resource);
|
|
278
283
|
|
|
279
284
|
// src/schema/props.ts
|
|
285
|
+
import { z as z7 } from "zod";
|
|
286
|
+
|
|
287
|
+
// src/schema/animation-schema.ts
|
|
288
|
+
import { StyleValue } from "@webstudio-is/css-engine";
|
|
280
289
|
import { z as z6 } from "zod";
|
|
281
|
-
var
|
|
290
|
+
var literalUnion = (arr) => z6.union(
|
|
291
|
+
arr.map((val) => z6.literal(val))
|
|
292
|
+
);
|
|
293
|
+
var RANGE_UNITS = [
|
|
294
|
+
"%",
|
|
295
|
+
"px",
|
|
296
|
+
"cm",
|
|
297
|
+
"mm",
|
|
298
|
+
"q",
|
|
299
|
+
"in",
|
|
300
|
+
"pt",
|
|
301
|
+
"pc",
|
|
302
|
+
"em",
|
|
303
|
+
"rem",
|
|
304
|
+
"ex",
|
|
305
|
+
"rex",
|
|
306
|
+
"cap",
|
|
307
|
+
"rcap",
|
|
308
|
+
"ch",
|
|
309
|
+
"rch",
|
|
310
|
+
"lh",
|
|
311
|
+
"rlh",
|
|
312
|
+
"vw",
|
|
313
|
+
"svw",
|
|
314
|
+
"lvw",
|
|
315
|
+
"dvw",
|
|
316
|
+
"vh",
|
|
317
|
+
"svh",
|
|
318
|
+
"lvh",
|
|
319
|
+
"dvh",
|
|
320
|
+
"vi",
|
|
321
|
+
"svi",
|
|
322
|
+
"lvi",
|
|
323
|
+
"dvi",
|
|
324
|
+
"vb",
|
|
325
|
+
"svb",
|
|
326
|
+
"lvb",
|
|
327
|
+
"dvb",
|
|
328
|
+
"vmin",
|
|
329
|
+
"svmin",
|
|
330
|
+
"lvmin",
|
|
331
|
+
"dvmin",
|
|
332
|
+
"vmax",
|
|
333
|
+
"svmax",
|
|
334
|
+
"lvmax",
|
|
335
|
+
"dvmax"
|
|
336
|
+
];
|
|
337
|
+
var rangeUnitSchema = literalUnion(RANGE_UNITS);
|
|
338
|
+
var rangeUnitValueSchema = z6.union([
|
|
339
|
+
z6.object({
|
|
340
|
+
type: z6.literal("unit"),
|
|
341
|
+
value: z6.number(),
|
|
342
|
+
unit: rangeUnitSchema
|
|
343
|
+
}),
|
|
344
|
+
z6.object({
|
|
345
|
+
type: z6.literal("unparsed"),
|
|
346
|
+
value: z6.string()
|
|
347
|
+
})
|
|
348
|
+
]);
|
|
349
|
+
var insetUnitValueSchema = z6.union([
|
|
350
|
+
rangeUnitValueSchema,
|
|
351
|
+
z6.object({
|
|
352
|
+
type: z6.literal("keyword"),
|
|
353
|
+
value: z6.literal("auto")
|
|
354
|
+
})
|
|
355
|
+
]);
|
|
356
|
+
var keyframeStylesSchema = z6.record(StyleValue);
|
|
357
|
+
var animationKeyframeSchema = z6.object({
|
|
358
|
+
offset: z6.number().optional(),
|
|
359
|
+
styles: keyframeStylesSchema
|
|
360
|
+
});
|
|
361
|
+
var keyframeEffectOptionsSchema = z6.object({
|
|
362
|
+
easing: z6.string().optional(),
|
|
363
|
+
fill: z6.union([
|
|
364
|
+
z6.literal("none"),
|
|
365
|
+
z6.literal("forwards"),
|
|
366
|
+
z6.literal("backwards"),
|
|
367
|
+
z6.literal("both")
|
|
368
|
+
]).optional()
|
|
369
|
+
// FillMode
|
|
370
|
+
});
|
|
371
|
+
var scrollNamedRangeSchema = z6.union([
|
|
372
|
+
z6.literal("start"),
|
|
373
|
+
z6.literal("end")
|
|
374
|
+
]);
|
|
375
|
+
var scrollRangeValueSchema = z6.tuple([
|
|
376
|
+
scrollNamedRangeSchema,
|
|
377
|
+
rangeUnitValueSchema
|
|
378
|
+
]);
|
|
379
|
+
var scrollRangeOptionsSchema = z6.object({
|
|
380
|
+
rangeStart: scrollRangeValueSchema.optional(),
|
|
381
|
+
rangeEnd: scrollRangeValueSchema.optional()
|
|
382
|
+
});
|
|
383
|
+
var animationAxisSchema = z6.union([
|
|
384
|
+
z6.literal("block"),
|
|
385
|
+
z6.literal("inline"),
|
|
386
|
+
z6.literal("x"),
|
|
387
|
+
z6.literal("y")
|
|
388
|
+
]);
|
|
389
|
+
var viewNamedRangeSchema = z6.union([
|
|
390
|
+
z6.literal("contain"),
|
|
391
|
+
z6.literal("cover"),
|
|
392
|
+
z6.literal("entry"),
|
|
393
|
+
z6.literal("exit"),
|
|
394
|
+
z6.literal("entry-crossing"),
|
|
395
|
+
z6.literal("exit-crossing")
|
|
396
|
+
]);
|
|
397
|
+
var viewRangeValueSchema = z6.tuple([
|
|
398
|
+
viewNamedRangeSchema,
|
|
399
|
+
rangeUnitValueSchema
|
|
400
|
+
]);
|
|
401
|
+
var viewRangeOptionsSchema = z6.object({
|
|
402
|
+
rangeStart: viewRangeValueSchema.optional(),
|
|
403
|
+
rangeEnd: viewRangeValueSchema.optional()
|
|
404
|
+
});
|
|
405
|
+
var baseAnimation = z6.object({
|
|
406
|
+
name: z6.string().optional(),
|
|
407
|
+
description: z6.string().optional(),
|
|
408
|
+
keyframes: z6.array(animationKeyframeSchema)
|
|
409
|
+
});
|
|
410
|
+
var scrollAnimationSchema = baseAnimation.merge(
|
|
411
|
+
z6.object({
|
|
412
|
+
timing: keyframeEffectOptionsSchema.merge(scrollRangeOptionsSchema)
|
|
413
|
+
})
|
|
414
|
+
);
|
|
415
|
+
var scrollActionSchema = z6.object({
|
|
416
|
+
type: z6.literal("scroll"),
|
|
417
|
+
source: z6.union([z6.literal("closest"), z6.literal("nearest"), z6.literal("root")]).optional(),
|
|
418
|
+
axis: animationAxisSchema.optional(),
|
|
419
|
+
animations: z6.array(scrollAnimationSchema),
|
|
420
|
+
isPinned: z6.boolean().optional(),
|
|
421
|
+
debug: z6.boolean().optional()
|
|
422
|
+
});
|
|
423
|
+
var viewAnimationSchema = baseAnimation.merge(
|
|
424
|
+
z6.object({
|
|
425
|
+
timing: keyframeEffectOptionsSchema.merge(viewRangeOptionsSchema)
|
|
426
|
+
})
|
|
427
|
+
);
|
|
428
|
+
var viewActionSchema = z6.object({
|
|
429
|
+
type: z6.literal("view"),
|
|
430
|
+
subject: z6.string().optional(),
|
|
431
|
+
axis: animationAxisSchema.optional(),
|
|
432
|
+
animations: z6.array(viewAnimationSchema),
|
|
433
|
+
insetStart: insetUnitValueSchema.optional(),
|
|
434
|
+
insetEnd: insetUnitValueSchema.optional(),
|
|
435
|
+
isPinned: z6.boolean().optional(),
|
|
436
|
+
debug: z6.boolean().optional()
|
|
437
|
+
});
|
|
438
|
+
var animationActionSchema = z6.discriminatedUnion("type", [
|
|
439
|
+
scrollActionSchema,
|
|
440
|
+
viewActionSchema
|
|
441
|
+
]);
|
|
442
|
+
|
|
443
|
+
// src/schema/props.ts
|
|
444
|
+
var PropId = z7.string();
|
|
282
445
|
var baseProp = {
|
|
283
446
|
id: PropId,
|
|
284
|
-
instanceId:
|
|
285
|
-
name:
|
|
286
|
-
required:
|
|
447
|
+
instanceId: z7.string(),
|
|
448
|
+
name: z7.string(),
|
|
449
|
+
required: z7.optional(z7.boolean())
|
|
287
450
|
};
|
|
288
|
-
var Prop =
|
|
289
|
-
|
|
451
|
+
var Prop = z7.union([
|
|
452
|
+
z7.object({
|
|
290
453
|
...baseProp,
|
|
291
|
-
type:
|
|
292
|
-
value:
|
|
454
|
+
type: z7.literal("number"),
|
|
455
|
+
value: z7.number()
|
|
293
456
|
}),
|
|
294
|
-
|
|
457
|
+
z7.object({
|
|
295
458
|
...baseProp,
|
|
296
|
-
type:
|
|
297
|
-
value:
|
|
459
|
+
type: z7.literal("string"),
|
|
460
|
+
value: z7.string()
|
|
298
461
|
}),
|
|
299
|
-
|
|
462
|
+
z7.object({
|
|
300
463
|
...baseProp,
|
|
301
|
-
type:
|
|
302
|
-
value:
|
|
464
|
+
type: z7.literal("boolean"),
|
|
465
|
+
value: z7.boolean()
|
|
303
466
|
}),
|
|
304
|
-
|
|
467
|
+
z7.object({
|
|
305
468
|
...baseProp,
|
|
306
|
-
type:
|
|
307
|
-
value:
|
|
469
|
+
type: z7.literal("json"),
|
|
470
|
+
value: z7.unknown()
|
|
308
471
|
}),
|
|
309
|
-
|
|
472
|
+
z7.object({
|
|
310
473
|
...baseProp,
|
|
311
|
-
type:
|
|
312
|
-
value:
|
|
474
|
+
type: z7.literal("asset"),
|
|
475
|
+
value: z7.string()
|
|
313
476
|
// asset id
|
|
314
477
|
}),
|
|
315
|
-
|
|
478
|
+
z7.object({
|
|
316
479
|
...baseProp,
|
|
317
|
-
type:
|
|
318
|
-
value:
|
|
319
|
-
|
|
480
|
+
type: z7.literal("page"),
|
|
481
|
+
value: z7.union([
|
|
482
|
+
z7.string(),
|
|
320
483
|
// page id
|
|
321
|
-
|
|
322
|
-
pageId:
|
|
323
|
-
instanceId:
|
|
484
|
+
z7.object({
|
|
485
|
+
pageId: z7.string(),
|
|
486
|
+
instanceId: z7.string()
|
|
324
487
|
})
|
|
325
488
|
])
|
|
326
489
|
}),
|
|
327
|
-
|
|
490
|
+
z7.object({
|
|
328
491
|
...baseProp,
|
|
329
|
-
type:
|
|
330
|
-
value:
|
|
492
|
+
type: z7.literal("string[]"),
|
|
493
|
+
value: z7.array(z7.string())
|
|
331
494
|
}),
|
|
332
|
-
|
|
495
|
+
z7.object({
|
|
333
496
|
...baseProp,
|
|
334
|
-
type:
|
|
497
|
+
type: z7.literal("parameter"),
|
|
335
498
|
// data source id
|
|
336
|
-
value:
|
|
499
|
+
value: z7.string()
|
|
337
500
|
}),
|
|
338
|
-
|
|
501
|
+
z7.object({
|
|
339
502
|
...baseProp,
|
|
340
|
-
type:
|
|
503
|
+
type: z7.literal("resource"),
|
|
341
504
|
// resource id
|
|
342
|
-
value:
|
|
505
|
+
value: z7.string()
|
|
343
506
|
}),
|
|
344
|
-
|
|
507
|
+
z7.object({
|
|
345
508
|
...baseProp,
|
|
346
|
-
type:
|
|
509
|
+
type: z7.literal("expression"),
|
|
347
510
|
// expression code
|
|
348
|
-
value:
|
|
511
|
+
value: z7.string()
|
|
349
512
|
}),
|
|
350
|
-
|
|
513
|
+
z7.object({
|
|
351
514
|
...baseProp,
|
|
352
|
-
type:
|
|
353
|
-
value:
|
|
354
|
-
|
|
355
|
-
type:
|
|
356
|
-
args:
|
|
357
|
-
code:
|
|
515
|
+
type: z7.literal("action"),
|
|
516
|
+
value: z7.array(
|
|
517
|
+
z7.object({
|
|
518
|
+
type: z7.literal("execute"),
|
|
519
|
+
args: z7.array(z7.string()),
|
|
520
|
+
code: z7.string()
|
|
358
521
|
})
|
|
359
522
|
)
|
|
523
|
+
}),
|
|
524
|
+
z7.object({
|
|
525
|
+
...baseProp,
|
|
526
|
+
type: z7.literal("animationAction"),
|
|
527
|
+
value: animationActionSchema
|
|
360
528
|
})
|
|
361
529
|
]);
|
|
362
|
-
var Props =
|
|
530
|
+
var Props = z7.map(PropId, Prop);
|
|
363
531
|
|
|
364
532
|
// src/schema/breakpoints.ts
|
|
365
|
-
import { z as
|
|
366
|
-
var BreakpointId =
|
|
367
|
-
var Breakpoint =
|
|
533
|
+
import { z as z8 } from "zod";
|
|
534
|
+
var BreakpointId = z8.string();
|
|
535
|
+
var Breakpoint = z8.object({
|
|
368
536
|
id: BreakpointId,
|
|
369
|
-
label:
|
|
370
|
-
minWidth:
|
|
371
|
-
maxWidth:
|
|
537
|
+
label: z8.string(),
|
|
538
|
+
minWidth: z8.number().optional(),
|
|
539
|
+
maxWidth: z8.number().optional()
|
|
372
540
|
}).refine(({ minWidth, maxWidth }) => {
|
|
373
541
|
return (
|
|
374
542
|
// Either min or max width have to be defined
|
|
@@ -376,7 +544,7 @@ var Breakpoint = z7.object({
|
|
|
376
544
|
minWidth === void 0 && maxWidth === void 0
|
|
377
545
|
);
|
|
378
546
|
}, "Either minWidth or maxWidth should be defined");
|
|
379
|
-
var Breakpoints =
|
|
547
|
+
var Breakpoints = z8.map(BreakpointId, Breakpoint);
|
|
380
548
|
var initialBreakpoints = [
|
|
381
549
|
{ id: "placeholder", label: "Base" },
|
|
382
550
|
{ id: "placeholder", label: "Tablet", maxWidth: 991 },
|
|
@@ -385,52 +553,51 @@ var initialBreakpoints = [
|
|
|
385
553
|
];
|
|
386
554
|
|
|
387
555
|
// src/schema/style-sources.ts
|
|
388
|
-
import { z as
|
|
389
|
-
var StyleSourceId =
|
|
390
|
-
var StyleSourceToken =
|
|
391
|
-
type:
|
|
556
|
+
import { z as z9 } from "zod";
|
|
557
|
+
var StyleSourceId = z9.string();
|
|
558
|
+
var StyleSourceToken = z9.object({
|
|
559
|
+
type: z9.literal("token"),
|
|
392
560
|
id: StyleSourceId,
|
|
393
|
-
name:
|
|
561
|
+
name: z9.string()
|
|
394
562
|
});
|
|
395
|
-
var StyleSourceLocal =
|
|
396
|
-
type:
|
|
563
|
+
var StyleSourceLocal = z9.object({
|
|
564
|
+
type: z9.literal("local"),
|
|
397
565
|
id: StyleSourceId
|
|
398
566
|
});
|
|
399
|
-
var StyleSource =
|
|
400
|
-
var StyleSources =
|
|
567
|
+
var StyleSource = z9.union([StyleSourceToken, StyleSourceLocal]);
|
|
568
|
+
var StyleSources = z9.map(StyleSourceId, StyleSource);
|
|
401
569
|
|
|
402
570
|
// src/schema/style-source-selections.ts
|
|
403
|
-
import { z as
|
|
404
|
-
var InstanceId2 =
|
|
405
|
-
var StyleSourceId2 =
|
|
406
|
-
var StyleSourceSelection =
|
|
571
|
+
import { z as z10 } from "zod";
|
|
572
|
+
var InstanceId2 = z10.string();
|
|
573
|
+
var StyleSourceId2 = z10.string();
|
|
574
|
+
var StyleSourceSelection = z10.object({
|
|
407
575
|
instanceId: InstanceId2,
|
|
408
|
-
values:
|
|
576
|
+
values: z10.array(StyleSourceId2)
|
|
409
577
|
});
|
|
410
|
-
var StyleSourceSelections =
|
|
578
|
+
var StyleSourceSelections = z10.map(InstanceId2, StyleSourceSelection);
|
|
411
579
|
|
|
412
580
|
// src/schema/styles.ts
|
|
413
|
-
import { z as
|
|
414
|
-
import { StyleValue } from "@webstudio-is/css-engine";
|
|
415
|
-
var StyleDeclRaw =
|
|
416
|
-
styleSourceId:
|
|
417
|
-
breakpointId:
|
|
418
|
-
state:
|
|
581
|
+
import { z as z11 } from "zod";
|
|
582
|
+
import { StyleValue as StyleValue2 } from "@webstudio-is/css-engine";
|
|
583
|
+
var StyleDeclRaw = z11.object({
|
|
584
|
+
styleSourceId: z11.string(),
|
|
585
|
+
breakpointId: z11.string(),
|
|
586
|
+
state: z11.optional(z11.string()),
|
|
419
587
|
// @todo can't figure out how to make property to be enum
|
|
420
|
-
property:
|
|
421
|
-
value:
|
|
422
|
-
listed:
|
|
588
|
+
property: z11.string(),
|
|
589
|
+
value: StyleValue2,
|
|
590
|
+
listed: z11.boolean().optional()
|
|
423
591
|
});
|
|
424
592
|
var StyleDecl = StyleDeclRaw;
|
|
425
593
|
var getStyleDeclKey = (styleDecl) => {
|
|
426
594
|
return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
|
|
427
595
|
};
|
|
428
|
-
var Styles =
|
|
596
|
+
var Styles = z11.map(z11.string(), StyleDecl);
|
|
429
597
|
|
|
430
598
|
// src/schema/deployment.ts
|
|
431
|
-
import { z as
|
|
432
|
-
var Templates =
|
|
433
|
-
"vanilla",
|
|
599
|
+
import { z as z12 } from "zod";
|
|
600
|
+
var Templates = z12.enum([
|
|
434
601
|
"docker",
|
|
435
602
|
"vercel",
|
|
436
603
|
"netlify",
|
|
@@ -438,179 +605,185 @@ var Templates = z11.enum([
|
|
|
438
605
|
"ssg-netlify",
|
|
439
606
|
"ssg-vercel"
|
|
440
607
|
]);
|
|
441
|
-
var Deployment =
|
|
442
|
-
|
|
443
|
-
destination:
|
|
444
|
-
name:
|
|
445
|
-
assetsDomain:
|
|
608
|
+
var Deployment = z12.union([
|
|
609
|
+
z12.object({
|
|
610
|
+
destination: z12.literal("static"),
|
|
611
|
+
name: z12.string(),
|
|
612
|
+
assetsDomain: z12.string(),
|
|
446
613
|
// Must be validated very strictly
|
|
447
|
-
templates:
|
|
614
|
+
templates: z12.array(Templates)
|
|
448
615
|
}),
|
|
449
|
-
|
|
450
|
-
destination:
|
|
451
|
-
domains:
|
|
452
|
-
assetsDomain:
|
|
616
|
+
z12.object({
|
|
617
|
+
destination: z12.literal("saas").optional(),
|
|
618
|
+
domains: z12.array(z12.string()),
|
|
619
|
+
assetsDomain: z12.string().optional(),
|
|
453
620
|
/**
|
|
454
621
|
* @deprecated This field is deprecated, use `domains` instead.
|
|
455
622
|
*/
|
|
456
|
-
projectDomain:
|
|
457
|
-
excludeWstdDomainFromSearch:
|
|
623
|
+
projectDomain: z12.string().optional(),
|
|
624
|
+
excludeWstdDomainFromSearch: z12.boolean().optional()
|
|
458
625
|
})
|
|
459
626
|
]);
|
|
460
627
|
|
|
461
628
|
// src/schema/webstudio.ts
|
|
462
|
-
import { z as
|
|
463
|
-
var WebstudioFragment =
|
|
464
|
-
children:
|
|
465
|
-
instances:
|
|
466
|
-
assets:
|
|
467
|
-
dataSources:
|
|
468
|
-
resources:
|
|
469
|
-
props:
|
|
470
|
-
breakpoints:
|
|
471
|
-
styleSourceSelections:
|
|
472
|
-
styleSources:
|
|
473
|
-
styles:
|
|
629
|
+
import { z as z13 } from "zod";
|
|
630
|
+
var WebstudioFragment = z13.object({
|
|
631
|
+
children: z13.array(InstanceChild),
|
|
632
|
+
instances: z13.array(Instance),
|
|
633
|
+
assets: z13.array(Asset),
|
|
634
|
+
dataSources: z13.array(DataSource),
|
|
635
|
+
resources: z13.array(Resource),
|
|
636
|
+
props: z13.array(Prop),
|
|
637
|
+
breakpoints: z13.array(Breakpoint),
|
|
638
|
+
styleSourceSelections: z13.array(StyleSourceSelection),
|
|
639
|
+
styleSources: z13.array(StyleSource),
|
|
640
|
+
styles: z13.array(StyleDecl)
|
|
474
641
|
});
|
|
475
642
|
|
|
476
643
|
// src/schema/prop-meta.ts
|
|
477
|
-
import { z as
|
|
644
|
+
import { z as z14 } from "zod";
|
|
478
645
|
var common = {
|
|
479
|
-
label:
|
|
480
|
-
description:
|
|
481
|
-
required:
|
|
646
|
+
label: z14.string().optional(),
|
|
647
|
+
description: z14.string().optional(),
|
|
648
|
+
required: z14.boolean()
|
|
482
649
|
};
|
|
483
|
-
var Number =
|
|
650
|
+
var Number = z14.object({
|
|
484
651
|
...common,
|
|
485
|
-
control:
|
|
486
|
-
type:
|
|
487
|
-
defaultValue:
|
|
652
|
+
control: z14.literal("number"),
|
|
653
|
+
type: z14.literal("number"),
|
|
654
|
+
defaultValue: z14.number().optional()
|
|
488
655
|
});
|
|
489
|
-
var Range =
|
|
656
|
+
var Range = z14.object({
|
|
490
657
|
...common,
|
|
491
|
-
control:
|
|
492
|
-
type:
|
|
493
|
-
defaultValue:
|
|
658
|
+
control: z14.literal("range"),
|
|
659
|
+
type: z14.literal("number"),
|
|
660
|
+
defaultValue: z14.number().optional()
|
|
494
661
|
});
|
|
495
|
-
var Text =
|
|
662
|
+
var Text = z14.object({
|
|
496
663
|
...common,
|
|
497
|
-
control:
|
|
498
|
-
type:
|
|
499
|
-
defaultValue:
|
|
664
|
+
control: z14.literal("text"),
|
|
665
|
+
type: z14.literal("string"),
|
|
666
|
+
defaultValue: z14.string().optional(),
|
|
500
667
|
/**
|
|
501
668
|
* The number of rows in <textarea>. If set to 0 an <input> will be used instead.
|
|
502
669
|
* In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
|
|
503
670
|
*/
|
|
504
|
-
rows:
|
|
671
|
+
rows: z14.number().optional()
|
|
505
672
|
});
|
|
506
|
-
var Code =
|
|
673
|
+
var Code = z14.object({
|
|
507
674
|
...common,
|
|
508
|
-
control:
|
|
509
|
-
type:
|
|
510
|
-
language:
|
|
511
|
-
defaultValue:
|
|
675
|
+
control: z14.literal("code"),
|
|
676
|
+
type: z14.literal("string"),
|
|
677
|
+
language: z14.union([z14.literal("html"), z14.literal("markdown")]),
|
|
678
|
+
defaultValue: z14.string().optional()
|
|
512
679
|
});
|
|
513
|
-
var CodeText =
|
|
680
|
+
var CodeText = z14.object({
|
|
514
681
|
...common,
|
|
515
|
-
control:
|
|
516
|
-
type:
|
|
517
|
-
defaultValue:
|
|
682
|
+
control: z14.literal("codetext"),
|
|
683
|
+
type: z14.literal("string"),
|
|
684
|
+
defaultValue: z14.string().optional()
|
|
518
685
|
});
|
|
519
|
-
var Color =
|
|
686
|
+
var Color = z14.object({
|
|
520
687
|
...common,
|
|
521
|
-
control:
|
|
522
|
-
type:
|
|
523
|
-
defaultValue:
|
|
688
|
+
control: z14.literal("color"),
|
|
689
|
+
type: z14.literal("string"),
|
|
690
|
+
defaultValue: z14.string().optional()
|
|
524
691
|
});
|
|
525
|
-
var Boolean =
|
|
692
|
+
var Boolean = z14.object({
|
|
526
693
|
...common,
|
|
527
|
-
control:
|
|
528
|
-
type:
|
|
529
|
-
defaultValue:
|
|
694
|
+
control: z14.literal("boolean"),
|
|
695
|
+
type: z14.literal("boolean"),
|
|
696
|
+
defaultValue: z14.boolean().optional()
|
|
530
697
|
});
|
|
531
|
-
var Radio =
|
|
698
|
+
var Radio = z14.object({
|
|
532
699
|
...common,
|
|
533
|
-
control:
|
|
534
|
-
type:
|
|
535
|
-
defaultValue:
|
|
536
|
-
options:
|
|
700
|
+
control: z14.literal("radio"),
|
|
701
|
+
type: z14.literal("string"),
|
|
702
|
+
defaultValue: z14.string().optional(),
|
|
703
|
+
options: z14.array(z14.string())
|
|
537
704
|
});
|
|
538
|
-
var InlineRadio =
|
|
705
|
+
var InlineRadio = z14.object({
|
|
539
706
|
...common,
|
|
540
|
-
control:
|
|
541
|
-
type:
|
|
542
|
-
defaultValue:
|
|
543
|
-
options:
|
|
707
|
+
control: z14.literal("inline-radio"),
|
|
708
|
+
type: z14.literal("string"),
|
|
709
|
+
defaultValue: z14.string().optional(),
|
|
710
|
+
options: z14.array(z14.string())
|
|
544
711
|
});
|
|
545
|
-
var Select =
|
|
712
|
+
var Select = z14.object({
|
|
546
713
|
...common,
|
|
547
|
-
control:
|
|
548
|
-
type:
|
|
549
|
-
defaultValue:
|
|
550
|
-
options:
|
|
714
|
+
control: z14.literal("select"),
|
|
715
|
+
type: z14.literal("string"),
|
|
716
|
+
defaultValue: z14.string().optional(),
|
|
717
|
+
options: z14.array(z14.string())
|
|
551
718
|
});
|
|
552
|
-
var Check =
|
|
719
|
+
var Check = z14.object({
|
|
553
720
|
...common,
|
|
554
|
-
control:
|
|
555
|
-
type:
|
|
556
|
-
defaultValue:
|
|
557
|
-
options:
|
|
721
|
+
control: z14.literal("check"),
|
|
722
|
+
type: z14.literal("string[]"),
|
|
723
|
+
defaultValue: z14.array(z14.string()).optional(),
|
|
724
|
+
options: z14.array(z14.string())
|
|
558
725
|
});
|
|
559
|
-
var InlineCheck =
|
|
726
|
+
var InlineCheck = z14.object({
|
|
560
727
|
...common,
|
|
561
|
-
control:
|
|
562
|
-
type:
|
|
563
|
-
defaultValue:
|
|
564
|
-
options:
|
|
728
|
+
control: z14.literal("inline-check"),
|
|
729
|
+
type: z14.literal("string[]"),
|
|
730
|
+
defaultValue: z14.array(z14.string()).optional(),
|
|
731
|
+
options: z14.array(z14.string())
|
|
565
732
|
});
|
|
566
|
-
var MultiSelect =
|
|
733
|
+
var MultiSelect = z14.object({
|
|
567
734
|
...common,
|
|
568
|
-
control:
|
|
569
|
-
type:
|
|
570
|
-
defaultValue:
|
|
571
|
-
options:
|
|
735
|
+
control: z14.literal("multi-select"),
|
|
736
|
+
type: z14.literal("string[]"),
|
|
737
|
+
defaultValue: z14.array(z14.string()).optional(),
|
|
738
|
+
options: z14.array(z14.string())
|
|
572
739
|
});
|
|
573
|
-
var File =
|
|
740
|
+
var File = z14.object({
|
|
574
741
|
...common,
|
|
575
|
-
control:
|
|
576
|
-
type:
|
|
577
|
-
defaultValue:
|
|
742
|
+
control: z14.literal("file"),
|
|
743
|
+
type: z14.literal("string"),
|
|
744
|
+
defaultValue: z14.string().optional(),
|
|
578
745
|
/** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
|
|
579
|
-
accept:
|
|
746
|
+
accept: z14.string().optional()
|
|
580
747
|
});
|
|
581
|
-
var Url =
|
|
748
|
+
var Url = z14.object({
|
|
582
749
|
...common,
|
|
583
|
-
control:
|
|
584
|
-
type:
|
|
585
|
-
defaultValue:
|
|
750
|
+
control: z14.literal("url"),
|
|
751
|
+
type: z14.literal("string"),
|
|
752
|
+
defaultValue: z14.string().optional()
|
|
586
753
|
});
|
|
587
|
-
var Json =
|
|
754
|
+
var Json = z14.object({
|
|
588
755
|
...common,
|
|
589
|
-
control:
|
|
590
|
-
type:
|
|
591
|
-
defaultValue:
|
|
756
|
+
control: z14.literal("json"),
|
|
757
|
+
type: z14.literal("json"),
|
|
758
|
+
defaultValue: z14.unknown().optional()
|
|
592
759
|
});
|
|
593
|
-
var Date =
|
|
760
|
+
var Date = z14.object({
|
|
594
761
|
...common,
|
|
595
|
-
control:
|
|
762
|
+
control: z14.literal("date"),
|
|
596
763
|
// @todo not sure what type should be here
|
|
597
764
|
// (we don't support Date yet, added for completeness)
|
|
598
|
-
type:
|
|
599
|
-
defaultValue:
|
|
765
|
+
type: z14.literal("string"),
|
|
766
|
+
defaultValue: z14.string().optional()
|
|
767
|
+
});
|
|
768
|
+
var Action = z14.object({
|
|
769
|
+
...common,
|
|
770
|
+
control: z14.literal("action"),
|
|
771
|
+
type: z14.literal("action"),
|
|
772
|
+
defaultValue: z14.undefined().optional()
|
|
600
773
|
});
|
|
601
|
-
var
|
|
774
|
+
var TextContent = z14.object({
|
|
602
775
|
...common,
|
|
603
|
-
control:
|
|
604
|
-
type:
|
|
605
|
-
defaultValue:
|
|
776
|
+
control: z14.literal("textContent"),
|
|
777
|
+
type: z14.literal("string"),
|
|
778
|
+
defaultValue: z14.string().optional()
|
|
606
779
|
});
|
|
607
|
-
var
|
|
780
|
+
var AnimationAction = z14.object({
|
|
608
781
|
...common,
|
|
609
|
-
control:
|
|
610
|
-
type:
|
|
611
|
-
defaultValue:
|
|
782
|
+
control: z14.literal("animationAction"),
|
|
783
|
+
type: z14.literal("animationAction"),
|
|
784
|
+
defaultValue: z14.undefined().optional()
|
|
612
785
|
});
|
|
613
|
-
var PropMeta =
|
|
786
|
+
var PropMeta = z14.union([
|
|
614
787
|
Number,
|
|
615
788
|
Range,
|
|
616
789
|
Text,
|
|
@@ -629,104 +802,105 @@ var PropMeta = z13.union([
|
|
|
629
802
|
Json,
|
|
630
803
|
Date,
|
|
631
804
|
Action,
|
|
632
|
-
TextContent
|
|
805
|
+
TextContent,
|
|
806
|
+
AnimationAction
|
|
633
807
|
]);
|
|
634
808
|
|
|
635
809
|
// src/schema/embed-template.ts
|
|
636
|
-
import { z as
|
|
637
|
-
import { StyleValue as
|
|
638
|
-
var EmbedTemplateText =
|
|
639
|
-
type:
|
|
640
|
-
value:
|
|
641
|
-
placeholder:
|
|
810
|
+
import { z as z15 } from "zod";
|
|
811
|
+
import { StyleValue as StyleValue3 } from "@webstudio-is/css-engine";
|
|
812
|
+
var EmbedTemplateText = z15.object({
|
|
813
|
+
type: z15.literal("text"),
|
|
814
|
+
value: z15.string(),
|
|
815
|
+
placeholder: z15.boolean().optional()
|
|
642
816
|
});
|
|
643
|
-
var EmbedTemplateExpression =
|
|
644
|
-
type:
|
|
645
|
-
value:
|
|
817
|
+
var EmbedTemplateExpression = z15.object({
|
|
818
|
+
type: z15.literal("expression"),
|
|
819
|
+
value: z15.string()
|
|
646
820
|
});
|
|
647
|
-
var EmbedTemplateVariable =
|
|
648
|
-
alias:
|
|
649
|
-
initialValue:
|
|
821
|
+
var EmbedTemplateVariable = z15.object({
|
|
822
|
+
alias: z15.optional(z15.string()),
|
|
823
|
+
initialValue: z15.unknown()
|
|
650
824
|
});
|
|
651
|
-
var EmbedTemplateProp =
|
|
652
|
-
|
|
653
|
-
type:
|
|
654
|
-
name:
|
|
655
|
-
value:
|
|
825
|
+
var EmbedTemplateProp = z15.union([
|
|
826
|
+
z15.object({
|
|
827
|
+
type: z15.literal("number"),
|
|
828
|
+
name: z15.string(),
|
|
829
|
+
value: z15.number()
|
|
656
830
|
}),
|
|
657
|
-
|
|
658
|
-
type:
|
|
659
|
-
name:
|
|
660
|
-
value:
|
|
831
|
+
z15.object({
|
|
832
|
+
type: z15.literal("string"),
|
|
833
|
+
name: z15.string(),
|
|
834
|
+
value: z15.string()
|
|
661
835
|
}),
|
|
662
|
-
|
|
663
|
-
type:
|
|
664
|
-
name:
|
|
665
|
-
value:
|
|
836
|
+
z15.object({
|
|
837
|
+
type: z15.literal("boolean"),
|
|
838
|
+
name: z15.string(),
|
|
839
|
+
value: z15.boolean()
|
|
666
840
|
}),
|
|
667
|
-
|
|
668
|
-
type:
|
|
669
|
-
name:
|
|
670
|
-
value:
|
|
841
|
+
z15.object({
|
|
842
|
+
type: z15.literal("string[]"),
|
|
843
|
+
name: z15.string(),
|
|
844
|
+
value: z15.array(z15.string())
|
|
671
845
|
}),
|
|
672
|
-
|
|
673
|
-
type:
|
|
674
|
-
name:
|
|
675
|
-
value:
|
|
846
|
+
z15.object({
|
|
847
|
+
type: z15.literal("json"),
|
|
848
|
+
name: z15.string(),
|
|
849
|
+
value: z15.unknown()
|
|
676
850
|
}),
|
|
677
|
-
|
|
678
|
-
type:
|
|
679
|
-
name:
|
|
680
|
-
code:
|
|
851
|
+
z15.object({
|
|
852
|
+
type: z15.literal("expression"),
|
|
853
|
+
name: z15.string(),
|
|
854
|
+
code: z15.string()
|
|
681
855
|
}),
|
|
682
|
-
|
|
683
|
-
type:
|
|
684
|
-
name:
|
|
685
|
-
variableName:
|
|
686
|
-
variableAlias:
|
|
856
|
+
z15.object({
|
|
857
|
+
type: z15.literal("parameter"),
|
|
858
|
+
name: z15.string(),
|
|
859
|
+
variableName: z15.string(),
|
|
860
|
+
variableAlias: z15.optional(z15.string())
|
|
687
861
|
}),
|
|
688
|
-
|
|
689
|
-
type:
|
|
690
|
-
name:
|
|
691
|
-
value:
|
|
692
|
-
|
|
693
|
-
type:
|
|
694
|
-
args:
|
|
695
|
-
code:
|
|
862
|
+
z15.object({
|
|
863
|
+
type: z15.literal("action"),
|
|
864
|
+
name: z15.string(),
|
|
865
|
+
value: z15.array(
|
|
866
|
+
z15.object({
|
|
867
|
+
type: z15.literal("execute"),
|
|
868
|
+
args: z15.optional(z15.array(z15.string())),
|
|
869
|
+
code: z15.string()
|
|
696
870
|
})
|
|
697
871
|
)
|
|
698
872
|
})
|
|
699
873
|
]);
|
|
700
|
-
var EmbedTemplateStyleDeclRaw =
|
|
874
|
+
var EmbedTemplateStyleDeclRaw = z15.object({
|
|
701
875
|
// State selector, e.g. :hover
|
|
702
|
-
state:
|
|
703
|
-
property:
|
|
704
|
-
value:
|
|
876
|
+
state: z15.optional(z15.string()),
|
|
877
|
+
property: z15.string(),
|
|
878
|
+
value: StyleValue3
|
|
705
879
|
});
|
|
706
880
|
var EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
|
|
707
|
-
var EmbedTemplateInstance =
|
|
708
|
-
() =>
|
|
709
|
-
type:
|
|
710
|
-
component:
|
|
711
|
-
label:
|
|
712
|
-
variables:
|
|
713
|
-
props:
|
|
714
|
-
styles:
|
|
881
|
+
var EmbedTemplateInstance = z15.lazy(
|
|
882
|
+
() => z15.object({
|
|
883
|
+
type: z15.literal("instance"),
|
|
884
|
+
component: z15.string(),
|
|
885
|
+
label: z15.optional(z15.string()),
|
|
886
|
+
variables: z15.optional(z15.record(z15.string(), EmbedTemplateVariable)),
|
|
887
|
+
props: z15.optional(z15.array(EmbedTemplateProp)),
|
|
888
|
+
styles: z15.optional(z15.array(EmbedTemplateStyleDecl)),
|
|
715
889
|
children: WsEmbedTemplate
|
|
716
890
|
})
|
|
717
891
|
);
|
|
718
|
-
var WsEmbedTemplate =
|
|
719
|
-
() =>
|
|
720
|
-
|
|
892
|
+
var WsEmbedTemplate = z15.lazy(
|
|
893
|
+
() => z15.array(
|
|
894
|
+
z15.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
|
|
721
895
|
)
|
|
722
896
|
);
|
|
723
897
|
|
|
724
898
|
// src/schema/component-meta.ts
|
|
725
|
-
import { z as
|
|
726
|
-
var WsComponentPropsMeta =
|
|
727
|
-
props:
|
|
899
|
+
import { z as z16 } from "zod";
|
|
900
|
+
var WsComponentPropsMeta = z16.object({
|
|
901
|
+
props: z16.record(PropMeta),
|
|
728
902
|
// Props that will be always visible in properties panel.
|
|
729
|
-
initialProps:
|
|
903
|
+
initialProps: z16.array(z16.string()).optional()
|
|
730
904
|
});
|
|
731
905
|
var componentCategories = [
|
|
732
906
|
"general",
|
|
@@ -741,10 +915,10 @@ var componentCategories = [
|
|
|
741
915
|
"internal"
|
|
742
916
|
];
|
|
743
917
|
var stateCategories = ["states", "component-states"];
|
|
744
|
-
var ComponentState =
|
|
745
|
-
category:
|
|
746
|
-
selector:
|
|
747
|
-
label:
|
|
918
|
+
var ComponentState = z16.object({
|
|
919
|
+
category: z16.enum(stateCategories).optional(),
|
|
920
|
+
selector: z16.string(),
|
|
921
|
+
label: z16.string()
|
|
748
922
|
});
|
|
749
923
|
var defaultStates = [
|
|
750
924
|
{ selector: ":hover", label: "Hover" },
|
|
@@ -753,28 +927,33 @@ var defaultStates = [
|
|
|
753
927
|
{ selector: ":focus-visible", label: "Focus Visible" },
|
|
754
928
|
{ selector: ":focus-within", label: "Focus Within" }
|
|
755
929
|
];
|
|
756
|
-
var WsComponentMeta =
|
|
757
|
-
category:
|
|
930
|
+
var WsComponentMeta = z16.object({
|
|
931
|
+
category: z16.enum(componentCategories).optional(),
|
|
758
932
|
// container - can accept other components with dnd or be edited as text
|
|
759
933
|
// control - usually form controls like inputs, without children
|
|
760
934
|
// embed - images, videos or other embeddable components, without children
|
|
761
935
|
// rich-text-child - formatted text fragment, not listed in components list
|
|
762
|
-
type:
|
|
936
|
+
type: z16.enum(["container", "control", "embed", "rich-text-child"]),
|
|
937
|
+
/**
|
|
938
|
+
* a property used as textual placeholder when no content specified while in builder
|
|
939
|
+
* also signals to not insert components inside unless dropped explicitly
|
|
940
|
+
*/
|
|
941
|
+
placeholder: z16.string().optional(),
|
|
763
942
|
constraints: Matchers.optional(),
|
|
764
943
|
// when this field is specified component receives
|
|
765
944
|
// prop with index of same components withiin specified ancestor
|
|
766
945
|
// important to automatically enumerate collections without
|
|
767
946
|
// naming every item manually
|
|
768
|
-
indexWithinAncestor:
|
|
769
|
-
label:
|
|
770
|
-
description:
|
|
771
|
-
icon:
|
|
772
|
-
presetStyle:
|
|
773
|
-
|
|
947
|
+
indexWithinAncestor: z16.optional(z16.string()),
|
|
948
|
+
label: z16.optional(z16.string()),
|
|
949
|
+
description: z16.string().optional(),
|
|
950
|
+
icon: z16.string(),
|
|
951
|
+
presetStyle: z16.optional(
|
|
952
|
+
z16.record(z16.string(), z16.array(EmbedTemplateStyleDecl))
|
|
774
953
|
),
|
|
775
|
-
states:
|
|
776
|
-
template:
|
|
777
|
-
order:
|
|
954
|
+
states: z16.optional(z16.array(ComponentState)),
|
|
955
|
+
template: z16.optional(WsEmbedTemplate),
|
|
956
|
+
order: z16.number().optional()
|
|
778
957
|
});
|
|
779
958
|
|
|
780
959
|
// src/core-metas.ts
|
|
@@ -974,6 +1153,13 @@ import {
|
|
|
974
1153
|
parseExpressionAt
|
|
975
1154
|
} from "acorn";
|
|
976
1155
|
import { simple } from "acorn-walk";
|
|
1156
|
+
var SYSTEM_VARIABLE_ID = ":system";
|
|
1157
|
+
var systemParameter = {
|
|
1158
|
+
id: SYSTEM_VARIABLE_ID,
|
|
1159
|
+
scopeInstanceId: ROOT_INSTANCE_ID,
|
|
1160
|
+
type: "parameter",
|
|
1161
|
+
name: "system"
|
|
1162
|
+
};
|
|
977
1163
|
var lintExpression = ({
|
|
978
1164
|
expression,
|
|
979
1165
|
availableVariables = /* @__PURE__ */ new Set(),
|
|
@@ -1225,11 +1411,17 @@ var generateObjectExpression = (map) => {
|
|
|
1225
1411
|
return generated;
|
|
1226
1412
|
};
|
|
1227
1413
|
var dataSourceVariablePrefix = "$ws$dataSource$";
|
|
1228
|
-
var
|
|
1414
|
+
var encodeDataVariableId = (id) => {
|
|
1415
|
+
if (id === SYSTEM_VARIABLE_ID) {
|
|
1416
|
+
return "$ws$system";
|
|
1417
|
+
}
|
|
1229
1418
|
const encoded = id.replaceAll("-", "__DASH__");
|
|
1230
1419
|
return `${dataSourceVariablePrefix}${encoded}`;
|
|
1231
1420
|
};
|
|
1232
|
-
var
|
|
1421
|
+
var decodeDataVariableId = (name) => {
|
|
1422
|
+
if (name === "$ws$system") {
|
|
1423
|
+
return SYSTEM_VARIABLE_ID;
|
|
1424
|
+
}
|
|
1233
1425
|
if (name.startsWith(dataSourceVariablePrefix)) {
|
|
1234
1426
|
const encoded = name.slice(dataSourceVariablePrefix.length);
|
|
1235
1427
|
return encoded.replaceAll("__DASH__", "-");
|
|
@@ -1246,8 +1438,11 @@ var generateExpression = ({
|
|
|
1246
1438
|
expression,
|
|
1247
1439
|
executable: true,
|
|
1248
1440
|
replaceVariable: (identifier) => {
|
|
1249
|
-
const depId =
|
|
1250
|
-
|
|
1441
|
+
const depId = decodeDataVariableId(identifier);
|
|
1442
|
+
let dep = depId ? dataSources.get(depId) : void 0;
|
|
1443
|
+
if (depId === SYSTEM_VARIABLE_ID) {
|
|
1444
|
+
dep = systemParameter;
|
|
1445
|
+
}
|
|
1251
1446
|
if (dep) {
|
|
1252
1447
|
usedDataSources?.set(dep.id, dep);
|
|
1253
1448
|
return scope.getName(dep.id, dep.name);
|
|
@@ -1439,12 +1634,11 @@ var generateResources = ({
|
|
|
1439
1634
|
`;
|
|
1440
1635
|
}
|
|
1441
1636
|
if (dataSource.type === "parameter") {
|
|
1442
|
-
if (dataSource.id
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
const name = scope.getName(dataSource.id, dataSource.name);
|
|
1446
|
-
generatedVariables += ` const ${name} = _props.system
|
|
1637
|
+
if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
|
|
1638
|
+
const name = scope.getName(dataSource.id, dataSource.name);
|
|
1639
|
+
generatedVariables += ` const ${name} = _props.system
|
|
1447
1640
|
`;
|
|
1641
|
+
}
|
|
1448
1642
|
}
|
|
1449
1643
|
}
|
|
1450
1644
|
let generated = "";
|
|
@@ -1641,7 +1835,7 @@ var generatePageMeta = ({
|
|
|
1641
1835
|
continue;
|
|
1642
1836
|
}
|
|
1643
1837
|
if (dataSource.type === "parameter") {
|
|
1644
|
-
if (dataSource.id === page.systemDataSourceId) {
|
|
1838
|
+
if (dataSource.id === page.systemDataSourceId || dataSource.id === SYSTEM_VARIABLE_ID) {
|
|
1645
1839
|
const valueName = localScope.getName(dataSource.id, dataSource.name);
|
|
1646
1840
|
generated += ` let ${valueName} = system
|
|
1647
1841
|
`;
|
|
@@ -1685,6 +1879,182 @@ var generatePageMeta = ({
|
|
|
1685
1879
|
`;
|
|
1686
1880
|
return generated;
|
|
1687
1881
|
};
|
|
1882
|
+
|
|
1883
|
+
// src/css.ts
|
|
1884
|
+
import { kebabCase } from "change-case";
|
|
1885
|
+
import {
|
|
1886
|
+
createRegularStyleSheet,
|
|
1887
|
+
generateAtomic
|
|
1888
|
+
} from "@webstudio-is/css-engine";
|
|
1889
|
+
import { getFontFaces } from "@webstudio-is/fonts";
|
|
1890
|
+
var addFontRules = ({
|
|
1891
|
+
sheet,
|
|
1892
|
+
assets,
|
|
1893
|
+
assetBaseUrl
|
|
1894
|
+
}) => {
|
|
1895
|
+
const fontAssets = [];
|
|
1896
|
+
for (const asset of assets.values()) {
|
|
1897
|
+
if (asset.type === "font") {
|
|
1898
|
+
fontAssets.push(asset);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
|
|
1902
|
+
for (const fontFace of fontFaces) {
|
|
1903
|
+
sheet.addFontFaceRule(fontFace);
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
var createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
|
|
1907
|
+
if (styleValue.type === "image" && styleValue.value.type === "asset") {
|
|
1908
|
+
const asset = assets.get(styleValue.value.value);
|
|
1909
|
+
if (asset === void 0) {
|
|
1910
|
+
return { type: "keyword", value: "none" };
|
|
1911
|
+
}
|
|
1912
|
+
const url = `${assetBaseUrl}${asset.name}`;
|
|
1913
|
+
return {
|
|
1914
|
+
type: "image",
|
|
1915
|
+
value: {
|
|
1916
|
+
type: "url",
|
|
1917
|
+
url
|
|
1918
|
+
},
|
|
1919
|
+
hidden: styleValue.hidden
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
var normalizeClassName = (name) => kebabCase(name);
|
|
1924
|
+
var generateCss = ({
|
|
1925
|
+
assets,
|
|
1926
|
+
instances,
|
|
1927
|
+
props,
|
|
1928
|
+
breakpoints,
|
|
1929
|
+
styles,
|
|
1930
|
+
styleSourceSelections,
|
|
1931
|
+
componentMetas,
|
|
1932
|
+
assetBaseUrl,
|
|
1933
|
+
atomic
|
|
1934
|
+
}) => {
|
|
1935
|
+
const fontSheet = createRegularStyleSheet({ name: "ssr" });
|
|
1936
|
+
const presetSheet = createRegularStyleSheet({ name: "ssr" });
|
|
1937
|
+
const userSheet = createRegularStyleSheet({ name: "ssr" });
|
|
1938
|
+
addFontRules({ sheet: fontSheet, assets, assetBaseUrl });
|
|
1939
|
+
presetSheet.addMediaRule("presets");
|
|
1940
|
+
const presetClasses = /* @__PURE__ */ new Map();
|
|
1941
|
+
const scope = createScope([], normalizeClassName, "-");
|
|
1942
|
+
for (const [component, meta] of componentMetas) {
|
|
1943
|
+
const [_namespace, componentName] = parseComponentName(component);
|
|
1944
|
+
const className = `w-${scope.getName(component, meta.label ?? componentName)}`;
|
|
1945
|
+
const presetStyle = Object.entries(meta.presetStyle ?? {});
|
|
1946
|
+
if (presetStyle.length > 0) {
|
|
1947
|
+
presetClasses.set(component, className);
|
|
1948
|
+
}
|
|
1949
|
+
for (const [tag, styles2] of presetStyle) {
|
|
1950
|
+
const selector = component === rootComponent ? ":root" : `${tag}.${className}`;
|
|
1951
|
+
const rule = presetSheet.addNestingRule(selector);
|
|
1952
|
+
for (const declaration of styles2) {
|
|
1953
|
+
rule.setDeclaration({
|
|
1954
|
+
breakpoint: "presets",
|
|
1955
|
+
selector: declaration.state ?? "",
|
|
1956
|
+
property: declaration.property,
|
|
1957
|
+
value: declaration.value
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
for (const breakpoint of breakpoints.values()) {
|
|
1963
|
+
userSheet.addMediaRule(breakpoint.id, breakpoint);
|
|
1964
|
+
}
|
|
1965
|
+
const imageValueTransformer = createImageValueTransformer(assets, {
|
|
1966
|
+
assetBaseUrl
|
|
1967
|
+
});
|
|
1968
|
+
userSheet.setTransformer(imageValueTransformer);
|
|
1969
|
+
for (const styleDecl of styles.values()) {
|
|
1970
|
+
const rule = userSheet.addMixinRule(styleDecl.styleSourceId);
|
|
1971
|
+
rule.setDeclaration({
|
|
1972
|
+
breakpoint: styleDecl.breakpointId,
|
|
1973
|
+
selector: styleDecl.state ?? "",
|
|
1974
|
+
property: styleDecl.property,
|
|
1975
|
+
value: styleDecl.value
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
const classes = /* @__PURE__ */ new Map();
|
|
1979
|
+
const parentIdByInstanceId = /* @__PURE__ */ new Map();
|
|
1980
|
+
for (const instance of instances.values()) {
|
|
1981
|
+
const presetClass = presetClasses.get(instance.component);
|
|
1982
|
+
if (presetClass) {
|
|
1983
|
+
classes.set(instance.id, [presetClass]);
|
|
1984
|
+
}
|
|
1985
|
+
for (const child of instance.children) {
|
|
1986
|
+
if (child.type === "id") {
|
|
1987
|
+
parentIdByInstanceId.set(child.value, instance.id);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
|
|
1992
|
+
for (const prop of props.values()) {
|
|
1993
|
+
if (prop.name === "selector" && prop.type === "string") {
|
|
1994
|
+
descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
const instanceByRule = /* @__PURE__ */ new Map();
|
|
1998
|
+
for (const selection of styleSourceSelections.values()) {
|
|
1999
|
+
let { instanceId } = selection;
|
|
2000
|
+
const { values } = selection;
|
|
2001
|
+
if (instanceId === ROOT_INSTANCE_ID) {
|
|
2002
|
+
const rule2 = userSheet.addNestingRule(`:root`);
|
|
2003
|
+
rule2.applyMixins(values);
|
|
2004
|
+
continue;
|
|
2005
|
+
}
|
|
2006
|
+
let descendantSuffix = "";
|
|
2007
|
+
const instance = instances.get(instanceId);
|
|
2008
|
+
if (instance === void 0) {
|
|
2009
|
+
continue;
|
|
2010
|
+
}
|
|
2011
|
+
if (instance.component === descendantComponent) {
|
|
2012
|
+
const parentId = parentIdByInstanceId.get(instanceId);
|
|
2013
|
+
const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
|
|
2014
|
+
if (parentId && descendantSelector) {
|
|
2015
|
+
descendantSuffix = descendantSelector;
|
|
2016
|
+
instanceId = parentId;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
const meta = componentMetas.get(instance.component);
|
|
2020
|
+
const [_namespace, shortName] = parseComponentName(instance.component);
|
|
2021
|
+
const baseName = instance.label ?? meta?.label ?? shortName;
|
|
2022
|
+
const className = `w-${scope.getName(instanceId, baseName)}`;
|
|
2023
|
+
if (atomic === false) {
|
|
2024
|
+
let classList = classes.get(instanceId);
|
|
2025
|
+
if (classList === void 0) {
|
|
2026
|
+
classList = [];
|
|
2027
|
+
classes.set(instanceId, classList);
|
|
2028
|
+
}
|
|
2029
|
+
classList.push(className);
|
|
2030
|
+
}
|
|
2031
|
+
const rule = userSheet.addNestingRule(`.${className}`, descendantSuffix);
|
|
2032
|
+
rule.applyMixins(values);
|
|
2033
|
+
instanceByRule.set(rule, instanceId);
|
|
2034
|
+
}
|
|
2035
|
+
const fontCss = fontSheet.cssText;
|
|
2036
|
+
const presetCss = presetSheet.cssText.replaceAll(
|
|
2037
|
+
"@media all ",
|
|
2038
|
+
"@layer presets "
|
|
2039
|
+
);
|
|
2040
|
+
if (atomic) {
|
|
2041
|
+
const { cssText } = generateAtomic(userSheet, {
|
|
2042
|
+
getKey: (rule) => instanceByRule.get(rule),
|
|
2043
|
+
transformValue: imageValueTransformer,
|
|
2044
|
+
classes
|
|
2045
|
+
});
|
|
2046
|
+
return {
|
|
2047
|
+
cssText: `${fontCss}${presetCss}
|
|
2048
|
+
${cssText}`,
|
|
2049
|
+
classes
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
return {
|
|
2053
|
+
cssText: `${fontCss}${presetCss}
|
|
2054
|
+
${userSheet.cssText}`,
|
|
2055
|
+
classes
|
|
2056
|
+
};
|
|
2057
|
+
};
|
|
1688
2058
|
export {
|
|
1689
2059
|
Asset,
|
|
1690
2060
|
Assets,
|
|
@@ -1724,11 +2094,13 @@ export {
|
|
|
1724
2094
|
Prop,
|
|
1725
2095
|
PropMeta,
|
|
1726
2096
|
Props,
|
|
2097
|
+
RANGE_UNITS,
|
|
1727
2098
|
ROOT_FOLDER_ID,
|
|
1728
2099
|
ROOT_INSTANCE_ID,
|
|
1729
2100
|
Resource,
|
|
1730
2101
|
ResourceRequest,
|
|
1731
2102
|
Resources,
|
|
2103
|
+
SYSTEM_VARIABLE_ID,
|
|
1732
2104
|
StyleDecl,
|
|
1733
2105
|
StyleSource,
|
|
1734
2106
|
StyleSourceSelection,
|
|
@@ -1740,6 +2112,9 @@ export {
|
|
|
1740
2112
|
WebstudioFragment,
|
|
1741
2113
|
WsComponentMeta,
|
|
1742
2114
|
WsEmbedTemplate,
|
|
2115
|
+
addFontRules,
|
|
2116
|
+
animationActionSchema,
|
|
2117
|
+
animationKeyframeSchema,
|
|
1743
2118
|
blockComponent,
|
|
1744
2119
|
blockTemplateComponent,
|
|
1745
2120
|
blockTemplateMeta,
|
|
@@ -1747,19 +2122,21 @@ export {
|
|
|
1747
2122
|
componentCategories,
|
|
1748
2123
|
coreMetas,
|
|
1749
2124
|
corePropsMetas,
|
|
2125
|
+
createImageValueTransformer,
|
|
1750
2126
|
createScope,
|
|
1751
|
-
decodeDataSourceVariable,
|
|
1752
|
-
|
|
2127
|
+
decodeDataVariableId as decodeDataSourceVariable,
|
|
2128
|
+
decodeDataVariableId,
|
|
1753
2129
|
defaultStates,
|
|
1754
2130
|
descendantComponent,
|
|
1755
2131
|
documentTypes,
|
|
1756
|
-
encodeDataSourceVariable,
|
|
1757
|
-
|
|
2132
|
+
encodeDataVariableId as encodeDataSourceVariable,
|
|
2133
|
+
encodeDataVariableId,
|
|
1758
2134
|
executeExpression,
|
|
1759
2135
|
findPageByIdOrPath,
|
|
1760
2136
|
findParentFolderByChildId,
|
|
1761
2137
|
findTreeInstanceIds,
|
|
1762
2138
|
findTreeInstanceIdsExcludingSlotDescendants,
|
|
2139
|
+
generateCss,
|
|
1763
2140
|
generateExpression,
|
|
1764
2141
|
generateObjectExpression,
|
|
1765
2142
|
generatePageMeta,
|
|
@@ -1769,6 +2146,7 @@ export {
|
|
|
1769
2146
|
getStaticSiteMapXml,
|
|
1770
2147
|
getStyleDeclKey,
|
|
1771
2148
|
initialBreakpoints,
|
|
2149
|
+
insetUnitValueSchema,
|
|
1772
2150
|
isCoreComponent,
|
|
1773
2151
|
isLiteralExpression,
|
|
1774
2152
|
isPathnamePattern,
|
|
@@ -1778,8 +2156,12 @@ export {
|
|
|
1778
2156
|
parseComponentName,
|
|
1779
2157
|
parseObjectExpression,
|
|
1780
2158
|
portalComponent,
|
|
2159
|
+
rangeUnitValueSchema,
|
|
1781
2160
|
replaceFormActionsWithResources,
|
|
1782
2161
|
rootComponent,
|
|
2162
|
+
scrollAnimationSchema,
|
|
1783
2163
|
stateCategories,
|
|
1784
|
-
|
|
2164
|
+
systemParameter,
|
|
2165
|
+
transpileExpression,
|
|
2166
|
+
viewAnimationSchema
|
|
1785
2167
|
};
|