@webstudio-is/sdk 0.274.5 → 0.275.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -346,12 +346,29 @@ var pages = z2.object({
346
346
 
347
347
  // src/schema/instances.ts
348
348
  import { z as z3 } from "zod";
349
+ var textChildValue = z3.string();
349
350
  var textChild = z3.object({
350
351
  type: z3.literal("text"),
351
- value: z3.string(),
352
+ value: textChildValue,
352
353
  placeholder: z3.boolean().optional()
353
354
  });
354
355
  var instanceId = z3.string();
356
+ var instanceComponent = z3.string().min(1);
357
+ var instanceTag = z3.string().min(1, "Tag cannot be empty").describe(
358
+ "Optional HTML tag override for component rendering. Omit for component defaults; never pass an empty string."
359
+ );
360
+ var instanceAttributes = z3.object({
361
+ component: instanceComponent,
362
+ tag: instanceTag.optional(),
363
+ label: z3.string().optional()
364
+ });
365
+ var instanceCreateInput = instanceAttributes.partial({
366
+ component: true
367
+ });
368
+ var instanceFilterInput = instanceAttributes.pick({
369
+ component: true,
370
+ tag: true
371
+ }).partial();
355
372
  var idChild = z3.object({
356
373
  type: z3.literal("id"),
357
374
  value: instanceId
@@ -364,9 +381,9 @@ var instanceChild = z3.union([idChild, textChild, expressionChild]);
364
381
  var instance = z3.object({
365
382
  type: z3.literal("instance"),
366
383
  id: instanceId,
367
- component: z3.string(),
368
- tag: z3.string().optional(),
369
- label: z3.string().optional(),
384
+ component: instanceAttributes.shape.component,
385
+ tag: instanceAttributes.shape.tag,
386
+ label: instanceAttributes.shape.label,
370
387
  children: z3.array(instanceChild)
371
388
  });
372
389
  var instances = z3.map(instanceId, instance);
@@ -394,8 +411,8 @@ var dataSourceVariableValue = z4.union([
394
411
  }),
395
412
  z4.object({
396
413
  type: z4.literal("json"),
397
- value: z4.unknown()
398
- })
414
+ value: z4.unknown().optional()
415
+ }).transform((value) => ({ ...value, value: value.value ?? null }))
399
416
  ]);
