@brimsites/brimjs 0.0.0-stage → 1.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/LICENSE +110 -0
- package/README.md +22 -2
- package/bin/brim.js +5 -0
- package/dist/cli.js +3802 -0
- package/editor-dist/editor.css +1 -0
- package/editor-dist/editor.js +91 -0
- package/package.json +71 -3
- package/skills/brim-convert/SKILL.md +256 -0
- package/skills/brim-hosting/SKILL.md +221 -0
- package/src/astro-shim.d.ts +5 -0
- package/src/auth/accounts.ts +341 -0
- package/src/auth/password.ts +34 -0
- package/src/auth/permissions.ts +44 -0
- package/src/blocks/accordion/Accordion.astro +48 -0
- package/src/blocks/accordion/accordion.css +63 -0
- package/src/blocks/analytics/Analytics.astro +45 -0
- package/src/blocks/analytics/ConsentBanner.astro +41 -0
- package/src/blocks/analytics/analytics.client.ts +125 -0
- package/src/blocks/analytics/analytics.css +51 -0
- package/src/blocks/analytics/consent.ts +51 -0
- package/src/blocks/button/Button.astro +64 -0
- package/src/blocks/button/button.css +100 -0
- package/src/blocks/carousel/Carousel.astro +140 -0
- package/src/blocks/carousel/carousel.client.ts +153 -0
- package/src/blocks/carousel/carousel.css +181 -0
- package/src/blocks/data/icons.ts +285 -0
- package/src/blocks/data/image-shapes.ts +91 -0
- package/src/blocks/data/social-icons.ts +41 -0
- package/src/blocks/data/social-networks.ts +256 -0
- package/src/blocks/divider/Divider.astro +27 -0
- package/src/blocks/divider/divider.css +17 -0
- package/src/blocks/form/Captcha.astro +27 -0
- package/src/blocks/form/Form.astro +250 -0
- package/src/blocks/form/FormField.astro +138 -0
- package/src/blocks/form/Newsletter.astro +80 -0
- package/src/blocks/form/form.client.ts +339 -0
- package/src/blocks/form/form.css +271 -0
- package/src/blocks/gallery/ImageGallery.astro +126 -0
- package/src/blocks/gallery/gallery.css +43 -0
- package/src/blocks/gallery/lightbox.client.ts +178 -0
- package/src/blocks/gallery/lightbox.css +134 -0
- package/src/blocks/icon/Icon.astro +41 -0
- package/src/blocks/icon/icon.css +16 -0
- package/src/blocks/image/Image.astro +158 -0
- package/src/blocks/image/image.css +42 -0
- package/src/blocks/images.ts +64 -0
- package/src/blocks/in-editor.client.ts +8 -0
- package/src/blocks/listing/Listing.astro +288 -0
- package/src/blocks/listing/ListingCards.astro +48 -0
- package/src/blocks/listing/listing.css +136 -0
- package/src/blocks/listing/query.ts +363 -0
- package/src/blocks/map/Map.astro +75 -0
- package/src/blocks/map/map.css +32 -0
- package/src/blocks/schemas/accordion.ts +118 -0
- package/src/blocks/schemas/button.ts +78 -0
- package/src/blocks/schemas/carousel.ts +133 -0
- package/src/blocks/schemas/divider.ts +29 -0
- package/src/blocks/schemas/form-field-types.ts +29 -0
- package/src/blocks/schemas/form.ts +350 -0
- package/src/blocks/schemas/icon.ts +24 -0
- package/src/blocks/schemas/image-gallery.ts +54 -0
- package/src/blocks/schemas/image.ts +87 -0
- package/src/blocks/schemas/index.ts +33 -0
- package/src/blocks/schemas/listing.ts +14 -0
- package/src/blocks/schemas/map.ts +81 -0
- package/src/blocks/schemas/newsletter.ts +324 -0
- package/src/blocks/schemas/social-media.ts +348 -0
- package/src/blocks/schemas/text.ts +151 -0
- package/src/blocks/schemas/video.ts +57 -0
- package/src/blocks/search/Search.astro +147 -0
- package/src/blocks/search/search.css +69 -0
- package/src/blocks/search/state.ts +28 -0
- package/src/blocks/settings.ts +94 -0
- package/src/blocks/social/SocialMedia.astro +102 -0
- package/src/blocks/social/social-links.ts +16 -0
- package/src/blocks/social/social.css +31 -0
- package/src/blocks/theme.ts +35 -0
- package/src/blocks/types.ts +52 -0
- package/src/blocks/video/Video.astro +90 -0
- package/src/blocks/video/video-source.ts +77 -0
- package/src/blocks/video/video.client.ts +43 -0
- package/src/blocks/video/video.css +29 -0
- package/src/check.ts +1119 -0
- package/src/cli.ts +493 -0
- package/src/components/Blocks.astro +68 -0
- package/src/components/Field.astro +61 -0
- package/src/components/Footer.astro +36 -0
- package/src/components/Link.astro +18 -0
- package/src/components/MobileMenu.astro +77 -0
- package/src/components/Navbar.astro +42 -0
- package/src/components/RichText.astro +32 -0
- package/src/components/Seo.astro +202 -0
- package/src/components/Setting.astro +46 -0
- package/src/components/Shared.astro +17 -0
- package/src/components/Text.astro +91 -0
- package/src/components/blocks.css +86 -0
- package/src/components/index.ts +27 -0
- package/src/components/mobile-menu.client.ts +21 -0
- package/src/components/mobile-menu.css +52 -0
- package/src/components/text.css +48 -0
- package/src/config.ts +413 -0
- package/src/content/block-layout.ts +63 -0
- package/src/content/block-values.ts +48 -0
- package/src/content/content-check.ts +174 -0
- package/src/content/content-types.ts +408 -0
- package/src/content/drafts.ts +115 -0
- package/src/content/feed.ts +237 -0
- package/src/content/field-types.ts +107 -0
- package/src/content/history.ts +140 -0
- package/src/content/ids.ts +50 -0
- package/src/content/image-size.ts +212 -0
- package/src/content/image-sizes.ts +126 -0
- package/src/content/item-fields.ts +110 -0
- package/src/content/item-head.ts +126 -0
- package/src/content/item-image.ts +26 -0
- package/src/content/item-path.ts +122 -0
- package/src/content/items.ts +580 -0
- package/src/content/language-scopes.ts +40 -0
- package/src/content/media.ts +271 -0
- package/src/content/menus.ts +51 -0
- package/src/content/page-templates.ts +52 -0
- package/src/content/redirects.ts +112 -0
- package/src/content/references.ts +165 -0
- package/src/content/rich-text.ts +63 -0
- package/src/content/search.ts +167 -0
- package/src/content/seed.ts +229 -0
- package/src/content/site-settings.ts +111 -0
- package/src/content/sitemap.ts +143 -0
- package/src/content/store.ts +225 -0
- package/src/content/tags.ts +67 -0
- package/src/content/text-default.ts +139 -0
- package/src/content/types.ts +137 -0
- package/src/content/validate.ts +253 -0
- package/src/content/validation-error.ts +2 -0
- package/src/db/cached.ts +140 -0
- package/src/db/database.ts +15 -0
- package/src/db/libsql.ts +29 -0
- package/src/db/schema.ts +189 -0
- package/src/db/url.ts +44 -0
- package/src/editor/client/BlockSettings.tsx +1063 -0
- package/src/editor/client/Chrome.tsx +284 -0
- package/src/editor/client/ContentBrowser.tsx +1299 -0
- package/src/editor/client/Editor.tsx +1756 -0
- package/src/editor/client/HistoryPanel.tsx +114 -0
- package/src/editor/client/ImagesWidget.tsx +113 -0
- package/src/editor/client/Inspector.tsx +127 -0
- package/src/editor/client/ItemForm.tsx +535 -0
- package/src/editor/client/LinkWidget.tsx +440 -0
- package/src/editor/client/ListingPanel.tsx +99 -0
- package/src/editor/client/Login.tsx +338 -0
- package/src/editor/client/Menu.tsx +64 -0
- package/src/editor/client/PageSettings.tsx +270 -0
- package/src/editor/client/RedirectsSettings.tsx +130 -0
- package/src/editor/client/Resize.tsx +204 -0
- package/src/editor/client/Sidebar.tsx +51 -0
- package/src/editor/client/SiteMap.tsx +568 -0
- package/src/editor/client/SiteSettings.tsx +409 -0
- package/src/editor/client/TextTools.tsx +391 -0
- package/src/editor/client/Toolbar.tsx +449 -0
- package/src/editor/client/VideoUpload.tsx +251 -0
- package/src/editor/client/api.ts +417 -0
- package/src/editor/client/brand.ts +20 -0
- package/src/editor/client/connection.ts +98 -0
- package/src/editor/client/context.ts +19 -0
- package/src/editor/client/css.d.ts +2 -0
- package/src/editor/client/editor.css +4656 -0
- package/src/editor/client/fields.tsx +812 -0
- package/src/editor/client/icons.tsx +174 -0
- package/src/editor/client/keys.ts +15 -0
- package/src/editor/client/kinds.ts +289 -0
- package/src/editor/client/languages.ts +32 -0
- package/src/editor/client/main.tsx +100 -0
- package/src/editor/client/responses.ts +26 -0
- package/src/editor/client/rich-text.ts +326 -0
- package/src/editor/client/site-tree.ts +239 -0
- package/src/editor/client/theme.ts +55 -0
- package/src/editor/client/tsconfig.json +18 -0
- package/src/editor/client/tus.ts +137 -0
- package/src/editor/client/use-rect.ts +50 -0
- package/src/editor/client/widgets.tsx +1218 -0
- package/src/forms/captcha.ts +83 -0
- package/src/forms/define.ts +166 -0
- package/src/forms/fields.ts +197 -0
- package/src/forms/file-types.ts +108 -0
- package/src/forms/files.ts +216 -0
- package/src/forms/form-page.ts +9 -0
- package/src/forms/handler.ts +622 -0
- package/src/forms/spec.ts +89 -0
- package/src/forms/store.ts +96 -0
- package/src/forms/work.ts +50 -0
- package/src/icons/library.ts +144 -0
- package/src/icons/load.ts +63 -0
- package/src/index.ts +99 -0
- package/src/init.ts +257 -0
- package/src/integration.ts +469 -0
- package/src/mail/mailer.ts +197 -0
- package/src/mail/notify.ts +272 -0
- package/src/mail/settings.ts +173 -0
- package/src/mail/templates.ts +191 -0
- package/src/mcp/page-nodes.ts +209 -0
- package/src/mcp/server.ts +111 -0
- package/src/mcp/tools.ts +637 -0
- package/src/runtime/TemplatePage.astro +39 -0
- package/src/runtime/TemplatePageStatic.astro +13 -0
- package/src/runtime/admin-route.ts +80 -0
- package/src/runtime/connect.ts +53 -0
- package/src/runtime/content.ts +188 -0
- package/src/runtime/context.ts +131 -0
- package/src/runtime/form-files.ts +18 -0
- package/src/runtime/forms-route.ts +33 -0
- package/src/runtime/forms.ts +28 -0
- package/src/runtime/icons.ts +5 -0
- package/src/runtime/media.ts +175 -0
- package/src/runtime/middleware.ts +186 -0
- package/src/runtime/nav.ts +13 -0
- package/src/runtime/query-reads.ts +49 -0
- package/src/runtime/query-store.ts +16 -0
- package/src/runtime/request-state.ts +69 -0
- package/src/runtime/robots.ts +29 -0
- package/src/runtime/rss-static.ts +16 -0
- package/src/runtime/rss.ts +29 -0
- package/src/runtime/server.ts +29 -0
- package/src/runtime/sitemap.ts +34 -0
- package/src/runtime/template-paths.ts +34 -0
- package/src/runtime/uploads-route.ts +13 -0
- package/src/seed-cli.ts +253 -0
- package/src/server/auth.ts +31 -0
- package/src/server/fetch-image.ts +219 -0
- package/src/server/handler.ts +2106 -0
- package/src/server/http.ts +162 -0
- package/src/server/locales.ts +73 -0
- package/src/server/node.ts +57 -0
- package/src/server/query-params.ts +249 -0
- package/src/server/rate-limit.ts +72 -0
- package/src/server/video-host.ts +162 -0
- package/src/starter.ts +70 -0
- package/src/version.ts +4 -0
- package/src/virtual.d.ts +65 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { normalizePagePath } from "../../content/ids.ts";
|
|
3
|
+
import { defaultScope } from "../../runtime/request-state.ts";
|
|
4
|
+
import "./listing.css";
|
|
5
|
+
import type { NodeScope } from "../../runtime/context.ts";
|
|
6
|
+
import config from "virtual:brim/config";
|
|
7
|
+
import { connect } from "../../runtime/connect.ts";
|
|
8
|
+
import { type ContentItem, getContentType, getItems, getTerms } from "../../runtime/content.ts";
|
|
9
|
+
import { tagsOf } from "../../content/tags.ts";
|
|
10
|
+
import { optionLabel, optionsOf, standardField } from "../../content/content-types.ts";
|
|
11
|
+
import { itemPicture } from "../../content/item-image.ts";
|
|
12
|
+
import ListingCards from "./ListingCards.astro";
|
|
13
|
+
import { type BrowseState, type FilterValue, browseItems, prefillOf, queryItems } from "./query.ts";
|
|
14
|
+
|
|
15
|
+
const LABELS = {
|
|
16
|
+
search: "Search",
|
|
17
|
+
apply: "Apply",
|
|
18
|
+
reset: "Clear all",
|
|
19
|
+
results: "{count} results",
|
|
20
|
+
empty: "Nothing matches what you picked.",
|
|
21
|
+
pages: "Pages",
|
|
22
|
+
previous: "Previous",
|
|
23
|
+
next: "Next",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Lists the items of a content type. Which items and in what order is the site's code: `filter`, `sort`, `order`,
|
|
28
|
+
* `limit`, `exclude`. The owner changes what is listed by editing the items; selecting the listing in the editor
|
|
29
|
+
* opens them, or adds one that lands in this list.
|
|
30
|
+
*
|
|
31
|
+
* Pass a function to write the markup of one item; without one, a plain card per item:
|
|
32
|
+
*
|
|
33
|
+
* <Listing nodeId="guides" type="doc" filter={{ section: "Guides" }} sort="order">
|
|
34
|
+
* {(item) => <a href={item.url}>{item.title}</a>}
|
|
35
|
+
* </Listing>
|
|
36
|
+
*
|
|
37
|
+
* `facets`, `search` and `pageSize` let visitors narrow the list themselves, through the page's address
|
|
38
|
+
* (`?brand=Marazzi&q=lemn&page=2`), drawn on the server with no script. A `controls` function receives the
|
|
39
|
+
* whole state (`BrowseState`) to draw the search, facets and pages in the site's own markup instead.
|
|
40
|
+
*/
|
|
41
|
+
interface Props {
|
|
42
|
+
nodeId: string;
|
|
43
|
+
/** Key of the content type to list. */
|
|
44
|
+
type: string;
|
|
45
|
+
scope?: NodeScope;
|
|
46
|
+
/** Only items whose fields have these values: `{ section: "Guides" }`, `{ featured: true }`, `{ tags: ["a", "b"] }`. */
|
|
47
|
+
filter?: Record<string, FilterValue>;
|
|
48
|
+
/** A field of the type, or `title`, `created`, `updated`. By default the newest first. */
|
|
49
|
+
sort?: string;
|
|
50
|
+
/** By default descending for `created` and `updated`, ascending for anything else. */
|
|
51
|
+
order?: "ascending" | "descending";
|
|
52
|
+
limit?: number;
|
|
53
|
+
/** Items left out, by id: on an item's page, `exclude={item.id}` lists the others. */
|
|
54
|
+
exclude?: string | string[];
|
|
55
|
+
|
|
56
|
+
/** For the plain card only. */
|
|
57
|
+
variation?: "grid" | "list";
|
|
58
|
+
columns?: number;
|
|
59
|
+
gap?: number;
|
|
60
|
+
/** The image field the card shows; by default `image`, or the first one of a type without it, `false` for none. */
|
|
61
|
+
image?: string | false;
|
|
62
|
+
/** The text field the card shows; by default `description`, or the first one of a type without it, `false` for none. */
|
|
63
|
+
text?: string | false;
|
|
64
|
+
/** The field whose tags the card shows as labels; by default `tags`, `false` for none. */
|
|
65
|
+
tags?: string | false;
|
|
66
|
+
/** Whether each card links to its item's page. By default it does when the type has pages. */
|
|
67
|
+
links?: boolean;
|
|
68
|
+
imageAspectRatio?: "auto" | "square" | "video" | "portrait";
|
|
69
|
+
|
|
70
|
+
/** Fields visitors pick values of, as checkboxes: `select`, `text`, `tags`, `number` or `boolean` fields. */
|
|
71
|
+
facets?: string[];
|
|
72
|
+
/** A search box: `true` searches the title and the type's text-like fields, a list names the fields to search. */
|
|
73
|
+
search?: boolean | string[];
|
|
74
|
+
/** How many items a page shows; visitors turn pages through the address. */
|
|
75
|
+
pageSize?: number;
|
|
76
|
+
/** Put before each of the listing's address parameters, for a page with more than one listing to browse. */
|
|
77
|
+
paramPrefix?: string;
|
|
78
|
+
/** Draws the search, facets, count and pages in the site's own markup, from the state; Brim then draws only the items. */
|
|
79
|
+
controls?: (state: BrowseState<ContentItem>) => unknown;
|
|
80
|
+
/** The words of the search, facets and pages, in the site's language. `{count}` in `results` is the number. */
|
|
81
|
+
labels?: Partial<typeof LABELS>;
|
|
82
|
+
|
|
83
|
+
/** Older names: `sort` and `order` with `created`/`title`, `limit`, and the card's options. */
|
|
84
|
+
sortOn?: "created" | "title";
|
|
85
|
+
sortOrder?: "ascending" | "descending";
|
|
86
|
+
maxItems?: number;
|
|
87
|
+
showImage?: boolean;
|
|
88
|
+
showDescription?: boolean;
|
|
89
|
+
enableItemLinks?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const props = Astro.props;
|
|
93
|
+
const { nodeId, type: typeKey, scope = defaultScope() } = props;
|
|
94
|
+
const type = getContentType(typeKey);
|
|
95
|
+
const listed = queryItems(await getItems(typeKey), {
|
|
96
|
+
filter: props.filter,
|
|
97
|
+
// A type the owner puts in order lists in that order unless the code sorts it otherwise.
|
|
98
|
+
sort: props.sort ?? props.sortOn ?? (type.ordered ? "position" : undefined),
|
|
99
|
+
order: props.order ?? props.sortOrder,
|
|
100
|
+
limit: props.limit ?? props.maxItems,
|
|
101
|
+
exclude: props.exclude,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Visitors narrow the list through the address, which only a page drawn on request has (the dev server and the
|
|
105
|
+
// Node server); a static copy, written once, lists every item.
|
|
106
|
+
const browsing = Boolean(props.facets?.length || props.search || props.pageSize) && config.mode !== "static";
|
|
107
|
+
const state: BrowseState<ContentItem> | undefined = browsing
|
|
108
|
+
? browseItems(
|
|
109
|
+
listed,
|
|
110
|
+
type.fields,
|
|
111
|
+
{
|
|
112
|
+
facets: props.facets,
|
|
113
|
+
search: props.search,
|
|
114
|
+
pageSize: props.pageSize,
|
|
115
|
+
paramPrefix: props.paramPrefix,
|
|
116
|
+
labels: browsing ? await referenceLabels(type) : undefined,
|
|
117
|
+
},
|
|
118
|
+
Astro.url.searchParams,
|
|
119
|
+
)
|
|
120
|
+
: undefined;
|
|
121
|
+
const items = state ? state.items : listed;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* What facets show for each value: the titles of the terms reference fields point at, by slug, and the labels of
|
|
125
|
+
* select choices, both in the page's language.
|
|
126
|
+
*/
|
|
127
|
+
async function referenceLabels(of: typeof type): Promise<Record<string, Record<string, string>>> {
|
|
128
|
+
const labels: Record<string, Record<string, string>> = {};
|
|
129
|
+
for (const field of of.fields) {
|
|
130
|
+
if (field.type === "select") {
|
|
131
|
+
labels[field.name] = Object.fromEntries(
|
|
132
|
+
optionsOf(field).map((option) => [option.value, optionLabel(field, option.value, Astro.currentLocale)]),
|
|
133
|
+
);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (field.type !== "reference" || !field.to) continue;
|
|
137
|
+
// A term not translated into the page's language yet shows in its own, never as its bare slug.
|
|
138
|
+
labels[field.name] = Object.fromEntries([...(await getTerms(field.to))].map(([slug, term]) => [slug, term.title]));
|
|
139
|
+
}
|
|
140
|
+
return labels;
|
|
141
|
+
}
|
|
142
|
+
const words = { ...LABELS, ...props.labels };
|
|
143
|
+
const anchor = `listing-${nodeId}`;
|
|
144
|
+
const ownControls = typeof props.controls === "function";
|
|
145
|
+
|
|
146
|
+
const showsText = props.text !== false && props.showDescription !== false;
|
|
147
|
+
const textField =
|
|
148
|
+
props.text ||
|
|
149
|
+
(standardField(type, "description") ?? type.fields.find(({ type: kind }) => kind === "textarea" || kind === "text"))
|
|
150
|
+
?.name;
|
|
151
|
+
const tagsField = props.tags === false ? undefined : (props.tags ?? "tags");
|
|
152
|
+
const labels = (item: ContentItem): string[] => (tagsField ? tagsOf(item.data[tagsField]) : []);
|
|
153
|
+
const links = props.links ?? props.enableItemLinks ?? Boolean(type.component);
|
|
154
|
+
const showsImage = props.image !== false && props.showImage !== false;
|
|
155
|
+
const custom = Astro.slots.has("default");
|
|
156
|
+
const ownImage = (item: ContentItem): { src: string; alt: string } | undefined => {
|
|
157
|
+
if (!showsImage) return undefined;
|
|
158
|
+
return props.image ? (item.data[props.image] as { src: string; alt: string } | undefined) : itemPicture(type, item);
|
|
159
|
+
};
|
|
160
|
+
// A card with no picture of its own takes its item page's preview image, the one its shared links show.
|
|
161
|
+
const previews = new Map<string, string>();
|
|
162
|
+
if (!custom && showsImage) {
|
|
163
|
+
const { content } = await connect(config.databaseUrl, config.authToken);
|
|
164
|
+
const missing = items.filter((item) => !ownImage(item)?.src);
|
|
165
|
+
// One read for every card, not one per card: a long list on a remote database made a round trip for each.
|
|
166
|
+
const seoByPath = missing.length > 0 ? await content.pageSeoSettings() : new Map();
|
|
167
|
+
for (const item of missing) {
|
|
168
|
+
const preview = seoByPath.get(normalizePagePath(item.url))?.image;
|
|
169
|
+
if (preview) previews.set(item.id, preview);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const image = (item: ContentItem): { src: string; alt: string } | undefined => {
|
|
173
|
+
const own = ownImage(item);
|
|
174
|
+
if (own?.src) return own;
|
|
175
|
+
const preview = previews.get(item.id);
|
|
176
|
+
return preview ? { src: preview, alt: item.title } : undefined;
|
|
177
|
+
};
|
|
178
|
+
const text = (item: ContentItem): string | undefined => {
|
|
179
|
+
return showsText && textField ? (item.data[textField] as string | undefined) : undefined;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const rendered = custom ? await Promise.all(items.map((item) => Astro.slots.render("default", [item]))) : [];
|
|
183
|
+
// What the editor needs to open these items, or add one that lands in this list.
|
|
184
|
+
const marker = Astro.locals.brim.marker("listing", nodeId, scope, {
|
|
185
|
+
type: type.key,
|
|
186
|
+
count: state ? state.total : items.length,
|
|
187
|
+
prefill: prefillOf(props.filter, type.fields),
|
|
188
|
+
});
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
{state ? (
|
|
192
|
+
<div class="brim-listing-browser" id={anchor} {...marker}>
|
|
193
|
+
{ownControls
|
|
194
|
+
? props.controls?.(state)
|
|
195
|
+
: (state.searchable || state.facets.length > 0) && (
|
|
196
|
+
<form class="brim-listing-browser__controls" method="get" action={`#${anchor}`}>
|
|
197
|
+
{state.otherParams.map(([name, value]) => (
|
|
198
|
+
<input type="hidden" name={name} value={value} />
|
|
199
|
+
))}
|
|
200
|
+
{state.searchable && (
|
|
201
|
+
<label class="brim-listing-browser__search">
|
|
202
|
+
<span>{words.search}</span>
|
|
203
|
+
<input type="search" name={state.searchParam} value={state.query} />
|
|
204
|
+
</label>
|
|
205
|
+
)}
|
|
206
|
+
{state.facets.map((facet) => (
|
|
207
|
+
<fieldset class="brim-listing-browser__facet">
|
|
208
|
+
<legend>{facet.label}</legend>
|
|
209
|
+
{facet.options.map((option) => (
|
|
210
|
+
<label class="brim-listing-browser__option">
|
|
211
|
+
<input type="checkbox" name={facet.param} value={option.value} checked={option.selected} />
|
|
212
|
+
<span>{option.label}</span>
|
|
213
|
+
<span class="brim-listing-browser__count">{option.count}</span>
|
|
214
|
+
</label>
|
|
215
|
+
))}
|
|
216
|
+
</fieldset>
|
|
217
|
+
))}
|
|
218
|
+
<div class="brim-listing-browser__actions">
|
|
219
|
+
<button type="submit">{words.apply}</button>
|
|
220
|
+
{state.narrowed && <a href={`${state.resetHref}#${anchor}`}>{words.reset}</a>}
|
|
221
|
+
</div>
|
|
222
|
+
</form>
|
|
223
|
+
)}
|
|
224
|
+
{!ownControls && (
|
|
225
|
+
<p class="brim-listing-browser__summary" role="status">
|
|
226
|
+
{words.results.replace("{count}", String(state.total))}
|
|
227
|
+
</p>
|
|
228
|
+
)}
|
|
229
|
+
<div
|
|
230
|
+
class="brim-listing"
|
|
231
|
+
data-variation={props.variation === "list" ? "list" : "grid"}
|
|
232
|
+
data-aspect={props.imageAspectRatio}
|
|
233
|
+
style={`--brim-listing-columns:${Number(props.columns) || 3};--brim-listing-gap:${Number(props.gap) || 24}px`}
|
|
234
|
+
{...(state ? {} : marker)}
|
|
235
|
+
>
|
|
236
|
+
<ListingCards
|
|
237
|
+
items={items}
|
|
238
|
+
rendered={rendered}
|
|
239
|
+
custom={custom}
|
|
240
|
+
links={links}
|
|
241
|
+
image={image}
|
|
242
|
+
text={text}
|
|
243
|
+
labels={labels}
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
{state.total === 0 && !ownControls && <p class="brim-listing-browser__empty">{words.empty}</p>}
|
|
247
|
+
{state.pageCount > 1 && !ownControls && (
|
|
248
|
+
<nav class="brim-listing-browser__pages" aria-label={words.pages}>
|
|
249
|
+
{state.page > 1 && (
|
|
250
|
+
<a href={`${state.pageHref(state.page - 1)}#${anchor}`} rel="prev">
|
|
251
|
+
{words.previous}
|
|
252
|
+
</a>
|
|
253
|
+
)}
|
|
254
|
+
{Array.from({ length: state.pageCount }, (_, index) => index + 1).map((page) => (
|
|
255
|
+
<a href={`${state.pageHref(page)}#${anchor}`} aria-current={page === state.page ? "page" : undefined}>
|
|
256
|
+
{page}
|
|
257
|
+
</a>
|
|
258
|
+
))}
|
|
259
|
+
{state.page < state.pageCount && (
|
|
260
|
+
<a href={`${state.pageHref(state.page + 1)}#${anchor}`} rel="next">
|
|
261
|
+
{words.next}
|
|
262
|
+
</a>
|
|
263
|
+
)}
|
|
264
|
+
</nav>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
) : (
|
|
268
|
+
<div
|
|
269
|
+
class="brim-listing"
|
|
270
|
+
data-variation={props.variation === "list" ? "list" : "grid"}
|
|
271
|
+
data-aspect={props.imageAspectRatio}
|
|
272
|
+
style={`--brim-listing-columns:${Number(props.columns) || 3};--brim-listing-gap:${Number(props.gap) || 24}px`}
|
|
273
|
+
{...(state ? {} : marker)}
|
|
274
|
+
>
|
|
275
|
+
<ListingCards
|
|
276
|
+
items={items}
|
|
277
|
+
rendered={rendered}
|
|
278
|
+
custom={custom}
|
|
279
|
+
links={links}
|
|
280
|
+
image={image}
|
|
281
|
+
text={text}
|
|
282
|
+
labels={labels}
|
|
283
|
+
/>
|
|
284
|
+
{items.length === 0 && Astro.locals.brim.editing && (
|
|
285
|
+
<p class="brim-listing__empty">No {type.label.toLowerCase()} here yet.</p>
|
|
286
|
+
)}
|
|
287
|
+
</div>
|
|
288
|
+
)}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* The items of a listing, as the site's own markup (`rendered`) or as Brim's plain cards. Split from `Listing` so
|
|
4
|
+
* the same cards are drawn whether or not visitors can narrow the list.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentItem } from "../../runtime/content.ts";
|
|
7
|
+
import { imageSources } from "../../runtime/media.ts";
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
items: ContentItem[];
|
|
11
|
+
rendered: string[];
|
|
12
|
+
custom: boolean;
|
|
13
|
+
links: boolean;
|
|
14
|
+
image: (item: ContentItem) => { src: string; alt: string } | undefined;
|
|
15
|
+
text: (item: ContentItem) => string | undefined;
|
|
16
|
+
labels: (item: ContentItem) => string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { items, rendered, custom, links, image, text, labels } = Astro.props;
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
{custom
|
|
23
|
+
? rendered.map((html) => <Fragment set:html={html} />)
|
|
24
|
+
: items.map((item) => {
|
|
25
|
+
const Card = links ? "a" : "div";
|
|
26
|
+
return (
|
|
27
|
+
<Card class="brim-listing__item" href={links ? item.url : undefined}>
|
|
28
|
+
{image(item)?.src && (
|
|
29
|
+
<img
|
|
30
|
+
class="brim-listing__image"
|
|
31
|
+
{...imageSources(image(item)?.src ?? "", "(max-width: 479px) 100vw, (max-width: 991px) 50vw, 33vw")}
|
|
32
|
+
alt={image(item)?.alt ?? ""}
|
|
33
|
+
loading="lazy"
|
|
34
|
+
decoding="async"
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
<span class="brim-listing__title">{item.title}</span>
|
|
38
|
+
{text(item) && <span class="brim-listing__text">{text(item)}</span>}
|
|
39
|
+
{labels(item).length > 0 && (
|
|
40
|
+
<span class="brim-listing__tags">
|
|
41
|
+
{labels(item).map((tag) => (
|
|
42
|
+
<span class="brim-listing__tag">{tag}</span>
|
|
43
|
+
))}
|
|
44
|
+
</span>
|
|
45
|
+
)}
|
|
46
|
+
</Card>
|
|
47
|
+
);
|
|
48
|
+
})}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* Listing block. Layout only; the look of a card belongs to the site. */
|
|
2
|
+
/* In the `brim` layer: any CSS of the site wins over it, whatever its selectors. */
|
|
3
|
+
@layer brim {
|
|
4
|
+
.brim-listing {
|
|
5
|
+
display: grid;
|
|
6
|
+
grid-template-columns: repeat(var(--brim-listing-columns, 3), minmax(0, 1fr));
|
|
7
|
+
gap: var(--brim-listing-gap, 24px);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.brim-listing[data-variation="list"] {
|
|
11
|
+
grid-template-columns: minmax(0, 1fr);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.brim-listing__item {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 0.5rem;
|
|
18
|
+
color: inherit;
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.brim-listing__image {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: auto;
|
|
25
|
+
object-fit: cover;
|
|
26
|
+
border-radius: var(--brim-theme-radius, 0.5rem);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.brim-listing[data-aspect="square"] .brim-listing__image {
|
|
30
|
+
aspect-ratio: 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.brim-listing[data-aspect="video"] .brim-listing__image {
|
|
34
|
+
aspect-ratio: 16 / 9;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.brim-listing[data-aspect="portrait"] .brim-listing__image {
|
|
38
|
+
aspect-ratio: 3 / 4;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.brim-listing__title {
|
|
42
|
+
font-weight: 600;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* An item's tags: small labels in the card's own colours, for the site to restyle. */
|
|
46
|
+
.brim-listing__tags {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
gap: 0.375rem;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.brim-listing__tag {
|
|
53
|
+
padding: 0.125em 0.625em;
|
|
54
|
+
border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
|
|
55
|
+
border-radius: 999px;
|
|
56
|
+
font-size: 0.75em;
|
|
57
|
+
line-height: 1.5;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@media (max-width: 991px) {
|
|
61
|
+
.brim-listing {
|
|
62
|
+
grid-template-columns: repeat(min(var(--brim-listing-columns, 3), 2), minmax(0, 1fr));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (max-width: 479px) {
|
|
67
|
+
.brim-listing {
|
|
68
|
+
grid-template-columns: minmax(0, 1fr);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* A listing visitors narrow themselves: search and facets, the results, then the pages. Layout only. */
|
|
73
|
+
.brim-listing-browser {
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: 1.5rem;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.brim-listing-browser__controls {
|
|
80
|
+
display: flex;
|
|
81
|
+
flex-wrap: wrap;
|
|
82
|
+
align-items: flex-start;
|
|
83
|
+
gap: 1rem 2rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.brim-listing-browser__search {
|
|
87
|
+
display: flex;
|
|
88
|
+
flex-direction: column;
|
|
89
|
+
gap: 0.25rem;
|
|
90
|
+
flex: 1 1 16rem;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.brim-listing-browser__facet {
|
|
94
|
+
display: flex;
|
|
95
|
+
flex-direction: column;
|
|
96
|
+
gap: 0.25rem;
|
|
97
|
+
margin: 0;
|
|
98
|
+
padding: 0;
|
|
99
|
+
border: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.brim-listing-browser__facet legend {
|
|
103
|
+
margin-bottom: 0.25rem;
|
|
104
|
+
font-weight: 600;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.brim-listing-browser__option {
|
|
108
|
+
display: flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
gap: 0.5rem;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.brim-listing-browser__count {
|
|
114
|
+
opacity: 0.6;
|
|
115
|
+
font-size: 0.875em;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.brim-listing-browser__actions {
|
|
119
|
+
display: flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
gap: 1rem;
|
|
122
|
+
align-self: flex-end;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.brim-listing-browser__pages {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-wrap: wrap;
|
|
128
|
+
justify-content: center;
|
|
129
|
+
gap: 0.5rem;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.brim-listing-browser__pages a[aria-current="page"] {
|
|
133
|
+
font-weight: 700;
|
|
134
|
+
text-decoration: none;
|
|
135
|
+
}
|
|
136
|
+
}
|