Commit e44db999 authored by Casey Ydenberg's avatar Casey Ydenberg
Browse files

Derive initial editor state from ancestor doc and commit

parent ccfb8abb
......@@ -24,6 +24,7 @@ import {
schema,
} from '@manuscripts/manuscript-transform'
import { BibliographyItem, Model } from '@manuscripts/manuscripts-json-schema'
import { checkout } from '@manuscripts/track-changes'
import { EditorState, Plugin } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import React from 'react'
......@@ -52,12 +53,18 @@ export interface EditorProps extends ViewerProps {
}
export default {
createState: (props: EditorProps) =>
EditorState.create<ManuscriptSchema>({
doc: props.doc,
createState: (props: EditorProps) => {
const { doc, commit } = props
const ancestorState = EditorState.create<ManuscriptSchema>({
doc,
schema,
plugins: plugins(props),
}),
})
if (!commit) {
return ancestorState
}
return checkout(doc, ancestorState, commit)
},
createView: (props: EditorProps): CreateView => (el, state, dispatch) =>
new EditorView(el, {
......
......@@ -28,7 +28,7 @@ import {
Model,
UserProfile,
} from '@manuscripts/manuscripts-json-schema'
import { Commit } from '@manuscripts/track-changes'
import { checkout, Commit } from '@manuscripts/track-changes'
import { History } from 'history'
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
......@@ -62,12 +62,18 @@ export interface ViewerProps {
}
export default {
createState: (props: ViewerProps) =>
EditorState.create<ManuscriptSchema>({
doc: props.doc,
createState: (props: ViewerProps) => {
const { doc, commit } = props
const ancestorState = EditorState.create<ManuscriptSchema>({
doc,
schema,
plugins: plugins(props),
}),
})
if (!commit) {
return ancestorState
}
return checkout(doc, ancestorState, commit)
},
createView: (props: ViewerProps): CreateView => (el, state, dispatch) =>
new EditorView<ManuscriptSchema>(el, {
......
......@@ -2154,10 +2154,10 @@
prosemirror-state "^1.3.3"
prosemirror-view "^1.16.0"
"@manuscripts/track-changes@^0.0.5":
version "0.0.5"
resolved "https://registry.npmjs.org/@manuscripts/track-changes/-/track-changes-0.0.5.tgz#0c27e3899445df7c9d50b3b657454d8324275e78"
integrity sha512-0s+yi6J0KnhhPAs5U13LAc6kEZGk3LwRd4lZsHb2KgvpU0KZum+2TRWd7eiL/BnJIoz3CWS1FhgY+DK0nQxFjw==
"@manuscripts/track-changes@^0.0.7":
version "0.0.7"
resolved "https://registry.npmjs.org/@manuscripts/track-changes/-/track-changes-0.0.7.tgz#cf1d585c3d16ba11fbd828a530b42fe331b7e494"
integrity sha512-OVbBqDQDOVtQK10MDqy9mY43qRcNtCnKvYjxNUmTXFFRhW3hEHBsPgB1P3T4I4FRnslTYZiRi49gK7j5mzTyUQ==
dependencies:
"@manuscripts/manuscripts-json-schema" "^1.45.6"
prosemirror-state "^1.3.3"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment