Skip to content

Commit

Permalink
chore: blocking( slab/quill#3521 )
Browse files Browse the repository at this point in the history
  • Loading branch information
shuta13 committed May 27, 2022
1 parent e653cd5 commit f70ebd7
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 31 deletions.
4 changes: 0 additions & 4 deletions common.css

This file was deleted.

26 changes: 22 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@
<html>
<head>
<title>poc block editor libs</title>
<link rel="stylesheet" href="common.css" />
<link href="/global.css" rel="stylesheet" />
</head>
<body>
<div id="editor"></div>
<div id="toolbar"></div>
<header>
<h1>poc block editor libs</h1>
</header>
<main>
<h2>With Quill</h2>
<section name="vanilla">
<h3>Vanilla</h3>
<div>
<div id="editor" class="editor"></div>
<span id="toolbar" class="toolbar">
<button class="ql-bold"></button>
<button id="cheer-button">🥳</button>
</span>
</div>
</section>
<section name="with-react">
<h3>With React</h3>
<div id="root"></div>
</section>
</main>
</body>
<script src="/src/index.ts"></script>
<script src="/src/index.tsx"></script>
</html>
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
},
"dependencies": {
"@types/quill": "2.0.9",
"quill": "1.3.7"
"@types/react": "18.0.9",
"@types/react-dom": "18.0.5",
"quill": "1.3.7",
"react": "18.1.0",
"react-dom": "18.1.0"
}
}
15 changes: 15 additions & 0 deletions src/assets/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
html,
body {
margin: 0;
}

* {
box-sizing: border-box;
}

.editor {
height: 160px;
}

.toolbar {
}
5 changes: 5 additions & 0 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react";

export const Editor: React.FC = () => {
return <></>;
};
5 changes: 5 additions & 0 deletions src/components/ToolBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react";

export const ToolBar: React.FC = () => {
return <></>;
};
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Editor";
export * from "./ToolBar";
Empty file removed src/helpers/.gitkeep
Empty file.
23 changes: 23 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Quill from "quill";

export type Delta = ReturnType<Quill["getContents"]>;

export const createQuill = (editor: HTMLElement, toolbar: HTMLElement) => {
return new Quill(editor, {
modules: {
toolbar: toolbar
},
placeholder: "なんか書いて",
theme: "snow"
});
};

export const createTextChangeHandler = (quill: Quill) => {
return (delta?: Delta) => {
const contents = quill.getContents();
console.log("contents: ", contents);
if (delta) {
console.log("delta ", delta);
}
};
};
19 changes: 0 additions & 19 deletions src/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "quill/dist/quill.snow.css";
import "./assets/styles/global.css";
import { createQuill, createTextChangeHandler } from "./helpers";
import { Editor, ToolBar } from "./components";

import React from "react";
import * as ReactDOM from "react-dom/client";

const editorElement = document.getElementById("editor")!;
const toolBarElement = document.getElementById("toolbar")!;
const quill = createQuill(editorElement, toolBarElement);
const handleTextChange = createTextChangeHandler(quill);
// NOTE: Output initial values
handleTextChange();
quill.on("text-change", handleTextChange);
const cheerButtonElement = document.getElementById("cheer-button")!;
cheerButtonElement.addEventListener("click", () => {
alert("Have a fun!");
});

const reactContainer = document.getElementById("root")!;
const root = ReactDOM.createRoot(reactContainer);
root.render(
<>
<Editor />
<ToolBar />
</>
);
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
"skipLibCheck": true,
"jsx": "react"
},
"include": ["src/**/*"]
}
"include": [
"src/**/*"
]
}

0 comments on commit f70ebd7

Please sign in to comment.