400
417
  var dataSource = z4.union([
401
418
  z4.object({
@@ -461,6 +478,7 @@ var resource = z5.object({
461
478
  });
462
479
  var resourceRequest = z5.object({
463
480
  name: z5.string(),
481
+ control: z5.optional(z5.union([z5.literal("system"), z5.literal("graphql")])),
464
482
  method,
465
483
  url: z5.string(),
466
484
  searchParams: z5.array(
@@ -571,7 +589,7 @@ var insetUnitValue = z6.union([
571
589
  value: z6.literal("auto")
572
590
  })
573
591
  ]);
574
- var keyframeStyles = z6.record(styleValue);
592
+ var keyframeStyles = z6.record(z6.string(), styleValue);
575
593
  var animationKeyframe = z6.object({
576
594
  offset: z6.number().optional(),
577
595
  styles: keyframeStyles
@@ -1076,6 +1094,13 @@ var componentCategories = [
1076
1094
  "hidden",
1077
1095
  "internal"
1078
1096
  ];
1097
+ var normalizeComponentCategory = (category) => {
1098
+ return category ?? "hidden";
1099
+ };
1100
+ var shouldFilterComponentCategory = (category) => {
1101
+ const normalized = normalizeComponentCategory(category);
1102
+ return normalized === "hidden" || normalized === "internal";
1103
+ };
1079
1104
  var componentState = z15.object({
1080
1105
  selector: z15.string(),
1081
1106
  label: z15.string()
@@ -1106,13 +1131,14 @@ var wsComponentMeta = z15.object({
1106
1131
  indexWithinAncestor: z15.optional(z15.string()),
1107
1132
  label: z15.optional(z15.string()),
1108
1133
  description: z15.string().optional(),
1134
+ deprecated: z15.boolean().optional(),
1109
1135
  icon: z15.string().optional(),
1110
1136
  presetStyle: z15.optional(z15.record(z15.string(), z15.array(presetStyleDecl))),
1111
1137
  states: z15.optional(z15.array(componentState)),
1112
1138
  order: z15.number().optional(),
1113
1139
  // properties and html attributes that will be always visible in properties panel
1114
1140
  initialProps: z15.array(z15.string()).optional(),
1115
- props: z15.record(propMeta).optional()
1141
+ props: z15.record(z15.string(), propMeta).optional()
1116
1142
  });
1117
1143
 
1118
1144
  // src/assets.ts
@@ -2906,6 +2932,10 @@ var generateResources = ({
2906
2932
  `;
2907
2933
  generatedRequest += ` name: ${JSON.stringify(resource3.name)},
2908
2934
  `;
2935
+ if (resource3.control !== void 0) {
2936
+ generatedRequest += ` control: "${resource3.control}",
2937
+ `;
2938
+ }
2909
2939
  const url2 = generateExpression({
2910
2940
  expression: resource3.url,
2911
2941
  dataSources: dataSources2,
@@ -3069,6 +3099,26 @@ var replaceFormActionsWithResources = ({
3069
3099
  };
3070
3100
 
3071
3101
  // src/page-meta-generator.ts
3102
+ import { parseExpressionAt as parseExpressionAt2 } from "acorn";
3103
+ var normalizeStringExpression = (expression) => {
3104
+ const trimmedExpression = expression.trim();
3105
+ try {
3106
+ const parsedExpression = parseExpressionAt2(trimmedExpression, 0, {
3107
+ ecmaVersion: "latest"
3108
+ });
3109
+ if (parsedExpression.end === trimmedExpression.length) {
3110
+ if (parsedExpression.type === "Identifier" && trimmedExpression !== "undefined" && trimmedExpression.includes("$ws$") === false) {
3111
+ return JSON.stringify(expression);
3112
+ }
3113
+ return expression;
3114
+ }
3115
+ } catch {
3116
+ }
3117
+ if (trimmedExpression.includes("$ws$")) {
3118
+ return expression;
3119
+ }
3120
+ return JSON.stringify(expression);
3121
+ };
3072
3122
  var generatePageMeta = ({
3073
3123
  globalScope,
3074
3124
  page: page2,
@@ -3078,13 +3128,13 @@ var generatePageMeta = ({
3078
3128
  const localScope = createScope(["system", "resources"]);
3079
3129
  const usedDataSources = /* @__PURE__ */ new Map();
3080
3130
  const titleExpression = generateExpression({
3081
- expression: page2.title,
3131
+ expression: normalizeStringExpression(page2.title),
3082
3132
  dataSources: dataSources2,
3083
3133
  usedDataSources,
3084
3134
  scope: localScope
3085
3135
  });
3086
3136
  const descriptionExpression = generateExpression({
3087
- expression: page2.meta.description ?? "undefined",
3137
+ expression: normalizeStringExpression(page2.meta.description ?? "undefined"),
3088
3138
  dataSources: dataSources2,
3089
3139
  usedDataSources,
3090
3140
  scope: localScope
@@ -3096,7 +3146,7 @@ var generatePageMeta = ({
3096
3146
  scope: localScope
3097
3147
  });
3098
3148
  const languageExpression = generateExpression({
3099
- expression: page2.meta.language ?? "undefined",
3149
+ expression: normalizeStringExpression(page2.meta.language ?? "undefined"),
3100
3150
  dataSources: dataSources2,
3101
3151
  usedDataSources,
3102
3152
  scope: localScope
@@ -3105,7 +3155,9 @@ var generatePageMeta = ({
3105
3155
  page2.meta.socialImageAssetId ? assets2.get(page2.meta.socialImageAssetId)?.name : void 0
3106
3156
  );
3107
3157
  const socialImageUrlExpression = generateExpression({
3108
- expression: page2.meta.socialImageUrl ?? "undefined",
3158
+ expression: normalizeStringExpression(
3159
+ page2.meta.socialImageUrl ?? "undefined"
3160
+ ),
3109
3161
  dataSources: dataSources2,
3110
3162
  usedDataSources,
3111
3163
  scope: localScope
@@ -3117,13 +3169,13 @@ var generatePageMeta = ({
3117
3169
  scope: localScope
3118
3170
  });
3119
3171
  const redirectExpression = generateExpression({
3120
- expression: page2.meta.redirect ?? "undefined",
3172
+ expression: normalizeStringExpression(page2.meta.redirect ?? "undefined"),
3121
3173
  dataSources: dataSources2,
3122
3174
  usedDataSources,
3123
3175
  scope: localScope
3124
3176
  });
3125
3177
  const contentExpression = generateExpression({
3126
- expression: page2.meta.content ?? "undefined",
3178
+ expression: normalizeStringExpression(page2.meta.content ?? "undefined"),
3127
3179
  dataSources: dataSources2,
3128
3180
  usedDataSources,
3129
3181
  scope: localScope
@@ -3137,7 +3189,7 @@ var generatePageMeta = ({
3137
3189
  }
3138
3190
  const propertyExpression = JSON.stringify(customMeta.property);
3139
3191
  const contentExpression2 = generateExpression({
3140
- expression: customMeta.content,
3192
+ expression: normalizeStringExpression(customMeta.content),
3141
3193
  dataSources: dataSources2,
3142
3194
  usedDataSources,
3143
3195
  scope: localScope
@@ -3444,6 +3496,132 @@ ${userSheet.cssText}`,
3444
3496
  classes
3445
3497
  };
3446
3498
  };
3499
+
3500
+ // src/input-json-schema.ts
3501
+ var unique = (values) => [...new Set(values)];
3502
+ var toInputJsonSchemaObject = (schema) => {
3503
+ if (schema === void 0) {
3504
+ return;
3505
+ }
3506
+ if (schema === true) {
3507
+ return {};
3508
+ }
3509
+ if (schema === false) {
3510
+ return { not: {} };
3511
+ }
3512
+ return schema;
3513
+ };
3514
+ var annotationInputJsonSchemaFields = /* @__PURE__ */ new Set(["description", "default"]);
3515
+ var isUnconstrainedInputJsonSchema = (schema) => Object.entries(schema).every(
3516
+ ([field, value]) => value === void 0 || annotationInputJsonSchemaFields.has(field)
3517
+ );
3518
+ var inputJsonSchemaAcceptsType = (schema, type, options = {}) => {
3519
+ if (options.treatUnconstrainedAsAny === true && isUnconstrainedInputJsonSchema(schema)) {
3520
+ return true;
3521
+ }
3522
+ const schemaObject = toInputJsonSchemaObject(schema);
3523
+ if (schemaObject === void 0) {
3524
+ return false;
3525
+ }
3526
+ const types = schemaObject.type === void 0 ? [] : Array.isArray(schemaObject.type) ? schemaObject.type : [schemaObject.type];
3527
+ if (types.includes(type)) {
3528
+ return true;
3529
+ }
3530
+ if (type === "object" && (schemaObject.properties !== void 0 || schemaObject.required !== void 0 || schemaObject.additionalProperties !== void 0)) {
3531
+ return true;
3532
+ }
3533
+ if (type === "array" && (schemaObject.items !== void 0 || schemaObject.prefixItems !== void 0 || schemaObject.minItems !== void 0 || schemaObject.maxItems !== void 0)) {
3534
+ return true;
3535
+ }
3536
+ for (const combinator of ["anyOf", "oneOf"]) {
3537
+ if (schemaObject[combinator] !== void 0) {
3538
+ return schemaObject[combinator].some((item) => {
3539
+ const itemSchema = toInputJsonSchemaObject(item);
3540
+ return itemSchema === void 0 ? false : inputJsonSchemaAcceptsType(itemSchema, type, options);
3541
+ });
3542
+ }
3543
+ }
3544
+ if (schemaObject.allOf !== void 0) {
3545
+ return schemaObject.allOf.length > 0 && schemaObject.allOf.every((item) => {
3546
+ const itemSchema = toInputJsonSchemaObject(item);
3547
+ return itemSchema === void 0 ? false : inputJsonSchemaAcceptsType(itemSchema, type, options);
3548
+ });
3549
+ }
3550
+ return false;
3551
+ };
3552
+ var combineInputJsonSchemas = (left, right, combinator) => ({ [combinator]: [left, right] });
3553
+ var inputJsonSchemaCombinators = ["anyOf", "oneOf", "allOf"];
3554
+ var collectInputJsonSchemaBranchValue = (schema, readValue, combineValues) => {
3555
+ let value = readValue(schema);
3556
+ for (const combinator of inputJsonSchemaCombinators) {
3557
+ for (const item of schema?.[combinator] ?? []) {
3558
+ const itemSchema = toInputJsonSchemaObject(item);
3559
+ const itemValue = collectInputJsonSchemaBranchValue(
3560
+ itemSchema,
3561
+ readValue,
3562
+ combineValues
3563
+ );
3564
+ if (itemValue !== void 0) {
3565
+ value = value === void 0 ? itemValue : combineValues(value, itemValue, combinator);
3566
+ }
3567
+ }
3568
+ }
3569
+ return value;
3570
+ };
3571
+ var mergeInputJsonSchemaProperties = (left, right, combinator) => {
3572
+ const result = { ...left };
3573
+ for (const [field, schema] of Object.entries(right)) {
3574
+ const current = result[field];
3575
+ result[field] = current === void 0 ? schema : combineInputJsonSchemas(current, schema, combinator);
3576
+ }
3577
+ return result;
3578
+ };
3579
+ var getInputJsonSchemaProperties = (schema) => collectInputJsonSchemaBranchValue(
3580
+ schema,
3581
+ (schema2) => {
3582
+ const properties = Object.entries(schema2?.properties ?? {}).flatMap(
3583
+ ([field, value]) => {
3584
+ const valueSchema = toInputJsonSchemaObject(value);
3585
+ return valueSchema === void 0 ? [] : [[field, valueSchema]];
3586
+ }
3587
+ );
3588
+ return properties.length === 0 ? void 0 : Object.fromEntries(properties);
3589
+ },
3590
+ mergeInputJsonSchemaProperties
3591
+ );
3592
+ var getInputJsonSchemaAdditionalProperties = (schema) => collectInputJsonSchemaBranchValue(
3593
+ schema,
3594
+ (schema2) => typeof schema2?.additionalProperties === "object" ? schema2.additionalProperties : schema2?.additionalProperties === true ? {} : void 0,
3595
+ combineInputJsonSchemas
3596
+ );
3597
+ var intersectStrings = (left, right) => left.filter((value) => right.includes(value));
3598
+ var getInputJsonSchemaRequiredFields = (schema) => {
3599
+ if (schema === void 0) {
3600
+ return [];
3601
+ }
3602
+ const allOfRequired = schema.allOf?.map(toInputJsonSchemaObject).filter((schema2) => schema2 !== void 0).flatMap(getInputJsonSchemaRequiredFields);
3603
+ const anyBranchSchemas = [...schema.anyOf ?? [], ...schema.oneOf ?? []].map(toInputJsonSchemaObject).filter((schema2) => schema2 !== void 0);
3604
+ const anyOfRequired = anyBranchSchemas.length === 0 ? void 0 : anyBranchSchemas.map(getInputJsonSchemaRequiredFields).reduce(intersectStrings);
3605
+ return unique([
3606
+ ...schema.required ?? [],
3607
+ ...allOfRequired ?? [],
3608
+ ...anyOfRequired ?? []
3609
+ ]);
3610
+ };
3611
+ var getInputJsonSchemaMetadata = (inputSchema) => {
3612
+ const properties = getInputJsonSchemaProperties(inputSchema) ?? {};
3613
+ return {
3614
+ inputFields: Object.keys(properties),
3615
+ requiredInputFields: getInputJsonSchemaRequiredFields(inputSchema).filter(
3616
+ (field) => field in properties
3617
+ ),
3618
+ inputFieldTypes: Object.fromEntries(
3619
+ Object.entries(properties).flatMap(
3620
+ ([field, schema]) => inputJsonSchemaAcceptsType(schema, "array") ? [[field, "array"]] : []
3621
+ )
3622
+ )
3623
+ };
3624
+ };
3447
3625
  export {
3448
3626
  ALLOWED_FILE_EXTENSIONS,
3449
3627
  ALLOWED_FILE_TYPES,
@@ -3524,6 +3702,9 @@ export {
3524
3702
  getHtmlTagFromInstance,
3525
3703
  getHtmlTagsFromProps,
3526
3704
  getIndexesWithinAncestors,
3705
+ getInputJsonSchemaAdditionalProperties,
3706
+ getInputJsonSchemaMetadata,
3707
+ getInputJsonSchemaProperties,
3527
3708
  getMimeTypeByExtension,
3528
3709
  getMimeTypeByFilename,
3529
3710
  getPageById,
@@ -3535,9 +3716,15 @@ export {
3535
3716
  imageAsset,
3536
3717
  imageMeta,
3537
3718
  initialBreakpoints,
3719
+ inputJsonSchemaAcceptsType,
3538
3720
  insetUnitValue,
3539
3721
  instance,
3722
+ instanceAttributes,
3540
3723
  instanceChild,
3724
+ instanceComponent,
3725
+ instanceCreateInput,
3726
+ instanceFilterInput,
3727
+ instanceTag,
3541
3728
  instances,
3542
3729
  isAbsoluteUrl,
3543
3730
  isAllowedExtension,
@@ -3553,6 +3740,7 @@ export {
3553
3740
  isRootFolder,
3554
3741
  lintExpression,
3555
3742
  matchPathnameParams,
3743
+ normalizeComponentCategory,
3556
3744
  page,
3557
3745
  pageAuth,
3558
3746
  pageId,
@@ -3580,6 +3768,7 @@ export {
3580
3768
  resources,
3581
3769
  rootComponent,
3582
3770
  scrollAnimation,
3771
+ shouldFilterComponentCategory,
3583
3772
  styleDecl,
3584
3773
  styleSource,
3585
3774
  styleSourceSelection,
@@ -3590,6 +3779,8 @@ export {
3590
3779
  tags,
3591
3780
  templates,
3592
3781
  textChild,
3782
+ textChildValue,
3783
+ toInputJsonSchemaObject,
3593
3784
  toRuntimeAsset,
3594
3785
  transpileExpression,
3595
3786
  validateFileName,
package/lib/runtime.js CHANGED
@@ -152,7 +152,8 @@ var isBraveBrowser = () => {
152
152
  // src/runtime.ts
153
153
  var tagProperty = "data-ws-tag";
154
154
  var getTagFromProps = (props) => {
155
- return props[tagProperty];
155
+ const tag = props[tagProperty];
156
+ return typeof tag === "string" && tag.length > 0 ? tag : void 0;
156
157
  };
157
158
  var indexProperty = "data-ws-index";
158
159
  var getIndexWithinAncestorFromProps = (props) => {
package/lib/schema.js CHANGED
@@ -91,8 +91,8 @@ var dataSourceVariableValue = z3.union([
91
91
  }),
92
92
  z3.object({
93
93
  type: z3.literal("json"),
94
- value: z3.unknown()
95
- })
94
+ value: z3.unknown().optional()
95
+ }).transform((value) => ({ ...value, value: value.value ?? null }))
96
96
  ]);
97
97
  var dataSource = z3.union([
98
98
  z3.object({
@@ -155,12 +155,29 @@ var deployment = z4.union([
155
155
 
156
156
  // src/schema/instances.ts
157
157
  import { z as z5 } from "zod";
158
+ var textChildValue = z5.string();
158
159
  var textChild = z5.object({
159
160
  type: z5.literal("text"),
160
- value: z5.string(),
161
+ value: textChildValue,
161
162
  placeholder: z5.boolean().optional()
162
163
  });
163
164
  var instanceId = z5.string();
165
+ var instanceComponent = z5.string().min(1);
166
+ var instanceTag = z5.string().min(1, "Tag cannot be empty").describe(
167
+ "Optional HTML tag override for component rendering. Omit for component defaults; never pass an empty string."
168
+ );
169
+ var instanceAttributes = z5.object({
170
+ component: instanceComponent,
171
+ tag: instanceTag.optional(),
172
+ label: z5.string().optional()
173
+ });
174
+ var instanceCreateInput = instanceAttributes.partial({
175
+ component: true
176
+ });
177
+ var instanceFilterInput = instanceAttributes.pick({
178
+ component: true,
179
+ tag: true
180
+ }).partial();
164
181
  var idChild = z5.object({
165
182
  type: z5.literal("id"),
166
183
  value: instanceId
@@ -173,9 +190,9 @@ var instanceChild = z5.union([idChild, textChild, expressionChild]);
173
190
  var instance = z5.object({
174
191
  type: z5.literal("instance"),
175
192
  id: instanceId,
176
- component: z5.string(),
177
- tag: z5.string().optional(),
178
- label: z5.string().optional(),
193
+ component: instanceAttributes.shape.component,
194
+ tag: instanceAttributes.shape.tag,
195
+ label: instanceAttributes.shape.label,
179
196
  children: z5.array(instanceChild)
180
197
  });
181
198
  var instances = z5.map(instanceId, instance);
@@ -571,7 +588,7 @@ var insetUnitValue = z7.union([
571
588
  value: z7.literal("auto")
572
589
  })
573
590
  ]);
574
- var keyframeStyles = z7.record(styleValue);
591
+ var keyframeStyles = z7.record(z7.string(), styleValue);
575
592
  var animationKeyframe = z7.object({
576
593
  offset: z7.number().optional(),
577
594
  styles: keyframeStyles
@@ -777,6 +794,7 @@ var resource = z9.object({
777
794
  });
778
795
  var resourceRequest = z9.object({
779
796
  name: z9.string(),
797
+ control: z9.optional(z9.union([z9.literal("system"), z9.literal("graphql")])),
780
798
  method,
781
799
  url: z9.string(),
782
800
  searchParams: z9.array(
@@ -865,7 +883,12 @@ export {
865
883
  imageMeta,
866
884
  initialBreakpoints,
867
885
  instance,
886
+ instanceAttributes,
868
887
  instanceChild,
888
+ instanceComponent,
889
+ instanceCreateInput,
890
+ instanceFilterInput,
891
+ instanceTag,
869
892
  instances,
870
893
  page,
871
894
  pageAuth,
@@ -891,5 +914,6 @@ export {
891
914
  styleSources,
892
915
  styles,
893
916
  templates,
894
- textChild
917
+ textChild,
918
+ textChildValue
895
919
  };
@@ -24,5 +24,6 @@ export * from "./url-pattern";
24
24
  export * from "./link-utils";
25
25
  export * from "./css";
26
26
  export * from "./__generated__/tags";
27
+ export { getInputJsonSchemaAdditionalProperties, getInputJsonSchemaMetadata, getInputJsonSchemaProperties, inputJsonSchemaAcceptsType, toInputJsonSchemaObject, type InputJsonSchema, type InputJsonSchemaValue, type InputJsonSchemaMetadata, } from "./input-json-schema";
27
28
  export type { AnimationAction, AnimationActionScroll, AnimationActionView, AnimationKeyframe, KeyframeStyles, RangeUnit, RangeUnitValue, ScrollNamedRange, ScrollRangeValue, ViewNamedRange, ViewRangeValue, ScrollAnimation, ViewAnimation, InsetUnitValue, DurationUnitValue, IterationsUnitValue, TimeUnit, } from "./schema/animation-schema";
28
29
  export { animationAction, scrollAnimation, viewAnimation, rangeUnitValue, animationKeyframe, insetUnitValue, durationUnitValue, RANGE_UNITS, } from "./schema/animation-schema";
@@ -0,0 +1,15 @@
1
+ import type { JSONSchema } from "json-schema-typed";
2
+ export type InputJsonSchema = JSONSchema.Interface;
3
+ export type InputJsonSchemaValue = JSONSchema;
4
+ export type InputJsonSchemaMetadata = {
5
+ inputFields: readonly string[];
6
+ requiredInputFields: readonly string[];
7
+ inputFieldTypes: Partial<Record<string, "array">>;
8
+ };
9
+ export declare const toInputJsonSchemaObject: (schema: InputJsonSchemaValue | undefined) => InputJsonSchema | undefined;
10
+ export declare const inputJsonSchemaAcceptsType: (schema: InputJsonSchema, type: string, options?: {
11
+ treatUnconstrainedAsAny?: boolean;
12
+ }) => boolean;
13
+ export declare const getInputJsonSchemaProperties: (schema: InputJsonSchema | undefined) => Record<string, InputJsonSchema> | undefined;
14
+ export declare const getInputJsonSchemaAdditionalProperties: (schema: InputJsonSchema | undefined) => InputJsonSchema | undefined;
15
+ export declare const getInputJsonSchemaMetadata: (inputSchema: InputJsonSchema) => InputJsonSchemaMetadata;