Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a playground #23

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Create playground with basic Atlassian editor
  • Loading branch information
pmeinhardt committed Mar 13, 2022
commit c788bf5557f7bd51a64203a96b5a57e8170b3570
2 changes: 2 additions & 0 deletions playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.parcel-cache/
dist/
11 changes: 11 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ADF-to-Markdown Playground</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="index.tsx"></script>
</body>
</html>
64 changes: 64 additions & 0 deletions playground/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { useCallback, useState } from "react";
import { render } from "react-dom";

import { Editor, EditorContext, WithEditorActions } from "@atlaskit/editor-core";

const defaultValue = {
version: 1,
type: "doc",
content: [
{
type: "paragraph",
content: [
{ type: "text", text: "Hello " },
{ type: "text", text: "World", marks: [{ type: "strong" }] },
{ type: "text", text: "!" },
],
},
],
};

function EditorWrapper({ actions, setValue }) {
const onChange = useCallback(async () => {
const value = await actions.getValue();
// console.log("change", value);
setValue(value);
}, [actions]);

return (
<Editor
appearance="comment"
defaultValue={defaultValue}
onChange={onChange}
/>
);
}

function App() {
const [value, setValue] = useState();

return (
<div>
<div>
<h2>Editor</h2>
<EditorContext>
<WithEditorActions render={(actions) => <EditorWrapper actions={actions} setValue={setValue} />} />
</EditorContext>
</div>
<div>
<h2>ADF representation</h2>
<pre>
<code>
{JSON.stringify(value, null, 2)}
</code>
</pre>
</div>
<div>
<h2>Markdown (TODO)</h2>
</div>
</div>
);
}

const root = document.getElementById("root");
render(<App />, root);
Loading