@crombolo/schema 0.29.0 → 0.30.2
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/package.json +3 -3
- package/src/scaffold.ts +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.2",
|
|
4
4
|
"description": "Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.30.2",
|
|
32
|
+
"@crombolo/data": "0.30.2"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/scaffold.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* byte what `types rewrite` would.
|
|
9
9
|
*/
|
|
10
10
|
import type { SchemaForm, SchemaFormField, SchemaWorkflow } from '@crombolo/core'
|
|
11
|
+
import { pascal } from './generate.ts'
|
|
11
12
|
import type { SchemaContentType, SchemaProperty, SchemaTab, SchemaTypeKind } from './model.ts'
|
|
12
13
|
import { allProperties } from './model.ts'
|
|
13
14
|
|
|
@@ -232,6 +233,26 @@ export function newWorkflow(options: NewWorkflowOptions): SchemaWorkflow {
|
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
|
|
236
|
+
/**
|
|
237
|
+
* A block's component (story 184): `components/blocks/<alias>.tsx`, which
|
|
238
|
+
* `<Blocks>` renders an element type's blocks with, typed by the interface
|
|
239
|
+
* `crombolo generate` writes for it.
|
|
240
|
+
*/
|
|
241
|
+
export function blockScaffold(type: SchemaContentType): string {
|
|
242
|
+
const name = pascal(type.alias)
|
|
243
|
+
const shown = allProperties(type).find(
|
|
244
|
+
(property) => property.type === 'textstring' || property.type === 'textarea',
|
|
245
|
+
)
|
|
246
|
+
const body = shown ? `{content.text('${shown.alias}')}` : `{content.contentType.alias}`
|
|
247
|
+
return `import type { BlockProps } from '@crombolo/crombolo'
|
|
248
|
+
import type { ${name} } from '../../schema/content-types'
|
|
249
|
+
|
|
250
|
+
export default function ${name}Block({ content }: BlockProps<${name}>) {
|
|
251
|
+
return <div class="block-${type.alias}">${body}</div>
|
|
252
|
+
}
|
|
253
|
+
`
|
|
254
|
+
}
|
|
255
|
+
|
|
235
256
|
/** The view a scaffolded content type points at, if it has not got one yet. */
|
|
236
257
|
export function viewScaffold(type: SchemaContentType): string {
|
|
237
258
|
const rendered = allProperties(type)
|