@templatical/types
v0.64.1
Published
Shared TypeScript types, block factory functions, and event emitter for Templatical email editor
Maintainers
Readme
@templatical/types
Shared TypeScript types, block factory functions, and type guards for the Templatical email editor.
Package with no required runtime dependencies containing all shared types for the Templatical email editor ecosystem. Block schemas, template config, factory helpers, and type guards. The custom-block Liquid factory takes an optional liquidjs peer.
Use this directly if you need to programmatically create or transform Templatical templates — for example, in a backend service, codegen pipeline, or migration script.
Install
npm install @templatical/typesUsage
import {
createTitleBlock,
createParagraphBlock,
createButtonBlock,
isImage,
isSection,
} from '@templatical/types';
import type { TemplateContent, Block } from '@templatical/types';
// Build a template programmatically
const content: TemplateContent = {
blocks: [
createTitleBlock({ text: 'Welcome to Templatical', level: 1 }),
createParagraphBlock({ text: 'Build email templates visually.' }),
createButtonBlock({ text: 'Get started', href: 'https://templatical.com' }),
],
settings: { width: 600, backgroundColor: '#ffffff' },
};
// Type-narrow blocks safely
function describeBlock(block: Block): string {
if (isImage(block)) return `Image: ${block.src}`;
if (isSection(block)) return `Section with ${block.columns.length} columns`;
return block.type;
}What's exported
- Block types —
Block,TitleBlock,ParagraphBlock,ImageBlock,ButtonBlock,SectionBlock,DividerBlock,SpacerBlock,SocialIconsBlock,MenuBlock,TableBlock,HtmlBlock,VideoBlock,CountdownBlock,CustomBlock - Factory functions —
createTitleBlock(),createParagraphBlock(), etc. for every block type - Custom-block Liquid engine —
createCustomBlockLiquid(liquidjs)for the same escaped template output in the editor, CLI and a headless resolver. Install the optionalliquidjspeer to use it; see the Custom blocks guide. - Type guards —
isTitle(),isParagraph(),isImage(),isSection(), etc. - Template types —
Template,TemplateContent,TemplateSettings - Theme types —
ThemeOverrides,UiTheme,BlockDefaults,FontsConfig - Config types —
MergeTagsConfig,DisplayConditionsConfig,CustomBlockDefinition - Event emitter —
EventEmitter(used internally by core) - Merge tag presets — common merge tag definitions (Mailchimp, etc.)
Documentation
Full reference at docs.templatical.com.
License
MIT
