From 33757e9d5f1ae78cc73890910c74a875752d7582 Mon Sep 17 00:00:00 2001 From: Christopher Hlubek Date: Thu, 8 Feb 2024 10:38:02 +0100 Subject: [PATCH] Import React types properly --- src/lib/components/ContentCollectionProvider.tsx | 6 +++--- src/lib/components/ContentComponent.tsx | 4 +++- src/server/components/ContentCollection.tsx | 3 +-- src/server/components/ContentCollectionProvider.tsx | 13 +++++++------ src/server/components/ContentComponent.tsx | 4 +++- src/server/components/ContentComponentProvider.tsx | 13 +++++++------ src/server/components/Editable.tsx | 10 ++++------ src/server/utils/nodeTypes.ts | 4 +++- src/types/index.ts | 4 +++- tsconfig.json | 6 +----- 10 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/lib/components/ContentCollectionProvider.tsx b/src/lib/components/ContentCollectionProvider.tsx index 55eef36..99d0d25 100644 --- a/src/lib/components/ContentCollectionProvider.tsx +++ b/src/lib/components/ContentCollectionProvider.tsx @@ -1,4 +1,4 @@ -import { useContext } from 'react'; +import { ReactNode, useContext } from 'react'; import NeosContext from '../../utils/context'; import { useContentCollection } from '../../utils/hooks'; @@ -11,8 +11,8 @@ type ContentCollectionProviderProps = { children, }: { collectionProps: Record; - children: React.ReactNode; - }) => React.ReactNode; + children: ReactNode; + }) => ReactNode; }; export default function ContentCollectionProvider({ nodeName, children }: ContentCollectionProviderProps) { diff --git a/src/lib/components/ContentComponent.tsx b/src/lib/components/ContentComponent.tsx index f521ddc..13c8122 100644 --- a/src/lib/components/ContentComponent.tsx +++ b/src/lib/components/ContentComponent.tsx @@ -1,8 +1,10 @@ +import { ReactNode } from 'react'; + import { useContentComponent } from '../../utils/hooks'; type ContentComponentProps = { as?: keyof JSX.IntrinsicElements; - children: React.ReactNode; + children: ReactNode; [x: string]: any; }; diff --git a/src/server/components/ContentCollection.tsx b/src/server/components/ContentCollection.tsx index ec49423..5318b2d 100644 --- a/src/server/components/ContentCollection.tsx +++ b/src/server/components/ContentCollection.tsx @@ -1,5 +1,4 @@ import { ContextProps } from '../../types'; -import { useInBackend } from '../utils/hooks'; import ContentCollectionProvider from './ContentCollectionProvider'; type ContentCollectionProps = { @@ -10,7 +9,7 @@ type ContentCollectionProps = { }; const ContentCollection = async ({ ctx, as = 'div', nodeName, ...rest }: ContentCollectionProps) => { - const inBackend = useInBackend(ctx); + const inBackend = ctx.inBackend; const { className, ...restAttributes } = rest; const Component = as; diff --git a/src/server/components/ContentCollectionProvider.tsx b/src/server/components/ContentCollectionProvider.tsx index ebb0485..770010f 100644 --- a/src/server/components/ContentCollectionProvider.tsx +++ b/src/server/components/ContentCollectionProvider.tsx @@ -1,6 +1,7 @@ +import { ReactNode } from 'react'; + import { ContextProps } from '../../types'; -import { useInBackend } from '../utils/hooks'; -import { useContentCollection } from '../utils/hooks'; +import { withContentCollection } from '../utils/hooks'; import ContentComponentIncludes from './client/ContentComponentIncludes'; import NodeRenderer from './NodeRenderer'; @@ -12,13 +13,13 @@ type ContentCollectionProviderProps = { children, }: { collectionProps: Record; - children: React.ReactNode; - }) => React.ReactNode; + children: ReactNode; + }) => ReactNode; }; const ContentCollectionProvider = async ({ ctx, nodeName, children }: ContentCollectionProviderProps) => { - const inBackend = useInBackend(ctx); - const { collectionNode, collectionProps } = await useContentCollection(ctx, nodeName)(); + const inBackend = ctx.inBackend; + const { collectionNode, collectionProps } = await withContentCollection(ctx, nodeName); if (!collectionNode) { return null; diff --git a/src/server/components/ContentComponent.tsx b/src/server/components/ContentComponent.tsx index f13cd80..e60b6b1 100644 --- a/src/server/components/ContentComponent.tsx +++ b/src/server/components/ContentComponent.tsx @@ -1,10 +1,12 @@ +import { ReactNode } from 'react'; + import { ContextProps } from '../../types'; import ContentComponentProvider from './ContentComponentProvider'; type ContentComponentProps = { ctx: ContextProps; as?: keyof JSX.IntrinsicElements; - children: React.ReactNode; + children: ReactNode; [x: string]: any; }; diff --git a/src/server/components/ContentComponentProvider.tsx b/src/server/components/ContentComponentProvider.tsx index 0765a55..09fad49 100644 --- a/src/server/components/ContentComponentProvider.tsx +++ b/src/server/components/ContentComponentProvider.tsx @@ -1,6 +1,7 @@ +import { ReactNode } from 'react'; + import { ContextProps } from '../../types'; -import { useInBackend } from '../utils/hooks'; -import { useContentComponent } from '../utils/hooks'; +import { withContentComponent } from '../utils/hooks'; import ContentComponentIncludes from './client/ContentComponentIncludes'; type ContentComponentProviderProps = { @@ -10,13 +11,13 @@ type ContentComponentProviderProps = { includes, }: { componentProps: Record; - includes: React.ReactNode; - }) => React.ReactNode; + includes: ReactNode; + }) => ReactNode; }; const ContentComponentProvider = async ({ ctx, children }: ContentComponentProviderProps) => { - const inBackend = useInBackend(ctx); - const { componentNode, componentProps } = await useContentComponent(ctx)(); + const inBackend = ctx.inBackend; + const { componentNode, componentProps } = await withContentComponent(ctx); if (!componentNode) { return null; diff --git a/src/server/components/Editable.tsx b/src/server/components/Editable.tsx index 57f296e..b18793d 100644 --- a/src/server/components/Editable.tsx +++ b/src/server/components/Editable.tsx @@ -1,5 +1,5 @@ import { ContextProps } from '../../types'; -import { useEditPreviewMode, useInBackend, useNode } from '../utils/hooks'; +import { withEditPreviewMode, withNode } from '../utils/hooks'; type EditableProps = { ctx: ContextProps; @@ -9,12 +9,10 @@ type EditableProps = { }; const Editable = async ({ ctx, as = 'div', property, ...rest }: EditableProps) => { - const inBackend = useInBackend(ctx); - const loadNode = useNode(ctx); - const loadEditPreviewMode = useEditPreviewMode(ctx); + const inBackend = ctx.inBackend; - const node = await loadNode(); - const editPreviewMode = await loadEditPreviewMode(); + const node = await withNode(ctx); + const editPreviewMode = await withEditPreviewMode(ctx); if (!node) { return null; diff --git a/src/server/utils/nodeTypes.ts b/src/server/utils/nodeTypes.ts index ac1f6e7..56ee4ee 100644 --- a/src/server/utils/nodeTypes.ts +++ b/src/server/utils/nodeTypes.ts @@ -1,3 +1,5 @@ +import { FC } from 'react'; + import { ContextProps, NeosNodeTypes } from '../../types'; let nodeTypes: NeosNodeTypes; @@ -6,6 +8,6 @@ export function initNodeTypes(data: NeosNodeTypes) { nodeTypes = data; } -export function getNodeType(nodeTypeName: string): React.FC<{ ctx: ContextProps }> | undefined { +export function getNodeType(nodeTypeName: string): FC<{ ctx: ContextProps }> | undefined { return nodeTypes?.[nodeTypeName]; } diff --git a/src/types/index.ts b/src/types/index.ts index dc6fb17..7dec840 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,5 @@ +import { FC } from 'react'; + declare global { interface Document { __isInitialized?: boolean; @@ -80,7 +82,7 @@ export interface BackendEditPreviewMode { options: Record | null; } -export type NeosNodeTypes = Record>; +export type NeosNodeTypes = Record>; export interface NeosContextProps { node: NeosContentNode; diff --git a/tsconfig.json b/tsconfig.json index ede3c0a..4f97f5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,11 +15,7 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "outDir": ".", - "rootDir": "src", - "paths": { - "next": ["node_modules/next"], - "react": ["node_modules/react"] - } + "rootDir": "src" }, "include": ["src/**/*"], "exclude": ["./*.js", "./*.d.ts"]