-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added README.md and added initial functionality for inline fields.
- Loading branch information
Showing
8 changed files
with
262 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
export * from "./fields/AbstractField"; | ||
export * from "./lib/createDirectusClient"; | ||
export * from "./react/DirectusProvider"; | ||
export * from "./react/AuthProvider"; | ||
export * from "./react/DirectusProvider"; | ||
export * from "./react/useDirectusFields"; | ||
export * from "./react/usePreview"; | ||
export * from "./tina/InlineFields/PreviewInlineText"; | ||
export * from "./tina/InlineFields/PreviewInlineWysiwyg"; | ||
export * from "./tina/Tina"; | ||
export * from "./fields/AbstractField"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { createContext, useContext } from "react"; | ||
import React, { createContext, useContext } from "react"; | ||
|
||
export const PreviewContext = createContext<boolean>(false); | ||
const PreviewContext = createContext<boolean>(null); | ||
|
||
export function usePreview() { | ||
const preview = useContext(PreviewContext); | ||
|
||
if(preview === null) { | ||
throw('No PreviewContext found') | ||
} | ||
return preview; | ||
} | ||
|
||
export function PreviewProvider({ | ||
children, | ||
value, | ||
}: { | ||
children?: React.ReactNode; | ||
value: boolean; | ||
}) { | ||
return ( | ||
<PreviewContext.Provider value={value}>{children}</PreviewContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { InlineText as default } from "react-tinacms-inline"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useEffect } from "react"; | ||
import { usePreview } from "src/react/usePreview"; | ||
|
||
export function PreviewInlineText({ | ||
children, | ||
name, | ||
}: { | ||
name: string; | ||
children: React.ReactNode; | ||
}) { | ||
const preview = usePreview(); | ||
const [InlineText, setInlineText] = React.useState<JSX.Element>(); | ||
useEffect(() => { | ||
if (!InlineText && preview) { | ||
import("react-tinacms-inline").then(({ InlineText }) => | ||
setInlineText(<InlineText name={name}/>) | ||
); | ||
} | ||
}, [preview]); | ||
|
||
if (InlineText && preview) { | ||
return InlineText | ||
} | ||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useEffect } from "react"; | ||
import { usePreview } from "src/react/usePreview"; | ||
|
||
export function PreviewInlineWysiwyg({ | ||
children, | ||
name, | ||
format, | ||
}: { | ||
name: string; | ||
children: React.ReactNode; | ||
format: "html" | "markdown"; | ||
}) { | ||
const preview = usePreview(); | ||
const [InlineWysiwyg, setInlineWysiwyg] = React.useState<JSX.Element>(); | ||
useEffect(() => { | ||
if (!InlineWysiwyg && preview) { | ||
import("react-tinacms-editor").then(({ InlineWysiwyg }) => | ||
setInlineWysiwyg( | ||
<InlineWysiwyg name={name} format={format}> | ||
{children} | ||
</InlineWysiwyg> | ||
) | ||
); | ||
} | ||
}, [preview]); | ||
|
||
if (InlineWysiwyg && preview) { | ||
return InlineWysiwyg; | ||
} | ||
return <>{children}</>; | ||
} |