-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add package
@remirror/extension-track-changes
New package based on prosemirror website demo.
- Loading branch information
Showing
14 changed files
with
830 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const config = require('../../support/jest/jest.config'); | ||
|
||
module.exports = { | ||
...config, | ||
displayName: { name: require('./package.json').name.replace('@remirror/', ''), color: 'pink' }, | ||
}; |
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 @@ | ||
{ | ||
"name": "@remirror/extension-track-changes", | ||
"version": "0.0.0", | ||
"description": "Track user changes in your remirror editor.", | ||
"keywords": [ | ||
"remirror", | ||
"extension" | ||
], | ||
"homepage": "https://github.com/remirror/remirror/tree/next/@remirror/extension-track-changes", | ||
"repository": "https://github.com/remirror/remirror/tree/master/@remirror/extension-track-changes", | ||
"license": "MIT", | ||
"contributors": [ | ||
"Ifiok Jr. <ifiokotung@gmail.com>" | ||
], | ||
"sideEffects": false, | ||
"main": "dist/extension-track-changes.cjs.js", | ||
"module": "dist/extension-track-changes.esm.js", | ||
"types": "dist/extension-track-changes.cjs.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"@babel/runtime": "^7.10.2" | ||
}, | ||
"devDependencies": { | ||
"@remirror/core": "^0.11.0", | ||
"@remirror/pm": "^0.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@remirror/core": "^0.11.0", | ||
"@remirror/pm": "^0.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"meta": { | ||
"sizeLimit": "5 KB" | ||
} | ||
} |
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,44 @@ | ||
# @remirror/extension-track-changes | ||
|
||
> Track user changes in your remirror editor. | ||
[![Version][version]][npm] [![Weekly Downloads][downloads-badge]][npm] | ||
[![Bundled size][size-badge]][size] [![Typed Codebase][typescript]](./src/index.ts) | ||
![MIT License][license] | ||
|
||
[version]: https://flat.badgen.net/npm/v/@remirror/extension-track-changes | ||
[npm]: https://npmjs.com/package/@remirror/extension-track-changes | ||
[license]: https://flat.badgen.net/badge/license/MIT/purple | ||
[size]: https://bundlephobia.com/result?p=@remirror/extension-track-changes | ||
[size-badge]: https://flat.badgen.net/bundlephobia/minzip/@remirror/extension-track-changes | ||
[typescript]: https://flat.badgen.net/badge/icon/TypeScript?icon=typescript&label | ||
[downloads-badge]: https://badgen.net/npm/dw/@remirror/extension-track-changes/red?icon=npm | ||
|
||
## Installation | ||
|
||
```bash | ||
# yarn | ||
yarn add @remirror/extension-track-changes @remirror/pm | ||
|
||
# pnpm | ||
pnpm add @remirror/extension-track-changes @remirror/pm | ||
|
||
# npm | ||
npm install @remirror/extension-track-changes @remirror/pm | ||
``` | ||
|
||
## Usage | ||
|
||
The following code creates an instance of this extension. | ||
|
||
```ts | ||
import { TrackChangesExtension } from '@remirror/extension-track-changes'; | ||
|
||
const extension = new TrackChangesExtension(); | ||
``` | ||
|
||
## Credits | ||
|
||
This package was bootstrapped with [monots]. | ||
|
||
[monots]: https://github.com/monots/monots |
95 changes: 95 additions & 0 deletions
95
@remirror/extension-track-changes/src/__tests__/track-changes-extension.spec.ts
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,95 @@ | ||
import { renderEditor } from 'jest-remirror'; | ||
|
||
import { isExtensionValid } from '@remirror/test-fixtures'; | ||
|
||
import { TrackChangesExtension, TrackChangesOptions } from '..'; | ||
|
||
test('is valid', () => { | ||
expect(isExtensionValid(TrackChangesExtension, {})); | ||
}); | ||
|
||
function create(options?: TrackChangesOptions) { | ||
const { | ||
add, | ||
nodes: { p, doc }, | ||
view, | ||
commands, | ||
helpers, | ||
} = renderEditor([new TrackChangesExtension(options)]); | ||
const node = doc(p('This is not yet committed')); | ||
|
||
return { add, p, doc, view, commands, node, helpers }; | ||
} | ||
|
||
test('#commitChange', () => { | ||
const { add, commands, node, helpers } = create(); | ||
|
||
const { insertText } = add(node); | ||
|
||
commands.commitChange('first commit'); | ||
expect(helpers.getCommits()).toHaveLength(1); | ||
|
||
insertText('\nmore stuff'); | ||
commands.commitChange('commit two'); | ||
|
||
expect(helpers.getCommits().map((commit) => commit.message)).toMatchInlineSnapshot(` | ||
Array [ | ||
"first commit", | ||
"commit two", | ||
] | ||
`); | ||
}); | ||
|
||
describe('#revertCommit', () => { | ||
it('can revert the commit', () => { | ||
const { add, commands, node, helpers, view } = create(); | ||
|
||
const { insertText } = add(node); | ||
commands.commitChange('first commit'); | ||
|
||
insertText('\nmore stuff'); | ||
commands.commitChange('commit two'); | ||
|
||
commands.revertCommit(); | ||
|
||
expect(helpers.getCommits().map((commit) => commit.message)).toMatchInlineSnapshot(` | ||
Array [ | ||
"first commit", | ||
"commit two", | ||
"Revert: 'commit two'", | ||
] | ||
`); | ||
|
||
expect(view.state.doc).toEqualRemirrorDocument(node); | ||
}); | ||
|
||
it('can revert any of the commits', () => { | ||
const { add, commands, node, helpers, view, doc, p } = create(); | ||
|
||
const { insertText } = add(node); | ||
commands.commitChange('first commit'); | ||
|
||
insertText('\nmore stuff'); | ||
commands.commitChange('commit two'); | ||
insertText(' final changes'); | ||
commands.commitChange('final commit'); | ||
|
||
const commit = helpers.getCommit(1); | ||
commands.revertCommit(commit); | ||
|
||
expect(helpers.getCommits().map((commit) => commit.message)).toMatchInlineSnapshot(` | ||
Array [ | ||
"first commit", | ||
"commit two", | ||
"final commit", | ||
"Revert: 'commit two'", | ||
] | ||
`); | ||
|
||
expect(view.state.doc).toEqualRemirrorDocument( | ||
doc(p('This is not yet committed final changes')), | ||
); | ||
}); | ||
|
||
it.todo('test when the first commit is reverted'); | ||
}); |
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 './track-changes-extension'; |
Oops, something went wrong.