@tramo-digital/types 0.0.0
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/README.md +220 -0
- package/dist/CHANGELOG.md +31 -0
- package/dist/README.md +220 -0
- package/dist/package.json +42 -0
- package/dist/src/base/component.d.ts +75 -0
- package/dist/src/base/component.d.ts.map +1 -0
- package/dist/src/base/component.js +1 -0
- package/dist/src/base/data-loader.d.ts +110 -0
- package/dist/src/base/data-loader.d.ts.map +1 -0
- package/dist/src/base/data-loader.js +1 -0
- package/dist/src/base/design-tokens.d.ts +189 -0
- package/dist/src/base/design-tokens.d.ts.map +1 -0
- package/dist/src/base/design-tokens.js +58 -0
- package/dist/src/base/index.d.ts +4 -0
- package/dist/src/base/index.d.ts.map +1 -0
- package/dist/src/base/index.js +3 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -0
- package/dist/src/models/compositions/accordion.d.ts +43 -0
- package/dist/src/models/compositions/accordion.d.ts.map +1 -0
- package/dist/src/models/compositions/accordion.js +1 -0
- package/dist/src/models/compositions/banner.d.ts +36 -0
- package/dist/src/models/compositions/banner.d.ts.map +1 -0
- package/dist/src/models/compositions/banner.js +1 -0
- package/dist/src/models/compositions/carousel.d.ts +13 -0
- package/dist/src/models/compositions/carousel.d.ts.map +1 -0
- package/dist/src/models/compositions/carousel.js +1 -0
- package/dist/src/models/compositions/collage.d.ts +39 -0
- package/dist/src/models/compositions/collage.d.ts.map +1 -0
- package/dist/src/models/compositions/collage.js +1 -0
- package/dist/src/models/compositions/content-grid.d.ts +44 -0
- package/dist/src/models/compositions/content-grid.d.ts.map +1 -0
- package/dist/src/models/compositions/content-grid.js +1 -0
- package/dist/src/models/compositions/faq.d.ts +42 -0
- package/dist/src/models/compositions/faq.d.ts.map +1 -0
- package/dist/src/models/compositions/faq.js +1 -0
- package/dist/src/models/compositions/footer.d.ts +135 -0
- package/dist/src/models/compositions/footer.d.ts.map +1 -0
- package/dist/src/models/compositions/footer.js +1 -0
- package/dist/src/models/compositions/header.d.ts +98 -0
- package/dist/src/models/compositions/header.d.ts.map +1 -0
- package/dist/src/models/compositions/header.js +1 -0
- package/dist/src/models/compositions/hero-enhanced.d.ts +27 -0
- package/dist/src/models/compositions/hero-enhanced.d.ts.map +1 -0
- package/dist/src/models/compositions/hero-enhanced.js +1 -0
- package/dist/src/models/compositions/hero.d.ts +62 -0
- package/dist/src/models/compositions/hero.d.ts.map +1 -0
- package/dist/src/models/compositions/hero.js +1 -0
- package/dist/src/models/compositions/link-group.d.ts +93 -0
- package/dist/src/models/compositions/link-group.d.ts.map +1 -0
- package/dist/src/models/compositions/link-group.js +1 -0
- package/dist/src/models/compositions/media-quote.d.ts +48 -0
- package/dist/src/models/compositions/media-quote.d.ts.map +1 -0
- package/dist/src/models/compositions/media-quote.js +1 -0
- package/dist/src/models/compositions/media-split.d.ts +37 -0
- package/dist/src/models/compositions/media-split.d.ts.map +1 -0
- package/dist/src/models/compositions/media-split.js +1 -0
- package/dist/src/models/compositions/media-text.d.ts +42 -0
- package/dist/src/models/compositions/media-text.d.ts.map +1 -0
- package/dist/src/models/compositions/media-text.js +1 -0
- package/dist/src/models/compositions/quote-banner.d.ts +66 -0
- package/dist/src/models/compositions/quote-banner.d.ts.map +1 -0
- package/dist/src/models/compositions/quote-banner.js +1 -0
- package/dist/src/models/compositions/quote-section.d.ts +63 -0
- package/dist/src/models/compositions/quote-section.d.ts.map +1 -0
- package/dist/src/models/compositions/quote-section.js +1 -0
- package/dist/src/models/compositions/statement-section.d.ts +49 -0
- package/dist/src/models/compositions/statement-section.d.ts.map +1 -0
- package/dist/src/models/compositions/statement-section.js +1 -0
- package/dist/src/models/compositions/tabs.d.ts +84 -0
- package/dist/src/models/compositions/tabs.d.ts.map +1 -0
- package/dist/src/models/compositions/tabs.js +1 -0
- package/dist/src/models/index.d.ts +54 -0
- package/dist/src/models/index.d.ts.map +1 -0
- package/dist/src/models/index.js +57 -0
- package/dist/src/models/layout/container.d.ts +17 -0
- package/dist/src/models/layout/container.d.ts.map +1 -0
- package/dist/src/models/layout/container.js +1 -0
- package/dist/src/models/layout/drawer.d.ts +31 -0
- package/dist/src/models/layout/drawer.d.ts.map +1 -0
- package/dist/src/models/layout/drawer.js +1 -0
- package/dist/src/models/layout/grid.d.ts +137 -0
- package/dist/src/models/layout/grid.d.ts.map +1 -0
- package/dist/src/models/layout/grid.js +1 -0
- package/dist/src/models/layout/index.d.ts +5 -0
- package/dist/src/models/layout/index.d.ts.map +1 -0
- package/dist/src/models/layout/index.js +4 -0
- package/dist/src/models/layout/stack.d.ts +21 -0
- package/dist/src/models/layout/stack.d.ts.map +1 -0
- package/dist/src/models/layout/stack.js +1 -0
- package/dist/src/models/patterns/author.d.ts +23 -0
- package/dist/src/models/patterns/author.d.ts.map +1 -0
- package/dist/src/models/patterns/author.js +1 -0
- package/dist/src/models/patterns/breadcrumb.d.ts +31 -0
- package/dist/src/models/patterns/breadcrumb.d.ts.map +1 -0
- package/dist/src/models/patterns/breadcrumb.js +1 -0
- package/dist/src/models/patterns/button.d.ts +99 -0
- package/dist/src/models/patterns/button.d.ts.map +1 -0
- package/dist/src/models/patterns/button.js +1 -0
- package/dist/src/models/patterns/card.d.ts +42 -0
- package/dist/src/models/patterns/card.d.ts.map +1 -0
- package/dist/src/models/patterns/card.js +1 -0
- package/dist/src/models/patterns/content.d.ts +96 -0
- package/dist/src/models/patterns/content.d.ts.map +1 -0
- package/dist/src/models/patterns/content.js +1 -0
- package/dist/src/models/patterns/form-group.d.ts +55 -0
- package/dist/src/models/patterns/form-group.d.ts.map +1 -0
- package/dist/src/models/patterns/form-group.js +1 -0
- package/dist/src/models/patterns/navigation.d.ts +62 -0
- package/dist/src/models/patterns/navigation.d.ts.map +1 -0
- package/dist/src/models/patterns/navigation.js +1 -0
- package/dist/src/models/patterns/strip-banner.d.ts +75 -0
- package/dist/src/models/patterns/strip-banner.d.ts.map +1 -0
- package/dist/src/models/patterns/strip-banner.js +1 -0
- package/dist/src/models/patterns/teaser.d.ts +88 -0
- package/dist/src/models/patterns/teaser.d.ts.map +1 -0
- package/dist/src/models/patterns/teaser.js +1 -0
- package/dist/src/models/patterns/text-link.d.ts +59 -0
- package/dist/src/models/patterns/text-link.d.ts.map +1 -0
- package/dist/src/models/patterns/text-link.js +1 -0
- package/dist/src/models/primitives/avatar.d.ts +24 -0
- package/dist/src/models/primitives/avatar.d.ts.map +1 -0
- package/dist/src/models/primitives/avatar.js +1 -0
- package/dist/src/models/primitives/badge.d.ts +24 -0
- package/dist/src/models/primitives/badge.d.ts.map +1 -0
- package/dist/src/models/primitives/badge.js +1 -0
- package/dist/src/models/primitives/checkbox.d.ts +69 -0
- package/dist/src/models/primitives/checkbox.d.ts.map +1 -0
- package/dist/src/models/primitives/checkbox.js +1 -0
- package/dist/src/models/primitives/frame.d.ts +11 -0
- package/dist/src/models/primitives/frame.d.ts.map +1 -0
- package/dist/src/models/primitives/frame.js +1 -0
- package/dist/src/models/primitives/icon.d.ts +21 -0
- package/dist/src/models/primitives/icon.d.ts.map +1 -0
- package/dist/src/models/primitives/icon.js +1 -0
- package/dist/src/models/primitives/image.d.ts +33 -0
- package/dist/src/models/primitives/image.d.ts.map +1 -0
- package/dist/src/models/primitives/image.js +1 -0
- package/dist/src/models/primitives/input.d.ts +94 -0
- package/dist/src/models/primitives/input.d.ts.map +1 -0
- package/dist/src/models/primitives/input.js +1 -0
- package/dist/src/models/primitives/interface-icon.d.ts +20 -0
- package/dist/src/models/primitives/interface-icon.d.ts.map +1 -0
- package/dist/src/models/primitives/interface-icon.js +1 -0
- package/dist/src/models/primitives/list.d.ts +58 -0
- package/dist/src/models/primitives/list.d.ts.map +1 -0
- package/dist/src/models/primitives/list.js +1 -0
- package/dist/src/models/primitives/loader.d.ts +23 -0
- package/dist/src/models/primitives/loader.d.ts.map +1 -0
- package/dist/src/models/primitives/loader.js +1 -0
- package/dist/src/models/primitives/logo.d.ts +28 -0
- package/dist/src/models/primitives/logo.d.ts.map +1 -0
- package/dist/src/models/primitives/logo.js +1 -0
- package/dist/src/models/primitives/overlay.d.ts +29 -0
- package/dist/src/models/primitives/overlay.d.ts.map +1 -0
- package/dist/src/models/primitives/overlay.js +1 -0
- package/dist/src/models/primitives/radio.d.ts +71 -0
- package/dist/src/models/primitives/radio.d.ts.map +1 -0
- package/dist/src/models/primitives/radio.js +1 -0
- package/dist/src/models/primitives/select.d.ts +62 -0
- package/dist/src/models/primitives/select.d.ts.map +1 -0
- package/dist/src/models/primitives/select.js +1 -0
- package/dist/src/models/primitives/separator.d.ts +20 -0
- package/dist/src/models/primitives/separator.d.ts.map +1 -0
- package/dist/src/models/primitives/separator.js +1 -0
- package/dist/src/models/primitives/text-block.d.ts +25 -0
- package/dist/src/models/primitives/text-block.d.ts.map +1 -0
- package/dist/src/models/primitives/text-block.js +1 -0
- package/dist/src/models/primitives/text-body.d.ts +40 -0
- package/dist/src/models/primitives/text-body.d.ts.map +1 -0
- package/dist/src/models/primitives/text-body.js +1 -0
- package/dist/src/models/primitives/text-display.d.ts +40 -0
- package/dist/src/models/primitives/text-display.d.ts.map +1 -0
- package/dist/src/models/primitives/text-display.js +1 -0
- package/dist/src/models/primitives/text-eyebrow.d.ts +40 -0
- package/dist/src/models/primitives/text-eyebrow.d.ts.map +1 -0
- package/dist/src/models/primitives/text-eyebrow.js +1 -0
- package/dist/src/models/primitives/text-heading.d.ts +22 -0
- package/dist/src/models/primitives/text-heading.d.ts.map +1 -0
- package/dist/src/models/primitives/text-heading.js +1 -0
- package/dist/src/models/primitives/text-quote.d.ts +32 -0
- package/dist/src/models/primitives/text-quote.d.ts.map +1 -0
- package/dist/src/models/primitives/text-quote.js +1 -0
- package/dist/src/models/primitives/textarea.d.ts +60 -0
- package/dist/src/models/primitives/textarea.d.ts.map +1 -0
- package/dist/src/models/primitives/textarea.js +1 -0
- package/dist/src/models/primitives/toggle.d.ts +95 -0
- package/dist/src/models/primitives/toggle.d.ts.map +1 -0
- package/dist/src/models/primitives/toggle.js +1 -0
- package/dist/src/models/primitives/video.d.ts +39 -0
- package/dist/src/models/primitives/video.d.ts.map +1 -0
- package/dist/src/models/primitives/video.js +1 -0
- package/dist/src/pages/index.d.ts +2 -0
- package/dist/src/pages/index.d.ts.map +1 -0
- package/dist/src/pages/index.js +1 -0
- package/dist/src/pages/page-document.d.ts +62 -0
- package/dist/src/pages/page-document.d.ts.map +1 -0
- package/dist/src/pages/page-document.js +8 -0
- package/dist/src/schema/index.d.ts +68 -0
- package/dist/src/schema/index.d.ts.map +1 -0
- package/dist/src/schema/index.js +2 -0
- package/dist/src/utils/helpers.d.ts +87 -0
- package/dist/src/utils/helpers.d.ts.map +1 -0
- package/dist/src/utils/helpers.js +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/string.d.ts +66 -0
- package/dist/src/utils/string.d.ts.map +1 -0
- package/dist/src/utils/string.js +7 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @tramo-digital/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the Open Design System component-driven design system. This library provides type-safe component models, validation utilities, and Standard Schema integration for building scalable, data-driven UI components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tramo-digital/types
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @tramo-digital/types
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @tramo-digital/types
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
This library provides a modern, data-driven approach to component typing with:
|
|
18
|
+
|
|
19
|
+
- **Component Models** - Data-centric component definitions with type safety
|
|
20
|
+
- **Standard Schema Integration** - Runtime validation with library-agnostic schema support
|
|
21
|
+
- **Loader System** - Async data loading with validation for server-side rendering
|
|
22
|
+
- **Utility Types** - String manipulation and type transformation helpers
|
|
23
|
+
- **Framework Agnostic** - Works with React, Vue, and vanilla JavaScript
|
|
24
|
+
|
|
25
|
+
## Core Concepts
|
|
26
|
+
|
|
27
|
+
### Component Models
|
|
28
|
+
|
|
29
|
+
Components are defined as data models with optional loaders, events, and validation:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { HeroModel, BaseComponentModel } from '@tramo-digital/types';
|
|
33
|
+
|
|
34
|
+
// Pre-built component models
|
|
35
|
+
const hero: HeroModel = {
|
|
36
|
+
_type: 'hero',
|
|
37
|
+
data: {
|
|
38
|
+
title: 'Welcome to our platform',
|
|
39
|
+
subtitle: 'Build amazing experiences',
|
|
40
|
+
ctaText: 'Get Started',
|
|
41
|
+
ctaLink: '/signup'
|
|
42
|
+
},
|
|
43
|
+
events: {
|
|
44
|
+
onCtaClick: (event) => console.log('CTA clicked', event)
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Create custom component models
|
|
49
|
+
interface CustomModel extends BaseComponentModel<'custom', MyData, MyEvents> {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Standard Schema Integration
|
|
53
|
+
|
|
54
|
+
Leverage any Standard Schema compatible library (Zod, Valibot, ArkType) for validation:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { z } from 'zod';
|
|
58
|
+
import { BaseComponentModelWithSchema, safeValidateWithSchema } from '@tramo-digital/types';
|
|
59
|
+
|
|
60
|
+
const UserSchema = z.object({
|
|
61
|
+
name: z.string(),
|
|
62
|
+
email: z.string().email(),
|
|
63
|
+
role: z.enum(['admin', 'user'])
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
interface UserComponent extends BaseComponentModelWithSchema<
|
|
67
|
+
'user',
|
|
68
|
+
typeof UserSchema,
|
|
69
|
+
UserEvents
|
|
70
|
+
> {}
|
|
71
|
+
|
|
72
|
+
const userComponent: UserComponent = {
|
|
73
|
+
_type: 'user',
|
|
74
|
+
_schema: UserSchema,
|
|
75
|
+
loader: async (context) => {
|
|
76
|
+
const userData = await fetchUser(context?.user?.id);
|
|
77
|
+
return await safeValidateWithSchema(UserSchema, userData);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Async Data Loading
|
|
83
|
+
|
|
84
|
+
Components can load and validate data asynchronously:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { ComponentLoader, LoaderContext } from '@tramo-digital/types';
|
|
88
|
+
|
|
89
|
+
const createHeroLoader: ComponentLoader<HeroData> = async (context) => {
|
|
90
|
+
try {
|
|
91
|
+
const data = await fetchHeroFromCMS(context?.request?.params?.id);
|
|
92
|
+
return { value: data }; // Success result
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return { issues: [{ message: 'Failed to load hero data' }] }; // Error result
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 📦 Available Components
|
|
100
|
+
|
|
101
|
+
### Primitive Components
|
|
102
|
+
- `ButtonModel` - Interactive button components
|
|
103
|
+
- `IconModel` - Icon display components
|
|
104
|
+
- `ImageModel` - Image components with responsive features
|
|
105
|
+
- `ContentModel` - Text content components
|
|
106
|
+
- `AccordionItemModel` - Individual accordion panels
|
|
107
|
+
- `CarouselItemModel` - Carousel slide components
|
|
108
|
+
|
|
109
|
+
### Pattern Components
|
|
110
|
+
- `HeroModel` - Hero sections with CTA
|
|
111
|
+
- `CardModel` - Content cards
|
|
112
|
+
- `AccordionModel` - Expandable content sections
|
|
113
|
+
- `CarouselModel` - Image/content sliders
|
|
114
|
+
- `BannerModel` - Promotional banners
|
|
115
|
+
- `MarqueeModel` - Scrolling text displays
|
|
116
|
+
- `CountdownTimerModel` - Timer components
|
|
117
|
+
|
|
118
|
+
### Layout Components
|
|
119
|
+
- `GridContainerModel` - CSS Grid containers
|
|
120
|
+
- `GridItemModel` - Grid item positioning
|
|
121
|
+
- `OneColModel` - Single column layouts
|
|
122
|
+
- `TwoColModel` - Two column layouts
|
|
123
|
+
|
|
124
|
+
### Composition Components
|
|
125
|
+
- `HeroAccordionModel` - Hero sections with integrated accordions
|
|
126
|
+
|
|
127
|
+
## 🛠 Utility Types
|
|
128
|
+
|
|
129
|
+
Transform and manipulate types with built-in utilities:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { ToSnakeCase, ToPascalCase, ComponentType } from '@tramo-digital/types';
|
|
133
|
+
|
|
134
|
+
type Example1 = ToSnakeCase<'MyComponent'>; // 'my_component'
|
|
135
|
+
type Example2 = ToPascalCase<'my_component'>; // 'MyComponent'
|
|
136
|
+
type Example3 = ComponentType<'UserCard'>; // 'user_card'
|
|
137
|
+
|
|
138
|
+
// Filter components by type
|
|
139
|
+
type HeroComponents = FilterByType<AllComponents, 'hero'>;
|
|
140
|
+
|
|
141
|
+
// Make specific properties optional/required
|
|
142
|
+
type PartialHero = PartialBy<HeroModel, 'events' | 'loader'>;
|
|
143
|
+
type RequiredHero = RequiredBy<HeroModel, 'data'>;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 🔒 Runtime Validation
|
|
147
|
+
|
|
148
|
+
Validate data at runtime with Standard Schema compatible validators:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import {
|
|
152
|
+
validateWithSchema,
|
|
153
|
+
safeValidateWithSchema,
|
|
154
|
+
isStandardSchema,
|
|
155
|
+
ValidationError
|
|
156
|
+
} from '@tramo-digital/types';
|
|
157
|
+
|
|
158
|
+
// Throws on validation failure
|
|
159
|
+
const validData = await validateWithSchema(schema, data);
|
|
160
|
+
|
|
161
|
+
// Returns result object (safe, no throwing)
|
|
162
|
+
const result = await safeValidateWithSchema(schema, data);
|
|
163
|
+
if ('issues' in result) {
|
|
164
|
+
console.error('Validation failed:', result.issues);
|
|
165
|
+
} else {
|
|
166
|
+
console.log('Valid data:', result.value);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check if object is a valid schema
|
|
170
|
+
if (isStandardSchema(someSchema)) {
|
|
171
|
+
// Safe to use with validation functions
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 🔧 Framework Integration
|
|
176
|
+
|
|
177
|
+
Works seamlessly with popular frameworks:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// React
|
|
181
|
+
import { HeroModel } from '@tramo-digital/types';
|
|
182
|
+
const HeroComponent: React.FC<{ model: HeroModel }> = ({ model }) => {
|
|
183
|
+
// Use model.data, model.events, etc.
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Vue
|
|
187
|
+
import { HeroModel } from '@tramo-digital/types';
|
|
188
|
+
defineComponent({
|
|
189
|
+
props: {
|
|
190
|
+
model: { type: Object as PropType<HeroModel>, required: true }
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## 🎯 Best Practices
|
|
197
|
+
|
|
198
|
+
1. **Use Type-Safe Models**: Always use the provided component models for consistency
|
|
199
|
+
2. **Validate External Data**: Use schema validation for data from APIs or user input
|
|
200
|
+
3. **Leverage Loaders**: Use component loaders for async data fetching with error handling
|
|
201
|
+
4. **Compose Components**: Build complex UIs by composing simpler component models
|
|
202
|
+
5. **Framework Agnostic**: Keep business logic in models, UI logic in framework components
|
|
203
|
+
|
|
204
|
+
## 📚 Advanced Usage
|
|
205
|
+
|
|
206
|
+
For detailed examples and advanced patterns, see:
|
|
207
|
+
- [Standard Schema Integration Guide](./STANDARD_SCHEMA_INTEGRATION.md)
|
|
208
|
+
- Component-specific documentation in `/src/models/`
|
|
209
|
+
|
|
210
|
+
## 🤝 Contributing
|
|
211
|
+
|
|
212
|
+
This library uses:
|
|
213
|
+
- **TypeScript 5.8+** for modern type features
|
|
214
|
+
- **Standard Schema v1** for validation interfaces
|
|
215
|
+
- **ESM modules** for modern bundle compatibility
|
|
216
|
+
- **Strict type checking** for maximum safety
|
|
217
|
+
|
|
218
|
+
## 📄 License
|
|
219
|
+
|
|
220
|
+
Part of the Open Design System design system. See main repository for license details.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @tramo-digital/types
|
|
2
|
+
|
|
3
|
+
## 0.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add loader property to base model
|
|
8
|
+
|
|
9
|
+
## 0.0.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Auto-generated changeset by GitHub Action
|
|
14
|
+
|
|
15
|
+
## 0.0.6
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- b0789d8: Add tokens override example in Text Block
|
|
20
|
+
|
|
21
|
+
## 0.0.5
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Add base design tokens types
|
|
26
|
+
|
|
27
|
+
## 0.0.4
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 2a3f941: Removed React reference from library
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @tramo-digital/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the Open Design System component-driven design system. This library provides type-safe component models, validation utilities, and Standard Schema integration for building scalable, data-driven UI components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tramo-digital/types
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @tramo-digital/types
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @tramo-digital/types
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
This library provides a modern, data-driven approach to component typing with:
|
|
18
|
+
|
|
19
|
+
- **Component Models** - Data-centric component definitions with type safety
|
|
20
|
+
- **Standard Schema Integration** - Runtime validation with library-agnostic schema support
|
|
21
|
+
- **Loader System** - Async data loading with validation for server-side rendering
|
|
22
|
+
- **Utility Types** - String manipulation and type transformation helpers
|
|
23
|
+
- **Framework Agnostic** - Works with React, Vue, and vanilla JavaScript
|
|
24
|
+
|
|
25
|
+
## Core Concepts
|
|
26
|
+
|
|
27
|
+
### Component Models
|
|
28
|
+
|
|
29
|
+
Components are defined as data models with optional loaders, events, and validation:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { HeroModel, BaseComponentModel } from '@tramo-digital/types';
|
|
33
|
+
|
|
34
|
+
// Pre-built component models
|
|
35
|
+
const hero: HeroModel = {
|
|
36
|
+
_type: 'hero',
|
|
37
|
+
data: {
|
|
38
|
+
title: 'Welcome to our platform',
|
|
39
|
+
subtitle: 'Build amazing experiences',
|
|
40
|
+
ctaText: 'Get Started',
|
|
41
|
+
ctaLink: '/signup'
|
|
42
|
+
},
|
|
43
|
+
events: {
|
|
44
|
+
onCtaClick: (event) => console.log('CTA clicked', event)
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Create custom component models
|
|
49
|
+
interface CustomModel extends BaseComponentModel<'custom', MyData, MyEvents> {}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Standard Schema Integration
|
|
53
|
+
|
|
54
|
+
Leverage any Standard Schema compatible library (Zod, Valibot, ArkType) for validation:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { z } from 'zod';
|
|
58
|
+
import { BaseComponentModelWithSchema, safeValidateWithSchema } from '@tramo-digital/types';
|
|
59
|
+
|
|
60
|
+
const UserSchema = z.object({
|
|
61
|
+
name: z.string(),
|
|
62
|
+
email: z.string().email(),
|
|
63
|
+
role: z.enum(['admin', 'user'])
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
interface UserComponent extends BaseComponentModelWithSchema<
|
|
67
|
+
'user',
|
|
68
|
+
typeof UserSchema,
|
|
69
|
+
UserEvents
|
|
70
|
+
> {}
|
|
71
|
+
|
|
72
|
+
const userComponent: UserComponent = {
|
|
73
|
+
_type: 'user',
|
|
74
|
+
_schema: UserSchema,
|
|
75
|
+
loader: async (context) => {
|
|
76
|
+
const userData = await fetchUser(context?.user?.id);
|
|
77
|
+
return await safeValidateWithSchema(UserSchema, userData);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Async Data Loading
|
|
83
|
+
|
|
84
|
+
Components can load and validate data asynchronously:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { ComponentLoader, LoaderContext } from '@tramo-digital/types';
|
|
88
|
+
|
|
89
|
+
const createHeroLoader: ComponentLoader<HeroData> = async (context) => {
|
|
90
|
+
try {
|
|
91
|
+
const data = await fetchHeroFromCMS(context?.request?.params?.id);
|
|
92
|
+
return { value: data }; // Success result
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return { issues: [{ message: 'Failed to load hero data' }] }; // Error result
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 📦 Available Components
|
|
100
|
+
|
|
101
|
+
### Primitive Components
|
|
102
|
+
- `ButtonModel` - Interactive button components
|
|
103
|
+
- `IconModel` - Icon display components
|
|
104
|
+
- `ImageModel` - Image components with responsive features
|
|
105
|
+
- `ContentModel` - Text content components
|
|
106
|
+
- `AccordionItemModel` - Individual accordion panels
|
|
107
|
+
- `CarouselItemModel` - Carousel slide components
|
|
108
|
+
|
|
109
|
+
### Pattern Components
|
|
110
|
+
- `HeroModel` - Hero sections with CTA
|
|
111
|
+
- `CardModel` - Content cards
|
|
112
|
+
- `AccordionModel` - Expandable content sections
|
|
113
|
+
- `CarouselModel` - Image/content sliders
|
|
114
|
+
- `BannerModel` - Promotional banners
|
|
115
|
+
- `MarqueeModel` - Scrolling text displays
|
|
116
|
+
- `CountdownTimerModel` - Timer components
|
|
117
|
+
|
|
118
|
+
### Layout Components
|
|
119
|
+
- `GridContainerModel` - CSS Grid containers
|
|
120
|
+
- `GridItemModel` - Grid item positioning
|
|
121
|
+
- `OneColModel` - Single column layouts
|
|
122
|
+
- `TwoColModel` - Two column layouts
|
|
123
|
+
|
|
124
|
+
### Composition Components
|
|
125
|
+
- `HeroAccordionModel` - Hero sections with integrated accordions
|
|
126
|
+
|
|
127
|
+
## 🛠 Utility Types
|
|
128
|
+
|
|
129
|
+
Transform and manipulate types with built-in utilities:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { ToSnakeCase, ToPascalCase, ComponentType } from '@tramo-digital/types';
|
|
133
|
+
|
|
134
|
+
type Example1 = ToSnakeCase<'MyComponent'>; // 'my_component'
|
|
135
|
+
type Example2 = ToPascalCase<'my_component'>; // 'MyComponent'
|
|
136
|
+
type Example3 = ComponentType<'UserCard'>; // 'user_card'
|
|
137
|
+
|
|
138
|
+
// Filter components by type
|
|
139
|
+
type HeroComponents = FilterByType<AllComponents, 'hero'>;
|
|
140
|
+
|
|
141
|
+
// Make specific properties optional/required
|
|
142
|
+
type PartialHero = PartialBy<HeroModel, 'events' | 'loader'>;
|
|
143
|
+
type RequiredHero = RequiredBy<HeroModel, 'data'>;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 🔒 Runtime Validation
|
|
147
|
+
|
|
148
|
+
Validate data at runtime with Standard Schema compatible validators:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import {
|
|
152
|
+
validateWithSchema,
|
|
153
|
+
safeValidateWithSchema,
|
|
154
|
+
isStandardSchema,
|
|
155
|
+
ValidationError
|
|
156
|
+
} from '@tramo-digital/types';
|
|
157
|
+
|
|
158
|
+
// Throws on validation failure
|
|
159
|
+
const validData = await validateWithSchema(schema, data);
|
|
160
|
+
|
|
161
|
+
// Returns result object (safe, no throwing)
|
|
162
|
+
const result = await safeValidateWithSchema(schema, data);
|
|
163
|
+
if ('issues' in result) {
|
|
164
|
+
console.error('Validation failed:', result.issues);
|
|
165
|
+
} else {
|
|
166
|
+
console.log('Valid data:', result.value);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check if object is a valid schema
|
|
170
|
+
if (isStandardSchema(someSchema)) {
|
|
171
|
+
// Safe to use with validation functions
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 🔧 Framework Integration
|
|
176
|
+
|
|
177
|
+
Works seamlessly with popular frameworks:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// React
|
|
181
|
+
import { HeroModel } from '@tramo-digital/types';
|
|
182
|
+
const HeroComponent: React.FC<{ model: HeroModel }> = ({ model }) => {
|
|
183
|
+
// Use model.data, model.events, etc.
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Vue
|
|
187
|
+
import { HeroModel } from '@tramo-digital/types';
|
|
188
|
+
defineComponent({
|
|
189
|
+
props: {
|
|
190
|
+
model: { type: Object as PropType<HeroModel>, required: true }
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## 🎯 Best Practices
|
|
197
|
+
|
|
198
|
+
1. **Use Type-Safe Models**: Always use the provided component models for consistency
|
|
199
|
+
2. **Validate External Data**: Use schema validation for data from APIs or user input
|
|
200
|
+
3. **Leverage Loaders**: Use component loaders for async data fetching with error handling
|
|
201
|
+
4. **Compose Components**: Build complex UIs by composing simpler component models
|
|
202
|
+
5. **Framework Agnostic**: Keep business logic in models, UI logic in framework components
|
|
203
|
+
|
|
204
|
+
## 📚 Advanced Usage
|
|
205
|
+
|
|
206
|
+
For detailed examples and advanced patterns, see:
|
|
207
|
+
- [Standard Schema Integration Guide](./STANDARD_SCHEMA_INTEGRATION.md)
|
|
208
|
+
- Component-specific documentation in `/src/models/`
|
|
209
|
+
|
|
210
|
+
## 🤝 Contributing
|
|
211
|
+
|
|
212
|
+
This library uses:
|
|
213
|
+
- **TypeScript 5.8+** for modern type features
|
|
214
|
+
- **Standard Schema v1** for validation interfaces
|
|
215
|
+
- **ESM modules** for modern bundle compatibility
|
|
216
|
+
- **Strict type checking** for maximum safety
|
|
217
|
+
|
|
218
|
+
## 📄 License
|
|
219
|
+
|
|
220
|
+
Part of the Open Design System design system. See main repository for license details.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tramo-digital/types",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "tramo.digital - types",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"author": "carlosp0veda",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"import": "./dist/src/index.d.ts",
|
|
14
|
+
"require": "./dist/src/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"tslib": "^2.3.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.8.3"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -b .",
|
|
25
|
+
"publish": "pnpm publish",
|
|
26
|
+
"publish-local": "npm publish --registry http://localhost:4873 --access public"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"!**/*.tsbuildinfo"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0",
|
|
34
|
+
"pnpm": ">=9.0.0"
|
|
35
|
+
},
|
|
36
|
+
"volta": {
|
|
37
|
+
"node": "22.16.0",
|
|
38
|
+
"pnpm": "10.4.0"
|
|
39
|
+
},
|
|
40
|
+
"module": "./src/index.js",
|
|
41
|
+
"main": "./src/index.js"
|
|
42
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '../schema/index.js';
|
|
2
|
+
import type { ComponentLoaderWithSchema, SimpleLoader } from './data-loader.js';
|
|
3
|
+
import type { BaseDesignTokens, ColorPalette, ColorSource, CustomColor } from './design-tokens.js';
|
|
4
|
+
/**
|
|
5
|
+
* Base Component Model Interface
|
|
6
|
+
*
|
|
7
|
+
* Core interface that all component models must extend.
|
|
8
|
+
* Provides the foundational structure for component data models.
|
|
9
|
+
*/
|
|
10
|
+
export type BaseComponentModel<ComponentType = string, TData = Record<string, unknown>, TEvents = Record<string, unknown>, TTokens extends BaseDesignTokens = BaseDesignTokens> = {
|
|
11
|
+
/** Optional unique identifier for the component */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Generic data object that holds all dynamic content data for the component */
|
|
14
|
+
data?: TData;
|
|
15
|
+
/** Optional event handlers */
|
|
16
|
+
events?: TEvents;
|
|
17
|
+
/** Design token overrides */
|
|
18
|
+
tokens?: TTokens;
|
|
19
|
+
/** Optional classname for additional styling */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** Optional color palette for the component */
|
|
22
|
+
colorPalette?: ColorPalette;
|
|
23
|
+
/** Optional custom color for the component */
|
|
24
|
+
customColor?: CustomColor;
|
|
25
|
+
/** Optional color source for the component */
|
|
26
|
+
colorSource?: ColorSource;
|
|
27
|
+
/** Optional loader that can be used to load the data for the component */
|
|
28
|
+
loader?: SimpleLoader<TData>;
|
|
29
|
+
/**
|
|
30
|
+
* Unique component type identifier in snake_case
|
|
31
|
+
* Should match the component name converted to snake_case
|
|
32
|
+
* Examples: 'button', 'hero', 'grid_container', 'accordion_item'
|
|
33
|
+
*/
|
|
34
|
+
_type?: ComponentType;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Enhanced Base Component Model with Schema Validation
|
|
38
|
+
*
|
|
39
|
+
* Supports Standard Schema compatible validators from external libraries
|
|
40
|
+
* like Zod, Valibot, ArkType, etc.
|
|
41
|
+
*/
|
|
42
|
+
export interface BaseComponentModelWithSchema<ComponentType = string, Schema extends StandardSchemaV1 = StandardSchemaV1, TEvents = Record<string, unknown>, TTokens extends BaseDesignTokens = BaseDesignTokens> {
|
|
43
|
+
id?: string;
|
|
44
|
+
/** Optional event handlers */
|
|
45
|
+
events?: TEvents;
|
|
46
|
+
/** Design token overrides */
|
|
47
|
+
tokens?: TTokens;
|
|
48
|
+
/** Generic data object that holds all dynamic content data for the component */
|
|
49
|
+
data?: StandardSchemaV1.InferOutput<Schema>;
|
|
50
|
+
/** Optional color source for the component */
|
|
51
|
+
colorSource?: ColorSource;
|
|
52
|
+
/** Optional custom color for the component */
|
|
53
|
+
customColor?: CustomColor;
|
|
54
|
+
/** Optional color palette for the component */
|
|
55
|
+
colorPalette?: ColorPalette;
|
|
56
|
+
/**
|
|
57
|
+
* Standard Schema compatible validator for component data
|
|
58
|
+
* Can be from Zod, Valibot, ArkType, or any other compatible library
|
|
59
|
+
*/
|
|
60
|
+
_schema?: Schema;
|
|
61
|
+
/**
|
|
62
|
+
* Enhanced loader that works with the schema validator
|
|
63
|
+
* Returns validated component data using Standard Schema result pattern
|
|
64
|
+
*/
|
|
65
|
+
loader?: ComponentLoaderWithSchema<Schema>;
|
|
66
|
+
/**
|
|
67
|
+
* Unique component type identifier in snake_case
|
|
68
|
+
* Should match the component name converted to snake_case
|
|
69
|
+
* Examples: 'button', 'hero', 'grid_container', 'accordion_item'
|
|
70
|
+
*/
|
|
71
|
+
_type: ComponentType;
|
|
72
|
+
}
|
|
73
|
+
/** Backward compatibility alias */
|
|
74
|
+
export type ComponentModel<ComponentType = string, Data = Record<string, unknown>, Events = Record<string, unknown>, TTokens extends BaseDesignTokens = BaseDesignTokens> = BaseComponentModel<ComponentType, Data, Events, TTokens>;
|
|
75
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/base/component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,CAC5B,aAAa,GAAG,MAAM,EACtB,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,IACjD;IACF,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,8BAA8B;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B,CAC3C,aAAa,GAAG,MAAM,EACtB,MAAM,SAAS,gBAAgB,GAAG,gBAAgB,EAClD,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB;IAEnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,IAAI,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5C,8CAA8C;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,+CAA+C;IAC/C,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC3C;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,mCAAmC;AACnC,MAAM,MAAM,cAAc,CACxB,aAAa,GAAG,MAAM,EACtB,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,IACjD,kBAAkB,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|