forked from Milkdown/milkdown
-
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.
- Loading branch information
1 parent
f614070
commit bb3ce6d
Showing
17 changed files
with
344 additions
and
21 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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/main.ts"></script> | ||
</body> | ||
</html> |
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,69 @@ | ||
import { Editor } from '@milkdown/core'; | ||
import { commonmark } from '@milkdown/preset-commonmark'; | ||
|
||
import '@milkdown/theme-nord/lib/theme.css'; | ||
|
||
import './style.css'; | ||
|
||
const markdown = ` | ||
# Milkdown Test | ||
## Blockquote | ||
> Milkdown is an editor. | ||
## Marks Paragraph | ||
Hello, ***milkdown* nice \`to\` meet *you***! | ||
There should be a line break before this. | ||
--- | ||
## Image and Link | ||
**Of course you can add image! ![cat](https://th.bing.com/th/id/OIP.EiYMXYhAnpsXnVmwJAq1jAHaEo?pid=ImgDet&rs=1 "kitty")** | ||
Your *[link is here](https://bing.com "bing")*, have a look. | ||
![Alt text][id] | ||
[id]: https://th.bing.com/th/id/OIP.EiYMXYhAnpsXnVmwJAq1jAHaEo?pid=ImgDet&rs=1 "The Cat" | ||
## Lists | ||
* list item 1 | ||
1. is this the real life | ||
2. is this just fantasy | ||
* list item 2 | ||
* sub list item 1 | ||
some explain | ||
* sub list item 2 | ||
* list item 3 | ||
## Code | ||
\`\`\`javascript | ||
const milkdown = new Milkdown(); | ||
milkdown.create(); | ||
\`\`\` | ||
--- | ||
Now you can play! | ||
`; | ||
|
||
const root = document.getElementById('app'); | ||
|
||
if (!root) throw new Error(); | ||
|
||
new Editor({ | ||
root, | ||
defaultValue: markdown, | ||
listener: { | ||
// markdown: [(x) => console.log(x())], | ||
}, | ||
}) | ||
.use(commonmark) | ||
.create(); |
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,3 @@ | ||
body { | ||
margin: 0; | ||
} |
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,32 @@ | ||
{ | ||
"name": "@milkdown/react", | ||
"version": "4.1.2", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"start": "vite", | ||
"watch": "tsc -w", | ||
"test": "jest", | ||
"tsc": "tsc --noEmit", | ||
"build": "tsc" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"dependencies": { | ||
"tslib": "^2.2.0" | ||
}, | ||
"peerDependencies": { | ||
"@milkdown/core": "*", | ||
"react": "*", | ||
"react-dom": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "*", | ||
"@types/react-dom": "*", | ||
"@milkdown/core": "*", | ||
"react": "*", | ||
"react-dom": "*" | ||
} | ||
} |
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,15 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
export type Renderer = { | ||
reactElement: React.ReactNode; | ||
element: HTMLElement; | ||
}; | ||
|
||
export const Portals: React.FC<{ renderers: Record<string, Renderer> }> = ({ renderers }) => ( | ||
<> | ||
{Object.entries(renderers).map(([key, renderer]) => | ||
ReactDOM.createPortal(renderer.reactElement, renderer.element, key), | ||
)} | ||
</> | ||
); |
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,69 @@ | ||
import { Node as ProsemirrorNode } from 'prosemirror-model'; | ||
import { NodeView, Decoration } from 'prosemirror-view'; | ||
|
||
export function id() { | ||
return [1e7, -1e3, -4e3, -8e3, -1e11] | ||
.map((x) => x.toString()) | ||
.join('') | ||
.replace(/[018]/g, (c) => | ||
(Number(c) ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16), | ||
); | ||
} | ||
|
||
abstract class NodeViewBase implements NodeView { | ||
abstract get dom(): Node | null; | ||
abstract get contentDOM(): Node | null; | ||
|
||
abstract update?: Required<NodeView>['update']; | ||
|
||
abstract destroy?: Required<NodeView>['destroy']; | ||
} | ||
|
||
export class ReactNodeView extends NodeViewBase { | ||
override get dom(): Node | null { | ||
throw new Error('To be implemented'); | ||
} | ||
override get contentDOM(): Node | null { | ||
if (this.#node.isLeaf) return null; | ||
|
||
return this.#contentDOMElement; | ||
} | ||
|
||
#node: ProsemirrorNode; | ||
#decorations: Decoration[]; | ||
#contentDOMElement: HTMLElement | null; | ||
#getPos: () => number; | ||
|
||
constructor(node: ProsemirrorNode, decorations: Decoration[], getPos: () => number) { | ||
super(); | ||
this.#node = node; | ||
this.#decorations = decorations; | ||
this.#getPos = getPos; | ||
|
||
// TODO: remove HACK | ||
this.#getPos; | ||
|
||
this.#contentDOMElement = this.#node.isLeaf | ||
? null | ||
: document.createElement(this.#node.isInline ? 'span' : 'div'); | ||
} | ||
|
||
override update = (node: ProsemirrorNode, decorations: Decoration[]) => { | ||
if (node.type !== this.#node.type) { | ||
return false; | ||
} | ||
|
||
if (node === this.#node && this.#decorations === decorations) { | ||
return true; | ||
} | ||
|
||
this.#node = node; | ||
this.#decorations = decorations; | ||
|
||
return true; | ||
}; | ||
|
||
override destroy = () => { | ||
this.#contentDOMElement = null; | ||
}; | ||
} |
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 * from './ReactNodeView'; |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "lib", | ||
"jsx": "react" | ||
}, | ||
"include": ["src"] | ||
} |
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,21 @@ | ||
import { defineConfig } from 'vite'; | ||
import reactRefresh from '@vitejs/plugin-react-refresh'; | ||
|
||
export default defineConfig({ | ||
root: 'app', | ||
optimizeDeps: { | ||
include: [ | ||
'prosemirror-model', | ||
'prosemirror-view', | ||
'prosemirror-state', | ||
'prosemirror-commands', | ||
'prosemirror-inputrules', | ||
'prosemirror-keymap', | ||
'prosemirror-schema-list', | ||
'prosemirror-history', | ||
'prosemirror-transform', | ||
'prosemirror-gapcursor', | ||
], | ||
}, | ||
plugins: [reactRefresh()], | ||
}); |
Oops, something went wrong.