v0.9.0
This commit is contained in:
commit
860182098c
277 files changed
+18338
No files matched your search
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { classes, safeUrl } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-before-after', classes(style)]">
|
||||
<div class="mb-inner mb-split">
|
||||
<figure>
|
||||
<img :src="safeUrl(data.before)" alt="Before" loading="lazy" />
|
||||
<figcaption>Before</figcaption>
|
||||
</figure>
|
||||
<figure>
|
||||
<img :src="safeUrl(data.after)" alt="After" loading="lazy" />
|
||||
<figcaption>After</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, type Component } from 'vue';
|
||||
import { blockComponents } from './components';
|
||||
import type { Block } from './support';
|
||||
|
||||
// Draws the blocks of a page (`Blocks::for()` as a prop): one component per type. `components` replaces or adds a type of the site;
|
||||
// a type without a component draws nothing.
|
||||
const props = defineProps<{ blocks: Block[]; components?: Record<string, Component> }>();
|
||||
const map = computed(() => ({ ...blockComponents, ...(props.components ?? {}) }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="block in blocks" :key="block.id">
|
||||
<component :is="map[block.type]" v-if="map[block.type]" :data="block.data" :style="block.style" :items="block.items" />
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { safeUrl } from './support';
|
||||
|
||||
defineProps<{ buttons?: { label?: string; url?: string; style?: string }[] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p v-if="buttons && buttons.length" class="mb-buttons">
|
||||
<template v-for="(button, index) in buttons" :key="index">
|
||||
<a v-if="button.label" :class="['mb-btn', button.style === 'secondary' ? 'mb-btn--secondary' : 'mb-btn--primary']" :href="safeUrl(button.url)">{{ button.label }}</a>
|
||||
</template>
|
||||
</p>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import Buttons from './Buttons.vue';
|
||||
import { classes, pick, safeUrl, type Item } from './support';
|
||||
|
||||
// A record is shown under the usual names: title or name, summary / story / quote / intro / role, photo / picture / image, url / link.
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string>; items?: Item[] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-cards', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<p v-if="data.eyebrow" class="mb-eyebrow">{{ data.eyebrow }}</p>
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<div class="mb-grid">
|
||||
<article v-for="(item, index) in items || []" :key="item.id ?? index" class="mb-card">
|
||||
<img v-if="pick(item, ['photo', 'picture', 'image'])" :src="safeUrl(pick(item, ['photo', 'picture', 'image']))" alt="" loading="lazy" />
|
||||
<h3>
|
||||
<a v-if="pick(item, ['url', 'link'])" :href="safeUrl(pick(item, ['url', 'link']))">{{ pick(item, ['title', 'name', 'label']) }}</a>
|
||||
<template v-else>{{ pick(item, ['title', 'name', 'label']) }}</template>
|
||||
</h3>
|
||||
<p v-if="pick(item, ['summary', 'story', 'quote', 'intro', 'role'])">{{ pick(item, ['summary', 'story', 'quote', 'intro', 'role']) }}</p>
|
||||
</article>
|
||||
</div>
|
||||
<Buttons v-if="data.button_label" :buttons="[{ label: data.button_label, url: data.button_url, style: 'secondary' }]" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-chips', classes(style)]">
|
||||
<ul class="mb-inner">
|
||||
<li v-for="(chip, index) in data.items || []" :key="index">{{ chip }}</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import Buttons from './Buttons.vue';
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-cta', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h2>{{ data.title }}</h2>
|
||||
<p v-if="data.text">{{ data.text }}</p>
|
||||
<Buttons :buttons="data.buttons" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<hr :class="['mb-block mb-divider', classes(style)]" />
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
// The `FAQPage` data for search engines comes from the server (`structured_data` of the page API, or `Blocks::structuredData()`):
|
||||
// print it in the head of the page; a Vue template cannot hold a script tag.
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-faq', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<details v-for="(item, index) in data.items || []" :key="index">
|
||||
<summary>{{ item.question }}</summary>
|
||||
<p>{{ item.answer }}</p>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
// The form of a request (callback, question, quote, contact) posts to the requests module of the package (`manager.leads.form`), with
|
||||
// its honeypot, its signed moment and Turnstile. That needs fields and a token the site knows how to build, so the shipped component only
|
||||
// shows the title and the text: a site replaces it with its own form (`components` of the renderer), see the README.
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-form', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<p v-if="data.text">{{ data.text }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { classes, safeUrl } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-gallery', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<div class="mb-grid">
|
||||
<img v-for="(photo, index) in data.photos || []" :key="index" :src="safeUrl(photo)" alt="" loading="lazy" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import Buttons from './Buttons.vue';
|
||||
import { classes, safeUrl } from './support';
|
||||
|
||||
const props = defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
const background = computed(() => (props.data.photo ? { '--mb-hero-image': `url('${safeUrl(props.data.photo)}')` } : {}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-hero', classes(style)]" :style="background">
|
||||
<div class="mb-inner">
|
||||
<p v-if="data.eyebrow" class="mb-eyebrow">{{ data.eyebrow }}</p>
|
||||
<h1>{{ data.title }}</h1>
|
||||
<p v-if="data.roles && data.roles.length" class="mb-roles">{{ data.roles.join(' · ') }}</p>
|
||||
<p v-if="data.intro" class="mb-lead">{{ data.intro }}</p>
|
||||
<Buttons :buttons="data.buttons" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { classes, safeUrl } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-image', classes(style)]">
|
||||
<figure class="mb-inner">
|
||||
<img :src="safeUrl(data.photo)" :alt="data.caption || ''" loading="lazy" />
|
||||
<figcaption v-if="data.caption">{{ data.caption }}</figcaption>
|
||||
</figure>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-page-title', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h1>{{ data.title }}</h1>
|
||||
<!-- `intro_html` is made on the server from Markdown with raw HTML escaped -->
|
||||
<div v-if="data.intro" class="mb-prose" v-html="data.intro_html" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-points-box', classes(style)]">
|
||||
<div class="mb-inner">
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<ul class="mb-points">
|
||||
<li v-for="(point, index) in data.points || []" :key="index">{{ point }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-quote', classes(style)]">
|
||||
<blockquote class="mb-inner">
|
||||
<p>{{ data.quote }}</p>
|
||||
<footer v-if="data.name">
|
||||
{{ data.name }} <span v-if="data.role">{{ data.role }}</span>
|
||||
</footer>
|
||||
</blockquote>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-rich-text', classes(style)]">
|
||||
<!-- `body_html` is made on the server from Markdown with raw HTML escaped -->
|
||||
<div class="mb-inner mb-prose" v-html="data.body_html" />
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="['mb-block mb-spacer', classes(style)]" aria-hidden="true" />
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { classes } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-stats', classes(style)]">
|
||||
<dl class="mb-inner mb-grid">
|
||||
<div v-for="(item, index) in data.items || []" :key="index">
|
||||
<dt>{{ item.label }}</dt>
|
||||
<dd>{{ item.value }}{{ item.suffix }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { classes, safeUrl } from './support';
|
||||
|
||||
defineProps<{ data: Record<string, any>; style?: Record<string, string> }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="['mb-block mb-text-media', classes(style)]">
|
||||
<div class="mb-inner mb-split">
|
||||
<div class="mb-text">
|
||||
<h2 v-if="data.title">{{ data.title }}</h2>
|
||||
<div class="mb-prose" v-html="data.body_html" />
|
||||
<ul v-if="data.points && data.points.length" class="mb-points">
|
||||
<li v-for="(point, index) in data.points" :key="index">{{ point }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<figure v-if="data.photo" class="mb-media">
|
||||
<img :src="safeUrl(data.photo)" :alt="data.caption || data.title || ''" loading="lazy" />
|
||||
<figcaption v-if="data.caption">{{ data.caption }}</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { Component } from 'vue';
|
||||
import BeforeAfter from './BeforeAfter.vue';
|
||||
import Cards from './Cards.vue';
|
||||
import Chips from './Chips.vue';
|
||||
import Cta from './Cta.vue';
|
||||
import Divider from './Divider.vue';
|
||||
import Faq from './Faq.vue';
|
||||
import Form from './Form.vue';
|
||||
import Gallery from './Gallery.vue';
|
||||
import Hero from './Hero.vue';
|
||||
import ImageBlock from './ImageBlock.vue';
|
||||
import PageTitle from './PageTitle.vue';
|
||||
import PointsBox from './PointsBox.vue';
|
||||
import Quote from './Quote.vue';
|
||||
import RichText from './RichText.vue';
|
||||
import Spacer from './Spacer.vue';
|
||||
import Stats from './Stats.vue';
|
||||
import TextMedia from './TextMedia.vue';
|
||||
|
||||
/** The components of the block types the package ships, by type. A site adds or replaces by giving `components` to the renderer. */
|
||||
export const blockComponents: Record<string, Component> = {
|
||||
hero: Hero,
|
||||
page_title: PageTitle,
|
||||
rich_text: RichText,
|
||||
text_media: TextMedia,
|
||||
image: ImageBlock,
|
||||
points_box: PointsBox,
|
||||
gallery: Gallery,
|
||||
before_after: BeforeAfter,
|
||||
quote: Quote,
|
||||
stats: Stats,
|
||||
chips: Chips,
|
||||
faq: Faq,
|
||||
cards: Cards,
|
||||
cta: Cta,
|
||||
form: Form,
|
||||
divider: Divider,
|
||||
spacer: Spacer,
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
export { blockComponents } from './components';
|
||||
export { default as BlockRenderer } from './BlockRenderer.vue';
|
||||
export { classes, pick, safeUrl } from './support';
|
||||
export type { Block } from './support';
|
||||
@@ -0,0 +1,28 @@
|
||||
export type BlockData = Record<string, any>;
|
||||
export type Item = Record<string, any>;
|
||||
export type Block = { id: string; type: string; data: BlockData; style: Record<string, string>; items?: Item[] };
|
||||
|
||||
/** An address that is safe in an `href` or `src`: http(s), a path, `mailto:`, `tel:` or an anchor; anything else becomes `#`. */
|
||||
export function safeUrl(url: unknown): string {
|
||||
const value = typeof url === 'string' ? url.trim() : '';
|
||||
|
||||
return /^(https?:\/\/|\/(?!\/)|#|mailto:|tel:)/i.test(value) && !/[\s"'()<>\\]/.test(value) ? value : '#';
|
||||
}
|
||||
|
||||
/** CSS classes for the style options of a block: `mb--background-dark mb--width-wide`. */
|
||||
export function classes(style: Record<string, string> | undefined): string {
|
||||
return Object.entries(style ?? {})
|
||||
.map(([name, value]) => `mb--${name.replace(/[^a-z0-9_-]/gi, '')}-${String(value).replace(/[^a-z0-9_-]/gi, '')}`)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
/** The first non-empty text of a record under one of the usual names (a card shows a title or name, a summary or quote, a photo, a url). */
|
||||
export function pick(item: Item, keys: string[]): string | undefined {
|
||||
for (const key of keys) {
|
||||
if (typeof item[key] === 'string' && item[key] !== '') {
|
||||
return item[key];
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
Reference in new issue
Block a user