@webstudio-is/react-sdk 0.0.0-588fe22 → 0.0.0-7a19155

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
@@ -54,182 +54,11 @@ var generateRemixParams = (pathname) => {
54
54
  return generated;
55
55
  };
56
56
 
57
- // src/css/global-rules.ts
58
- import { getFontFaces } from "@webstudio-is/fonts";
59
- var addGlobalRules = (sheet, { assets, assetBaseUrl }) => {
60
- const fontAssets = [];
61
- for (const asset of assets.values()) {
62
- if (asset.type === "font") {
63
- fontAssets.push(asset);
64
- }
65
- }
66
- const fontFaces = getFontFaces(fontAssets, { assetBaseUrl });
67
- for (const fontFace of fontFaces) {
68
- sheet.addFontFaceRule(fontFace);
69
- }
70
- };
71
-
72
- // src/css/css.ts
73
- import {
74
- createRegularStyleSheet,
75
- generateAtomic
76
- } from "@webstudio-is/css-engine";
77
- import {
78
- ROOT_INSTANCE_ID,
79
- createScope,
80
- parseComponentName,
81
- descendantComponent,
82
- rootComponent
83
- } from "@webstudio-is/sdk";
84
- import { kebabCase } from "change-case";
85
- var createImageValueTransformer = (assets, { assetBaseUrl }) => (styleValue) => {
86
- if (styleValue.type === "image" && styleValue.value.type === "asset") {
87
- const asset = assets.get(styleValue.value.value);
88
- if (asset === void 0) {
89
- return { type: "keyword", value: "none" };
90
- }
91
- const url = `${assetBaseUrl}${asset.name}`;
92
- return {
93
- type: "image",
94
- value: {
95
- type: "url",
96
- url
97
- },
98
- hidden: styleValue.hidden
99
- };
100
- }
101
- };
102
- var normalizeClassName = (name) => kebabCase(name);
103
- var generateCss = ({
104
- assets,
105
- instances,
106
- props,
107
- breakpoints,
108
- styles,
109
- styleSourceSelections,
110
- componentMetas,
111
- assetBaseUrl,
112
- atomic
113
- }) => {
114
- const globalSheet = createRegularStyleSheet({ name: "ssr" });
115
- const sheet = createRegularStyleSheet({ name: "ssr" });
116
- addGlobalRules(globalSheet, { assets, assetBaseUrl });
117
- globalSheet.addMediaRule("presets");
118
- const presetClasses = /* @__PURE__ */ new Map();
119
- const scope = createScope([], normalizeClassName, "-");
120
- for (const [component, meta] of componentMetas) {
121
- const [_namespace, componentName] = parseComponentName(component);
122
- const className = `w-${scope.getName(component, meta.label ?? componentName)}`;
123
- const presetStyle = Object.entries(meta.presetStyle ?? {});
124
- if (presetStyle.length > 0) {
125
- presetClasses.set(component, className);
126
- }
127
- for (const [tag, styles2] of presetStyle) {
128
- const selector = component === rootComponent ? ":root" : `:where(${tag}.${className})`;
129
- const rule = globalSheet.addNestingRule(selector);
130
- for (const declaration of styles2) {
131
- rule.setDeclaration({
132
- breakpoint: "presets",
133
- selector: declaration.state ?? "",
134
- property: declaration.property,
135
- value: declaration.value
136
- });
137
- }
138
- }
139
- }
140
- for (const breakpoint of breakpoints.values()) {
141
- sheet.addMediaRule(breakpoint.id, breakpoint);
142
- }
143
- const imageValueTransformer = createImageValueTransformer(assets, {
144
- assetBaseUrl
145
- });
146
- sheet.setTransformer(imageValueTransformer);
147
- for (const styleDecl of styles.values()) {
148
- const rule = sheet.addMixinRule(styleDecl.styleSourceId);
149
- rule.setDeclaration({
150
- breakpoint: styleDecl.breakpointId,
151
- selector: styleDecl.state ?? "",
152
- property: styleDecl.property,
153
- value: styleDecl.value
154
- });
155
- }
156
- const classes = /* @__PURE__ */ new Map();
157
- const parentIdByInstanceId = /* @__PURE__ */ new Map();
158
- for (const instance of instances.values()) {
159
- const presetClass = presetClasses.get(instance.component);
160
- if (presetClass) {
161
- classes.set(instance.id, [presetClass]);
162
- }
163
- for (const child of instance.children) {
164
- if (child.type === "id") {
165
- parentIdByInstanceId.set(child.value, instance.id);
166
- }
167
- }
168
- }
169
- const descendantSelectorByInstanceId = /* @__PURE__ */ new Map();
170
- for (const prop of props.values()) {
171
- if (prop.name === "selector" && prop.type === "string") {
172
- descendantSelectorByInstanceId.set(prop.instanceId, prop.value);
173
- }
174
- }
175
- const instanceByRule = /* @__PURE__ */ new Map();
176
- for (const selection of styleSourceSelections.values()) {
177
- let { instanceId } = selection;
178
- const { values } = selection;
179
- if (instanceId === ROOT_INSTANCE_ID) {
180
- const rule2 = sheet.addNestingRule(`:root`);
181
- rule2.applyMixins(values);
182
- continue;
183
- }
184
- let descendantSuffix = "";
185
- const instance = instances.get(instanceId);
186
- if (instance === void 0) {
187
- continue;
188
- }
189
- if (instance.component === descendantComponent) {
190
- const parentId = parentIdByInstanceId.get(instanceId);
191
- const descendantSelector = descendantSelectorByInstanceId.get(instanceId);
192
- if (parentId && descendantSelector) {
193
- descendantSuffix = descendantSelector;
194
- instanceId = parentId;
195
- }
196
- }
197
- const meta = componentMetas.get(instance.component);
198
- const [_namespace, shortName] = parseComponentName(instance.component);
199
- const baseName = instance.label ?? meta?.label ?? shortName;
200
- const className = `w-${scope.getName(instanceId, baseName)}`;
201
- if (atomic === false) {
202
- let classList = classes.get(instanceId);
203
- if (classList === void 0) {
204
- classList = [];
205
- classes.set(instanceId, classList);
206
- }
207
- classList.push(className);
208
- }
209
- const rule = sheet.addNestingRule(`.${className}`, descendantSuffix);
210
- rule.applyMixins(values);
211
- instanceByRule.set(rule, instanceId);
212
- }
213
- if (atomic) {
214
- const { cssText } = generateAtomic(sheet, {
215
- getKey: (rule) => instanceByRule.get(rule),
216
- transformValue: imageValueTransformer,
217
- classes
218
- });
219
- return { cssText: `${globalSheet.cssText}
220
- ${cssText}`, classes };
221
- }
222
- return {
223
- cssText: `${globalSheet.cssText}
224
- ${sheet.cssText}`,
225
- classes
226
- };
227
- };
228
-
229
57
  // src/props.ts
