Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Content Block publish component generator #4495

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Component generator
  • Loading branch information
istarkov committed Dec 2, 2024
commit b9267e8b860fff9bc605fcf23b7de136c85b1bdd
15 changes: 14 additions & 1 deletion packages/react-sdk/src/component-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
transpileExpression,
} from "@webstudio-is/sdk";
import { indexAttribute, isAttributeNameSafe, showAttribute } from "./props";
import { collectionComponent, descendantComponent } from "./core-components";
import {
blockComponent,
blockTemplateComponent,
collectionComponent,
descendantComponent,
} from "./core-components";
import type { IndexesWithinAncestors } from "./instance-utils";

/**
Expand Down Expand Up @@ -231,6 +236,10 @@ export const generateJsxElement = ({
}

let generatedElement = "";
if (instance.component === blockTemplateComponent) {
istarkov marked this conversation as resolved.
Show resolved Hide resolved
return "";
}

if (instance.component === collectionComponent) {
// prevent generating invalid collection
if (
Expand All @@ -246,6 +255,10 @@ export const generateJsxElement = ({
generatedElement += children;
generatedElement += `</Fragment>\n`;
generatedElement += `)}\n`;
} else if (instance.component === blockComponent) {
if (instance.children.length > 1) {
generatedElement += children;
}
istarkov marked this conversation as resolved.
Show resolved Hide resolved
} else {
const [_namespace, shortName] = parseComponentName(instance.component);
const componentVariable = scope.getName(instance.component, shortName);
Expand Down