/* Field sets, groups and child collections shared by several entity manifests (adminSchema.ts has the overview). */ import { preview } from "../text.ts"; import { PLATFORMS } from "../platforms.ts"; import { FORMATTING_HELP } from "../../components/InlineText.tsx"; import { mediaUrl } from "../media.ts"; export const PLACE_FIELDS = [ { path: "venue", label: "Venue" }, { path: "address", label: "Address", full: true }, { path: "locality", label: "City" }, { path: "state_code", label: "State", help: "Two letters, US only" }, { path: "country", label: "Country", help: "Defaults to US" }, { path: "location_label", label: "Display location", help: "Overrides the line built from city and state" }, { path: "latitude", label: "Latitude", widget: "number" }, { path: "longitude", label: "Longitude", widget: "number" }, { path: "is_online", label: "Online", widget: "checkbox" }, ]; export const PUBLISHED_FIELD = { path: "is_published", label: "Published", widget: "checkbox" }; /* Only means anything on a published record. Unticked, its own page still works but the site's lists, counts and the QR page leave it out. See 027_listed.sql for exactly which. */ export const LISTED_FIELD = { path: "is_listed", label: "Listed", widget: "checkbox", help: "Unticked: only reachable by its link", }; /* For entities whose lists the site orders by hand. Events sort by date and people by sort_name, so they take the first two alone. */ export const PUBLISH_FIELDS = [ PUBLISHED_FIELD, LISTED_FIELD, { path: "sort_order", label: "Sort order", widget: "number" }, ]; /* The parts of an affiliation that read the same from either end: the person's list of roles, and the team's list of members. */ export const AFFILIATION_ROLE_FIELDS = [ { path: "title", label: "Title", help: "eg. Board Chair, Team Lead" }, { path: "role", label: "Role", widget: "select", options: ["lead", "board", "staff", "volunteer", "member"], }, { path: "is_owner", label: "Owner", widget: "checkbox", help: "Listed first (can be more than one)" }, { path: "started_on", label: "Started", widget: "date" }, { path: "ended_on", label: "Ended", widget: "date", help: "Blank means current" }, { path: "is_public", label: "Public", widget: "checkbox" }, ]; /* The timeline panel that appears on an event or organization once the box is ticked. Paths are prefixed with the extension key, exactly as 'region.scope' and 'private.notes' are. Everything here is an override. Left blank, the history page falls back to the record's own title, date and logo through v_timeline, which is the point of referencing rather than copying. */ export const timelineExtensionFields = (noun) => [ { path: "timeline.occurred_on", label: "Date on the timeline", help: `Blank uses the ${noun}'s own date. Partial dates are fine: 2012, 2012-06`, }, { path: "timeline.precision", label: "Date precision", widget: "select", options: ["year", "month", "day"], help: "How much of the date to trust. 'year' files it under 'Elsewhere in 2012'", }, { path: "timeline.title", label: "Title override", full: true, help: `Blank uses the ${noun}'s name`, }, { path: "timeline.blurb", label: "Blurb override", widget: "textarea", full: true, help: `Blank uses the ${noun}'s tagline`, }, { path: "timeline.meta", label: "Secondary line", help: "Region, venue, recipient" }, { path: "timeline.link_url", label: "Link override", help: `Blank links to the ${noun}'s own page`, }, { path: "timeline.is_featured", label: "Featured", widget: "checkbox", help: "Shown large, above the month list for its year", }, { path: "timeline.is_published", label: "Visible on the history page", widget: "checkbox" }, { path: "timeline.sort_order", label: "Sort order", widget: "number" }, ]; /* The checkbox itself, plus the panel it gates. One entry in `groups`. */ export const timelineGroup = (noun) => ({ legend: "Timeline", note: `Adds this ${noun} to the history page. Nothing is copied, the entry ` + `reads this record, so editing it here updates the timeline too.`, fields: [ { path: "in_timeline", label: "On the timeline", widget: "checkbox", help: "Show this on the history page", }, ], }); export const timelineDetailGroup = (noun) => ({ legend: "Timeline entry", when: { path: "in_timeline", value: 1 }, note: "Every field here is optional. Blank means \u201cuse the record's own value\u201d.", fields: timelineExtensionFields(noun), }); /* Featured cards (030_featured_cards.sql), a front page collection now and the Community blog's next, so it's written once. Fields show by kind; switching kind clears the ones that stop applying (see `when` in fields.tsx). */ export const FEATURED_KINDS = [ ["record", "A page on this site (event, org, person…)"], ["link", "A link (article, post, any URL)"], ["video", "A video (YouTube, Vimeo, Facebook)"], ]; export const featuredCardsChild = { key: "featured_cards", label: "Featured cards", note: "Shown by the Featured Content section, in this order.", addLabel: "Add card", title: (row, options) => row.title || options?.record_refs?.find((o) => o.kind === row.ref_kind && o.id === row.ref_id)?.label || row.url || "New card", blank: { kind: "", ref_kind: "", ref_id: "", url: "", title: "" }, fields: [ { path: "kind", label: "Card type", widget: "select", options: FEATURED_KINDS, required: true, }, { path: "ref_kind", label: "Record type", widget: "select", options: ["event", "organization", "person", "team", "award"], required: true, when: { path: "kind", value: "record" }, }, { path: "ref_id", label: "Record", widget: "select", optionsFrom: "record_refs", filterBy: (option, row) => option.kind === row.ref_kind, required: true, when: { path: "kind", value: "record" }, help: "Its title, picture and link fill the card. Anything typed below overrides them.", }, { path: "url", label: "URL", widget: "linkPreview", previewWhen: { path: "kind", value: "link" }, required: true, full: true, when: { path: "kind", value: ["link", "video"] }, }, { path: "eyebrow", label: "Label", help: "Small text above the title, eg. Article, Watch" }, { path: "title", label: "Title" }, { path: "blurb", label: "Blurb", widget: "textarea", full: true }, { path: "image", label: "Image", widget: "image", resolve: mediaUrl, full: true, help: "Default: the record's own picture, or for a YouTube video, its thumbnail.", }, ], }; /* The two collections every entity carries. */ export const linksChild = { key: "links", label: "Links and socials", addLabel: "Add link", title: (row) => row.label || row.url || "New link", blank: { kind: "action", label: "", url: "", is_primary: 0 }, fields: [ { path: "kind", label: "Kind", widget: "select", options: ["action", "social", "website", "email"], }, { path: "platform", label: "Platform", widget: "select", options: PLATFORMS.map((platform) => [platform.id, platform.label]), blankLabel: "Default: no icon", help: "Shows the platform's icon on the button.", }, { path: "label", label: "Label", required: true }, { path: "url", label: "URL", required: true, full: true }, { path: "is_primary", label: "Primary", widget: "checkbox" }, ], }; /* Hosts. One row is one host, ordered, and each is either an organization or a person, never both, which the CHECK on event_hosts enforces and this form can only ask nicely about. The first row supplies the logo and colour when the event sets neither, so the order here is data rather than a display choice. A person supplies neither: there is no colour on a person and a headshot is not a logo, so a person-hosted event with no colour of its own falls through to the section default. */ export const hostsChild = { key: "event_hosts", label: "Hosts", addLabel: "Add host", title: (row, options) => options?.organizations?.find((o) => o.id === row.org_id)?.label ?? options?.people?.find((p) => p.id === row.person_id)?.label ?? "New host", blank: { org_id: "", person_id: "" }, fields: [ { path: "org_id", label: "Organization", widget: "select", optionsFrom: "organizations", blankLabel: "Default: none", help: "Host Organization" }, { path: "person_id", label: "Person", widget: "select", optionsFrom: "people", blankLabel: "Default: none", help: "Use if the host is an individual, choose between person and org host, not both.", }, ], }; /* Content blocks. The type decides which fields appear (`when`), what the text box is for (`help` as a function), and whether the block has items; the preview under each open block is the site's own renderer. Types and what they read: ContentBlocks.tsx. */ export const BLOCK_TYPES = [ ["paragraph", "Paragraph", "Body text. Formatting: " + FORMATTING_HELP], ["heading", "Heading", "A section heading."], ["subheading", "Subheading", "A smaller heading under a heading."], ["callout", "Callout", "A note or announcement in a tinted box. Formatting: " + FORMATTING_HELP], ["quote", "Quote", "A quotation, with who said it. Formatting: " + FORMATTING_HELP], ["list", "List", "Bulleted items, each optionally linked, with an optional detail."], ["links", "Link buttons", "A row of outlined buttons, one per item."], ["button", "Button", "One filled call-to-action button, eg. Register, Donate."], ["image", "Image", "A picture, with alt text and an optional caption and link."], ["video", "Video", "A YouTube, Vimeo or Facebook video, or a video file, played in place."], ["schedule", "Schedule", "Entries in one tab per day, each folding out for more. The text is an optional intro."], ["table", "Table", "A grid of text, eg. a comparison chart: one row per line, cells split by |, the first row the header."], ["cards", "Link cards", "Cards with a picture, title and description, each a link to a page or a file, like a link shared in a chat; up to three in a row. Paste a link and press Fetch preview, or Choose a file."], ["divider", "Divider", "A thin line between parts."], ]; /* An item field that only a schedule's entries have. */ export const SCHEDULE_ENTRY = { scope: "parent", path: "type", value: "schedule" }; /* Item fields for a link card, and for every other kind of item. */ export const CARD_ITEM = { scope: "parent", path: "type", value: "cards" }; export const NOT_CARD_ITEM = { scope: "parent", path: "type", value: ["list", "links", "schedule"] }; export const blockTypeLabel = (type) => BLOCK_TYPES.find(([value]) => value === type)?.[1] ?? type; export const TEXT_TYPES = ["paragraph", "heading", "subheading", "callout", "quote", "button", "image", "video", "schedule", "table"]; export const TEXT_HELP = { paragraph: FORMATTING_HELP, callout: FORMATTING_HELP, quote: FORMATTING_HELP, button: "The button's label, eg. Register now", image: "Caption shown under the image. Optional.", video: "Caption shown under the video. Optional.", schedule: "Optional intro above the tabs. " + FORMATTING_HELP, table: "One row per line; cells split by |. The first row is the header. eg. Platform | Price | Best for. " + "Cells take the same formatting as a paragraph. A | inside a cell is written \|.", }; export const TEXT_LABEL = { button: "Label", image: "Caption", video: "Caption", schedule: "Intro", table: "Rows" }; export const HREF_HELP = { paragraph: "Optional. Makes the whole paragraph one link. For a link inside the text, use [text](url).", button: "Where the button goes, eg. /give or https://…", image: "Optional. Makes the image a link.", video: "The video's page, eg. https://www.youtube.com/watch?v=…, or a video file", }; export const blocksChild = { key: "content_blocks", label: "Content blocks", addLabel: "Add block", preview: "contentBlock", title: (row) => { const label = blockTypeLabel(row.type) || "Block"; const text = preview(row.text || row.href || row.media || "", 40); return text ? `${label}: ${text}` : label; }, blank: { slot: "body", type: "paragraph", text: "" }, fields: [ { path: "slot", label: "Shown in", widget: "select", options: [ ["body", "The page"], ["card", "The card (paragraphs only)"], ], }, { path: "type", label: "Type", widget: "select", options: BLOCK_TYPES.map(([value, label]) => [value, label]), help: (row) => BLOCK_TYPES.find(([value]) => value === row?.type)?.[2], }, { path: "text", label: (row) => TEXT_LABEL[row?.type] ?? "Text", widget: "textarea", full: true, when: { path: "type", value: TEXT_TYPES }, help: (row) => TEXT_HELP[row?.type], }, { path: "cite", label: "Attribution", help: "Who said it, eg. Jane Doe, Retreat 2024", full: true, when: { path: "type", value: "quote" }, }, { path: "href", label: "Link", full: true, files: true, filesWhen: { path: "type", value: ["paragraph", "button", "image"] }, when: { path: "type", value: ["paragraph", "button", "image", "video"] }, help: (row) => HREF_HELP[row?.type], }, { path: "media", label: "Image", widget: "image", resolve: mediaUrl, full: true, when: { path: "type", value: ["image", "video"] }, help: (row) => row?.type === "video" ? "Still shown before it plays. Default: YouTube's own thumbnail." : undefined, }, { path: "alt", label: "Alt text", full: true, when: { path: "type", value: "image" }, help: "Describes the picture for someone who can't see it, eg. Campers around a fire at dusk", }, ], children: [ { key: "items", label: "Items", addLabel: "Add item", when: { path: "type", value: ["list", "links", "schedule", "cards"] }, title: (row) => [row.day, row.time, row.text].filter(Boolean).join(" · ") || "New item", blank: { text: "" }, fields: [ { path: "day", label: "Day", help: "The tab it's under, eg. Friday. Entries with the same day share a tab, in this order.", when: SCHEDULE_ENTRY, }, { path: "time", label: "Time", help: "eg. 7:00pm, or 9:00 to 10:30am", when: SCHEDULE_ENTRY }, // A card: the link first, so Fetch preview can fill the rest. { path: "url", label: "Link", widget: "linkPreview", previewFills: { title: "text", blurb: "detail", image: "media" }, files: true, full: true, help: "A page on this site (eg. /retreats), anywhere else, or a file (Choose a file). Fetch preview fills the title, description and picture from a page; a file fills its name and first-page picture.", when: CARD_ITEM, }, { path: "text", label: "Text", required: true, help: "Schedules: the entry's title. Cards: the card's title" }, { path: "location", label: "Location", help: "eg. Main Hall", when: SCHEDULE_ENTRY, }, { path: "person_id", label: "Person", widget: "select", optionsFrom: "people", blankLabel: "Default: none", help: "Who hosts or speaks: shown with their photo, linked to their page", when: SCHEDULE_ENTRY, }, { path: "detail", label: "Detail", help: "A line under the text. Lists: shown after the text", when: NOT_CARD_ITEM }, { path: "detail", label: "Description", widget: "textarea", full: true, when: CARD_ITEM }, { path: "url", label: "URL", help: "Blank for plain text. Link buttons need one.", files: true, when: NOT_CARD_ITEM }, { path: "media", label: "Picture", widget: "image", resolve: mediaUrl, full: true, help: "Optional. Default: none, the card is text only.", when: CARD_ITEM, }, { path: "description", label: "More", widget: "textarea", full: true, help: "Shown when the entry is folded out. " + FORMATTING_HELP, when: SCHEDULE_ENTRY, }, { path: "media", label: "Graphic", widget: "image", resolve: mediaUrl, full: true, help: "Optional, in the fold-out: a map of the site, a slide, a poster", when: SCHEDULE_ENTRY, }, { path: "media_alt", label: "Graphic description", full: true, help: "For screen readers: what the graphic shows, eg. a map of the camp. Default: skipped as decoration.", when: SCHEDULE_ENTRY, }, { path: "map", label: "Map", full: true, help: "Optional, in the fold-out: a place or address for a Google map, eg. Camp Hebron, Halifax PA", when: SCHEDULE_ENTRY, }, ], }, ], };