Skip to content

Commit

Permalink
feature(stackbit): draft for object inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Jul 9, 2024
1 parent c1492fc commit 76da340
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@kickstartds/jsonschema2stackbit",
"comment": "add draft of inlining capability",
"type": "patch"
}
],
"packageName": "@kickstartds/jsonschema2stackbit"
}
21 changes: 19 additions & 2 deletions tools/jsonschema2stackbit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PageModel
} from '@stackbit/types';
import { type JSONSchema, TypeName } from 'json-schema-typed/draft-07';
import { traverse } from 'object-traversal';

import { GenericType, ITypeMapping } from './@types/index.js';
export * from './@types/index.js';
Expand Down Expand Up @@ -76,6 +77,19 @@ export function convert({
{ components: [], templates: [], globals: [] }
);

traverse(
reduced,
({ key, value, parent }) => {
if (value && value.group && value.group === 'INLINE') {
console.log(key, value, parent);
}
},
{
cycleHandling: false,
traversalType: 'breadth-first'
}
);

return reduced;
}

Expand Down Expand Up @@ -113,12 +127,13 @@ function isCmsAnnotatedSchema(schema: unknown): schema is JSONSchema.Interface &
'x-cms-group-name': string;
'x-cms-group-title'?: string;
'x-cms-group-icon'?: string;
'x-cms-group-inline'?: boolean;
} {
return (
typeof schema === 'object' &&
schema !== null &&
'x-cms-group-name' in schema &&
schema['x-cms-group-name'] !== undefined
(('x-cms-group-name' in schema && schema['x-cms-group-name'] !== undefined) ||
('x-cms-group-inline' in schema && schema['x-cms-group-inline'] === true))
);
}

Expand Down Expand Up @@ -220,6 +235,7 @@ function processObject({
label: title || toPascalCase(name),
description,
type: 'page',
hideContent: true,
fields: reducedFields,
fieldGroups
};
Expand Down Expand Up @@ -252,6 +268,7 @@ function processObject({
};
if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-group-name'])
field.group = subSchema['x-cms-group-name'];
if (isCmsAnnotatedSchema(subSchema) && subSchema['x-cms-group-inline']) field.group = 'INLINE';

return { field };
}
Expand Down

0 comments on commit 76da340

Please sign in to comment.