From 71ee061f2ebcb1ac9d7cdf40acf0d4b616497f6e Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Tue, 9 Jul 2024 22:54:47 -0400 Subject: [PATCH] move block components to blocks folder --- app/[doc_id]/Doc.tsx | 2 +- app/[doc_id]/page.tsx | 2 +- components/{ => Blocks}/BlockOptions.tsx | 10 +-- components/{ => Blocks}/CardBlock.tsx | 2 +- components/{ => Blocks}/ExternalLinkBlock.tsx | 2 +- components/{ => Blocks}/ImageBlock.tsx | 6 +- .../TextBlock/RenderYJSFragment.tsx | 2 +- components/{ => Blocks}/TextBlock/index.tsx | 2 +- components/{ => Blocks}/TextBlock/keymap.ts | 0 components/{ => Blocks}/TextBlock/schema.ts | 2 +- .../{ => Blocks}/TextBlock/useHandlePaste.ts | 0 components/{Blocks.tsx => Blocks/index.tsx} | 4 +- components/Cards.tsx | 2 +- components/LinkBlock.tsx | 84 ------------------- components/Toolbar/HighlightButton.tsx | 2 +- components/Toolbar/LinkButton.tsx | 2 +- components/Toolbar/index.tsx | 2 +- components/utils/UpdatePageTitle.tsx | 2 +- src/utils/getBlocksAsHTML.tsx | 2 +- src/utils/prosemirror/rangeHasMark.ts | 2 +- 20 files changed, 24 insertions(+), 108 deletions(-) rename components/{ => Blocks}/BlockOptions.tsx (96%) rename components/{ => Blocks}/CardBlock.tsx (98%) rename components/{ => Blocks}/ExternalLinkBlock.tsx (97%) rename components/{ => Blocks}/ImageBlock.tsx (90%) rename components/{ => Blocks}/TextBlock/RenderYJSFragment.tsx (98%) rename components/{ => Blocks}/TextBlock/index.tsx (99%) rename components/{ => Blocks}/TextBlock/keymap.ts (100%) rename components/{ => Blocks}/TextBlock/schema.ts (98%) rename components/{ => Blocks}/TextBlock/useHandlePaste.ts (100%) rename components/{Blocks.tsx => Blocks/index.tsx} (98%) delete mode 100644 components/LinkBlock.tsx diff --git a/app/[doc_id]/Doc.tsx b/app/[doc_id]/Doc.tsx index d42d1edf..c1a175d9 100644 --- a/app/[doc_id]/Doc.tsx +++ b/app/[doc_id]/Doc.tsx @@ -7,7 +7,7 @@ import { Cards } from "components/Cards"; import { ThemeProvider } from "components/ThemeManager/ThemeProvider"; import { MobileFooter } from "components/MobileFooter"; import { PopUpProvider } from "components/Toast"; -import { YJSFragmentToString } from "components/TextBlock/RenderYJSFragment"; +import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment"; import { EntitySetContext, EntitySetProvider, diff --git a/app/[doc_id]/page.tsx b/app/[doc_id]/page.tsx index b85b821e..24c2565b 100644 --- a/app/[doc_id]/page.tsx +++ b/app/[doc_id]/page.tsx @@ -11,7 +11,7 @@ import { Cards } from "components/Cards"; import { ThemeProvider } from "components/ThemeManager/ThemeProvider"; import { MobileFooter } from "components/MobileFooter"; import { PopUpProvider } from "components/Toast"; -import { YJSFragmentToString } from "components/TextBlock/RenderYJSFragment"; +import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment"; import { Doc } from "./Doc"; export const preferredRegion = ["sfo1"]; diff --git a/components/BlockOptions.tsx b/components/Blocks/BlockOptions.tsx similarity index 96% rename from components/BlockOptions.tsx rename to components/Blocks/BlockOptions.tsx index 937d0f69..09af4b98 100644 --- a/components/BlockOptions.tsx +++ b/components/Blocks/BlockOptions.tsx @@ -6,16 +6,16 @@ import { BlockLinkSmall, CheckTiny, CloseTiny, -} from "./Icons"; +} from "components/Icons"; import { generateKeyBetween } from "fractional-indexing"; import { addImage } from "src/utils/addImage"; -import { focusCard } from "./Cards"; +import { focusCard } from "components/Cards"; import { useState } from "react"; -import { Separator } from "./Layout"; +import { Separator } from "components/Layout"; import { addLinkBlock } from "src/utils/addLinkBlock"; -import { useEntitySetContext } from "./EntitySetProvider"; +import { useEntitySetContext } from "components/EntitySetProvider"; import { v7 } from "uuid"; -import { Input } from "./Input"; +import { Input } from "components/Input"; type Props = { parent: string; diff --git a/components/CardBlock.tsx b/components/Blocks/CardBlock.tsx similarity index 98% rename from components/CardBlock.tsx rename to components/Blocks/CardBlock.tsx index 5e172ff9..cf8af8e0 100644 --- a/components/CardBlock.tsx +++ b/components/Blocks/CardBlock.tsx @@ -2,7 +2,7 @@ import { BlockProps } from "components/Blocks"; import { focusCard } from "components/Cards"; import { useEntity, useReplicache } from "src/replicache"; import { useUIState } from "src/useUIState"; -import { RenderedTextBlock } from "./TextBlock"; +import { RenderedTextBlock } from "components/Blocks/TextBlock"; import { useDocMetadata } from "src/hooks/queries/useDocMetadata"; export function CardBlock(props: BlockProps) { diff --git a/components/ExternalLinkBlock.tsx b/components/Blocks/ExternalLinkBlock.tsx similarity index 97% rename from components/ExternalLinkBlock.tsx rename to components/Blocks/ExternalLinkBlock.tsx index 544de85d..efe20871 100644 --- a/components/ExternalLinkBlock.tsx +++ b/components/Blocks/ExternalLinkBlock.tsx @@ -1,5 +1,5 @@ import { useEntity } from "src/replicache"; -import { CloseTiny } from "./Icons"; +import { CloseTiny } from "components/Icons"; export const ExternalLinkBlock = (props: { entityID: string }) => { let previewImage = useEntity(props.entityID, "link/preview"); diff --git a/components/ImageBlock.tsx b/components/Blocks/ImageBlock.tsx similarity index 90% rename from components/ImageBlock.tsx rename to components/Blocks/ImageBlock.tsx index 9e0d0580..bbb10580 100644 --- a/components/ImageBlock.tsx +++ b/components/Blocks/ImageBlock.tsx @@ -1,12 +1,12 @@ "use client"; import { useEntity, useReplicache } from "src/replicache"; -import { BlockProps } from "./Blocks"; +import { BlockProps } from "components/Blocks"; import { useUIState } from "src/useUIState"; import { theme } from "tailwind.config"; -import { CloseContrastSmall } from "./Icons"; +import { CloseContrastSmall } from "components/Icons"; import useMeasure from "react-use-measure"; -import { useEntitySetContext } from "./EntitySetProvider"; +import { useEntitySetContext } from "components/EntitySetProvider"; export function ImageBlock(props: BlockProps) { let { rep, permission_token } = useReplicache(); diff --git a/components/TextBlock/RenderYJSFragment.tsx b/components/Blocks/TextBlock/RenderYJSFragment.tsx similarity index 98% rename from components/TextBlock/RenderYJSFragment.tsx rename to components/Blocks/TextBlock/RenderYJSFragment.tsx index 3ff74aa7..08c04c98 100644 --- a/components/TextBlock/RenderYJSFragment.tsx +++ b/components/Blocks/TextBlock/RenderYJSFragment.tsx @@ -1,7 +1,7 @@ import { XmlElement, XmlHook, XmlText } from "yjs"; import { nodes, marks } from "prosemirror-schema-basic"; import { CSSProperties } from "react"; -import { theme } from "../../tailwind.config"; +import { theme } from "tailwind.config"; export function RenderYJSFragment({ node, diff --git a/components/TextBlock/index.tsx b/components/Blocks/TextBlock/index.tsx similarity index 99% rename from components/TextBlock/index.tsx rename to components/Blocks/TextBlock/index.tsx index e4509fcf..971be695 100644 --- a/components/TextBlock/index.tsx +++ b/components/Blocks/TextBlock/index.tsx @@ -31,7 +31,7 @@ import { useUIState } from "src/useUIState"; import { MarkType, DOMParser as ProsemirrorDOMParser } from "prosemirror-model"; import { useAppEventListener } from "src/eventBus"; import { addLinkBlock } from "src/utils/addLinkBlock"; -import { BlockOptions } from "components/BlockOptions"; +import { BlockOptions } from "components/Blocks/BlockOptions"; import { setEditorState, useEditorStates } from "src/state/useEditorState"; import { isIOS } from "@react-aria/utils"; import { useIsMobile } from "src/hooks/isMobile"; diff --git a/components/TextBlock/keymap.ts b/components/Blocks/TextBlock/keymap.ts similarity index 100% rename from components/TextBlock/keymap.ts rename to components/Blocks/TextBlock/keymap.ts diff --git a/components/TextBlock/schema.ts b/components/Blocks/TextBlock/schema.ts similarity index 98% rename from components/TextBlock/schema.ts rename to components/Blocks/TextBlock/schema.ts index 65ce1b13..ffd17266 100644 --- a/components/TextBlock/schema.ts +++ b/components/Blocks/TextBlock/schema.ts @@ -1,6 +1,6 @@ import { Schema, Node, MarkSpec } from "prosemirror-model"; import { marks } from "prosemirror-schema-basic"; -import { theme } from "../../tailwind.config"; +import { theme } from "tailwind.config"; let baseSchema = { marks: { diff --git a/components/TextBlock/useHandlePaste.ts b/components/Blocks/TextBlock/useHandlePaste.ts similarity index 100% rename from components/TextBlock/useHandlePaste.ts rename to components/Blocks/TextBlock/useHandlePaste.ts diff --git a/components/Blocks.tsx b/components/Blocks/index.tsx similarity index 98% rename from components/Blocks.tsx rename to components/Blocks/index.tsx index 3a3dd5b6..73ad598e 100644 --- a/components/Blocks.tsx +++ b/components/Blocks/index.tsx @@ -1,6 +1,6 @@ "use client"; import { Fact, useEntity, useReplicache } from "src/replicache"; -import { TextBlock } from "components/TextBlock"; +import { TextBlock } from "components/Blocks/TextBlock"; import { generateKeyBetween } from "fractional-indexing"; import { useEffect } from "react"; import { elementId } from "src/utils/elementId"; @@ -13,7 +13,7 @@ import { ExternalLinkBlock } from "./ExternalLinkBlock"; import { BlockOptions } from "./BlockOptions"; import { useBlocks } from "src/hooks/queries/useBlocks"; import { setEditorState, useEditorStates } from "src/state/useEditorState"; -import { useEntitySetContext } from "./EntitySetProvider"; +import { useEntitySetContext } from "components/EntitySetProvider"; import { scanIndex } from "src/replicache/utils"; import { v7 } from "uuid"; diff --git a/components/Cards.tsx b/components/Cards.tsx index 0fb325f4..66cd826a 100644 --- a/components/Cards.tsx +++ b/components/Cards.tsx @@ -1,6 +1,6 @@ "use client"; import { useUIState } from "src/useUIState"; -import { Blocks, focusBlock } from "./Blocks"; +import { Blocks, focusBlock } from "components/Blocks"; import useMeasure from "react-use-measure"; import { elementId } from "src/utils/elementId"; import { ThemePopover } from "./ThemeManager/ThemeSetter"; diff --git a/components/LinkBlock.tsx b/components/LinkBlock.tsx deleted file mode 100644 index 185cf41c..00000000 --- a/components/LinkBlock.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { useState } from "react"; -import { CloseContrastSmall, CloseTiny } from "./Icons"; -import { theme } from "tailwind.config"; - -type linkType = { - url: string; - title?: string | null; - description?: string | null; - image?: { - url: string; - width: number; - height: number; - } | null; - logo?: { - url: string; - width?: number; - height?: number; - } | null; - author?: string | null; -}; - -export const ExternalLinkBlock = () => { - let [title, setTitle] = useState("Title"); - let [description, setDescription] = useState( - "hello, this is a little description. I want it to be a little bit long so that I can see if it wrapping around but it thought it was long enought and it wasn't actually so im adding a little more on", - ); - let [link, setLink] = useState({ - url: "www.hello.com", - title: "Title", - description: "hi I'm a description", - image: { - url: "/", - width: 64, - height: 64, - }, - logo: { - url: "/", - width: 64, - height: 64, - }, - author: "me", - }); - - return ( - -
- -
-
- {link.title} -
-
- {link.description} -
-
-
- {link.url} -
-
- -
- - ); -}; diff --git a/components/Toolbar/HighlightButton.tsx b/components/Toolbar/HighlightButton.tsx index e83f5e56..e9453c47 100644 --- a/components/Toolbar/HighlightButton.tsx +++ b/components/Toolbar/HighlightButton.tsx @@ -1,6 +1,6 @@ import { setEditorState, useEditorStates } from "src/state/useEditorState"; import { useUIState } from "src/useUIState"; -import { schema } from "components/TextBlock/schema"; +import { schema } from "components/Blocks/TextBlock/schema"; import { TextSelection } from "prosemirror-state"; import { toggleMarkInFocusedBlock } from "./TextDecorationButton"; import * as Popover from "@radix-ui/react-popover"; diff --git a/components/Toolbar/LinkButton.tsx b/components/Toolbar/LinkButton.tsx index 4e17be8e..5ec7d9d2 100644 --- a/components/Toolbar/LinkButton.tsx +++ b/components/Toolbar/LinkButton.tsx @@ -1,4 +1,4 @@ -import { schema } from "components/TextBlock/schema"; +import { schema } from "components/Blocks/TextBlock/schema"; import { EditorState, TextSelection } from "prosemirror-state"; import { useUIState } from "src/useUIState"; import { ToolbarButton } from "."; diff --git a/components/Toolbar/index.tsx b/components/Toolbar/index.tsx index d4475b9d..2708ea51 100644 --- a/components/Toolbar/index.tsx +++ b/components/Toolbar/index.tsx @@ -21,7 +21,7 @@ import { } from "components/Icons"; import { create } from "zustand"; import { combine } from "zustand/middleware"; -import { schema } from "components/TextBlock/schema"; +import { schema } from "components/Blocks/TextBlock/schema"; import { TextDecorationButton } from "./TextDecorationButton"; import { TextBlockTypeButton, diff --git a/components/utils/UpdatePageTitle.tsx b/components/utils/UpdatePageTitle.tsx index e2d57ec5..2c46f952 100644 --- a/components/utils/UpdatePageTitle.tsx +++ b/components/utils/UpdatePageTitle.tsx @@ -5,7 +5,7 @@ import { useBlocks } from "src/hooks/queries/useBlocks"; import { useEntity } from "src/replicache"; import * as Y from "yjs"; import * as base64 from "base64-js"; -import { YJSFragmentToString } from "components/TextBlock/RenderYJSFragment"; +import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment"; export function UpdatePageTitle(props: { entityID: string }) { let blocks = useBlocks(props.entityID).filter( diff --git a/src/utils/getBlocksAsHTML.tsx b/src/utils/getBlocksAsHTML.tsx index ddb07491..c63be24b 100644 --- a/src/utils/getBlocksAsHTML.tsx +++ b/src/utils/getBlocksAsHTML.tsx @@ -4,7 +4,7 @@ import { scanIndex } from "src/replicache/utils"; import { renderToStaticMarkup } from "react-dom/server"; import * as Y from "yjs"; import * as base64 from "base64-js"; -import { RenderYJSFragment } from "components/TextBlock/RenderYJSFragment"; +import { RenderYJSFragment } from "components/Blocks/TextBlock/RenderYJSFragment"; import { Block } from "components/Blocks"; export async function getBlocksAsHTML( diff --git a/src/utils/prosemirror/rangeHasMark.ts b/src/utils/prosemirror/rangeHasMark.ts index 4eec5ba9..9aa5b128 100644 --- a/src/utils/prosemirror/rangeHasMark.ts +++ b/src/utils/prosemirror/rangeHasMark.ts @@ -1,4 +1,4 @@ -import { schema } from "components/TextBlock/schema"; +import { schema } from "components/Blocks/TextBlock/schema"; import { Mark, MarkType } from "prosemirror-model"; import { EditorState } from "prosemirror-state"; -- 2.51.2