The text editor (Tiptap) only produces simple HTML: headings, bold, italic, strikethrough, links, lists, pull quotes, lines. Layouts that were hand-written HTML in text blocks get their own blocks (Cards with pictures or numbered steps, FAQ), one-offs and embeds go in an HTML block, and every block can have an anchor for #links. Text blocks get alignment and a small (footnote) size. Existing text blocks the editor can't represent become HTML blocks that render exactly as before (migration, and backup import for old files); text that is only centred becomes centred text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
107 lines
3.9 KiB
TypeScript
107 lines
3.9 KiB
TypeScript
import { v4 as uuid } from 'uuid';
|
|
import type { BlockType, ContentBlock } from '$lib/types';
|
|
|
|
export const blockLabels: Record<BlockType, string> = {
|
|
text: 'Text',
|
|
image_text: 'Image + Text',
|
|
timeline: 'Timeline',
|
|
hero: 'Hero',
|
|
button: 'Button',
|
|
spacer: 'Spacer',
|
|
testimonials: 'Testimonials',
|
|
upcoming_calendar: 'Upcoming Calendar',
|
|
shop: 'Shop',
|
|
checkout: 'Checkout',
|
|
cards: 'Cards',
|
|
faq: 'FAQ',
|
|
html: 'HTML'
|
|
};
|
|
|
|
export const blockTypes = Object.keys(blockLabels) as BlockType[];
|
|
|
|
export function createBlock(type: BlockType): ContentBlock {
|
|
const base = { id: uuid(), type, data: {} as Record<string, any> };
|
|
switch (type) {
|
|
case 'text':
|
|
base.data = { content: '<h2>New text block</h2><p>Add your copy here.</p>' };
|
|
break;
|
|
case 'image_text':
|
|
base.data = { url: '', alt: '', content: '<h2>Image and text</h2><p>Add content here.</p>', imagePosition: 'left' };
|
|
break;
|
|
case 'timeline':
|
|
base.data = { items: [{ title: 'Milestone', description: 'Describe this moment.' }] };
|
|
break;
|
|
case 'hero':
|
|
base.data = {
|
|
heading: 'Holistic and Experiential Learning about Happiness',
|
|
subheading: 'Individual sessions, workshops and events in Oslo',
|
|
buttonLabel: 'BOOK NOW',
|
|
buttonUrl: ''
|
|
};
|
|
break;
|
|
case 'button':
|
|
base.data = {
|
|
label: 'Learn More',
|
|
href: '/',
|
|
variant: 'primary',
|
|
size: 'md',
|
|
alignment: 'center'
|
|
};
|
|
break;
|
|
case 'spacer':
|
|
base.data = { height: 64 };
|
|
break;
|
|
case 'testimonials':
|
|
base.data = {
|
|
title: 'What They Say About Me',
|
|
items: [
|
|
{ text: 'Recently I started to experience incredible whole-body orgasms. And now I know how it works. My awareness around sexuality changed for good and I feel like a boss of my own life. What a joy to have this freedom of choice.', title: 'Anne' },
|
|
{ text: 'I never thought it was possible to sense so much pleasure in my body without intense stimulations I got used to. After the series of sessions, I could feel something like a trance state by receiving only a gentle touch. That was a totally new experience for me.', title: 'Espen' },
|
|
{ text: "Eva's sexual healing methods should be accessible to everyone. I am amazed by the depth and integrity of the message she conveys through her work. I was meeting Eva for healing my body and, as a result, I reconnected with my heart and soul too.", title: 'Marie' },
|
|
{ text: "It is hard to surprise me with any sexual activity since I had many exciting experiments in my life. But I always suspected that there might be something more I have not yet felt and tried. Thanks to Eva I realised how much power I've got. Under her guidance, I have learnt to maximise my orgasmic potential and consciously play with arousal. By the way, my wife is also happy that I became enthusiastic about new sexual practices.", title: 'Jan' }
|
|
]
|
|
};
|
|
break;
|
|
case 'upcoming_calendar':
|
|
base.data = {
|
|
title: 'Upcoming Events',
|
|
categories: []
|
|
};
|
|
break;
|
|
case 'shop':
|
|
base.data = {
|
|
title: 'Our Services',
|
|
itemTypeFilter: 'all',
|
|
itemIds: [],
|
|
layout: 'grid'
|
|
};
|
|
break;
|
|
case 'checkout':
|
|
base.data = {
|
|
title: 'Checkout',
|
|
heading: 'Complete your booking',
|
|
notesLabel: 'Notes or special requests'
|
|
};
|
|
break;
|
|
case 'cards':
|
|
base.data = {
|
|
heading: 'Section heading',
|
|
intro: '',
|
|
align: 'center',
|
|
style: 'image',
|
|
items: [1, 2, 3].map((n) => ({ imageUrl: '', imageAlt: '', title: `Card ${n}`, subtitle: '', text: '<p>A sentence or two.</p>', href: '', linkLabel: '' }))
|
|
};
|
|
break;
|
|
case 'faq':
|
|
base.data = {
|
|
heading: 'Questions people ask',
|
|
items: [{ question: 'What happens in the first session?', answer: '<p>Answer it here.</p>' }]
|
|
};
|
|
break;
|
|
case 'html':
|
|
base.data = { html: '' };
|
|
break;
|
|
}
|
|
base.data._background = { type: 'none', color: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
|
return base;
|
|
}
|