-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
20 changed files
with
310 additions
and
107 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,39 @@ | ||
import { EditorView } from 'prosemirror-view'; | ||
import { EditorState, Plugin } from 'prosemirror-state'; | ||
import { schemas } from '@schemas'; | ||
import { plugins } from '@plugins'; | ||
/* | ||
editor single intance | ||
*/ | ||
export default class Editor { | ||
view: EditorView; | ||
constructor(options: any) { | ||
this.view = this.initView(options); | ||
} | ||
|
||
initView(options: any) { | ||
const state = EditorState.create({ | ||
schema: schemas, | ||
plugins: plugins.concat(new Plugin({ | ||
props: { | ||
handleClick(view: EditorView, pos: number): boolean { | ||
return false; | ||
} | ||
} | ||
})) | ||
}); | ||
return new EditorView({ mount: document.getElementById(options.root) }, { | ||
state, | ||
editable(view): boolean { | ||
// Note: At the beginning, i want to design the structure like notion, such as not make the whole document contenteditable make the atom block instead to | ||
// but there is a problem which make the plugin view not update, so i have to return it back, sad. | ||
return true; | ||
}, | ||
attributes(state) { | ||
return { | ||
style: 'box-sizing: border-box;' | ||
} | ||
} | ||
}); | ||
} | ||
} |
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,51 +1,38 @@ | ||
import { EditorState, Plugin } from 'prosemirror-state'; | ||
|
||
import { EditorView } from 'prosemirror-view'; | ||
import {Fragment, Slice} from 'prosemirror-model'; | ||
import {findWrapping, ReplaceAroundStep} from 'prosemirror-transform'; | ||
|
||
import { render } from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
import ReactRootApp from '@components/index'; | ||
|
||
|
||
import { schemas } from '@schemas'; | ||
import { plugins } from '@plugins'; | ||
import Editor from './editor'; | ||
|
||
import './style.scss'; | ||
|
||
declare global { | ||
interface Window { | ||
d(): void, | ||
v: EditorView | ||
NEDITOR: any | ||
} | ||
} | ||
interface NotionEditorInterface { | ||
editor: any; | ||
} | ||
class NotionEditor implements NotionEditorInterface { | ||
editor: any; | ||
constructor(options = {}) { | ||
this.editor = null; | ||
this.active(options); | ||
} | ||
|
||
const root = document.getElementById('n-editor'); | ||
|
||
const state = EditorState.create({ | ||
schema: schemas, | ||
plugins: plugins.concat(new Plugin({ | ||
props: { | ||
handleClick(view: EditorView, pos: number): boolean { | ||
return false; | ||
} | ||
} | ||
})) | ||
}); | ||
|
||
const view = new EditorView({ mount: root }, { | ||
state, | ||
editable(view): boolean { | ||
// Note: At the beginning, i want to design the structure like notion, such as not make the whole document contenteditable make the atom block instead to | ||
// but there is a problem which make the plugin view not update, so i have to return it back, sad. | ||
return true; | ||
}, | ||
attributes(state) { | ||
return { | ||
style: 'box-sizing: border-box;' | ||
} | ||
active(options: any) { | ||
this.editor = new Editor(options); | ||
} | ||
}); | ||
} | ||
|
||
// Note: This should init by Client, we mock it. | ||
document.addEventListener('DOMContentLoaded', () => window.NEDITOR = new NotionEditor({ | ||
title: 'NotionEditor', | ||
root: 'n-editor' | ||
// other config | ||
})); | ||
// react view | ||
render(ReactRootApp(), document.getElementById('n-component')); |
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,15 @@ | ||
import { defaultParseDom, defaultSchemaAttrs } from '@utils/schema-helper'; | ||
import { DOMOutputSpec, Node } from 'prosemirror-model'; | ||
|
||
export const blockquote = { | ||
attrs: { | ||
...defaultSchemaAttrs('blockquote') | ||
}, | ||
content: 'block+', | ||
group: 'block', | ||
parseDOM: [ | ||
{ tag: 'blockquote' }, | ||
defaultParseDom('blockquote') | ||
], | ||
toDOM(node: Node): DOMOutputSpec { return ['div', node.attrs, 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,27 @@ | ||
import { defaultParseDom, defaultSchemaAttrs } from '@utils/schema-helper'; | ||
import { Node, DOMOutputSpec } from 'prosemirror-model'; | ||
|
||
export const code_block = { | ||
attrs: { | ||
...defaultSchemaAttrs('code-block'), | ||
}, | ||
content: 'text*', | ||
group: 'block', | ||
code: true, | ||
defining: true, | ||
marks: '', | ||
parseDOM: [ | ||
defaultParseDom('code-block'), | ||
{ | ||
tag: 'pre', | ||
preserveWhitespace: 'full' as "full", | ||
getAttrs: (node: HTMLElement) => ({ | ||
params: node.getAttribute('data-params') || '' | ||
}) | ||
} | ||
], | ||
toDOM(node: Node): DOMOutputSpec { | ||
// Note: use 'div' instead | ||
return ['pre', node.attrs.params ? {'data-params': node.attrs.params} : {}, ['code', 0]] | ||
} | ||
} |
Empty file.
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 @@ | ||
import { DOMOutputSpec } from 'prosemirror-model' | ||
|
||
export const hard_break = { | ||
inline: true, | ||
group: 'inline', | ||
selectable: false, | ||
parseDOM: [{ tag: 'br' }], | ||
toDOM(): DOMOutputSpec { return ['br'] } | ||
} |
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,28 @@ | ||
import { Node } from 'prosemirror-model'; | ||
import { defaultParseDom, defaultSchemaAttrs } from "@utils/schema-helper" | ||
|
||
export const heading = { | ||
attrs: { | ||
...defaultSchemaAttrs('heading'), | ||
level: { | ||
default: 1, | ||
} | ||
}, | ||
content: '(text | image)*', | ||
group: 'block', | ||
defining: true, | ||
parseDOM: [ | ||
{ tag: 'h1', attrs: { level: 1 } }, | ||
{ tag: 'h2', attrs: { level: 2 } }, | ||
{ tag: 'h3', attrs: { level: 3 } }, | ||
{ tag: 'h4', attrs: { level: 4 } }, | ||
{ tag: 'h5', attrs: { level: 5 } }, | ||
{ tag: 'h6', attrs: { level: 6 } }, | ||
defaultParseDom('heading'), | ||
], | ||
toDOM(node: Node) { | ||
return ['div', { | ||
'data-type': node.attrs.level, | ||
}, 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,15 @@ | ||
import { defaultParseDom, defaultSchemaAttrs } from '@utils/schema-helper'; | ||
import { DOMOutputSpec } from 'prosemirror-model'; | ||
|
||
|
||
export const hr = { | ||
attrs: { | ||
...defaultSchemaAttrs('hr'), | ||
}, | ||
group: 'block', | ||
parseDOM: [ | ||
{ tag: 'hr' }, | ||
defaultParseDom('hr'), | ||
], | ||
toDOM(): DOMOutputSpec { return ['div', ['hr']] } | ||
} |
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,24 @@ | ||
import { DOMOutputSpec, Node } from 'prosemirror-model'; | ||
import { defaultSchemaAttrs } from '@utils/schema-helper'; | ||
|
||
export const image = { | ||
inline: true, | ||
attrs: { | ||
...defaultSchemaAttrs('image'), | ||
src: {}, | ||
alt: { default: '' }, | ||
title: { default: '' } | ||
}, | ||
group: "inline", | ||
draggable: true, | ||
parseDOM: [{ | ||
tag: "img[src]", getAttrs(dom: HTMLElement) { | ||
return { | ||
src: dom.getAttribute("src"), | ||
title: dom.getAttribute("title"), | ||
alt: dom.getAttribute("alt") | ||
} | ||
} | ||
}], | ||
toDOM(node: Node): DOMOutputSpec { return ["img", node.attrs] } | ||
}; |
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
Oops, something went wrong.