diff --git a/src/reducers/odd/processClassMemberships.js b/src/reducers/odd/processClassMemberships.js index 0568f4d..950f122 100644 --- a/src/reducers/odd/processClassMemberships.js +++ b/src/reducers/odd/processClassMemberships.js @@ -53,7 +53,7 @@ export function processClassMemberships(specElement, specData, localData, change } export function createClassMemberships(specElement, specData, odd) { - if (specData.classes) { + if (specData.classes.atts.length > 0 && specData.classes.model.length > 0) { const classesEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'classes') for (const cl of specData.classes.atts.concat(specData.classes.model)) { const memberOf = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'memberOf') diff --git a/src/reducers/odd/updateElements.js b/src/reducers/odd/updateElements.js index 411170f..f1c1afa 100644 --- a/src/reducers/odd/updateElements.js +++ b/src/reducers/odd/updateElements.js @@ -24,6 +24,25 @@ export function updateElements(localsource, customization, odd) { // real change wouldn't really have happened. for (const el of customization.elements) { + const _cntToXml = (content, parent) => { + for (const cntItem of content) { + const cntItemEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', cntItem.type) + if (cntItem.key) { + cntItemEl.setAttribute('key', cntItem.key) + } + if (cntItem.maxOccurs) { + cntItemEl.setAttribute('maxOccurs', cntItem.maxOccurs) + } + if (cntItem.minOccurs) { + cntItemEl.setAttribute('minOccurs', cntItem.minOccurs) + } + if (cntItem.content) { + _cntToXml(cntItem.content, cntItemEl) + } + parent.appendChild(cntItemEl) + } + } + if (el._isNew) { // Create new spec const elSpec = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'elementSpec') @@ -41,10 +60,26 @@ export function updateElements(localsource, customization, odd) { createClassMemberships(elSpec, el, odd) // Create attributes - if (el.attributes) { + if (el.attributes.length > 0) { createAttributes(elSpec, el, odd) } + // Create content + if (el.content.length > 0) { + let contentEl = elSpec.querySelector('content') + if (!contentEl) { + contentEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', 'content') + // Place after documentation elements in right position + insertBetween( + elSpec, contentEl, + ['desc', 'gloss', 'altIdent', 'equiv', 'classes'], + ['valList', 'constraintSpec', 'attList', 'model', 'modelGrp', + 'modelSequence', 'exemplum', 'remarks', 'listRef']) + } + // JSON -> XML + _cntToXml(el.content, contentEl) + } + const schemaSpec = odd.querySelector('schemaSpec') schemaSpec.appendChild(elSpec) } else if (el._changed) { @@ -78,24 +113,6 @@ export function updateElements(localsource, customization, odd) { processAttributes(elSpec, el, localEl, localsource, odd) break case 'content': - const _cntToXml = (content, parent) => { - for (const cntItem of content) { - const cntItemEl = odd.createElementNS('http://www.tei-c.org/ns/1.0', cntItem.type) - if (cntItem.key) { - cntItemEl.setAttribute('key', cntItem.key) - } - if (cntItem.maxOccurs) { - cntItemEl.setAttribute('maxOccurs', cntItem.maxOccurs) - } - if (cntItem.minOccurs) { - cntItemEl.setAttribute('minOccurs', cntItem.minOccurs) - } - if (cntItem.content) { - _cntToXml(cntItem.content, cntItemEl) - } - parent.appendChild(cntItemEl) - } - } if (!deepCompare(el.content, localEl.content)) { elSpec = getOrSetElementSpec(odd, el.ident) let contentEl = elSpec.querySelector('content')