Skip to content

Commit

Permalink
Merge pull request #598 from substance/qc-mode
Browse files Browse the repository at this point in the history
Preparations for QC mode
  • Loading branch information
oliver7654 committed Jul 10, 2018
2 parents c021504 + 46213a2 commit 295e5d3
Show file tree
Hide file tree
Showing 59 changed files with 2,351 additions and 626 deletions.
19 changes: 1 addition & 18 deletions index.js
@@ -1,18 +1 @@
// TODO: add index files for the other folders as well
export * from './src/article/index'
export * from './src/editor/index'
export * from './src/reader/index'
export * from './src/entities/index'

export { default as Texture } from './src/Texture'
export { default as RichTextInput } from './src/rich-text-input/RichTextInput'
export { default as ArticleLoader } from './src/ArticleLoader'
export { default as PubMetaLoader } from './src/PubMetaLoader'
export { default as TextureArchive } from './src/TextureArchive'
export { default as AppChrome } from './src/AppChrome'
export { default as WebAppChrome } from './src/WebAppChrome'
export { default as DesktopAppChrome } from './src/DesktopAppChrome'
export { default as TextureWebApp } from './src/TextureWebApp'
export { default as TextureDesktopApp } from './src/TextureDesktopApp'
export { default as checkArchive } from './src/util/checkArchive'
export { default as vfsSaveHook } from './src/util/vfsSaveHook'
export * from './src/index'
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"lodash": "^4.14.1"
},
"peerDependency": {
"substance": "^1.0.0-preview.66"
"substance": "^1.0.0-preview.71"
},
"devDependencies": {
"dar-server": "^0.4.1",
Expand All @@ -21,7 +21,7 @@
"font-awesome": "4.5.0",
"nyc": "11.8.0",
"source-map-support": "0.5.3",
"substance": "1.0.0-preview.67",
"substance": "1.0.0-preview.71",
"substance-bundler": "0.25.4",
"substance-test": "0.12.2",
"tap-spec": "^4.1.1"
Expand Down
26 changes: 0 additions & 26 deletions src/ArticleLoader.js

This file was deleted.

72 changes: 26 additions & 46 deletions src/Texture.js
@@ -1,62 +1,42 @@
import { Component } from 'substance'
import EditorPackage from './editor/EditorPackage'
import TextureArticleAPI from './article/TextureArticleAPI'
import TextureConfigurator from './TextureConfigurator'
import ArticlePackage from './article/ArticlePackage'

// TODO: needs to be refactored to achieve a consistent structure.
// Currently TextureReader is a modified version of this implementation
// while editor/Editor.js is an AbstractWriter implementation.
// TODO: this should incoporate the 'Project' stuff that we have in Stencila
export default class Texture extends Component {

constructor(...args) {
constructor (...args) {
super(...args)
const archive = this.props.archive

this.manuscriptSession = archive.getEditorSession('manuscript')
const doc = this.manuscriptSession.getDocument()
this.pubMetaDbSession = archive.getEditorSession('pub-meta')
this.configurator = this.manuscriptSession.getConfigurator()
this.api = new TextureArticleAPI(
this.manuscriptSession,
this.pubMetaDbSession,
this.configurator.getModelRegistry()
)

// HACK: we need to expose referenceManager somehow, so it can be used in
// the JATSExporter. We may want to consider including referenceManager in
// TODO: Exporters should use the API instead
doc.referenceManager = this.api.getReferenceManager()
this.config = this._getConfiguration()
}

getChildContext() {
// ATTENTION: in Stencila we had regressions, because TextureEditorPackage.Editor
// is creating a different childContext which raises the chance for integration issues.
// So try to keep this as minimal as possible and rather change
// Editor.getChildContet() instead
return {
urlResolver: this.props.archive,
api: this.api,
configurator: this.getConfigurator(),
pubMetaDbSession: this.pubMetaDbSession,
referenceManager: this.api.getReferenceManager(),
footnoteManager: this.api.getFootnoteManager(),
figureManager: this.api.getFigureManager(),
tableManager: this.api.getTableManager()
render ($$) {
const archive = this.props.archive
let el = $$('div').addClass('sc-texture')

// TODO: Texture will support multipled resources in future
const ResourceComponent = this.config.getComponent('article')
const config = this.config.getConfiguration('article')
const articleSession = archive.getEditorSession('manuscript')
const pubMetaDbSession = archive.getEditorSession('pub-meta')
let props = {
articleSession,
pubMetaDbSession,
config
}
}

render($$) {
let el = $$('div').addClass('sc-texture')
el.append(
$$(EditorPackage.Editor, {
editorSession: this.manuscriptSession,
pubMetaDbSession: this.pubMetaDbSession
})
$$(ResourceComponent, props)
)
return el
}

getConfigurator() {
return this.configurator
}
_getConfiguration () {
let config = new TextureConfigurator()

// TODO: in future we want to make this configurable (plugin framework)
config.import(ArticlePackage)

return config
}
}
37 changes: 15 additions & 22 deletions src/AppChrome.js → src/TextureAppChrome.js
@@ -1,6 +1,6 @@
import { Component, DefaultDOMElement, platform } from 'substance'

export default class AppChrome extends Component {
export default class TextureAppChrome extends Component {
didMount () {
// when the developer console is not open, display when there is an error
if (!platform.devtools) {
Expand All @@ -16,30 +16,28 @@ export default class AppChrome extends Component {
} else {
this._init()
}

DefaultDOMElement.getBrowserWindow().on('keydown', this._keyDown, this)
DefaultDOMElement.getBrowserWindow().on('drop', this._supressDnD, this)
DefaultDOMElement.getBrowserWindow().on('dragover', this._supressDnD, this)
}

dispose() {
dispose () {
DefaultDOMElement.getBrowserWindow().off(this)
}

getChildContext() {
return this._childContext
getChildContext () {
return this._childContext || {}
}

getInitialState() {
getInitialState () {
return {
archive: undefined,
error: undefined
}
}

/*
4 initialisation stages
4 initialisation stages:
- _setupChildContext
- _initContext
- _loadArchive
Expand All @@ -64,40 +62,35 @@ export default class AppChrome extends Component {
return context
}

async _loadArchive() {
async _loadArchive () {
throw new Error('_loadArchive not implemented')
}

async _initArchive(archive) {
async _initArchive (archive) {
return archive
}

_afterInit() {}
_afterInit () {}

/*
We may want an explicit save button, that can be configured on app level,
but passed down to editor toolbars.
*/
_save() {
// TODO: need to rethink
_save () {
return this.state.archive.save().then(() => {
this._updateTitle(false)
}).catch(err => {
console.error(err)
})
}

_updateTitle() {
// no-op
}
_updateTitle () {}

_keyDown(event) {
if ( event.key === 'Dead' ) return
_keyDown (event) {
if (event.key === 'Dead') return
if (this._handleKeyDown) {
this._handleKeyDown(event)
}
}

_supressDnD(event) {
_supressDnD (event) {
event.preventDefault()
}
}
9 changes: 2 additions & 7 deletions src/TextureAppMixin.js
@@ -1,7 +1,6 @@
import { JATSImportDialog } from './article/index'
import TextureArchive from './TextureArchive'
import Texture from './Texture'
import EditorPackage from './editor/EditorPackage'
import TextureArchive from './TextureArchive'
import { JATSImportDialog } from './article/index'

export default function TextureAppMixin (ParentAppChrome) {
return class TextureApp extends ParentAppChrome {
Expand Down Expand Up @@ -34,9 +33,5 @@ export default function TextureAppMixin (ParentAppChrome) {
_getArchiveClass () {
return TextureArchive
}

_getArticleConfig () {
return EditorPackage
}
}
}
26 changes: 12 additions & 14 deletions src/TextureArchive.js
@@ -1,16 +1,14 @@
import { prettyPrintXML, DefaultDOMElement } from 'substance'
import { PersistedDocumentArchive } from './dar'
import ArticleLoader from './ArticleLoader'
import PubMetaLoader from './PubMetaLoader'
import { JATSExporter } from './article'
import { PersistedDocumentArchive } from './dar/index'
import { ArticleLoader, JATSExporter } from './article/index'
import { PubMetaLoader } from './entities/index'

export default class TextureArchive extends PersistedDocumentArchive {

/*
Creates EditorSessions from a raw archive.
This might involve some consolidation and ingestion.
*/
_ingest(rawArchive) {
_ingest (rawArchive) {
let sessions = {}
let manifestXML = _importManifest(rawArchive)
let manifestSession = this._loadManifest({ data: manifestXML })
Expand Down Expand Up @@ -39,7 +37,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
return sessions
}

_repair() {
_repair () {
let manifestSession = this.getEditorSession('manifest')
let entries = manifestSession.getDocument().getDocumentEntries()
let missingEntries = []
Expand All @@ -62,7 +60,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
})
}

_exportManifest(sessions, buffer, rawArchive) {
_exportManifest (sessions, buffer, rawArchive) {
let manifest = sessions.manifest.getDocument()
if (buffer.hasResourceChanged('manifest')) {
let manifestDom = manifest.toXML()
Expand All @@ -76,7 +74,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
}
}

_exportDocuments(sessions, buffer, rawArchive) {
_exportDocuments (sessions, buffer, rawArchive) {
// Note: we are only adding resources that have changed
// and only those which are registered in the manifest
let entries = this.getDocumentEntries()
Expand Down Expand Up @@ -104,7 +102,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
})
}

_loadDocument(type, record, sessions) {
_loadDocument (type, record, sessions) {
switch (type) {
case 'article': {
return ArticleLoader.load(record.data, {
Expand All @@ -117,7 +115,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
}
}

_exportDocument(type, session, sessions) {
_exportDocument (type, session, sessions) {
switch (type) {
case 'article': {
let jatsExporter = new JATSExporter()
Expand All @@ -134,7 +132,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
}
}

getTitle() {
getTitle () {
let editorSession = this.getEditorSession('manuscript')
let title = 'Untitled'
if (editorSession) {
Expand All @@ -152,7 +150,7 @@ export default class TextureArchive extends PersistedDocumentArchive {
Create an explicit entry for pub-meta.json, which does not
exist in the serialisation format
*/
function _importManifest(rawArchive) {
function _importManifest (rawArchive) {
let manifestXML = rawArchive.resources['manifest.xml'].data
let dom = DefaultDOMElement.parseXML(manifestXML)
let documentsEl = dom.find('documents')
Expand All @@ -170,7 +168,7 @@ function _importManifest(rawArchive) {
The serialised manifest should have no pub-meta document entry, so we
remove it here.
*/
function _exportManifest(manifestDom) {
function _exportManifest (manifestDom) {
let documents = manifestDom.find('documents')
let pubMetaEl = documents.find('document#pub-meta')
documents.removeChild(pubMetaEl)
Expand Down

0 comments on commit 295e5d3

Please sign in to comment.