diff --git a/app/lish/[did]/[publication]/[rkey]/DocumentPageRenderer.tsx b/app/lish/[did]/[publication]/[rkey]/DocumentPageRenderer.tsx index 0fcd6d74..34745fc5 100644 --- a/app/lish/[did]/[publication]/[rkey]/DocumentPageRenderer.tsx +++ b/app/lish/[did]/[publication]/[rkey]/DocumentPageRenderer.tsx @@ -2,6 +2,8 @@ import { AtpAgent } from "@atproto/api"; import { ids } from "lexicons/api/lexicons"; import { PubLeafletBlocksBskyPost, + PubLeafletBlocksOrderedList, + PubLeafletBlocksUnorderedList, PubLeafletPagesLinearDocument, PubLeafletPagesCanvas, } from "lexicons/api"; @@ -65,8 +67,9 @@ export async function DocumentPageRenderer({ let bskyPosts = pages.flatMap((p) => { let page = p as PubLeafletPagesLinearDocument.Main; - return page.blocks?.filter( - (b) => b.block.$type === ids.PubLeafletBlocksBskyPost, + return extractBlocksByType( + page.blocks || [], + ids.PubLeafletBlocksBskyPost, ); }) || []; @@ -81,7 +84,7 @@ export async function DocumentPageRenderer({ agent.getPosts( { uris: batch.map((p) => { - let block = p?.block as PubLeafletBlocksBskyPost.Main; + let block = p?.block as unknown as PubLeafletBlocksBskyPost.Main; return block.postRef.uri; }), }, @@ -98,10 +101,7 @@ export async function DocumentPageRenderer({ // Extract poll blocks and fetch vote data let pollBlocks = pages.flatMap((p) => { let page = p as PubLeafletPagesLinearDocument.Main; - return ( - page.blocks?.filter((b) => b.block.$type === ids.PubLeafletBlocksPoll) || - [] - ); + return extractBlocksByType(page.blocks || [], ids.PubLeafletBlocksPoll); }); let pollData = await fetchPollData( pollBlocks.map((b) => (b.block as any).pollRef.uri), @@ -123,7 +123,10 @@ export async function DocumentPageRenderer({ return ( - + ); } + +function extractBlocksByType( + blocks: PubLeafletPagesLinearDocument.Block[], + type: string, +): { block: { $type: string; [key: string]: unknown } }[] { + let results: { block: { $type: string; [key: string]: unknown } }[] = []; + for (let b of blocks) { + if (b.block.$type === type) { + results.push(b as { block: { $type: string; [key: string]: unknown } }); + } + if ( + b.block.$type === ids.PubLeafletBlocksOrderedList || + b.block.$type === ids.PubLeafletBlocksUnorderedList + ) { + let list = b.block as + | PubLeafletBlocksOrderedList.Main + | PubLeafletBlocksUnorderedList.Main; + extractFromListItems(list.children, type, results); + } + } + return results; +} + +function extractFromListItems( + items: + | PubLeafletBlocksOrderedList.ListItem[] + | PubLeafletBlocksUnorderedList.ListItem[], + type: string, + results: { block: { $type: string; [key: string]: unknown } }[], +) { + for (let item of items) { + if ((item.content as { $type?: string })?.$type === type) { + results.push({ + block: item.content as { $type: string; [key: string]: unknown }, + }); + } + if (item.children) { + extractFromListItems(item.children, type, results); + } + let orderedChildren = (item as PubLeafletBlocksUnorderedList.ListItem) + .orderedListChildren; + if (orderedChildren) { + extractFromListItems(orderedChildren.children, type, results); + } + let unorderedChildren = (item as PubLeafletBlocksOrderedList.ListItem) + .unorderedListChildren; + if (unorderedChildren) { + extractFromListItems(unorderedChildren.children, type, results); + } + } +} diff --git a/components/ActionBar/ProfileButton.tsx b/components/ActionBar/ProfileButton.tsx index be888213..2c3cc79f 100644 --- a/components/ActionBar/ProfileButton.tsx +++ b/components/ActionBar/ProfileButton.tsx @@ -15,7 +15,6 @@ import { ManageDomains } from "components/Domains/ManageDomains"; import { WebSmall } from "components/Icons/WebSmall"; import { useIsPro, useCanSeePro } from "src/hooks/useEntitlement"; import { LeafletPro } from "components/Icons/LeafletPro"; -import { ButtonPrimary } from "components/Buttons"; export const ProfileButton = () => { let { identity } = useIdentityData(); diff --git a/components/Blocks/TextBlock/keymap.ts b/components/Blocks/TextBlock/keymap.ts index cef6e570..3f9c1402 100644 --- a/components/Blocks/TextBlock/keymap.ts +++ b/components/Blocks/TextBlock/keymap.ts @@ -392,6 +392,15 @@ const enter = view?: EditorView, ) => { if (state.doc.textContent.startsWith("/")) return true; + // Empty list item: just outdent, don't create a new block + if ( + propsRef.current.listData && + propsRef.current.pageType !== "canvas" && + state.doc.content.size <= 2 + ) { + shifttab(propsRef, repRef)(); + return true; + } let tr = state.tr; let newContent = tr.doc.slice(state.selection.anchor); tr.delete(state.selection.anchor, state.doc.content.size); @@ -451,9 +460,6 @@ const enter = return; } if (propsRef.current.listData) { - if (state.doc.content.size <= 2) { - return shifttab(propsRef, repRef)(); - } let createChild = propsRef.current.nextBlock?.listData && propsRef.current.nextBlock.listData.depth >