-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
293cae2
commit c717bf6
Showing
9 changed files
with
353 additions
and
67 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
59 changes: 59 additions & 0 deletions
59
src/components/Blog/Post/ContextualEditingMode/PostAssist.tsx
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,59 @@ | ||
import React from "react"; | ||
import inContextualEditor from "@/scripts/Utils/In/ContextualEditingMode"; | ||
|
||
export type ContextualEditingPostAssistEvents = "showall" | "hideall"; | ||
|
||
declare global { | ||
interface HTMLElementEventMap { | ||
contextualeditingpostassist: CustomEvent<ContextualEditingPostAssistEvents>; | ||
} | ||
} | ||
|
||
export default function ContextualEditingPostAssist(): React.ReactNode { | ||
const inEditor = inContextualEditor(); | ||
|
||
return ( | ||
<> | ||
{inEditor && ( | ||
<div className="alert alert-info" role="alert"> | ||
<p> | ||
In contextual editing mode. Extra buttons are given to show or hide | ||
processor-heavy features during editing for performance. | ||
</p> | ||
<span>Dispatch event:</span> | ||
<br /> | ||
<button | ||
className="btn btn-sm btn-primary mt-2 me-2" | ||
onClick={() => { | ||
window.document.documentElement.dispatchEvent( | ||
new CustomEvent<ContextualEditingPostAssistEvents>( | ||
"contextualeditingpostassist", | ||
{ | ||
detail: "showall", | ||
}, | ||
), | ||
); | ||
}} | ||
> | ||
Show all | ||
</button> | ||
<button | ||
className="btn btn-sm btn-primary mt-2 me-2" | ||
onClick={() => { | ||
window.document.documentElement.dispatchEvent( | ||
new CustomEvent<ContextualEditingPostAssistEvents>( | ||
"contextualeditingpostassist", | ||
{ | ||
detail: "hideall", | ||
}, | ||
), | ||
); | ||
}} | ||
> | ||
Hide all | ||
</button> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
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,32 +1,82 @@ | ||
// noinspection XmlDeprecatedElement | ||
|
||
import React from "react"; | ||
import inContextualEditor from "@/scripts/Utils/In/ContextualEditingMode"; | ||
|
||
export default function MakeCodeArcadeProjectEditor({ | ||
id, | ||
}: { | ||
id: string; | ||
}): React.ReactNode { | ||
const inEditor = inContextualEditor(); | ||
|
||
const [showEditor, setShowEditor] = React.useState(!inEditor); | ||
|
||
function onContextualEditingPostAssist(event: CustomEvent) { | ||
if (event.detail === "showall") { | ||
setShowEditor(true); | ||
} else if (event.detail === "hideall") { | ||
setShowEditor(false); | ||
} | ||
} | ||
|
||
React.useEffect(() => { | ||
window.document.documentElement.addEventListener( | ||
"contextualeditingpostassist", | ||
onContextualEditingPostAssist, | ||
); | ||
|
||
return () => { | ||
window.document.documentElement.removeEventListener( | ||
"contextualeditingpostassist", | ||
onContextualEditingPostAssist, | ||
); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className="mb-2" | ||
style={{ | ||
position: "relative", | ||
height: 0, | ||
paddingBottom: "50vh", | ||
overflow: "hidden", | ||
}} | ||
> | ||
<iframe | ||
<> | ||
{inEditor && ( | ||
<> | ||
<button | ||
className="btn btn-sm btn-primary mb-2" | ||
onClick={() => { | ||
setShowEditor(!showEditor); | ||
}} | ||
> | ||
{showEditor ? "Hide" : "Show"} editor | ||
</button> | ||
{!showEditor && ( | ||
<p> | ||
<i>The blank space below is reserved for the editor.</i> | ||
</p> | ||
)} | ||
</> | ||
)} | ||
<div | ||
className="mb-2" | ||
style={{ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
width: "100%", | ||
height: "50vh", | ||
position: "relative", | ||
height: 0, | ||
paddingBottom: "50vh", | ||
overflow: "hidden", | ||
}} | ||
src={`https://arcade.makecode.com/#pub:${id}`} | ||
frameBorder="0" | ||
sandbox="allow-popups allow-forms allow-scripts allow-same-origin" | ||
></iframe> | ||
</div> | ||
> | ||
{showEditor && ( | ||
<iframe | ||
style={{ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
width: "100%", | ||
height: "50vh", | ||
}} | ||
src={`https://arcade.makecode.com/#pub:${id}`} | ||
frameBorder="0" | ||
sandbox="allow-popups allow-forms allow-scripts allow-same-origin" | ||
/> | ||
)} | ||
</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.