-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: successfully copied over basic editor from tiptap
For now this code is very much a typescript reimplimentation of tiptap Credit where credit is due [tiptap](https://github.com/scrumpy/tiptap) is a fantastic library.
- Loading branch information
Showing
37 changed files
with
1,100 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,7 @@ dependencies/**/yarn.lock | |
# Cypress | ||
/e2e/**/videos | ||
*.mp4 | ||
|
||
|
||
# | ||
.vscode |
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 @@ | ||
import { CommandFunction, Extension } from '@remirror/core'; | ||
import { history, redo, undo } from 'prosemirror-history'; | ||
|
||
export class History extends Extension { | ||
public name = 'history'; | ||
|
||
public keys() { | ||
const isMac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false; | ||
const keymap: Record<'Mod-z' | 'Shift-Mod-z' | 'Mod-y', CommandFunction> = { | ||
'Mod-y': () => false, | ||
'Mod-z': undo, | ||
'Shift-Mod-z': redo, | ||
}; | ||
|
||
if (!isMac) { | ||
keymap['Mod-y'] = redo; | ||
} | ||
|
||
return keymap; | ||
} | ||
|
||
get plugins() { | ||
return [history()]; | ||
} | ||
|
||
public commands() { | ||
return { | ||
undo: () => undo, | ||
redo: () => redo, | ||
}; | ||
} | ||
} |
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,38 @@ | ||
import { | ||
MarkExtension, | ||
markInputRule, | ||
markPasteRule, | ||
SchemaMarkTypeParams, | ||
toggleMark, | ||
} from '@remirror/core'; | ||
|
||
export class Code<GOptions extends {} = {}> extends MarkExtension<GOptions> { | ||
get name() { | ||
return 'code'; | ||
} | ||
|
||
get schema() { | ||
return { | ||
parseDOM: [{ tag: 'code' }], | ||
toDOM: () => ['code', 0], | ||
}; | ||
} | ||
|
||
public keys({ type }: SchemaMarkTypeParams) { | ||
return { | ||
'Mod-`': toggleMark(type), | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaMarkTypeParams) { | ||
return () => toggleMark(type); | ||
} | ||
|
||
public inputRules({ type }: SchemaMarkTypeParams) { | ||
return [markInputRule(/(?:`)([^`]+)(?:`)$/, type)]; | ||
} | ||
|
||
public pasteRules({ type }: SchemaMarkTypeParams) { | ||
return [markPasteRule(/(?:`)([^`]+)(?:`)/g, type)]; | ||
} | ||
} |
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,38 @@ | ||
import { | ||
MarkExtension, | ||
markInputRule, | ||
markPasteRule, | ||
SchemaMarkTypeParams, | ||
toggleMark, | ||
} from '@remirror/core'; | ||
|
||
export class Italic extends MarkExtension { | ||
get name() { | ||
return 'italic'; | ||
} | ||
|
||
get schema() { | ||
return { | ||
parseDOM: [{ tag: 'i' }, { tag: 'em' }, { style: 'font-style=italic' }], | ||
toDOM: () => ['em', 0], | ||
}; | ||
} | ||
|
||
public keys({ type }: SchemaMarkTypeParams) { | ||
return { | ||
'Mod-i': toggleMark(type), | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaMarkTypeParams) { | ||
return () => toggleMark(type); | ||
} | ||
|
||
public inputRules({ type }: SchemaMarkTypeParams) { | ||
return [markInputRule(/(?:^|[^*_])(?:\*|_)([^*_]+)(?:\*|_)$/, type)]; | ||
} | ||
|
||
public pasteRules({ type }: SchemaMarkTypeParams) { | ||
return [markPasteRule(/(?:^|[^*_])(?:\*|_)([^*_]+)(?:\*|_)/g, type)]; | ||
} | ||
} |
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,89 @@ | ||
import { | ||
Attrs, | ||
Cast, | ||
getMarkRange, | ||
MarkExtension, | ||
MarkExtensionSpec, | ||
pasteRule, | ||
removeMark, | ||
SchemaMarkTypeParams, | ||
updateMark, | ||
} from '@remirror/core'; | ||
import { Plugin, TextSelection } from 'prosemirror-state'; | ||
|
||
export class Link extends MarkExtension { | ||
get name() { | ||
return 'link'; | ||
} | ||
|
||
get schema(): MarkExtensionSpec { | ||
return { | ||
attrs: { | ||
href: { | ||
default: null, | ||
}, | ||
}, | ||
inclusive: false, | ||
parseDOM: [ | ||
{ | ||
tag: 'a[href]', | ||
getAttrs: dom => ({ | ||
href: Cast<Element>(dom).getAttribute('href'), | ||
}), | ||
}, | ||
], | ||
toDOM: node => [ | ||
'a', | ||
{ | ||
...node.attrs, | ||
rel: 'noopener noreferrer nofollow', | ||
}, | ||
0, | ||
], | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaMarkTypeParams) { | ||
return (attrs?: Attrs) => { | ||
if (attrs && attrs.href) { | ||
return updateMark(type, attrs); | ||
} | ||
|
||
return removeMark(type); | ||
}; | ||
} | ||
|
||
public pasteRules({ type }: SchemaMarkTypeParams) { | ||
return [ | ||
pasteRule( | ||
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g, | ||
type, | ||
url => ({ href: url as string }), | ||
), | ||
]; | ||
} | ||
|
||
get plugins() { | ||
return [ | ||
new Plugin({ | ||
props: { | ||
handleClick(view, pos) { | ||
const { schema, doc, tr } = view.state; | ||
const range = getMarkRange(doc.resolve(pos), schema.marks.link); | ||
|
||
if (!range) { | ||
return false; | ||
} | ||
|
||
const $start = doc.resolve(range.from); | ||
const $end = doc.resolve(range.to); | ||
const transaction = tr.setSelection(new TextSelection($start, $end)); | ||
|
||
view.dispatch(transaction); | ||
return true; | ||
}, | ||
}, | ||
}), | ||
]; | ||
} | ||
} |
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,53 @@ | ||
import { | ||
MarkExtension, | ||
MarkExtensionSpec, | ||
markInputRule, | ||
markPasteRule, | ||
SchemaMarkTypeParams, | ||
toggleMark, | ||
} from '@remirror/core'; | ||
|
||
export class Strike extends MarkExtension { | ||
get name() { | ||
return 'strike'; | ||
} | ||
|
||
get schema(): MarkExtensionSpec { | ||
return { | ||
parseDOM: [ | ||
{ | ||
tag: 's', | ||
}, | ||
{ | ||
tag: 'del', | ||
}, | ||
{ | ||
tag: 'strike', | ||
}, | ||
{ | ||
style: 'text-decoration', | ||
getAttrs: value => (value === 'line-through' ? {} : false), | ||
}, | ||
], | ||
toDOM: () => ['s', 0], | ||
}; | ||
} | ||
|
||
public keys({ type }: SchemaMarkTypeParams) { | ||
return { | ||
'Mod-d': toggleMark(type), | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaMarkTypeParams) { | ||
return () => toggleMark(type); | ||
} | ||
|
||
public inputRules({ type }: SchemaMarkTypeParams) { | ||
return [markInputRule(/~([^~]+)~$/, type)]; | ||
} | ||
|
||
public pasteRules({ type }: SchemaMarkTypeParams) { | ||
return [markPasteRule(/~([^~]+)~/g, type)]; | ||
} | ||
} |
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 @@ | ||
import { MarkExtension, MarkExtensionSpec, SchemaMarkTypeParams, toggleMark } from '@remirror/core'; | ||
|
||
export class Underline extends MarkExtension { | ||
get name() { | ||
return 'underline'; | ||
} | ||
|
||
get schema(): MarkExtensionSpec { | ||
return { | ||
parseDOM: [ | ||
{ | ||
tag: 'u', | ||
}, | ||
{ | ||
style: 'text-decoration', | ||
getAttrs: value => (value === 'underline' ? {} : false), | ||
}, | ||
], | ||
toDOM: () => ['u', 0], | ||
}; | ||
} | ||
|
||
public keys({ type }: SchemaMarkTypeParams) { | ||
return { | ||
'Mod-u': toggleMark(type), | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaMarkTypeParams) { | ||
return () => toggleMark(type); | ||
} | ||
} |
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 @@ | ||
import { NodeExtension, SchemaNodeTypeParams, toggleWrap, wrappingInputRule } from '@remirror/core'; | ||
|
||
export class Blockquote extends NodeExtension { | ||
get name() { | ||
return 'blockquote'; | ||
} | ||
|
||
get schema() { | ||
return { | ||
content: 'block*', | ||
group: 'block', | ||
defining: true, | ||
draggable: false, | ||
parseDOM: [{ tag: 'blockquote' }], | ||
toDOM: () => ['blockquote', 0], | ||
}; | ||
} | ||
|
||
public commands({ type }: SchemaNodeTypeParams) { | ||
return () => toggleWrap(type); | ||
} | ||
|
||
public keys({ type }: SchemaNodeTypeParams) { | ||
return { | ||
'Ctrl->': toggleWrap(type), | ||
}; | ||
} | ||
|
||
public inputRules({ type }: SchemaNodeTypeParams) { | ||
return [wrappingInputRule(/^\s*>\s$/, type)]; | ||
} | ||
} |
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,30 @@ | ||
import { NodeExtension, SchemaNodeTypeParams, toggleList, wrappingInputRule } from '@remirror/core'; | ||
|
||
export class Bullet extends NodeExtension { | ||
get name() { | ||
return 'bullet_list'; | ||
} | ||
|
||
get schema() { | ||
return { | ||
content: 'list_item+', | ||
group: 'block', | ||
parseDOM: [{ tag: 'ul' }], | ||
toDOM: () => ['ul', 0], | ||
}; | ||
} | ||
|
||
public commands({ type, schema }: SchemaNodeTypeParams) { | ||
return () => toggleList(type, schema.nodes.list_item); | ||
} | ||
|
||
public keys({ type, schema }: SchemaNodeTypeParams) { | ||
return { | ||
'Shift-Ctrl-8': toggleList(type, schema.nodes.list_item), | ||
}; | ||
} | ||
|
||
public inputRules({ type }: SchemaNodeTypeParams) { | ||
return [wrappingInputRule(/^\s*([-+*])\s$/, type)]; | ||
} | ||
} |
Oops, something went wrong.