From f02aac1b221fa8a06c21d6fe3983c94e37e961cf Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:20:34 +0100 Subject: [PATCH] Support for scene break blocks --- TODO.md | 8 ++- .../RichText/components/RTBlock/RTBlock.astro | 4 ++ .../RTBlock/components/RTBreak.astro | 61 +++++++++++++++++++ .../components/TableOfContentItem.astro | 19 +++++- src/i18n/wordings-keys.ts | 4 +- src/shared/payload/payload-sdk.ts | 33 +++++++++- 6 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 src/components/RichText/components/RTBlock/components/RTBreak.astro diff --git a/TODO.md b/TODO.md index 092a1bf..4ca19e2 100644 --- a/TODO.md +++ b/TODO.md @@ -4,12 +4,13 @@ - [Payload] Fix SDK endpoint not working in prod - [Folder] Add parent pages -- Support for scene break blocks - Add hover/active styling for settings options in topbar + language override - Highlight currently selected language option in language override tooltip +- Save cookies for longer than just the session ## Mid term +- Support for nameless section - [Collectibles] Create page for gallery - [Collectibles] Create page for scans - When the tags overflow, the tag group name should be align start (see http://localhost:12499/en/pages/magnitude-negative-chapter-1) @@ -29,3 +30,8 @@ - Global search function - Convert Rich text to simple text for indexing and open graph purposes - Anonymous comments + +## Bonus + +- Static HTML site export for archival +- Secret Terminal mode diff --git a/src/components/RichText/components/RTBlock/RTBlock.astro b/src/components/RichText/components/RTBlock/RTBlock.astro index 403d87b..b0485e0 100644 --- a/src/components/RichText/components/RTBlock/RTBlock.astro +++ b/src/components/RichText/components/RTBlock/RTBlock.astro @@ -3,11 +3,13 @@ import type { RichTextContext } from "src/utils/richText"; import RTSection from "./components/RTSection.astro"; import RTTranscript from "./components/RTTranscript.astro"; import { + isBlockNodeBreakBlock, isBlockNodeSectionBlock, isBlockNodeTranscriptBlock, type RichTextBlockNode, } from "src/shared/payload/payload-sdk"; import ErrorMessage from "components/ErrorMessage.astro"; +import RTBreak from "./components/RTBreak.astro"; interface Props { node: RichTextBlockNode; @@ -22,6 +24,8 @@ const { node, context } = Astro.props; ) : isBlockNodeTranscriptBlock(node) ? ( + ) : isBlockNodeBreakBlock(node) ? ( + ) : ( +
+
+
+
+
+ + ) : node.fields.type === BreakBlockType.sceneBreak ? ( +

***

+ ) : node.fields.type === BreakBlockType.dottedLine ? ( +
+ ) : node.fields.type === BreakBlockType.solidLine ? ( +
+ ) : ( + + ) +} + + diff --git a/src/components/TableOfContent/components/TableOfContentItem.astro b/src/components/TableOfContent/components/TableOfContentItem.astro index 8eba736..20d09ed 100644 --- a/src/components/TableOfContent/components/TableOfContentItem.astro +++ b/src/components/TableOfContent/components/TableOfContentItem.astro @@ -1,4 +1,5 @@ --- +import { getI18n } from "src/i18n/i18n"; import type { TableOfContentEntry } from "src/shared/payload/payload-sdk"; interface Props { @@ -6,12 +7,28 @@ interface Props { } const { entry } = Astro.props; + +const { t } = await getI18n(Astro.locals.currentLocale); + +const title = (() => { + switch (entry.type) { + case "sceneBreak": + return entry.title || t("pages.tableOfContent.sceneBreak", { index: entry.index }); + + case "break": + return entry.title || t("pages.tableOfContent.break", { index: entry.index }); + + case "section": + default: + return entry.title; + } +})(); --- {/* ------------------------------------------- HTML ------------------------------------------- */}
  • - {entry.title} + {title} { entry.children.length > 0 && (
      diff --git a/src/i18n/wordings-keys.ts b/src/i18n/wordings-keys.ts index 16281c3..7f4df7f 100644 --- a/src/i18n/wordings-keys.ts +++ b/src/i18n/wordings-keys.ts @@ -84,4 +84,6 @@ export type WordingKey = | "header.nav.parentPages.collections.collectible" | "header.nav.parentPages.tooltip" | "global.meta.description" - | "global.loading"; + | "global.loading" + | "pages.tableOfContent.sceneBreak" + | "pages.tableOfContent.break"; diff --git a/src/shared/payload/payload-sdk.ts b/src/shared/payload/payload-sdk.ts index 8afed30..1f85a53 100644 --- a/src/shared/payload/payload-sdk.ts +++ b/src/shared/payload/payload-sdk.ts @@ -795,12 +795,22 @@ export interface CueBlock { }; blockType: 'cueBlock'; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "BreakBlock". + */ +export interface BreakBlock { + type: 'Scene break' | 'Empty space' | 'Solid line' | 'Dotted line'; + id?: string | null; + blockName?: string | null; + blockType: 'breakBlock'; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "TranscriptBlock". */ export interface TranscriptBlock { - lines: (LineBlock | CueBlock)[]; + lines: (LineBlock | CueBlock | BreakBlock)[]; id?: string | null; blockName?: string | null; blockType: 'transcriptBlock'; @@ -874,6 +884,13 @@ export enum LanguageCodes { "zh" = "Chinese", } +export enum BreakBlockType { + sceneBreak = "Scene break", + space = "Empty space", + solidLine = "Solid line", + dottedLine = "Dotted line", +} + export enum CollectibleBindingTypes { Paperback = "Paperback", Hardcover = "Hardcover", @@ -1031,6 +1048,10 @@ export interface RichTextTranscriptBlock extends RichTextBlockNode { fields: TranscriptBlock; } +export interface RichTextBreakBlock extends RichTextBlockNode { + fields: BreakBlock; +} + export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode => node.type === "paragraph"; @@ -1080,19 +1101,22 @@ export const isBlockNodeTranscriptBlock = ( node: RichTextBlockNode ): node is RichTextTranscriptBlock => node.fields.blockType === "transcriptBlock"; +export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock => + node.fields.blockType === "breakBlock"; + /* BLOCKS */ /* TODO: TO BE REMOVED WHEN https://github.com/payloadcms/payload/issues/5216 is closed */ export interface CueBlock { content: RichTextContent; - blockType: 'cueBlock'; + blockType: "cueBlock"; id?: string | null; blockName?: string | null; } export interface LineBlock { content: RichTextContent; - blockType: 'lineBlock'; + blockType: "lineBlock"; id?: string | null; blockName?: string | null; } @@ -1109,6 +1133,7 @@ export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => block.blockType === "lineBlock"; + ////////////////// SDK ////////////////// import NodeCache from "node-cache"; @@ -1408,6 +1433,8 @@ export type EndpointCollectible = EndpointCollectiblePreview & { export type TableOfContentEntry = { prefix: string; title: string; + type: "sceneBreak" | "break" | "section"; + index: number; children: TableOfContentEntry[]; };