Skip to content

Commit 471c0d5

Browse files
authored
Update code generation for React (#126)
1 parent 91c6b85 commit 471c0d5

4 files changed

Lines changed: 26 additions & 18 deletions

File tree

package-lock.json

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
"@babel/types": "^7.28.5",
4242
"@croct/cache": "^0.5.1",
4343
"@croct/content": "^1.1.0",
44-
"@croct/content-model": "^0.21.1",
44+
"@croct/content-model": "^0.21.4",
4545
"@croct/json": "^2.1.0",
4646
"@croct/json5-parser": "^0.2.1",
4747
"@croct/logging": "^0.2.3",
4848
"@croct/md-lite": "^0.3.1",
49-
"@croct/sdk": "^0.18.2",
49+
"@croct/sdk": "^0.20.0",
5050
"@jsep-plugin/object": "^1.2.2",
5151
"@jsep-plugin/regex": "^1.0.4",
5252
"@jsep-plugin/spread": "^1.0.3",

src/application/project/code/generation/slot/plugReactExampleGenerator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export class PlugReactExampleGenerator extends ReactExampleGenerator {
2323

2424
protected writeSlotFetch(writer: CodeWriter, definition: SlotDefinition): void {
2525
const variable = this.options.contentVariable;
26+
const variableDeclaration = variable !== 'content' ? `content: ${variable}` : variable;
2627

27-
writer.write(`const ${variable} = useContent('${definition.id}@${definition.version}');`)
28+
writer.write(`const ${variableDeclaration} = useContent('${definition.id}@${definition.version}');`)
2829
.newLine();
2930
}
3031

src/infrastructure/application/validation/actions/createResourceOptionsValidator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,14 @@ const structureContentSchema = z.strictObject({
216216

217217
const listContentSchema = z.strictObject({
218218
type: z.literal('list'),
219-
items: z.array(z.lazy((): ZodType<Content> => contentSchema)),
219+
items: z.array(z.lazy(
220+
(): ZodType<Content> => z.intersection(contentSchema, z.object({
221+
label: z.string().optional(),
222+
})),
223+
)),
220224
}) satisfies ZodType<Content<'list'>>;
221225

222-
const contentSchema: ZodType<Content> = z.discriminatedUnion('type', [
226+
const contentSchema = z.discriminatedUnion('type', [
223227
textContentSchema,
224228
numberContentSchema,
225229
booleanContentSchema,

0 commit comments

Comments
 (0)