Skip to content

Commit

Permalink
Import React types properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hlubek committed Feb 8, 2024
1 parent 65588ca commit 33757e9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/lib/components/ContentCollectionProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react';
import { ReactNode, useContext } from 'react';

import NeosContext from '../../utils/context';
import { useContentCollection } from '../../utils/hooks';
Expand All @@ -11,8 +11,8 @@ type ContentCollectionProviderProps = {
children,
}: {
collectionProps: Record<string, string | boolean | undefined>;
children: React.ReactNode;
}) => React.ReactNode;
children: ReactNode;
}) => ReactNode;
};

export default function ContentCollectionProvider({ nodeName, children }: ContentCollectionProviderProps) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/ContentComponent.tsx
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down
3 changes: 1 addition & 2 deletions src/server/components/ContentCollection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ContextProps } from '../../types';
import { useInBackend } from '../utils/hooks';
import ContentCollectionProvider from './ContentCollectionProvider';

type ContentCollectionProps = {
Expand All @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions src/server/components/ContentCollectionProvider.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -12,13 +13,13 @@ type ContentCollectionProviderProps = {
children,
}: {
collectionProps: Record<string, string | boolean | undefined>;
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;
Expand Down
4 changes: 3 additions & 1 deletion src/server/components/ContentComponent.tsx
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down
13 changes: 7 additions & 6 deletions src/server/components/ContentComponentProvider.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -10,13 +11,13 @@ type ContentComponentProviderProps = {
includes,
}: {
componentProps: Record<string, string | boolean | undefined>;
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;
Expand Down
10 changes: 4 additions & 6 deletions src/server/components/Editable.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/server/utils/nodeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FC } from 'react';

import { ContextProps, NeosNodeTypes } from '../../types';

let nodeTypes: NeosNodeTypes;
Expand All @@ -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];
}
4 changes: 3 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FC } from 'react';

declare global {
interface Document {
__isInitialized?: boolean;
Expand Down Expand Up @@ -80,7 +82,7 @@ export interface BackendEditPreviewMode {
options: Record<string, any> | null;
}

export type NeosNodeTypes = Record<string, React.FC<{ ctx: ContextProps }>>;
export type NeosNodeTypes = Record<string, FC<{ ctx: ContextProps }>>;

export interface NeosContextProps {
node: NeosContentNode;
Expand Down
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 33757e9

Please sign in to comment.