diff --git a/actions/createPublication.ts b/actions/createPublication.ts index 23f7c3a7..de1c9eef 100644 --- a/actions/createPublication.ts +++ b/actions/createPublication.ts @@ -1,6 +1,6 @@ "use server"; import { TID } from "@atproto/common"; -import { AtpBaseClient } from "lexicons/src"; +import { AtpBaseClient } from "lexicons/api"; import { createOauthClient } from "src/atproto-oauth"; import { getIdentityData } from "actions/getIdentityData"; import { supabaseServerClient } from "supabase/serverClient"; diff --git a/actions/publishToPublication.ts b/actions/publishToPublication.ts index 47e59a27..3e3d7383 100644 --- a/actions/publishToPublication.ts +++ b/actions/publishToPublication.ts @@ -10,7 +10,7 @@ import { PubLeafletBlocksText, PubLeafletDocument, PubLeafletPagesLinearDocument, -} from "lexicons/src"; +} from "lexicons/api"; import { Block } from "components/Blocks/Block"; import { TID } from "@atproto/common"; import { supabaseServerClient } from "supabase/serverClient"; @@ -18,8 +18,8 @@ import { scanIndex, scanIndexLocal } from "src/replicache/utils"; import { Fact } from "src/replicache"; import { Attributes } from "src/replicache/attributes"; import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment"; -import { ids } from "lexicons/src/lexicons"; -import { OmitKey } from "lexicons/src/util"; +import { ids } from "lexicons/api/lexicons"; +import { OmitKey } from "lexicons/api/util"; import { BlobRef } from "@atproto/lexicon"; import { IdResolver } from "@atproto/identity"; import { AtUri } from "@atproto/syntax"; diff --git a/app/lish/PostList.tsx b/app/lish/PostList.tsx index 980db14c..09d27dd1 100644 --- a/app/lish/PostList.tsx +++ b/app/lish/PostList.tsx @@ -2,7 +2,7 @@ import Link from "next/link"; import { Separator } from "components/Layout"; import { Json } from "supabase/database.types"; -import { PubLeafletDocument } from "lexicons/src"; +import { PubLeafletDocument } from "lexicons/api"; import { ButtonPrimary } from "components/Buttons"; import { useIdentityData } from "components/IdentityProvider"; import { usePublicationRelationship } from "./[handle]/[publication]/usePublicationRelationship"; diff --git a/app/lish/[handle]/[publication]/[rkey]/page.tsx b/app/lish/[handle]/[publication]/[rkey]/page.tsx index ff46af84..ea68b07b 100644 --- a/app/lish/[handle]/[publication]/[rkey]/page.tsx +++ b/app/lish/[handle]/[publication]/[rkey]/page.tsx @@ -3,14 +3,14 @@ import { Footer } from "../../../Footer"; import { getPds, IdResolver } from "@atproto/identity"; import { supabaseServerClient } from "supabase/serverClient"; import { AtUri } from "@atproto/syntax"; -import { ids } from "lexicons/src/lexicons"; +import { ids } from "lexicons/api/lexicons"; import { PubLeafletBlocksHeader, PubLeafletBlocksImage, PubLeafletBlocksText, PubLeafletDocument, PubLeafletPagesLinearDocument, -} from "lexicons/src"; +} from "lexicons/api"; import { Metadata } from "next"; const idResolver = new IdResolver(); diff --git a/app/lish/[handle]/[publication]/page.tsx b/app/lish/[handle]/[publication]/page.tsx index 0c7a7ea8..93288907 100644 --- a/app/lish/[handle]/[publication]/page.tsx +++ b/app/lish/[handle]/[publication]/page.tsx @@ -7,7 +7,7 @@ import { AtpBaseClient, PubLeafletDocument, PubLeafletPublication, -} from "lexicons/src"; +} from "lexicons/api"; import { CallToActionButton } from "./CallToActionButton"; import { Metadata } from "next"; diff --git a/app/lish/page.tsx b/app/lish/page.tsx index 8e873d87..3be58f29 100644 --- a/app/lish/page.tsx +++ b/app/lish/page.tsx @@ -1,7 +1,7 @@ import { LishHome } from "./LishHome"; import { createClient } from "@supabase/supabase-js"; import { Database } from "supabase/database.types"; -import { AtpBaseClient, PubLeafletPagesLinearDocument } from "lexicons/src"; +import { AtpBaseClient, PubLeafletPagesLinearDocument } from "lexicons/api"; import { CredentialSession } from "@atproto/api"; import { createOauthClient } from "src/atproto-oauth"; import { getIdentityData } from "actions/getIdentityData"; diff --git a/appview/index.ts b/appview/index.ts index 701a4413..24d7b79b 100644 --- a/appview/index.ts +++ b/appview/index.ts @@ -3,12 +3,12 @@ import { Database, Json } from "supabase/database.types"; import { IdResolver } from "@atproto/identity"; const idResolver = new IdResolver(); import { Firehose, MemoryRunner } from "@atproto/sync"; -import { ids } from "lexicons/src/lexicons"; +import { ids } from "lexicons/api/lexicons"; import { PubLeafletDocument, PubLeafletPost, PubLeafletPublication, -} from "lexicons/src"; +} from "lexicons/api"; import { AtUri } from "@atproto/syntax"; import { writeFile, readFile } from "fs/promises"; diff --git a/components/Blocks/TextBlock/keymap.ts b/components/Blocks/TextBlock/keymap.ts index 12a41985..6cfc036b 100644 --- a/components/Blocks/TextBlock/keymap.ts +++ b/components/Blocks/TextBlock/keymap.ts @@ -46,21 +46,6 @@ export const TextBlockKeymap = ( }, "Ctrl-a": metaA(propsRef, repRef), "Meta-a": metaA(propsRef, repRef), - Tab: () => { - return um.withUndoGroup(() => { - if (useUIState.getState().selectedBlocks.length > 1) return false; - if (!repRef.current || !propsRef.current.previousBlock) return false; - indent( - propsRef.current, - propsRef.current.previousBlock, - repRef.current, - ); - return true; - }); - }, - "Shift-Tab": () => { - return um.withUndoGroup(shifttab(propsRef, repRef)); - }, Escape: (_state, _dispatch, view) => { view?.dom.blur(); useUIState.setState(() => ({ @@ -395,6 +380,10 @@ const enter = let newEntityID = v7(); let position: string; + useUIState.getState().setSelectedBlock({ + value: newEntityID, + parent: propsRef.current.parent, + }); let asyncRun = async () => { let blockType = propsRef.current.type === "heading" && state.selection.anchor <= 2 diff --git a/components/Blocks/useBlockKeyboardHandlers.ts b/components/Blocks/useBlockKeyboardHandlers.ts index 326d0104..89df10c3 100644 --- a/components/Blocks/useBlockKeyboardHandlers.ts +++ b/components/Blocks/useBlockKeyboardHandlers.ts @@ -27,10 +27,7 @@ export function useBlockKeyboardHandlers( let isSelected = useUIState((s) => { let selectedBlocks = s.selectedBlocks; - return ( - (!isTextBlock[props.type] || selectedBlocks.length > 1 || isLocked) && - !!s.selectedBlocks.find((b) => b.value === props.entityID) - ); + return !!s.selectedBlocks.find((b) => b.value === props.entityID); }); useEffect(() => { @@ -53,10 +50,11 @@ export function useBlockKeyboardHandlers( let el = e.target as HTMLElement; if ( - el.tagName === "LABEL" || - el.tagName === "INPUT" || - el.tagName === "TEXTAREA" || - el.contentEditable === "true" + (el.tagName === "LABEL" || + el.tagName === "INPUT" || + el.tagName === "TEXTAREA" || + el.contentEditable === "true") && + !isTextBlock[props.type] ) { if ((el as HTMLInputElement).value !== "" || e.key === "Tab") return; } @@ -89,8 +87,7 @@ type Args = { }; function Tab({ e, props, rep }: Args) { - // if tab or shift tab & not a textBlock, indent or outdent - if (isTextBlock[props.type]) return; + // if tab or shift tab, indent or outdent if (e.shiftKey) { e.preventDefault(); outdent(props, props.previousBlock, rep); @@ -104,6 +101,7 @@ function j(args: Args) { if (args.e.ctrlKey || args.e.metaKey) ArrowDown(args); } function ArrowDown({ e, props }: Args) { + if (isTextBlock[props.type]) return; e.preventDefault(); let nextBlock = props.nextBlock; if (nextBlock && useUIState.getState().selectedBlocks.length <= 1) @@ -118,6 +116,7 @@ function k(args: Args) { if (args.e.ctrlKey || args.e.metaKey) ArrowUp(args); } function ArrowUp({ e, props }: Args) { + if (isTextBlock[props.type]) return; e.preventDefault(); let prevBlock = props.previousBlock; if (prevBlock && useUIState.getState().selectedBlocks.length <= 1) { @@ -190,6 +189,7 @@ async function Backspace({ } async function Enter({ e, props, rep, entity_set }: Args) { + if (isTextBlock[props.type]) return; let newEntityID = v7(); let position; let el = e.target as HTMLElement; @@ -279,6 +279,7 @@ async function Enter({ e, props, rep, entity_set }: Args) { } function Escape({ e, props, areYouSure, setAreYouSure }: Args) { + if (isTextBlock[props.type]) return; e.preventDefault(); if (areYouSure) { setAreYouSure(false); diff --git a/components/ThemeManager/ThemeSetter.tsx b/components/ThemeManager/ThemeSetter.tsx index e97bc44b..be2763e4 100644 --- a/components/ThemeManager/ThemeSetter.tsx +++ b/components/ThemeManager/ThemeSetter.tsx @@ -543,6 +543,9 @@ export const LeafletBGPicker = (props: { e.currentTarget.value.length, ); }} + onPaste={(e) => { + console.log(e); + }} onKeyDown={(e) => { if (e.key === "Enter") { e.currentTarget.blur(); diff --git a/lexicons/src/index.ts b/lexicons/api/index.ts similarity index 100% rename from lexicons/src/index.ts rename to lexicons/api/index.ts index ad949a29..8425abf0 100644 --- a/lexicons/src/index.ts +++ b/lexicons/api/index.ts @@ -5,13 +5,13 @@ import { XrpcClient, FetchHandler, FetchHandlerOptions } from '@atproto/xrpc' import { schemas } from './lexicons.js' import { CID } from 'multiformats/cid' import { OmitKey, Un$Typed } from './util.js' +import * as PubLeafletDocument from './types/pub/leaflet/document.js' +import * as PubLeafletPost from './types/pub/leaflet/post.js' +import * as PubLeafletPublication from './types/pub/leaflet/publication.js' import * as PubLeafletBlocksHeader from './types/pub/leaflet/blocks/header.js' import * as PubLeafletBlocksImage from './types/pub/leaflet/blocks/image.js' import * as PubLeafletBlocksText from './types/pub/leaflet/blocks/text.js' -import * as PubLeafletDocument from './types/pub/leaflet/document.js' import * as PubLeafletPagesLinearDocument from './types/pub/leaflet/pages/linearDocument.js' -import * as PubLeafletPost from './types/pub/leaflet/post.js' -import * as PubLeafletPublication from './types/pub/leaflet/publication.js' import * as ComAtprotoLabelDefs from './types/com/atproto/label/defs.js' import * as ComAtprotoRepoApplyWrites from './types/com/atproto/repo/applyWrites.js' import * as ComAtprotoRepoCreateRecord from './types/com/atproto/repo/createRecord.js' @@ -26,13 +26,13 @@ import * as ComAtprotoRepoPutRecord from './types/com/atproto/repo/putRecord.js' import * as ComAtprotoRepoStrongRef from './types/com/atproto/repo/strongRef.js' import * as ComAtprotoRepoUploadBlob from './types/com/atproto/repo/uploadBlob.js' +export * as PubLeafletDocument from './types/pub/leaflet/document.js' +export * as PubLeafletPost from './types/pub/leaflet/post.js' +export * as PubLeafletPublication from './types/pub/leaflet/publication.js' export * as PubLeafletBlocksHeader from './types/pub/leaflet/blocks/header.js' export * as PubLeafletBlocksImage from './types/pub/leaflet/blocks/image.js' export * as PubLeafletBlocksText from './types/pub/leaflet/blocks/text.js' -export * as PubLeafletDocument from './types/pub/leaflet/document.js' export * as PubLeafletPagesLinearDocument from './types/pub/leaflet/pages/linearDocument.js' -export * as PubLeafletPost from './types/pub/leaflet/post.js' -export * as PubLeafletPublication from './types/pub/leaflet/publication.js' export * as ComAtprotoLabelDefs from './types/com/atproto/label/defs.js' export * as ComAtprotoRepoApplyWrites from './types/com/atproto/repo/applyWrites.js' export * as ComAtprotoRepoCreateRecord from './types/com/atproto/repo/createRecord.js' diff --git a/lexicons/src/lexicons.ts b/lexicons/api/lexicons.ts similarity index 99% rename from lexicons/src/lexicons.ts rename to lexicons/api/lexicons.ts index d0fb8c7d..cc623de7 100644 --- a/lexicons/src/lexicons.ts +++ b/lexicons/api/lexicons.ts @@ -10,6 +10,102 @@ import { import { $Typed, is$typed, maybe$typed } from './util.js' export const schemaDict = { + PubLeafletDocument: { + lexicon: 1, + id: 'pub.leaflet.document', + revision: 1, + description: 'A lexicon for long form rich media documents', + defs: { + main: { + type: 'record', + key: 'tid', + description: 'Record containing a document', + record: { + type: 'object', + required: ['pages', 'author', 'title', 'publication'], + properties: { + title: { + type: 'string', + maxLength: 128, + }, + publishedAt: { + type: 'string', + format: 'datetime', + }, + publication: { + type: 'string', + format: 'at-uri', + }, + author: { + type: 'string', + format: 'at-identifier', + }, + pages: { + type: 'array', + items: { + type: 'union', + refs: ['lex:pub.leaflet.pages.linearDocument'], + }, + }, + }, + }, + }, + }, + }, + PubLeafletPost: { + lexicon: 1, + id: 'pub.leaflet.post', + defs: { + main: { + type: 'record', + key: 'tid', + description: 'Record putting a post in a document', + record: { + type: 'object', + required: ['post', 'publishedAt'], + properties: { + publication: { + type: 'string', + format: 'at-uri', + }, + post: { + type: 'ref', + ref: 'lex:com.atproto.repo.strongRef', + }, + publishedAt: { + type: 'string', + format: 'datetime', + }, + }, + }, + }, + }, + }, + PubLeafletPublication: { + lexicon: 1, + id: 'pub.leaflet.publication', + defs: { + main: { + type: 'record', + key: 'tid', + description: 'Record declaring a publication', + record: { + type: 'object', + required: ['name'], + properties: { + name: { + type: 'string', + maxLength: 2000, + }, + description: { + type: 'string', + maxLength: 2000, + }, + }, + }, + }, + }, + }, PubLeafletBlocksHeader: { lexicon: 1, id: 'pub.leaflet.blocks.header', @@ -36,7 +132,7 @@ export const schemaDict = { defs: { main: { type: 'object', - required: ['image'], + required: ['image', 'aspectRatio'], properties: { image: { type: 'blob', @@ -83,48 +179,6 @@ export const schemaDict = { }, }, }, - PubLeafletDocument: { - lexicon: 1, - id: 'pub.leaflet.document', - revision: 1, - description: 'A lexicon for long form rich media documents', - defs: { - main: { - type: 'record', - key: 'tid', - description: 'Record containing a document', - record: { - type: 'object', - required: ['pages', 'author', 'title', 'publication'], - properties: { - title: { - type: 'string', - maxLength: 128, - }, - publishedAt: { - type: 'string', - format: 'datetime', - }, - publication: { - type: 'string', - format: 'at-uri', - }, - author: { - type: 'string', - format: 'at-identifier', - }, - pages: { - type: 'array', - items: { - type: 'union', - refs: ['lex:pub.leaflet.pages.linearDocument'], - }, - }, - }, - }, - }, - }, - }, PubLeafletPagesLinearDocument: { lexicon: 1, id: 'pub.leaflet.pages.linearDocument', @@ -174,60 +228,6 @@ export const schemaDict = { }, }, }, - PubLeafletPost: { - lexicon: 1, - id: 'pub.leaflet.post', - defs: { - main: { - type: 'record', - key: 'tid', - description: 'Record putting a post in a document', - record: { - type: 'object', - required: ['post', 'publishedAt'], - properties: { - publication: { - type: 'string', - format: 'at-uri', - }, - post: { - type: 'ref', - ref: 'lex:com.atproto.repo.strongRef', - }, - publishedAt: { - type: 'string', - format: 'datetime', - }, - }, - }, - }, - }, - }, - PubLeafletPublication: { - lexicon: 1, - id: 'pub.leaflet.publication', - defs: { - main: { - type: 'record', - key: 'tid', - description: 'Record declaring a publication', - record: { - type: 'object', - required: ['name'], - properties: { - name: { - type: 'string', - maxLength: 2000, - }, - description: { - type: 'string', - maxLength: 2000, - }, - }, - }, - }, - }, - }, ComAtprotoLabelDefs: { lexicon: 1, id: 'com.atproto.label.defs', @@ -1207,13 +1207,13 @@ export function validate( } export const ids = { + PubLeafletDocument: 'pub.leaflet.document', + PubLeafletPost: 'pub.leaflet.post', + PubLeafletPublication: 'pub.leaflet.publication', PubLeafletBlocksHeader: 'pub.leaflet.blocks.header', PubLeafletBlocksImage: 'pub.leaflet.blocks.image', PubLeafletBlocksText: 'pub.leaflet.blocks.text', - PubLeafletDocument: 'pub.leaflet.document', PubLeafletPagesLinearDocument: 'pub.leaflet.pages.linearDocument', - PubLeafletPost: 'pub.leaflet.post', - PubLeafletPublication: 'pub.leaflet.publication', ComAtprotoLabelDefs: 'com.atproto.label.defs', ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites', ComAtprotoRepoCreateRecord: 'com.atproto.repo.createRecord', diff --git a/lexicons/src/types/com/atproto/label/defs.ts b/lexicons/api/types/com/atproto/label/defs.ts similarity index 100% rename from lexicons/src/types/com/atproto/label/defs.ts rename to lexicons/api/types/com/atproto/label/defs.ts diff --git a/lexicons/src/types/com/atproto/repo/applyWrites.ts b/lexicons/api/types/com/atproto/repo/applyWrites.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/applyWrites.ts rename to lexicons/api/types/com/atproto/repo/applyWrites.ts diff --git a/lexicons/src/types/com/atproto/repo/createRecord.ts b/lexicons/api/types/com/atproto/repo/createRecord.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/createRecord.ts rename to lexicons/api/types/com/atproto/repo/createRecord.ts diff --git a/lexicons/src/types/com/atproto/repo/defs.ts b/lexicons/api/types/com/atproto/repo/defs.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/defs.ts rename to lexicons/api/types/com/atproto/repo/defs.ts diff --git a/lexicons/src/types/com/atproto/repo/deleteRecord.ts b/lexicons/api/types/com/atproto/repo/deleteRecord.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/deleteRecord.ts rename to lexicons/api/types/com/atproto/repo/deleteRecord.ts diff --git a/lexicons/src/types/com/atproto/repo/describeRepo.ts b/lexicons/api/types/com/atproto/repo/describeRepo.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/describeRepo.ts rename to lexicons/api/types/com/atproto/repo/describeRepo.ts diff --git a/lexicons/src/types/com/atproto/repo/getRecord.ts b/lexicons/api/types/com/atproto/repo/getRecord.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/getRecord.ts rename to lexicons/api/types/com/atproto/repo/getRecord.ts diff --git a/lexicons/src/types/com/atproto/repo/importRepo.ts b/lexicons/api/types/com/atproto/repo/importRepo.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/importRepo.ts rename to lexicons/api/types/com/atproto/repo/importRepo.ts diff --git a/lexicons/src/types/com/atproto/repo/listMissingBlobs.ts b/lexicons/api/types/com/atproto/repo/listMissingBlobs.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/listMissingBlobs.ts rename to lexicons/api/types/com/atproto/repo/listMissingBlobs.ts diff --git a/lexicons/src/types/com/atproto/repo/listRecords.ts b/lexicons/api/types/com/atproto/repo/listRecords.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/listRecords.ts rename to lexicons/api/types/com/atproto/repo/listRecords.ts diff --git a/lexicons/src/types/com/atproto/repo/putRecord.ts b/lexicons/api/types/com/atproto/repo/putRecord.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/putRecord.ts rename to lexicons/api/types/com/atproto/repo/putRecord.ts diff --git a/lexicons/src/types/com/atproto/repo/strongRef.ts b/lexicons/api/types/com/atproto/repo/strongRef.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/strongRef.ts rename to lexicons/api/types/com/atproto/repo/strongRef.ts diff --git a/lexicons/src/types/com/atproto/repo/uploadBlob.ts b/lexicons/api/types/com/atproto/repo/uploadBlob.ts similarity index 100% rename from lexicons/src/types/com/atproto/repo/uploadBlob.ts rename to lexicons/api/types/com/atproto/repo/uploadBlob.ts diff --git a/lexicons/src/types/pub/leaflet/blocks/header.ts b/lexicons/api/types/pub/leaflet/blocks/header.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/blocks/header.ts rename to lexicons/api/types/pub/leaflet/blocks/header.ts diff --git a/lexicons/src/types/pub/leaflet/blocks/image.ts b/lexicons/api/types/pub/leaflet/blocks/image.ts similarity index 97% rename from lexicons/src/types/pub/leaflet/blocks/image.ts rename to lexicons/api/types/pub/leaflet/blocks/image.ts index def7f6f5..e8275213 100644 --- a/lexicons/src/types/pub/leaflet/blocks/image.ts +++ b/lexicons/api/types/pub/leaflet/blocks/image.ts @@ -15,7 +15,7 @@ export interface Main { image: BlobRef /** Alt text description of the image, for accessibility. */ alt?: string - aspectRatio?: AspectRatio + aspectRatio: AspectRatio } const hashMain = 'main' diff --git a/lexicons/src/types/pub/leaflet/blocks/text.ts b/lexicons/api/types/pub/leaflet/blocks/text.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/blocks/text.ts rename to lexicons/api/types/pub/leaflet/blocks/text.ts diff --git a/lexicons/src/types/pub/leaflet/document.ts b/lexicons/api/types/pub/leaflet/document.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/document.ts rename to lexicons/api/types/pub/leaflet/document.ts diff --git a/lexicons/src/types/pub/leaflet/pages/linearDocument.ts b/lexicons/api/types/pub/leaflet/pages/linearDocument.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/pages/linearDocument.ts rename to lexicons/api/types/pub/leaflet/pages/linearDocument.ts diff --git a/lexicons/src/types/pub/leaflet/post.ts b/lexicons/api/types/pub/leaflet/post.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/post.ts rename to lexicons/api/types/pub/leaflet/post.ts diff --git a/lexicons/src/types/pub/leaflet/publication.ts b/lexicons/api/types/pub/leaflet/publication.ts similarity index 100% rename from lexicons/src/types/pub/leaflet/publication.ts rename to lexicons/api/types/pub/leaflet/publication.ts diff --git a/lexicons/src/util.ts b/lexicons/api/util.ts similarity index 100% rename from lexicons/src/util.ts rename to lexicons/api/util.ts diff --git a/lexicons/blocks.ts b/lexicons/blocks.ts deleted file mode 100644 index dcf35b08..00000000 --- a/lexicons/blocks.ts +++ /dev/null @@ -1,62 +0,0 @@ -import * as l from "./utils"; - -export const PubLeafletBlocksText = l.lexicon({ - id: "pub.leaflet.blocks.text", - defs: { - main: l.object({ - required: [], - properties: { - plaintext: l.string(), - }, - }), - }, -}); - -export const PubLeafletBlocksHeader = l.lexicon({ - id: "pub.leaflet.blocks.header", - defs: { - main: l.object({ - required: [], - properties: { - level: l.integer({ minimum: 1, maximum: 6 }), - plaintext: l.string(), - }, - }), - }, -}); - -export const PubLeafletBlocksImage = l.lexicon({ - id: "pub.leaflet.blocks.image", - defs: { - main: l.object({ - required: ["image", "aspectRatio"], - properties: { - image: l.blob({ accept: ["image/*"], maxSize: 1000000 }), - alt: { - type: "string", - description: "Alt text description of the image, for accessibility.", - }, - aspectRatio: { - type: "ref", - ref: "#aspectRatio", - }, - }, - }), - aspectRatio: l.object({ - required: ["width", "height"], - properties: { - width: l.integer(), - height: l.integer(), - }, - }), - }, -}); - -export const BlockLexicons = [ - PubLeafletBlocksText, - PubLeafletBlocksHeader, - PubLeafletBlocksImage, -]; -export const BlockUnion = l.union({ - refs: BlockLexicons.map((lexicon) => lexicon.id), -}); diff --git a/lexicons/build.ts b/lexicons/build.ts index 7d497397..ae0d7b4e 100644 --- a/lexicons/build.ts +++ b/lexicons/build.ts @@ -1,15 +1,17 @@ -import * as PageLexicons from "./pages"; -import { BlockLexicons } from "./blocks"; -import { PubLeafletDocument } from "./document"; -import * as PublicationLexicons from "./publication"; +import * as PageLexicons from "./src/pages"; +import { BlockLexicons } from "./src/blocks"; +import { PubLeafletDocument } from "./src/document"; +import * as PublicationLexicons from "./src/publication"; import * as fs from "fs"; import * as path from "path"; -import { PublicKeyPage } from "twilio/lib/rest/accounts/v1/credential/publicKey"; -const outdir = path.join("lexicons", "out"); -fs.rmSync(outdir, { recursive: true }); -fs.mkdirSync(outdir); +const outdir = path.join("lexicons", "pub", "leaflet"); + +if (fs.existsSync(outdir)) { + fs.rmSync(outdir, { recursive: true }); +} +fs.mkdirSync(outdir, { recursive: true }); const lexicons = [ PubLeafletDocument, @@ -20,6 +22,9 @@ const lexicons = [ // Write each lexicon to a file lexicons.forEach((lexicon) => { - const filename = path.join(outdir, lexicon.id.replace(/\./g, "_") + ".json"); + let id = lexicon.id.split("."); + let folder = path.join(outdir, ...id.slice(2, -1)); + if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true }); + const filename = path.join(folder, id[id.length - 1] + ".json"); fs.writeFileSync(filename, JSON.stringify(lexicon, null, 2)); }); diff --git a/lexicons/document.ts b/lexicons/document.ts deleted file mode 100644 index 964e06b2..00000000 --- a/lexicons/document.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { PubLeafletPagesLinearDocument } from "./pages/LinearDocument"; -import * as l from "./utils"; - -export const PubLeafletDocument = l.lexicon({ - id: "pub.leaflet.document", - revision: 1, - description: "A lexicon for long form rich media documents", - defs: { - main: l.record({ - key: "tid", - description: "Record containing a document", - record: l.object({ - required: ["pages", "author", "title", "publication"], - properties: { - title: l.string({ maxLength: 128 }), - publishedAt: l.string({ format: "datetime" }), - publication: l.string({ format: "at-uri" }), - author: l.string({ format: "at-identifier" }), - pages: l.array({ - items: l.union({ refs: [PubLeafletPagesLinearDocument.id] }), - }), - }, - }), - }), - }, -}); diff --git a/lexicons/pages/LinearDocument.ts b/lexicons/pages/LinearDocument.ts deleted file mode 100644 index ef2f85d1..00000000 --- a/lexicons/pages/LinearDocument.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { BlockUnion } from "../blocks"; -import * as l from "../utils"; - -const textAlignRefs = { - id: "ignore", - defs: { - textAlignLeft: l.token(), - textAlignCenter: l.token(), - textAlignRight: l.token(), - }, -}; - -export const PubLeafletPagesLinearDocument = l.lexicon({ - id: "pub.leaflet.pages.linearDocument", - defs: { - main: l.object({ - properties: { - blocks: { type: "array", items: l.ref("#block") }, - }, - }), - block: l.object({ - required: ["block"], - properties: { - block: BlockUnion, - alignment: l.string({ - knownValues: [ - l.refValue(null, "textAlignLeft"), - l.refValue(null, "textAlignCenter"), - l.refValue(null, "textAlignRight"), - ], - }), - }, - }), - ...textAlignRefs.defs, - }, -}); diff --git a/lexicons/out/pub_leaflet_blocks_header.json b/lexicons/pub/leaflet/blocks/header.json similarity index 100% rename from lexicons/out/pub_leaflet_blocks_header.json rename to lexicons/pub/leaflet/blocks/header.json diff --git a/lexicons/out/pub_leaflet_blocks_image.json b/lexicons/pub/leaflet/blocks/image.json similarity index 95% rename from lexicons/out/pub_leaflet_blocks_image.json rename to lexicons/pub/leaflet/blocks/image.json index ac6a8b74..275e4126 100644 --- a/lexicons/out/pub_leaflet_blocks_image.json +++ b/lexicons/pub/leaflet/blocks/image.json @@ -5,7 +5,8 @@ "main": { "type": "object", "required": [ - "image" + "image", + "aspectRatio" ], "properties": { "image": { diff --git a/lexicons/out/pub_leaflet_blocks_text.json b/lexicons/pub/leaflet/blocks/text.json similarity index 100% rename from lexicons/out/pub_leaflet_blocks_text.json rename to lexicons/pub/leaflet/blocks/text.json diff --git a/lexicons/out/pub_leaflet_document.json b/lexicons/pub/leaflet/document.json similarity index 100% rename from lexicons/out/pub_leaflet_document.json rename to lexicons/pub/leaflet/document.json diff --git a/lexicons/out/pub_leaflet_pages_linearDocument.json b/lexicons/pub/leaflet/pages/linearDocument.json similarity index 100% rename from lexicons/out/pub_leaflet_pages_linearDocument.json rename to lexicons/pub/leaflet/pages/linearDocument.json diff --git a/lexicons/out/pub_leaflet_post.json b/lexicons/pub/leaflet/post.json similarity index 100% rename from lexicons/out/pub_leaflet_post.json rename to lexicons/pub/leaflet/post.json diff --git a/lexicons/out/pub_leaflet_publication.json b/lexicons/pub/leaflet/publication.json similarity index 100% rename from lexicons/out/pub_leaflet_publication.json rename to lexicons/pub/leaflet/publication.json diff --git a/lexicons/publication.ts b/lexicons/publication.ts deleted file mode 100644 index 399f889a..00000000 --- a/lexicons/publication.ts +++ /dev/null @@ -1,35 +0,0 @@ -import * as l from "./utils"; -export const PubLeafletPublication = l.lexicon({ - id: "pub.leaflet.publication", - defs: { - main: l.record({ - key: "tid", - description: "Record declaring a publication", - record: l.object({ - required: ["name"], - properties: { - name: l.string({ maxLength: 2000 }), - description: l.string({ maxLength: 2000 }), - }, - }), - }), - }, -}); - -export const PubLeafletPublicationPost = l.lexicon({ - id: "pub.leaflet.post", - defs: { - main: l.record({ - key: "tid", - description: "Record putting a post in a document", - record: l.object({ - required: ["post", "publishedAt"], - properties: { - publication: l.string({ format: "at-uri" }), - post: { type: "ref", ref: "com.atproto.repo.strongRef" }, - publishedAt: { type: "string", format: "datetime" }, - }, - }), - }), - }, -}); diff --git a/lexicons/src/blocks.ts b/lexicons/src/blocks.ts new file mode 100644 index 00000000..a9c20a7f --- /dev/null +++ b/lexicons/src/blocks.ts @@ -0,0 +1,70 @@ +import { LexiconDoc, LexRefUnion } from "@atproto/lexicon"; + +export const PubLeafletBlocksText: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.blocks.text", + defs: { + main: { + type: "object", + required: [], + properties: { + plaintext: { type: "string" }, + }, + }, + }, +}; + +export const PubLeafletBlocksHeader: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.blocks.header", + defs: { + main: { + type: "object", + required: [], + properties: { + level: { type: "integer", minimum: 1, maximum: 6 }, + plaintext: { type: "string" }, + }, + }, + }, +}; + +export const PubLeafletBlocksImage: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.blocks.image", + defs: { + main: { + type: "object", + required: ["image", "aspectRatio"], + properties: { + image: { type: "blob", accept: ["image/*"], maxSize: 1000000 }, + alt: { + type: "string", + description: "Alt text description of the image, for accessibility.", + }, + aspectRatio: { + type: "ref", + ref: "#aspectRatio", + }, + }, + }, + aspectRatio: { + type: "object", + required: ["width", "height"], + properties: { + width: { type: "integer" }, + height: { type: "integer" }, + }, + }, + }, +}; + +export const BlockLexicons = [ + PubLeafletBlocksText, + PubLeafletBlocksHeader, + PubLeafletBlocksImage, +]; +export const BlockUnion: LexRefUnion = { + type: "union", + refs: BlockLexicons.map((lexicon) => lexicon.id), +}; diff --git a/lexicons/src/document.ts b/lexicons/src/document.ts new file mode 100644 index 00000000..20a07c0b --- /dev/null +++ b/lexicons/src/document.ts @@ -0,0 +1,33 @@ +import { LexiconDoc } from "@atproto/lexicon"; +import { PubLeafletPagesLinearDocument } from "./pages/LinearDocument"; + +export const PubLeafletDocument: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.document", + revision: 1, + description: "A lexicon for long form rich media documents", + defs: { + main: { + type: "record", + key: "tid", + description: "Record containing a document", + record: { + type: "object", + required: ["pages", "author", "title", "publication"], + properties: { + title: { type: "string", maxLength: 128 }, + publishedAt: { type: "string", format: "datetime" }, + publication: { type: "string", format: "at-uri" }, + author: { type: "string", format: "at-identifier" }, + pages: { + type: "array", + items: { + type: "union", + refs: [PubLeafletPagesLinearDocument.id], + }, + }, + }, + }, + }, + }, +}; diff --git a/lexicons/src/pages/LinearDocument.ts b/lexicons/src/pages/LinearDocument.ts new file mode 100644 index 00000000..873e1afb --- /dev/null +++ b/lexicons/src/pages/LinearDocument.ts @@ -0,0 +1,33 @@ +import { LexiconDoc } from "@atproto/lexicon"; +import { BlockUnion } from "../blocks"; + +export const PubLeafletPagesLinearDocument: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.pages.linearDocument", + defs: { + main: { + type: "object", + properties: { + blocks: { type: "array", items: { type: "ref", ref: "#block" } }, + }, + }, + block: { + type: "object", + required: ["block"], + properties: { + block: BlockUnion, + alignment: { + type: "string", + knownValues: [ + "#textAlignLeft", + "#textAlignCenter", + "#textAlignRight", + ], + }, + }, + }, + textAlignLeft: { type: "token" }, + textAlignCenter: { type: "token" }, + textAlignRight: { type: "token" }, + }, +}; diff --git a/lexicons/pages/index.ts b/lexicons/src/pages/index.ts similarity index 100% rename from lexicons/pages/index.ts rename to lexicons/src/pages/index.ts diff --git a/lexicons/src/publication.ts b/lexicons/src/publication.ts new file mode 100644 index 00000000..5fb9ce6c --- /dev/null +++ b/lexicons/src/publication.ts @@ -0,0 +1,42 @@ +import { LexiconDoc } from "@atproto/lexicon"; + +export const PubLeafletPublication: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.publication", + defs: { + main: { + type: "record", + key: "tid", + description: "Record declaring a publication", + record: { + type: "object", + required: ["name"], + properties: { + name: { type: "string", maxLength: 2000 }, + description: { type: "string", maxLength: 2000 }, + }, + }, + }, + }, +}; + +export const PubLeafletPublicationPost: LexiconDoc = { + lexicon: 1, + id: "pub.leaflet.post", + defs: { + main: { + type: "record", + key: "tid", + description: "Record putting a post in a document", + record: { + type: "object", + required: ["post", "publishedAt"], + properties: { + publication: { type: "string", format: "at-uri" }, + post: { type: "ref", ref: "com.atproto.repo.strongRef" }, + publishedAt: { type: "string", format: "datetime" }, + }, + }, + }, + }, +}; diff --git a/lexicons/utils.ts b/lexicons/utils.ts deleted file mode 100644 index 04b3b495..00000000 --- a/lexicons/utils.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { - LexArray, - // lexPrimitive - LexBoolean, - LexInteger, - LexString, - LexUnknown, - // lexIpldType - LexBytes, - LexCidLink, - // lexRefVariant - LexRef, - LexRefUnion, - // other - LexBlob, - lexRecord, - LexRecord, - LexObject, - LexiconDoc, - LexToken, -} from "@atproto/lexicon"; - -export const refValue = >( - l: T | null, - k?: keyof T["defs"] & string, -) => { - //Could improve this somehow, to ensure you have to pass in K if l is null? - if (l === null) return `#${k}` || ""; - return k ? `${l.id}#k` : l.id; -}; - -export const lexicon = (args: T) => { - return { - lexicon: 1, - ...args, - }; -}; - -export const record = ( - args: Omit & { - key: "tid" | "nsid" | `literal:${string}` | "any"; - }, -): LexRecord => ({ - type: "record", - ...args, -}); - -export const string = (args?: Omit) => - ({ type: "string", ...args }) as const; -export const token = (l?: { description: string }): LexToken => ({ - type: "token", - description: l?.description, -}); - -export const integer = (args?: Omit) => - ({ - type: "integer", - ...args, - }) as const; - -export const ref = (ref: string): LexRef => ({ type: "ref", ref }); - -export const array = (args: Omit): LexArray => ({ - type: "array", - ...args, -}); - -export const object = < - Properties extends { - [k: string]: - | LexArray - // lexPrimitive - | LexBoolean - | LexInteger - | LexString - | LexUnknown - // lexIpldType - | LexBytes - | LexCidLink - // lexRefVariant - | LexRef - | LexRefUnion - // other - | LexBlob; - }, - Required extends (keyof Properties & string)[], ->( - args: Omit & { - properties: Properties; - required?: Required; - }, -): LexObject => ({ - type: "object", - ...args, -}); - -export const blob = (args: Omit): LexBlob => ({ - type: "blob", - ...args, -}); -export const union = (args: Omit): LexRefUnion => ({ - type: "union", - ...args, -}); diff --git a/package.json b/package.json index 97397c73..ab61dd5b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "dev": "next dev", - "lexgen": "tsx ./lexicons/build.ts && lex gen-api ./lexicons/src ./lexicons/out/* ./lexicons/com/atproto/*/* --yes", + "lexgen": "tsx ./lexicons/build.ts && lex gen-api ./lexicons/api ./lexicons/pub/leaflet/* ./lexicons/pub/leaflet/*/* ./lexicons/com/atproto/*/* --yes", "wrangler-dev": "wrangler dev", "start-appview": "tsx --env-file='./.env.local' --watch appview/index.ts" },