[FRONT COMPONENTS] Move to twenty-sdk (#17587)

Move front components from twenty-shared to twenty-sdk
This commit is contained in:
Raphaël Bosi
2026-02-02 12:21:53 +00:00
committed by GitHub
parent b2218cbbf2
commit f0bc9fcb43
63 changed files with 146 additions and 139 deletions
@@ -0,0 +1,13 @@
import { type SourceFile, VariableDeclarationKind } from 'ts-morph';
export const addExportedConst = (
sourceFile: SourceFile,
name: string,
initializer: string,
): void => {
sourceFile.addVariableStatement({
isExported: true,
declarationKind: VariableDeclarationKind.Const,
declarations: [{ name, initializer }],
});
};
@@ -0,0 +1,13 @@
import { type SourceFile } from 'ts-morph';
export const addExportedType = (
sourceFile: SourceFile,
name: string,
type: string,
): void => {
sourceFile.addTypeAlias({
isExported: true,
name,
type,
});
};
@@ -0,0 +1,7 @@
import { type SourceFile } from 'ts-morph';
import { GENERATED_FILE_HEADER } from './generated-file-header';
export const addFileHeader = (sourceFile: SourceFile): void => {
sourceFile.insertText(0, GENERATED_FILE_HEADER + '\n\n');
};
@@ -0,0 +1,8 @@
import { type SourceFile } from 'ts-morph';
export const addStatement = (
sourceFile: SourceFile,
statement: string,
): void => {
sourceFile.addStatements(statement);
};
@@ -0,0 +1,3 @@
export const eventToReactProp = (eventName: string): string => {
return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
};
@@ -0,0 +1,3 @@
export const extractHtmlTag = (tag: string): string => {
return tag.startsWith('html-') ? tag.slice(5) : tag;
};
@@ -0,0 +1,20 @@
import { type PropertySchema } from '../schemas';
import { schemaTypeToConstructor } from './schema-type-to-constructor';
export const generatePropertiesConfig = (
properties: Record<string, PropertySchema>,
): string => {
const entries = Object.entries(properties);
if (entries.length === 0) {
return '{}';
}
const props = entries
.map(([name, schema]) => {
const constructorType = schemaTypeToConstructor(schema.type);
return `'${name}': { type: ${constructorType} }`;
})
.join(', ');
return `{ ${props} }`;
};
@@ -0,0 +1,21 @@
import { type PropertySchema } from '../schemas';
import { schemaTypeToTs } from './schema-type-to-ts';
export const generatePropertiesType = (
properties: Record<string, PropertySchema>,
): string => {
const entries = Object.entries(properties);
if (entries.length === 0) {
return 'Record<string, never>';
}
const props = entries
.map(([name, schema]) => {
const tsType = schemaTypeToTs(schema.type);
const optional = schema.optional ? '?' : '';
return `'${name}'${optional}: ${tsType}`;
})
.join('; ');
return `{ ${props} }`;
};
@@ -0,0 +1,8 @@
export const GENERATED_FILE_HEADER = `/*
* _____ _
*|_ _|_ _____ _ __ | |_ _ _
* | | \\ \\ /\\ / / _ \\ '_ \\| __| | | | Auto-generated file
* | | \\ V V / __/ | | | |_| |_| | Any edits to this will be overridden
* |_| \\_/\\_/ \\___|_| |_|\\__|\\__, |
* |___/
*/`;
@@ -0,0 +1,11 @@
export { addExportedConst } from './add-exported-const';
export { addExportedType } from './add-exported-type';
export { addFileHeader } from './add-file-header';
export { addStatement } from './add-statement';
export { eventToReactProp } from './event-to-react-prop';
export { extractHtmlTag } from './extract-html-tag';
export { GENERATED_FILE_HEADER } from './generated-file-header';
export { generatePropertiesConfig } from './generate-properties-config';
export { generatePropertiesType } from './generate-properties-type';
export { schemaTypeToConstructor } from './schema-type-to-constructor';
export { schemaTypeToTs } from './schema-type-to-ts';
@@ -0,0 +1,10 @@
import { type PropertySchema } from '../schemas';
const SCHEMA_TYPE_TO_CONSTRUCTOR: Record<PropertySchema['type'], string> = {
boolean: 'Boolean',
number: 'Number',
string: 'String',
};
export const schemaTypeToConstructor = (type: PropertySchema['type']): string =>
SCHEMA_TYPE_TO_CONSTRUCTOR[type];
@@ -0,0 +1,10 @@
import { type PropertySchema } from '../schemas';
const SCHEMA_TYPE_TO_TS: Record<PropertySchema['type'], string> = {
boolean: 'boolean',
number: 'number',
string: 'string',
};
export const schemaTypeToTs = (type: PropertySchema['type']): string =>
SCHEMA_TYPE_TO_TS[type];