-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Create + Another" card starts with previous card's structure (#100)
- Loading branch information
Showing
6 changed files
with
156 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ContentBlock, ContentBlockType } from "@/types"; | ||
import { | ||
isAudioBlock, | ||
isEmbedBlock, | ||
isHintBlock, | ||
isImageBlock, | ||
isMathBlock, | ||
isTextBlock, | ||
isVideoBlock, | ||
} from "./isBlockOfType"; | ||
|
||
/** | ||
* makes an empty content block of a particular type | ||
*/ | ||
export function makeContentBlock(type: ContentBlockType) { | ||
const block: ContentBlock = { | ||
id: crypto.randomUUID(), | ||
type, | ||
content: "", | ||
meta: null, | ||
}; | ||
|
||
if (isImageBlock(block)) { | ||
block.meta = { alt: "" }; | ||
return block; | ||
} | ||
|
||
if (isHintBlock(block)) { | ||
block.meta = { label: "Hint" }; | ||
return block; | ||
} | ||
|
||
if (isTextBlock(block)) { | ||
block.meta = { lang: null }; | ||
return block; | ||
} | ||
|
||
if (isAudioBlock(block)) { | ||
// using `isBlockOfType()` type guards to return the correct block type | ||
return block; | ||
} | ||
|
||
if (isVideoBlock(block)) { | ||
return block; | ||
} | ||
|
||
if (isEmbedBlock(block)) { | ||
return block; | ||
} | ||
|
||
if (isMathBlock(block)) { | ||
return block; | ||
} | ||
|
||
throw new Error(`Unknown block type: ${type}`); | ||
} |
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