@webstudio-is/react-sdk 0.292.0 → 0.294.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
@@ -57,7 +57,8 @@ var generateRemixParams = (pathname) => {
57
57
  // src/props.ts
58
58
  import {
59
59
  getPagePath,
60
- findPageByIdOrPath
60
+ findPageByIdOrPath,
61
+ findTreeInstanceIdsExcludingSubtrees
61
62
  } from "@webstudio-is/sdk";
62
63
  var normalizeProps = ({
63
64
  props,
@@ -163,6 +164,23 @@ var componentAttribute = "data-ws-component";
163
164
  var showAttribute = "data-ws-show";
164
165
  var inflatedAttribute = "data-ws-collapsed";
165
166
  var textContentAttribute = "data-ws-text-content";
167
+ var findTreeInstanceIdsExcludingStaticHidden = ({
168
+ instances,
169
+ props,
170
+ rootInstanceId
171
+ }) => {
172
+ const hiddenInstanceIds = /* @__PURE__ */ new Set();
173
+ for (const prop of props.values()) {
174
+ if (prop.name === showAttribute && prop.type === "boolean" && prop.value === false) {
175
+ hiddenInstanceIds.add(prop.instanceId);
176
+ }
177
+ }
178
+ return findTreeInstanceIdsExcludingSubtrees(
179
+ instances,
180
+ rootInstanceId,
181
+ hiddenInstanceIds
182
+ );
183
+ };
166
184
  var attributeNameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
167
185
  var attributeNameChar = attributeNameStartChar + ":\\-0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
168
186
  var validAttributeNameRegex = new RegExp(
@@ -223,7 +241,9 @@ import {
223
241
  parseComponentName,
224
242
  generateExpression,
225
243
  decodeDataSourceVariable,
244
+ contentBlockDocumentProp,
226
245
  blockComponent,
246
+ blockBodyComponent,
227
247
  blockTemplateComponent,
228
248
  collectionComponent,
229
249
  descendantComponent,
@@ -232,226 +252,10 @@ import {
232
252
  } from "@webstudio-is/sdk";
233
253
  import { transpileExpression } from "@webstudio-is/expression";
234
254
  import { indexProperty, tagProperty } from "@webstudio-is/sdk/runtime";
235
-
236
- // src/__generated__/standard-attributes.ts
237
- var standardAttributesToReactProps = {
238
- "accept-charset": "acceptCharset",
239
- accesskey: "accessKey",
240
- allowfullscreen: "allowFullScreen",
241
- autocapitalize: "autoCapitalize",
242
- autocomplete: "autoComplete",
243
- autocorrect: "autoCorrect",
244
- autofocus: "autoFocus",
245
- autoplay: "autoPlay",
246
- charset: "charSet",
247
- class: "className",
248
- colspan: "colSpan",
249
- contenteditable: "contentEditable",
250
- crossorigin: "crossOrigin",
251
- datetime: "dateTime",
252
- enctype: "encType",
253
- enterkeyhint: "enterKeyHint",
254
- fetchpriority: "fetchPriority",
255
- for: "htmlFor",
256
- formmethod: "formMethod",
257
- formaction: "formAction",
258
- formenctype: "formEncType",
259
- formnovalidate: "formNoValidate",
260
- formtarget: "formTarget",
261
- hreflang: "hrefLang",
262
- "http-equiv": "httpEquiv",
263
- imagesizes: "imageSizes",
264
- imagesrcset: "imageSrcSet",
265
- inputmode: "inputMode",
266
- itemid: "itemID",
267
- itemprop: "itemProp",
268
- itemref: "itemRef",
269
- itemscope: "itemScope",
270
- itemtype: "itemType",
271
- maxlength: "maxLength",
272
- minlength: "minLength",
273
- nomodule: "noModule",
274
- novalidate: "noValidate",
275
- playsinline: "playsInline",
276
- readonly: "readOnly",
277
- referrerpolicy: "referrerPolicy",
278
- rowspan: "rowSpan",
279
- spellcheck: "spellCheck",
280
- srcdoc: "srcDoc",
281
- srclang: "srcLang",
282
- srcset: "srcSet",
283
- tabindex: "tabIndex",
284
- usemap: "useMap",
285
- "alignment-baseline": "alignmentBaseline",
286
- "baseline-shift": "baselineShift",
287
- "clip-path": "clipPath",
288
- "clip-rule": "clipRule",
289
- "color-interpolation": "colorInterpolation",
290
- "color-interpolation-filters": "colorInterpolationFilters",
291
- "color-profile": "colorProfile",
292
- "color-rendering": "colorRendering",
293
- "dominant-baseline": "dominantBaseline",
294
- "enable-background": "enableBackground",
295
- "fill-opacity": "fillOpacity",
296
- "fill-rule": "fillRule",
297
- "flood-opacity": "floodOpacity",
298
- "flood-color": "floodColor",
299
- "font-family": "fontFamily",
300
- "font-size": "fontSize",
301
- "font-size-adjust": "fontSizeAdjust",
302
- "font-stretch": "fontStretch",
303
- "font-style": "fontStyle",
304
- "font-variant": "fontVariant",
305
- "font-weight": "fontWeight",
306
- "glyph-orientation-horizontal": "glyphOrientationHorizontal",
307
- "glyph-orientation-vertical": "glyphOrientationVertical",
308
- "image-rendering": "imageRendering",
309
- "letter-spacing": "letterSpacing",
310
- "lighting-color": "lightingColor",
311
- "marker-end": "markerEnd",
312
- "marker-mid": "markerMid",
313
- "marker-start": "markerStart",
314
- "pointer-events": "pointerEvents",
315
- popovertarget: "popoverTarget",
316
- popovertargetaction: "popoverTargetAction",
317
- "shape-rendering": "shapeRendering",
318
- "stop-color": "stopColor",
319
- "stop-opacity": "stopOpacity",
320
- "stroke-dasharray": "strokeDasharray",
321
- "stroke-dashoffset": "strokeDashoffset",
322
- "stroke-linecap": "strokeLinecap",
323
- "stroke-linejoin": "strokeLinejoin",
324
- "stroke-miterlimit": "strokeMiterlimit",
325
- "stroke-width": "strokeWidth",
326
- "stroke-opacity": "strokeOpacity",
327
- "text-anchor": "textAnchor",
328
- "text-decoration": "textDecoration",
329
- "text-rendering": "textRendering",
330
- "unicode-bidi": "unicodeBidi",
331
- "word-spacing": "wordSpacing",
332
- "writing-mode": "writingMode",
333
- "xlink:actuate": "xlinkActuate",
334
- "xlink:arcrole": "xlinkArcrole",
335
- "xlink:href": "xlinkHref",
336
- "xlink:role": "xlinkRole",
337
- "xlink:show": "xlinkShow",
338
- "xlink:title": "xlinkTitle",
339
- "xlink:type": "xlinkType",
340
- "xml:base": "xmlBase",
341
- "xml:lang": "xmlLang",
342
- "xml:space": "xmlSpace",
343
- dirname: "dirName"
344
- };
345
- var reactPropsToStandardAttributes = {
346
- acceptCharset: "accept-charset",
347
- accessKey: "accesskey",
348
- allowFullScreen: "allowfullscreen",
349
- autoCapitalize: "autocapitalize",
350
- autoComplete: "autocomplete",
351
- autoCorrect: "autocorrect",
352
- autoFocus: "autofocus",
353
- autoPlay: "autoplay",
354
- charSet: "charset",
355
- className: "class",
356
- colSpan: "colspan",
357
- contentEditable: "contenteditable",
358
- crossOrigin: "crossorigin",
359
- dateTime: "datetime",
360
- encType: "enctype",
361
- enterKeyHint: "enterkeyhint",
362
- fetchPriority: "fetchpriority",
363
- htmlFor: "for",
364
- formMethod: "formmethod",
365
- formAction: "formaction",
366
- formEncType: "formenctype",
367
- formNoValidate: "formnovalidate",
368
- formTarget: "formtarget",
369
- hrefLang: "hreflang",
370
- httpEquiv: "http-equiv",
371
- imageSizes: "imagesizes",
372
- imageSrcSet: "imagesrcset",
373
- inputMode: "inputmode",
374
- itemID: "itemid",
375
- itemProp: "itemprop",
376
- itemRef: "itemref",
377
- itemScope: "itemscope",
378
- itemType: "itemtype",
379
- maxLength: "maxlength",
380
- minLength: "minlength",
381
- noModule: "nomodule",
382
- noValidate: "novalidate",
383
- playsInline: "playsinline",
384
- readOnly: "readonly",
385
- referrerPolicy: "referrerpolicy",
386
- rowSpan: "rowspan",
387
- spellCheck: "spellcheck",
388
- srcDoc: "srcdoc",
389
- srcLang: "srclang",
390
- srcSet: "srcset",
391
- tabIndex: "tabindex",
392
- useMap: "usemap",
393
- alignmentBaseline: "alignment-baseline",
394
- baselineShift: "baseline-shift",
395
- clipPath: "clip-path",
396
- clipRule: "clip-rule",
397
- colorInterpolation: "color-interpolation",
398
- colorInterpolationFilters: "color-interpolation-filters",
399
- colorProfile: "color-profile",
400
- colorRendering: "color-rendering",
401
- dominantBaseline: "dominant-baseline",
402
- enableBackground: "enable-background",
403
- fillOpacity: "fill-opacity",
404
- fillRule: "fill-rule",
405
- floodOpacity: "flood-opacity",
406
- floodColor: "flood-color",
407
- fontFamily: "font-family",
408
- fontSize: "font-size",
409
- fontSizeAdjust: "font-size-adjust",
410
- fontStretch: "font-stretch",
411
- fontStyle: "font-style",
412
- fontVariant: "font-variant",
413
- fontWeight: "font-weight",
414
- glyphOrientationHorizontal: "glyph-orientation-horizontal",
415
- glyphOrientationVertical: "glyph-orientation-vertical",
416
- imageRendering: "image-rendering",
417
- letterSpacing: "letter-spacing",
418
- lightingColor: "lighting-color",
419
- markerEnd: "marker-end",
420
- markerMid: "marker-mid",
421
- markerStart: "marker-start",
422
- pointerEvents: "pointer-events",
423
- popoverTarget: "popovertarget",
424
- popoverTargetAction: "popovertargetaction",
425
- shapeRendering: "shape-rendering",
426
- stopColor: "stop-color",
427
- stopOpacity: "stop-opacity",
428
- strokeDasharray: "stroke-dasharray",
429
- strokeDashoffset: "stroke-dashoffset",
430
- strokeLinecap: "stroke-linecap",
431
- strokeLinejoin: "stroke-linejoin",
432
- strokeMiterlimit: "stroke-miterlimit",
433
- strokeWidth: "stroke-width",
434
- strokeOpacity: "stroke-opacity",
435
- textAnchor: "text-anchor",
436
- textDecoration: "text-decoration",
437
- textRendering: "text-rendering",
438
- unicodeBidi: "unicode-bidi",
439
- wordSpacing: "word-spacing",
440
- writingMode: "writing-mode",
441
- xlinkActuate: "xlink:actuate",
442
- xlinkArcrole: "xlink:arcrole",
443
- xlinkHref: "xlink:href",
444
- xlinkRole: "xlink:role",
445
- xlinkShow: "xlink:show",
446
- xlinkTitle: "xlink:title",
447
- xlinkType: "xlink:type",
448
- xmlBase: "xml:base",
449
- xmlLang: "xml:lang",
450
- xmlSpace: "xml:space",
451
- dirName: "dirname"
452
- };
453
-
454
- // src/component-generator.ts
255
+ import {
256
+ getJsxPropName,
257
+ mapAttributeNames
258
+ } from "@webstudio-is/content-engine/jsx-attributes";
455
259
  var generateAction = ({
456
260
  scope,
457
261
  prop,
@@ -548,6 +352,7 @@ var generateJsxElement = ({
548
352
  tagsOverrides,
549
353
  instance,
550
354
  props,
355
+ resources,
551
356
  dataSources,
552
357
  usedDataSources,
553
358
  indexesWithinAncestors,
@@ -574,10 +379,27 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
574
379
  let collectionItemValue;
575
380
  let collectionItemKeyValue;
576
381
  let classNameValue;
577
- for (const prop of props.values()) {
578
- if (prop.instanceId !== instance.id) {
579
- continue;
580
- }
382
+ const instanceProps = Array.from(props.values()).filter(
383
+ (prop) => prop.instanceId === instance.id
384
+ );
385
+ const instancePropNames = new Set(instanceProps.map((prop) => prop.name));
386
+ const projectedResourceProps = /* @__PURE__ */ new Map();
387
+ const componentPropNames = new Set(Object.keys(meta?.props ?? {}));
388
+ const acceptsHtmlAttributes = hasTags || instance.tag !== void 0 || instance.component === elementComponent;
389
+ const getGeneratedPropName = (instancePropName) => getJsxPropName({
390
+ instancePropName,
391
+ componentPropNames,
392
+ acceptsHtmlAttributes
393
+ });
394
+ const generatedPropNames = new Map(
395
+ mapAttributeNames({
396
+ attributes: instanceProps.filter(({ name }) => isAttributeNameSafe(name)),
397
+ direction: "instance-to-jsx",
398
+ componentPropNames,
399
+ acceptsHtmlAttributes
400
+ }).map(({ id, name }) => [id, name])
401
+ );
402
+ for (const prop of instanceProps) {
581
403
  const propValue = generatePropValue({
582
404
  scope,
583
405
  prop,
@@ -587,10 +409,18 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
587
409
  if (isAttributeNameSafe(prop.name) === false) {
588
410
  continue;
589
411
  }
590
- let name = prop.name;
591
- if (hasTags && !meta?.props?.[prop.name]) {
592
- name = standardAttributesToReactProps[prop.name] ?? prop.name;
412
+ if (prop.type === "resource") {
413
+ const propMeta = meta?.props?.[prop.name];
414
+ const resource = resources?.get(prop.value);
415
+ if (propMeta?.type === "resource" && resource !== void 0) {
416
+ for (const name2 of propMeta.generatedProps ?? []) {
417
+ if (instancePropNames.has(name2) === false && isAttributeNameSafe(name2)) {
418
+ projectedResourceProps.set(name2, resource[name2]);
419
+ }
420
+ }
421
+ }
593
422
  }
423
+ const name = generatedPropNames.get(prop.id) ?? prop.name;
594
424
  if (prop.name === showAttribute) {
595
425
  if (propValue === "true") {
596
426
  continue;
@@ -613,7 +443,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
613
443
  }
614
444
  continue;
615
445
  }
616
- if ((name === "className" || name === "class" && meta === void 0) && propValue !== void 0) {
446
+ if (name === "className" && propValue !== void 0) {
617
447
  classNameValue = propValue;
618
448
  continue;
619
449
  }
@@ -622,6 +452,11 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
622
452
  ${name}={${propValue}}`;
623
453
  }
624
454
  }
455
+ for (const [propName, value] of projectedResourceProps) {
456
+ const name = getGeneratedPropName(propName);
457
+ generatedProps += `
458
+ ${name}={${JSON.stringify(value)}}`;
459
+ }
625
460
  const classMapArray = classesMap?.get(instance.id);
626
461
  if (classMapArray || classNameValue) {
627
462
  let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
@@ -660,7 +495,7 @@ ${name}={${propValue}}`;
660
495
  `;
661
496
  generatedElement += `}
662
497
  `;
663
- } else if (instance.component === blockComponent) {
498
+ } else if (instance.component === blockComponent || instance.component === blockBodyComponent) {
664
499
  generatedElement += children;
665
500
  } else {
666
501
  let componentVariable;
@@ -716,11 +551,14 @@ var generateJsxChildren = ({
716
551
  children,
717
552
  instances,
718
553
  props,
554
+ resources,
719
555
  dataSources,
720
556
  usedDataSources,
721
557
  indexesWithinAncestors,
722
558
  classesMap,
723
- excludePlaceholders
559
+ excludePlaceholders,
560
+ publishedContentBlocks,
561
+ contentBodyOverride
724
562
  }) => {
725
563
  let generatedChildren = "";
726
564
  for (const child of children) {
@@ -750,6 +588,111 @@ var generateJsxChildren = ({
750
588
  if (instance === void 0) {
751
589
  continue;
752
590
  }
591
+ const publishedContent = publishedContentBlocks?.get(instance.id);
592
+ let generatedInstanceChildren;
593
+ if (contentBodyOverride?.instanceId === instance.id) {
594
+ generatedInstanceChildren = generateJsxChildren({
595
+ classesMap,
596
+ scope,
597
+ metas,
598
+ tagsOverrides,
599
+ children: contentBodyOverride.children,
600
+ instances,
601
+ props,
602
+ resources,
603
+ dataSources,
604
+ usedDataSources,
605
+ indexesWithinAncestors,
606
+ excludePlaceholders,
607
+ publishedContentBlocks
608
+ });
609
+ } else if (publishedContent === void 0) {
610
+ generatedInstanceChildren = generateJsxChildren({
611
+ classesMap,
612
+ scope,
613
+ metas,
614
+ tagsOverrides,
615
+ children: instance.children,
616
+ instances,
617
+ props,
618
+ resources,
619
+ dataSources,
620
+ usedDataSources,
621
+ indexesWithinAncestors,
622
+ excludePlaceholders,
623
+ publishedContentBlocks,
624
+ contentBodyOverride
625
+ });
626
+ } else {
627
+ const sourceExpression = publishedContent.sourceExpression === void 0 ? void 0 : generateExpression({
628
+ expression: publishedContent.sourceExpression,
629
+ dataSources,
630
+ usedDataSources,
631
+ scope
632
+ });
633
+ const documentParameter = Array.from(props.values()).find(
634
+ (prop) => prop.instanceId === instance.id && prop.name === contentBlockDocumentProp && prop.type === "parameter"
635
+ );
636
+ const documentDataSource = documentParameter === void 0 ? void 0 : dataSources.get(documentParameter.value);
637
+ if (documentDataSource !== void 0) {
638
+ usedDataSources.set(documentDataSource.id, documentDataSource);
639
+ }
640
+ const documentName = documentDataSource === void 0 ? void 0 : scope.getName(documentDataSource.id, documentDataSource.name);
641
+ const generatedCandidates = publishedContent.candidates.map(
642
+ ({
643
+ assetId,
644
+ dependencyRevision,
645
+ children: candidateChildren,
646
+ frontmatter
647
+ }) => {
648
+ const generated = generateJsxChildren({
649
+ classesMap,
650
+ scope,
651
+ metas,
652
+ tagsOverrides,
653
+ children: publishedContent.bodyInstanceId === void 0 ? candidateChildren : instance.children,
654
+ instances,
655
+ props,
656
+ resources,
657
+ dataSources,
658
+ usedDataSources,
659
+ indexesWithinAncestors,
660
+ excludePlaceholders,
661
+ publishedContentBlocks,
662
+ contentBodyOverride: publishedContent.bodyInstanceId === void 0 ? void 0 : {
663
+ instanceId: publishedContent.bodyInstanceId,
664
+ children: candidateChildren
665
+ }
666
+ });
667
+ const withDocument = documentName === void 0 ? generated : `{((${documentName}) => <Fragment>
668
+ ${generated}</Fragment>)(${JSON.stringify({ frontmatter })})}
669
+ `;
670
+ return {
671
+ assetId,
672
+ dependencyRevision,
673
+ generated: withDocument
674
+ };
675
+ }
676
+ );
677
+ if (sourceExpression === void 0) {
678
+ generatedInstanceChildren = generatedCandidates.map(
679
+ ({ dependencyRevision, generated }) => `<Fragment key=${JSON.stringify(dependencyRevision)}>
680
+ ${generated}</Fragment>
681
+ `
682
+ ).join("");
683
+ } else {
684
+ const sourceName = scope.getName(
685
+ `${instance.id}-published-source`,
686
+ "contentSource"
687
+ );
688
+ const branches = generatedCandidates.map(
689
+ ({ assetId, dependencyRevision, generated }) => `${sourceName} === ${JSON.stringify(assetId)} ? <Fragment key=${JSON.stringify(dependencyRevision)}>
690
+ ${generated}</Fragment>`
691
+ ).join(" : ");
692
+ generatedInstanceChildren = `{((${sourceName}) => ${branches.length === 0 ? "null" : `${branches} : null`})(${sourceExpression})}
693
+ `;
694
+ }
695
+ }
753
696
  generatedChildren += generateJsxElement({
754
697
  context: "jsx",
755
698
  scope,
@@ -757,23 +700,12 @@ var generateJsxChildren = ({
757
700
  tagsOverrides,
758
701
  instance,
759
702
  props,
703
+ resources,
760
704
  dataSources,
761
705
  usedDataSources,
762
706
  indexesWithinAncestors,
763
707
  classesMap,
764
- children: generateJsxChildren({
765
- classesMap,
766
- scope,
767
- metas,
768
- tagsOverrides,
769
- children: instance.children,
770
- instances,
771
- props,
772
- dataSources,
773
- usedDataSources,
774
- indexesWithinAncestors,
775
- excludePlaceholders
776
- })
708
+ children: generatedInstanceChildren
777
709
  });
778
710
  continue;
779
711
  }
@@ -788,10 +720,12 @@ var generateWebstudioComponent = ({
788
720
  parameters,
789
721
  instances,
790
722
  props,
723
+ resources,
791
724
  dataSources,
792
725
  metas,
793
726
  tagsOverrides,
794
- classesMap
727
+ classesMap,
728
+ publishedContentBlocks
795
729
  }) => {
796
730
  const instance = instances.get(rootInstanceId);
797
731
  const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
@@ -807,6 +741,7 @@ var generateWebstudioComponent = ({
807
741
  tagsOverrides,
808
742
  instance,
809
743
  props,
744
+ resources,
810
745
  dataSources,
811
746
  usedDataSources,
812
747
  indexesWithinAncestors,
@@ -818,10 +753,12 @@ var generateWebstudioComponent = ({
818
753
  children: instance.children,
819
754
  instances,
820
755
  props,
756
+ resources,
821
757
  dataSources,
822
758
  usedDataSources,
823
759
  indexesWithinAncestors,
824
- classesMap
760
+ classesMap,
761
+ publishedContentBlocks
825
762
  })
826
763
  });
827
764
  }
@@ -879,8 +816,17 @@ var generateWebstudioComponent = ({
879
816
  `;
880
817
  return generatedComponent;
881
818
  };
819
+
820
+ // src/standard-attributes.ts
821
+ import {
822
+ getInstancePropName,
823
+ getJsxPropName as getJsxPropName2,
824
+ reactPropsToStandardAttributes,
825
+ standardAttributesToReactProps
826
+ } from "@webstudio-is/content-engine/jsx-attributes";
882
827
  export {
883
828
  componentAttribute,
829
+ findTreeInstanceIdsExcludingStaticHidden,
884
830
  generateCollectionIterationCode,
885
831
  generateJsxChildren,
886
832
  generateJsxElement,
@@ -888,6 +834,8 @@ export {
888
834
  generateRemixRoute,
889
835
  generateWebstudioComponent,
890
836
  getCollectionEntries,
837
+ getInstancePropName,
838
+ getJsxPropName2 as getJsxPropName,
891
839
  idAttribute,
892
840
  inflatedAttribute,
893
841
  isAttributeNameSafe,
@@ -0,0 +1,13 @@
1
+ // src/standard-attributes.ts
2
+ import {
3
+ getInstancePropName,
4
+ getJsxPropName,
5
+ reactPropsToStandardAttributes,
6
+ standardAttributesToReactProps
7
+ } from "@webstudio-is/content-engine/jsx-attributes";
8
+ export {
9
+ getInstancePropName,
10
+ getJsxPropName,
11
+ reactPropsToStandardAttributes,
12
+ standardAttributesToReactProps
13
+ };
@@ -1,5 +1,16 @@
1
- import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors } from "@webstudio-is/sdk";
2
- export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
1
+ import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors, Resources } from "@webstudio-is/sdk";
2
+ export type PublishedContentBlock = Readonly<{
3
+ bodyInstanceId?: Instance["id"];
4
+ sourceExpression?: string;
5
+ candidates: readonly Readonly<{
6
+ assetId: string;
7
+ dependencyRevision: string;
8
+ children: Instance["children"];
9
+ frontmatter: Readonly<Record<string, unknown>>;
10
+ resourceIds?: readonly string[];
11
+ }>[];
12
+ }>;
13
+ export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, resources, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
3
14
  context?: "expression" | "jsx";
4
15
  scope: Scope;
5
16
  metas: Map<Instance["component"], WsComponentMeta>;
@@ -9,26 +20,33 @@ export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides
9
20
  tagsOverrides?: Record<string, string>;
10
21
  instance: Instance;
11
22
  props: Props;
23
+ resources?: Resources;
12
24
  dataSources: DataSources;
13
25
  usedDataSources: DataSources;
14
26
  indexesWithinAncestors: IndexesWithinAncestors;
15
27
  children: string;
16
28
  classesMap?: Map<string, Array<string>>;
17
29
  }) => string;
18
- export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
30
+ export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, resources, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, publishedContentBlocks, contentBodyOverride, }: {
19
31
  scope: Scope;
20
32
  metas: Map<Instance["component"], WsComponentMeta>;
21
33
  tagsOverrides?: Record<string, string>;
22
34
  children: Instance["children"];
23
35
  instances: Instances;
24
36
  props: Props;
37
+ resources?: Resources;
25
38
  dataSources: DataSources;
26
39
  usedDataSources: DataSources;
27
40
  indexesWithinAncestors: IndexesWithinAncestors;
28
41
  classesMap?: Map<string, Array<string>>;
29
42
  excludePlaceholders?: boolean;
43
+ publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
44
+ contentBodyOverride?: Readonly<{
45
+ instanceId: Instance["id"];
46
+ children: Instance["children"];
47
+ }>;
30
48
  }) => string;
31
- export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, tagsOverrides, classesMap, }: {
49
+ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, resources, dataSources, metas, tagsOverrides, classesMap, publishedContentBlocks, }: {
32
50
  scope: Scope;
33
51
  name: string;
34
52
  rootInstanceId: Instance["id"];
@@ -37,8 +55,10 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
37
55
  }>[];
38
56
  instances: Instances;
39
57
  props: Props;
58
+ resources?: Resources;
40
59
  dataSources: DataSources;
41
60
  classesMap: Map<string, Array<string>>;
61
+ publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
42
62
  metas: Map<Instance["component"], WsComponentMeta>;
43
63
  /**
44
64
  * Record<tag, componentDescriptor>
@@ -4,5 +4,5 @@ export * from "./props";
4
4
  export * from "./collection-utils";
5
5
  export type * from "./context";
6
6
  export type * from "./hook";
7
- export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, } from "./component-generator";
8
- export * from "./__generated__/standard-attributes";
7
+ export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, type PublishedContentBlock, } from "./component-generator";
8
+ export * from "./standard-attributes";
@@ -1,4 +1,4 @@
1
- import { type Prop, type Assets, type Pages, type ImageAsset } from "@webstudio-is/sdk";
1
+ import { type Prop, type Instances, type Props, type Assets, type Pages, type ImageAsset } from "@webstudio-is/sdk";
2
2
  export declare const normalizeProps: ({ props, assetBaseUrl, assets, uploadingImageAssets, pages, source, }: {
3
3
  props: Prop[];
4
4
  assetBaseUrl: string;
@@ -7,6 +7,14 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, uploadingIm
7
7
  pages: Pages;
8
8
  source: "canvas" | "prebuild";
9
9
  }) => ({
10
+ type: "expression";
11
+ value: string;
12
+ mode?: "read" | "readwrite" | undefined;
13
+ id: string;
14
+ instanceId: string;
15
+ name: string;
16
+ required?: boolean | undefined;
17
+ } | {
10
18
  id: string;
11
19
  instanceId: string;
12
20
  name: string;
@@ -72,13 +80,6 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, uploadingIm
72
80
  required?: boolean | undefined;
73
81
  type: "resource";
74
82
  value: string;
75
- } | {
76
- id: string;
77
- instanceId: string;
78
- name: string;
79
- required?: boolean | undefined;
80
- type: "expression";
81
- value: string;
82
83
  } | {
83
84
  id: string;
84
85
  instanceId: string;
@@ -1450,4 +1451,9 @@ export declare const componentAttribute: "data-ws-component";
1450
1451
  export declare const showAttribute: "data-ws-show";
1451
1452
  export declare const inflatedAttribute: "data-ws-collapsed";
1452
1453
  export declare const textContentAttribute: "data-ws-text-content";
1454
+ export declare const findTreeInstanceIdsExcludingStaticHidden: ({ instances, props, rootInstanceId, }: {
1455
+ instances: Instances;
1456
+ props: Props;
1457
+ rootInstanceId: string;
1458
+ }) => Set<string>;
1453
1459
  export declare const isAttributeNameSafe: (attributeName: string) => boolean;
@@ -0,0 +1 @@
1
+ export { getInstancePropName, getJsxPropName, reactPropsToStandardAttributes, standardAttributesToReactProps, } from "@webstudio-is/content-engine/jsx-attributes";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.292.0",
3
+ "version": "0.294.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -15,7 +15,7 @@
15
15
  "typescript": "7.0.2",
16
16
  "vitest": "^3.1.2",
17
17
  "zod": "^4.4.3",
18
- "@webstudio-is/template": "0.292.0",
18
+ "@webstudio-is/template": "0.294.0",
19
19
  "@webstudio-is/tsconfig": "1.0.7"
20
20
  },
21
21
  "peerDependencies": {
@@ -26,12 +26,13 @@
26
26
  "dependencies": {
27
27
  "change-case": "^5.4.4",
28
28
  "nanoid": "^5.1.5",
29
- "@webstudio-is/css-engine": "0.292.0",
30
- "@webstudio-is/fonts": "0.292.0",
31
- "@webstudio-is/icons": "^0.292.0",
32
- "@webstudio-is/image": "0.292.0",
33
- "@webstudio-is/expression": "0.292.0",
34
- "@webstudio-is/sdk": "0.292.0"
29
+ "@webstudio-is/content-engine": "0.294.0",
30
+ "@webstudio-is/css-engine": "0.294.0",
31
+ "@webstudio-is/fonts": "0.294.0",
32
+ "@webstudio-is/expression": "0.294.0",
33
+ "@webstudio-is/icons": "^0.294.0",
34
+ "@webstudio-is/sdk": "0.294.0",
35
+ "@webstudio-is/image": "0.294.0"
35
36
  },
36
37
  "exports": {
37
38
  ".": {
@@ -45,9 +46,9 @@
45
46
  "import": "./lib/runtime.js"
46
47
  },
47
48
  "./standard-attributes": {
48
- "webstudio": "./src/__generated__/standard-attributes.ts",
49
- "types": "./lib/types/__generated__/standard-attributes.d.ts",
50
- "import": "./lib/__generated__/standard-attributes.js"
49
+ "webstudio": "./src/standard-attributes.ts",
50
+ "types": "./lib/types/standard-attributes.d.ts",
51
+ "import": "./lib/standard-attributes.js"
51
52
  },
52
53
  "./placeholder": {
53
54
  "types": "./placeholder.d.ts"
@@ -62,7 +63,7 @@
62
63
  "private": false,
63
64
  "sideEffects": false,
64
65
  "scripts": {
65
- "build": "rm -rf lib && esbuild src/index.ts src/runtime.ts --outdir=lib --bundle --format=esm --packages=external",
66
+ "build": "rm -rf lib && esbuild src/index.ts src/runtime.ts src/standard-attributes.ts --outdir=lib --bundle --format=esm --packages=external",
66
67
  "dts": "tsc --project tsconfig.dts.json",
67
68
  "typecheck": "tsc --noEmit",
68
69
  "test": "vitest run"
package/placeholder.d.ts CHANGED
@@ -37,9 +37,13 @@ declare module "__CLIENT__" {
37
37
  declare module "__SERVER__" {
38
38
  import type { PageMeta, System, ResourceRequest } from "@webstudio-is/sdk";
39
39
 
40
- export const getResources: (props: { system: System }) => {
40
+ export const getResources: (props: {
41
+ system: System;
42
+ resources?: Record<string, any>;
43
+ }) => {
41
44
  data: Map<string, ResourceRequest>;
42
45
  action: Map<string, ResourceRequest>;
46
+ contentData?: Map<string, ResourceRequest>;
43
47
  };
44
48
 
45
49
  export const getPageMeta: (props: {
@@ -1,2 +0,0 @@
1
- export declare const standardAttributesToReactProps: Record<string, string>;
2
- export declare const reactPropsToStandardAttributes: Record<string, string>;