230
58
  import {
231
59
  getPagePath,
232
- findPageByIdOrPath
60
+ findPageByIdOrPath,
61
+ findTreeInstanceIdsExcludingSubtrees
233
62
  } from "@webstudio-is/sdk";
234
63
  var normalizeProps = ({
235
64
  props,
@@ -269,6 +98,14 @@ var normalizeProps = ({
269
98
  });
270
99
  continue;
271
100
  }
101
+ if (prop.name === "alt" && asset.type === "image") {
102
+ newProps.push({
103
+ ...propBase,
104
+ type: "string",
105
+ value: asset.description ?? ""
106
+ });
107
+ continue;
108
+ }
272
109
  newProps.push({
273
110
  ...propBase,
274
111
  type: "string",
@@ -325,11 +162,25 @@ var idAttribute = "data-ws-id";
325
162
  var selectorIdAttribute = "data-ws-selector";
326
163
  var componentAttribute = "data-ws-component";
327
164
  var showAttribute = "data-ws-show";
328
- var indexAttribute = "data-ws-index";
329
- var collapsedAttribute = "data-ws-collapsed";
165
+ var inflatedAttribute = "data-ws-collapsed";
330
166
  var textContentAttribute = "data-ws-text-content";
331
- var editablePlaceholderVariable = "--data-ws-editable-placeholder";
332
- var editingPlaceholderVariable = "--data-ws-editing-placeholder";
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
+ };
333
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";
334
185
  var attributeNameChar = attributeNameStartChar + ":\\-0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
335
186
  var validAttributeNameRegex = new RegExp(
@@ -353,349 +204,55 @@ var isAttributeNameSafe = (attributeName) => {
353
204
  return false;
354
205
  };
355
206
 
356
- // src/embed-template.ts
357
- import { nanoid } from "nanoid";
358
- import {
359
- encodeDataSourceVariable,
360
- transpileExpression
361
- } from "@webstudio-is/sdk";
362
- var getVariablValue = (value) => {
363
- if (typeof value === "string") {
364
- return { type: "string", value };
365
- }
366
- if (typeof value === "number") {
367
- return { type: "number", value };
368
- }
369
- if (typeof value === "boolean") {
370
- return { type: "boolean", value };
207
+ // src/collection-utils.ts
208
+ var getCollectionEntries = (data) => {
209
+ if (data === null || data === void 0) {
210
+ return [];
371
211
  }
372
- if (Array.isArray(value)) {
373
- return { type: "string[]", value };
374
- }
375
- return { type: "json", value };
376
- };
377
- var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByRef, styleSourceSelections, styleSources, styles, metas, defaultBreakpointId, generateId) => {
378
- const parentChildren = [];
379
- for (const item of treeTemplate) {
380
- if (item.type === "instance") {
381
- const instanceId = generateId();
382
- if (item.variables) {
383
- for (const [name, variable] of Object.entries(item.variables)) {
384
- if (dataSourceByRef.has(name)) {
385
- throw Error(`${name} data source already defined`);
386
- }
387
- dataSourceByRef.set(name, {
388
- type: "variable",
389
- id: generateId(),
390
- scopeInstanceId: instanceId,
391
- name: variable.alias ?? name,
392
- value: getVariablValue(variable.initialValue)
393
- });
394
- }
395
- }
396
- if (item.props) {
397
- for (const prop of item.props) {
398
- const propId = generateId();
399
- if (prop.type === "expression") {
400
- props.push({
401
- id: propId,
402
- instanceId,
403
- name: prop.name,
404
- type: "expression",
405
- // replace all references with variable names
406
- value: transpileExpression({
407
- expression: prop.code,
408
- replaceVariable: (ref) => {
409
- const id = dataSourceByRef.get(ref)?.id ?? ref;
410
- return encodeDataSourceVariable(id);
411
- }
412
- })
413
- });
414
- continue;
415
- }
416
- if (prop.type === "action") {
417
- props.push({
418
- id: propId,
419
- instanceId,
420
- type: "action",
421
- name: prop.name,
422
- value: prop.value.map((value) => {
423
- const args = value.args ?? [];
424
- return {
425
- type: "execute",
426
- args,
427
- // replace all references with variable names
428
- code: transpileExpression({
429
- expression: value.code,
430
- replaceVariable: (ref) => {
431
- if (args.includes(ref)) {
432
- return;
433
- }
434
- const id = dataSourceByRef.get(ref)?.id ?? ref;
435
- return encodeDataSourceVariable(id);
436
- }
437
- })
438
- };
439
- })
440
- });
441
- continue;
442
- }
443
- if (prop.type === "parameter") {
444
- const dataSourceId = generateId();
445
- dataSourceByRef.set(prop.variableName, {
446
- type: "parameter",
447
- id: dataSourceId,
448
- scopeInstanceId: instanceId,
449
- name: prop.variableAlias ?? prop.variableName
450
- });
451
- props.push({
452
- id: propId,
453
- instanceId,
454
- name: prop.name,
455
- type: "parameter",
456
- // replace variable reference with variable id
457
- value: dataSourceId
458
- });
459
- continue;
460
- }
461
- props.push({ id: propId, instanceId, ...prop });
462
- }
463
- }
464
- const styleSourceIds = [];
465
- if (item.styles) {
466
- const styleSourceId = generateId();
467
- styleSources.push({
468
- type: "local",
469
- id: styleSourceId
470
- });
471
- styleSourceIds.push(styleSourceId);
472
- for (const styleDecl of item.styles) {
473
- styles.push({
474
- breakpointId: defaultBreakpointId,
475
- styleSourceId,
476
- state: styleDecl.state,
477
- property: styleDecl.property,
478
- value: styleDecl.value
479
- });
480
- }
481
- }
482
- if (styleSourceIds.length > 0) {
483
- styleSourceSelections.push({
484
- instanceId,
485
- values: styleSourceIds
486
- });
487
- }
488
- const instance = {
489
- type: "instance",
490
- id: instanceId,
491
- label: item.label,
492
- component: item.component,
493
- children: []
494
- };
495
- instances.push(instance);
496
- instance.children = createInstancesFromTemplate(
497
- item.children,
498
- instances,
499
- props,
500
- dataSourceByRef,
501
- styleSourceSelections,
502
- styleSources,
503
- styles,
504
- metas,
505
- defaultBreakpointId,
506
- generateId
507
- );
508
- parentChildren.push({
509
- type: "id",
510
- value: instanceId
511
- });
512
- }
513
- if (item.type === "text") {
514
- parentChildren.push({
515
- type: "text",
516
- value: item.value,
517
- placeholder: item.placeholder
518
- });
519
- }
520
- if (item.type === "expression") {
521
- parentChildren.push({
522
- type: "expression",
523
- // replace all references with variable names
524
- value: transpileExpression({
525
- expression: item.value,
526
- replaceVariable: (ref) => {
527
- const id = dataSourceByRef.get(ref)?.id ?? ref;
528
- return encodeDataSourceVariable(id);
529
- }
530
- })
531
- });
532
- }
212
+ if (typeof data !== "object") {
213
+ return [];
533
214
  }
534
- return parentChildren;
535
- };
536
- var generateDataFromEmbedTemplate = (treeTemplate, metas, generateId = nanoid) => {
537
- const instances = [];
538
- const props = [];
539
- const dataSourceByRef = /* @__PURE__ */ new Map();
540
- const styleSourceSelections = [];
541
- const styleSources = [];
542
- const styles = [];
543
- const baseBreakpointId = generateId();
544
- const children = createInstancesFromTemplate(
545
- treeTemplate,
546
- instances,
547
- props,
548
- dataSourceByRef,
549
- styleSourceSelections,
550
- styleSources,
551
- styles,
552
- metas,
553
- baseBreakpointId,
554
- generateId
555
- );
556
- const breakpoints = [];
557
- if (styles.length > 0) {
558
- breakpoints.push({
559
- id: baseBreakpointId,
560
- label: ""
561
- });
215
+ const entries = Object.entries(data);
216
+ if (Array.isArray(data)) {
217
+ return entries.map(([key, value]) => [Number(key), value]);
562
218
  }
563
- return {
564
- children,
565
- instances,
566
- props,
567
- dataSources: Array.from(dataSourceByRef.values()),
568
- styleSourceSelections,
569
- styleSources,
570
- styles,
571
- breakpoints,
572
- assets: [],
573
- resources: []
574
- };
219
+ return entries;
575
220
  };
576
- var namespaceEmbedTemplateComponents = (template, namespace, components) => {
577
- return template.map((item) => {
578
- if (item.type === "text") {
579
- return item;
580
- }
581
- if (item.type === "expression") {
582
- return item;
583
- }
584
- if (item.type === "instance") {
585
- const prefix = components.has(item.component) ? `${namespace}:` : "";
586
- return {
587
- ...item,
588
- component: `${prefix}${item.component}`,
589
- children: namespaceEmbedTemplateComponents(
590
- item.children,
591
- namespace,
592
- components
593
- )
594
- };
595
- }
596
- item;
597
- throw Error("Impossible case");
598
- });
221
+ var isStaticCollectionExpression = (expression) => {
222
+ const trimmedExpression = expression.trim();
223
+ return trimmedExpression.startsWith("[") && trimmedExpression.endsWith("]") || trimmedExpression.startsWith("{") && trimmedExpression.endsWith("}") || trimmedExpression.startsWith("({") && trimmedExpression.endsWith("})");
599
224
  };
600
- var namespaceMatcher = (namespace, matcher) => {
601
- const newMatcher = structuredClone(matcher);
602
- if (newMatcher.component?.$eq) {
603
- newMatcher.component.$eq = `${namespace}:${newMatcher.component.$eq}`;
604
- }
605
- if (newMatcher.component?.$neq) {
606
- newMatcher.component.$neq = `${namespace}:${newMatcher.component.$neq}`;
607
- }
608
- if (newMatcher.component?.$in) {
609
- newMatcher.component.$in = newMatcher.component.$in.map(
610
- (component) => `${namespace}:${component}`
611
- );
612
- }
613
- if (newMatcher.component?.$nin) {
614
- newMatcher.component.$nin = newMatcher.component.$nin.map(
615
- (component) => `${namespace}:${component}`
616
- );
617
- }
618
- return newMatcher;
619
- };
620
- var namespaceMeta = (meta, namespace, components) => {
621
- const newMeta = { ...meta };
622
- if (newMeta.constraints) {
623
- if (Array.isArray(newMeta.constraints)) {
624
- newMeta.constraints = newMeta.constraints.map(
625
- (matcher) => namespaceMatcher(namespace, matcher)
626
- );
627
- } else {
628
- newMeta.constraints = namespaceMatcher(namespace, newMeta.constraints);
629
- }
630
- }
631
- if (newMeta.indexWithinAncestor) {
632
- newMeta.indexWithinAncestor = components.has(newMeta.indexWithinAncestor) ? `${namespace}:${newMeta.indexWithinAncestor}` : newMeta.indexWithinAncestor;
633
- }
634
- if (newMeta.template) {
635
- newMeta.template = namespaceEmbedTemplateComponents(
636
- newMeta.template,
637
- namespace,
638
- components
639
- );
640
- }
641
- return newMeta;
642
- };
643
-
644
- // src/instance-utils.ts
645
- var getIndexesWithinAncestors = (metas, instances, rootIds) => {
646
- const ancestors = /* @__PURE__ */ new Set();
647
- for (const meta of metas.values()) {
648
- if (meta.indexWithinAncestor !== void 0) {
649
- ancestors.add(meta.indexWithinAncestor);
650
- }
651
- }
652
- const indexes = /* @__PURE__ */ new Map();
653
- const traverseInstances = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
654
- const instance = instances2.get(instanceId);
655
- if (instance === void 0) {
656
- return;
657
- }
658
- const meta = metas.get(instance.component);
659
- if (meta === void 0) {
660
- return;
661
- }
662
- if (ancestors.has(instance.component)) {
663
- latestIndexes2 = new Map(latestIndexes2);
664
- latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
665
- }
666
- if (meta.indexWithinAncestor !== void 0) {
667
- const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
668
- if (ancestorIndexes !== void 0) {
669
- let index = ancestorIndexes.get(instance.component) ?? -1;
670
- index += 1;
671
- ancestorIndexes.set(instance.component, index);
672
- indexes.set(instance.id, index);
673
- }
674
- }
675
- for (const child of instance.children) {
676
- if (child.type === "id") {
677
- traverseInstances(instances2, child.value, latestIndexes2);
678
- }
679
- }
680
- };
681
- const latestIndexes = /* @__PURE__ */ new Map();
682
- for (const instanceId of rootIds) {
683
- traverseInstances(instances, instanceId, latestIndexes);
684
- }
685
- return indexes;
225
+ var generateCollectionIterationCode = ({
226
+ dataExpression,
227
+ keyVariable,
228
+ itemVariable
229
+ }) => {
230
+ const safeDataExpression = isStaticCollectionExpression(dataExpression) ? dataExpression : `${dataExpression} ?? {}`;
231
+ return `Object.entries(
232
+ // @ts-ignore
233
+ ${safeDataExpression}
234
+ ).map(([_key, ${itemVariable}]: any) => {
235
+ const ${keyVariable} = Array.isArray(${dataExpression}) ? Number(_key) : _key;
236
+ return`;
686
237
  };
687
238
 
688
239
  // src/component-generator.ts
689
240
  import {
690
- parseComponentName as parseComponentName2,
241
+ parseComponentName,
691
242
  generateExpression,
692
243
  decodeDataSourceVariable,
693
- transpileExpression as transpileExpression2,
244
+ contentBlockDocumentProp,
694
245
  blockComponent,
246
+ blockBodyComponent,
695
247
  blockTemplateComponent,
696
248
  collectionComponent,
697
- descendantComponent as descendantComponent2
249
+ descendantComponent,
250
+ getIndexesWithinAncestors,
251
+ elementComponent
698
252
  } from "@webstudio-is/sdk";
253
+ import { transpileExpression } from "@webstudio-is/expression";
254
+ import { indexProperty, tagProperty } from "@webstudio-is/sdk/runtime";
255
+ import { getJsxPropName } from "@webstudio-is/content-engine/jsx-attributes";
699
256
  var generateAction = ({
700
257
  scope,
701
258
  prop,
@@ -707,7 +264,7 @@ var generateAction = ({
707
264
  let assignersCode = "";
708
265
  for (const value of prop.value) {
709
266
  args = value.args;
710
- assignersCode += transpileExpression2({
267
+ assignersCode += transpileExpression({
711
268
  expression: value.code,
712
269
  executable: true,
713
270
  replaceVariable: (identifier, assignee) => {
@@ -758,7 +315,7 @@ var generatePropValue = ({
758
315
  if (prop.type === "asset" || prop.type === "page") {
759
316
  return;
760
317
  }
761
- if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
318
+ if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json" || prop.type === "animationAction") {
762
319
  return JSON.stringify(prop.value);
763
320
  }
764
321
  if (prop.type === "parameter") {
@@ -788,39 +345,83 @@ var generatePropValue = ({
788
345
  var generateJsxElement = ({
789
346
  context = "jsx",
790
347
  scope,
348
+ metas,
349
+ tagsOverrides,
791
350
  instance,
792
351
  props,
352
+ resources,
793
353
  dataSources,
794
354
  usedDataSources,
795
355
  indexesWithinAncestors,
796
356
  children,
797
357
  classesMap
798
358
  }) => {
799
- if (instance.component === descendantComponent2) {
359
+ if (instance.component === descendantComponent) {
800
360
  return "";
801
361
  }
362
+ const meta = metas.get(instance.component);
363
+ const hasTags = Object.keys(meta?.presetStyle ?? {}).length > 0;
802
364
  let generatedProps = "";
803
365
  const index = indexesWithinAncestors.get(instance.id);
804
366
  if (index !== void 0) {
805
367
  generatedProps += `
806
- ${indexAttribute}="${index}"`;
368
+ ${indexProperty}="${index}"`;
369
+ }
370
+ if (instance.tag !== void 0 && instance.component !== elementComponent) {
371
+ generatedProps += `
372
+ ${tagProperty}=${JSON.stringify(instance.tag)}`;
807
373
  }
808
374
  let conditionValue;
809
375
  let collectionDataValue;
810
376
  let collectionItemValue;
811
- let classNameValue;
377
+ let collectionItemKeyValue;
378
+ const classNameValues = [];
379
+ const projectedResourceProps = /* @__PURE__ */ new Map();
380
+ const componentPropNames = new Set(Object.keys(meta?.props ?? {}));
381
+ const acceptsHtmlAttributes = hasTags || instance.tag !== void 0 || instance.component === elementComponent;
382
+ const getGeneratedPropName = (instancePropName) => getJsxPropName({
383
+ instancePropName,
384
+ componentPropNames,
385
+ acceptsHtmlAttributes
386
+ });
387
+ const propsByGeneratedName = /* @__PURE__ */ new Map();
388
+ const classProps = /* @__PURE__ */ new Map();
812
389
  for (const prop of props.values()) {
813
- if (prop.instanceId !== instance.id) {
390
+ if (prop.instanceId !== instance.id || isAttributeNameSafe(prop.name) === false) {
391
+ continue;
392
+ }
393
+ const name = getGeneratedPropName(prop.name);
394
+ if (name === "className") {
395
+ classProps.set(prop.name, prop);
814
396
  continue;
815
397
  }
398
+ propsByGeneratedName.set(name, prop);
399
+ }
400
+ const generatedPropNames = /* @__PURE__ */ new Set([
401
+ ...propsByGeneratedName.keys(),
402
+ ...classProps.size > 0 ? ["className"] : []
403
+ ]);
404
+ for (const [name, prop] of [
405
+ ...propsByGeneratedName,
406
+ ...Array.from(classProps.values(), (prop2) => ["className", prop2])
407
+ ]) {
816
408
  const propValue = generatePropValue({
817
409
  scope,
818
410
  prop,
819
411
  dataSources,
820
412
  usedDataSources
821
413
  });
822
- if (isAttributeNameSafe(prop.name) === false) {
823
- continue;
414
+ if (prop.type === "resource") {
415
+ const propMeta = meta?.props?.[prop.name];
416
+ const resource = resources?.get(prop.value);
417
+ if (propMeta?.type === "resource" && resource !== void 0) {
418
+ for (const propName of propMeta.generatedProps ?? []) {
419
+ const generatedPropName = getGeneratedPropName(propName);
420
+ if (generatedPropNames.has(generatedPropName) === false && isAttributeNameSafe(propName)) {
421
+ projectedResourceProps.set(generatedPropName, resource[propName]);
422
+ }
423
+ }
424
+ }
824
425
  }
825
426
  if (prop.name === showAttribute) {
826
427
  if (propValue === "true") {
@@ -839,21 +440,28 @@ ${indexAttribute}="${index}"`;
839
440
  if (prop.name === "item") {
840
441
  collectionItemValue = propValue;
841
442
  }
443
+ if (prop.name === "itemKey") {
444
+ collectionItemKeyValue = propValue;
445
+ }
842
446
  continue;
843
447
  }
844
- if (prop.name === "className" && propValue !== void 0) {
845
- classNameValue = propValue;
448
+ if (name === "className" && propValue !== void 0) {
449
+ classNameValues.push(propValue);
846
450
  continue;
847
451
  }
848
452
  if (propValue !== void 0) {
849
453
  generatedProps += `
850
- ${prop.name}={${propValue}}`;
454
+ ${name}={${propValue}}`;
851
455
  }
852
456
  }
457
+ for (const [name, value] of projectedResourceProps) {
458
+ generatedProps += `
459
+ ${name}={${JSON.stringify(value)}}`;
460
+ }
853
461
  const classMapArray = classesMap?.get(instance.id);
854
- if (classMapArray || classNameValue) {
462
+ if (classMapArray || classNameValues.length > 0) {
855
463
  let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
856
- if (classNameValue) {
464
+ for (const classNameValue of classNameValues) {
857
465
  if (classNameTemplate) {
858
466
  classNameTemplate += " ";
859
467
  }
@@ -870,20 +478,39 @@ ${prop.name}={${propValue}}`;
870
478
  return "";
871
479
  }
872
480
  const indexVariable = scope.getName(`${instance.id}-index`, "index");
873
- generatedElement += `{${collectionDataValue}?.map((${collectionItemValue}: any, ${indexVariable}: number) =>
481
+ const keyVariable = collectionItemKeyValue ?? indexVariable;
482
+ generatedElement += `{${generateCollectionIterationCode({
483
+ dataExpression: collectionDataValue,
484
+ keyVariable,
485
+ itemVariable: collectionItemValue
486
+ })} (
874
487
  `;
875
- generatedElement += `<Fragment key={${indexVariable}}>
488
+ generatedElement += `<Fragment key={${keyVariable}}>
876
489
  `;
877
490
  generatedElement += children;
878
491
  generatedElement += `</Fragment>
879
492
  `;
880
- generatedElement += `)}
493
+ generatedElement += `)
494
+ `;
495
+ generatedElement += `})
496
+ `;
497
+ generatedElement += `}
881
498
  `;
882
- } else if (instance.component === blockComponent) {
499
+ } else if (instance.component === blockComponent || instance.component === blockBodyComponent) {
883
500
  generatedElement += children;
884
501
  } else {
885
- const [_namespace, shortName] = parseComponentName2(instance.component);
886
- const componentVariable = scope.getName(instance.component, shortName);
502
+ let componentVariable;
503
+ if (instance.component === elementComponent) {
504
+ componentVariable = instance.tag === "" ? "div" : instance.tag ?? "div";
505
+ const componentDescriptor = tagsOverrides?.[componentVariable];
506
+ if (componentDescriptor !== void 0) {
507
+ const [_importSource, importSpecifier] = componentDescriptor.split(":");
508
+ componentVariable = scope.getName(componentDescriptor, importSpecifier);
509
+ }
510
+ } else {
511
+ const [_namespace, shortName] = parseComponentName(instance.component);
512
+ componentVariable = scope.getName(instance.component, shortName);
513
+ }
887
514
  if (instance.children.length === 0) {
888
515
  generatedElement += `<${componentVariable}${generatedProps} />
889
516
  `;
@@ -920,14 +547,19 @@ ${prop.name}={${propValue}}`;
920
547
  };
921
548
  var generateJsxChildren = ({
922
549
  scope,
550
+ metas,
551
+ tagsOverrides,
923
552
  children,
924
553
  instances,
925
554
  props,
555
+ resources,
926
556
  dataSources,
927
557
  usedDataSources,
928
558
  indexesWithinAncestors,
929
559
  classesMap,
930
- excludePlaceholders
560
+ excludePlaceholders,
561
+ publishedContentBlocks,
562
+ contentBodyOverride
931
563
  }) => {
932
564
  let generatedChildren = "";
933
565
  for (const child of children) {
@@ -947,7 +579,7 @@ var generateJsxChildren = ({
947
579
  usedDataSources,
948
580
  scope
949
581
  });
950
- generatedChildren = `{${expression}}
582
+ generatedChildren += `{renderText(${expression})}
951
583
  `;
952
584
  continue;
953
585
  }
@@ -957,26 +589,124 @@ var generateJsxChildren = ({
957
589
  if (instance === void 0) {
958
590
  continue;
959
591
  }
592
+ const publishedContent = publishedContentBlocks?.get(instance.id);
593
+ let generatedInstanceChildren;
594
+ if (contentBodyOverride?.instanceId === instance.id) {
595
+ generatedInstanceChildren = generateJsxChildren({
596
+ classesMap,
597
+ scope,
598
+ metas,
599
+ tagsOverrides,
600
+ children: contentBodyOverride.children,
601
+ instances,
602
+ props,
603
+ resources,
604
+ dataSources,
605
+ usedDataSources,
606
+ indexesWithinAncestors,
607
+ excludePlaceholders,
608
+ publishedContentBlocks
609
+ });
610
+ } else if (publishedContent === void 0) {
611
+ generatedInstanceChildren = generateJsxChildren({
612
+ classesMap,
613
+ scope,
614
+ metas,
615
+ tagsOverrides,
616
+ children: instance.children,
617
+ instances,
618
+ props,
619
+ resources,
620
+ dataSources,
621
+ usedDataSources,
622
+ indexesWithinAncestors,
623
+ excludePlaceholders,
624
+ publishedContentBlocks,
625
+ contentBodyOverride
626
+ });
627
+ } else {
628
+ const sourceExpression = publishedContent.sourceExpression === void 0 ? void 0 : generateExpression({
629
+ expression: publishedContent.sourceExpression,
630
+ dataSources,
631
+ usedDataSources,
632
+ scope
633
+ });
634
+ const documentParameter = Array.from(props.values()).find(
635
+ (prop) => prop.instanceId === instance.id && prop.name === contentBlockDocumentProp && prop.type === "parameter"
636
+ );
637
+ const documentDataSource = documentParameter === void 0 ? void 0 : dataSources.get(documentParameter.value);
638
+ if (documentDataSource !== void 0) {
639
+ usedDataSources.set(documentDataSource.id, documentDataSource);
640
+ }
641
+ const documentName = documentDataSource === void 0 ? void 0 : scope.getName(documentDataSource.id, documentDataSource.name);
642
+ const generatedCandidates = publishedContent.candidates.map(
643
+ ({
644
+ assetId,
645
+ dependencyRevision,
646
+ children: candidateChildren,
647
+ frontmatter
648
+ }) => {
649
+ const generated = generateJsxChildren({
650
+ classesMap,
651
+ scope,
652
+ metas,
653
+ tagsOverrides,
654
+ children: publishedContent.bodyInstanceId === void 0 ? candidateChildren : instance.children,
655
+ instances,
656
+ props,
657
+ resources,
658
+ dataSources,
659
+ usedDataSources,
660
+ indexesWithinAncestors,
661
+ excludePlaceholders,
662
+ publishedContentBlocks,
663
+ contentBodyOverride: publishedContent.bodyInstanceId === void 0 ? void 0 : {
664
+ instanceId: publishedContent.bodyInstanceId,
665
+ children: candidateChildren
666
+ }
667
+ });
668
+ const withDocument = documentName === void 0 ? generated : `{((${documentName}) => <Fragment>
669
+ ${generated}</Fragment>)(${JSON.stringify({ frontmatter })})}
670
+ `;
671
+ return {
672
+ assetId,
673
+ dependencyRevision,
674
+ generated: withDocument
675
+ };
676
+ }
677
+ );
678
+ if (sourceExpression === void 0) {
679
+ generatedInstanceChildren = generatedCandidates.map(
680
+ ({ dependencyRevision, generated }) => `<Fragment key=${JSON.stringify(dependencyRevision)}>
681
+ ${generated}</Fragment>
682
+ `
683
+ ).join("");
684
+ } else {
685
+ const sourceName = scope.getName(
686
+ `${instance.id}-published-source`,
687
+ "contentSource"
688
+ );
689
+ const branches = generatedCandidates.map(
690
+ ({ assetId, dependencyRevision, generated }) => `${sourceName} === ${JSON.stringify(assetId)} ? <Fragment key=${JSON.stringify(dependencyRevision)}>
691
+ ${generated}</Fragment>`
692
+ ).join(" : ");
693
+ generatedInstanceChildren = `{((${sourceName}) => ${branches.length === 0 ? "null" : `${branches} : null`})(${sourceExpression})}
694
+ `;
695
+ }
696
+ }
960
697
  generatedChildren += generateJsxElement({
961
698
  context: "jsx",
962
699
  scope,
700
+ metas,
701
+ tagsOverrides,
963
702
  instance,
964
703
  props,
704
+ resources,
965
705
  dataSources,
966
706
  usedDataSources,
967
707
  indexesWithinAncestors,
968
708
  classesMap,
969
- children: generateJsxChildren({
970
- classesMap,
971
- scope,
972
- children: instance.children,
973
- instances,
974
- props,
975
- dataSources,
976
- usedDataSources,
977
- indexesWithinAncestors,
978
- excludePlaceholders
979
- })
709
+ children: generatedInstanceChildren
980
710
  });
981
711
  continue;
982
712
  }
@@ -991,50 +721,67 @@ var generateWebstudioComponent = ({
991
721
  parameters,
992
722
  instances,
993
723
  props,
724
+ resources,
994
725
  dataSources,
995
- indexesWithinAncestors,
996
- classesMap
726
+ metas,
727
+ tagsOverrides,
728
+ classesMap,
729
+ publishedContentBlocks
997
730
  }) => {
998
731
  const instance = instances.get(rootInstanceId);
999
- if (instance === void 0) {
1000
- return "";
1001
- }
732
+ const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
733
+ rootInstanceId
734
+ ]);
1002
735
  const usedDataSources = /* @__PURE__ */ new Map();
1003
- const generatedJsx = generateJsxElement({
1004
- context: "expression",
1005
- scope,
1006
- instance,
1007
- props,
1008
- dataSources,
1009
- usedDataSources,
1010
- indexesWithinAncestors,
1011
- classesMap,
1012
- children: generateJsxChildren({
736
+ let generatedJsx = "<></>\n";
737
+ if (instance) {
738
+ generatedJsx = generateJsxElement({
739
+ context: "expression",
1013
740
  scope,
1014
- children: instance.children,
1015
- instances,
741
+ metas,
742
+ tagsOverrides,
743
+ instance,
1016
744
  props,
745
+ resources,
1017
746
  dataSources,
1018
747
  usedDataSources,
1019
748
  indexesWithinAncestors,
1020
- classesMap
1021
- })
1022
- });
749
+ classesMap,
750
+ children: generateJsxChildren({
751
+ scope,
752
+ metas,
753
+ tagsOverrides,
754
+ children: instance.children,
755
+ instances,
756
+ props,
757
+ resources,
758
+ dataSources,
759
+ usedDataSources,
760
+ indexesWithinAncestors,
761
+ classesMap,
762
+ publishedContentBlocks
763
+ })
764
+ });
765
+ }
1023
766
  let generatedProps = "";
767
+ let generatedParameters = "";
768
+ const uniqueParameters = new Set(
769
+ parameters.map((parameter) => parameter.name)
770
+ );
1024
771
  if (parameters.length > 0) {
1025
- let generatedPropsValue = "{ ";
1026
- let generatedPropsType = "{ ";
772
+ let generatedPropsType = "";
773
+ for (const parameterName of uniqueParameters) {
774
+ generatedPropsType += `${parameterName}: any; `;
775
+ }
776
+ generatedProps = `_props: { ${generatedPropsType}}`;
1027
777
  for (const parameter of parameters) {
1028
778
  const dataSource = usedDataSources.get(parameter.value);
1029
779
  if (dataSource) {
1030
780
  const valueName = scope.getName(dataSource.id, dataSource.name);
1031
- generatedPropsValue += `${parameter.name}: ${valueName}, `;
781
+ generatedParameters += `const ${valueName} = _props.${parameter.name};
782
+ `;
1032
783
  }
1033
- generatedPropsType += `${parameter.name}: any; `;
1034
784
  }
1035
- generatedPropsValue += `}`;
1036
- generatedPropsType += `}`;
1037
- generatedProps = `${generatedPropsValue}: ${generatedPropsType}`;
1038
785
  }
1039
786
  let generatedDataSources = "";
1040
787
  for (const dataSource of usedDataSources.values()) {
@@ -1063,33 +810,40 @@ var generateWebstudioComponent = ({
1063
810
  let generatedComponent = "";
1064
811
  generatedComponent += `const ${name} = (${generatedProps}) => {
1065
812
  `;
813
+ generatedComponent += `${generatedParameters}`;
1066
814
  generatedComponent += `${generatedDataSources}`;
1067
815
  generatedComponent += `return ${generatedJsx}`;
1068
816
  generatedComponent += `}
1069
817
  `;
1070
818
  return generatedComponent;
1071
819
  };
820
+
821
+ // src/standard-attributes.ts
822
+ import {
823
+ getInstancePropName,
824
+ getJsxPropName as getJsxPropName2,
825
+ reactPropsToStandardAttributes,
826
+ standardAttributesToReactProps
827
+ } from "@webstudio-is/content-engine/jsx-attributes";
1072
828
  export {
1073
- addGlobalRules,
1074
- collapsedAttribute,
1075
829
  componentAttribute,
1076
- createImageValueTransformer,
1077
- editablePlaceholderVariable,
1078
- editingPlaceholderVariable,
1079
- generateCss,
1080
- generateDataFromEmbedTemplate,
830
+ findTreeInstanceIdsExcludingStaticHidden,
831
+ generateCollectionIterationCode,
1081
832
  generateJsxChildren,
1082
833
  generateJsxElement,
1083
834
  generateRemixParams,
1084
835
  generateRemixRoute,
1085
836
  generateWebstudioComponent,
1086
- getIndexesWithinAncestors,
837
+ getCollectionEntries,
838
+ getInstancePropName,
839
+ getJsxPropName2 as getJsxPropName,
1087
840
  idAttribute,
1088
- indexAttribute,
841
+ inflatedAttribute,
1089
842
  isAttributeNameSafe,
1090
- namespaceMeta,
1091
843
  normalizeProps,
844
+ reactPropsToStandardAttributes,
1092
845
  selectorIdAttribute,
1093
846
  showAttribute,
847
+ standardAttributesToReactProps,
1094
848
  textContentAttribute
1095
849
  };