diff --git a/packages/common/src/URN.js b/packages/common/src/URN.js index 4366029..74407c9 100644 --- a/packages/common/src/URN.js +++ b/packages/common/src/URN.js @@ -7,6 +7,8 @@ export default class URN { this.nss = null; this.textGroup = null; this.work = null; + this.versionPart = null; + this.workPart = null; this.reference = null; this.version = null; this.destructureUrn(); @@ -16,18 +18,19 @@ export default class URN { destructureUrn() { const split = this.absolute.split(this.delimiter); [this.scheme, this.nid, this.nss, this.work, this.reference] = split; - this.version = `${this.scheme}:${this.nid}:${this.nss}:${this.work}:`; - // eslint-disable-next-line prefer-destructuring - this.textGroup = this.version - .split('.')[0] - .split(':') - .slice(-1)[0]; + this.version = `${this.urnPrefix}:${this.work}:`; + const versionParts = this.version.split(':').slice(-2)[0].split('.'); + [this.textGroup, this.workPart, this.versionPart] = versionParts; } toString() { return this.absolute; } + get urnPrefix() { + return `${this.scheme}:${this.nid}:${this.nss}`; + } + get lcp() { return this.reference ? this.reference @@ -36,4 +39,26 @@ export default class URN { .slice(-1)[0] : null; } + + upTo(segment) { + // NOTE: Backported from https://github.com/scaife-viewer/scaife-viewer/blob/59fbb4eb6bd886285eb27bf95c5ea0ce578f2b3e/static/src/js/urn.js#L32C1-L49C4 + const segments = [this.urnPrefix, ':']; + if (segment === 'textGroup') { + segments.push(this.textGroup, ':'); + return segments.join(''); + } + if (segment === 'work') { + segments.push(this.textGroup, '.'); + segments.push(this.workPart, ':'); + return segments.join(''); + } + if (segment === 'version') { + return this.version + } + if (segment === 'reference') { + return this.absolute; + } + return null; + } + } diff --git a/packages/widget-toc/README.md b/packages/widget-toc/README.md index e69de29..9d8ca68 100644 --- a/packages/widget-toc/README.md +++ b/packages/widget-toc/README.md @@ -0,0 +1,25 @@ +# `widget-toc` + +The tables of contents (TOC) widget displays TOC entries. + +Each entry has a label and a URI. + +The URI can resolve to: + +- Another TOC (e.g., a list of lists) +- The URN of a CTS passage + +Possible implementations include: +- Browse folios from the Venetus A using the canonical book / line references (e.g. [urn:cite:scaife-viewer:toc.iliad-folio-ref-root](https://github.com/scaife-viewer/beyond-translation-site/blob/main/backend/data/tocs/toc.demo-root.json)) +- Browse CTS versions using card / para milestones extracted from TEI XML (e.g. [PerseusDL](https://github.com/scaife-viewer/beyond-translation-site/tree/feature/antigone-toc/backend/data/annotations/tocs/PerseusDL)) +- Navigate between a commentary and edition in differing text groups (e.g. [Eustathius’ Commentary on the Odyssey](https://scholarlyeditions.brill.com/eooc/) and [Odyssey](https://beyond-translation.perseus.org/reader/urn:cts:greekLit:tlg0012.tlg002.perseus-grc2:1.1-1.10)) + +## Configuration options + +`$scaife.config.showRelevantTOCs` + +Default value is `true`. + +If `true`, only show TOCs relevant to the current passage. + +Set to `false` to show all TOCs. diff --git a/packages/widget-toc/package.json b/packages/widget-toc/package.json index b1c3308..77cf1cc 100644 --- a/packages/widget-toc/package.json +++ b/packages/widget-toc/package.json @@ -10,6 +10,7 @@ "dependencies": { "@fortawesome/free-solid-svg-icons": "^6.4.2", "@scaife-viewer/common": "^0.6.0", - "@scaife-viewer/store": "^0.6.0" + "@scaife-viewer/store": "^0.6.0", + "graphql-tag": "^2.12.6" } } diff --git a/packages/widget-toc/src/TOC.vue b/packages/widget-toc/src/TOC.vue index cae8f9a..f1cbaee 100644 --- a/packages/widget-toc/src/TOC.vue +++ b/packages/widget-toc/src/TOC.vue @@ -1,13 +1,13 @@ @@ -65,6 +64,7 @@ flex-direction: column; width: 100%; } + // TODO: Retire grid due to weird wrapping issues .toc-grid { display: grid; align-items: baseline; diff --git a/packages/widget-toc/src/TOCWidget.vue b/packages/widget-toc/src/TOCWidget.vue index bf6ff9f..7a5ee53 100644 --- a/packages/widget-toc/src/TOCWidget.vue +++ b/packages/widget-toc/src/TOCWidget.vue @@ -1,32 +1,47 @@ diff --git a/packages/widget-toc/src/reducers.js b/packages/widget-toc/src/reducers.js index d3f2194..dd712b7 100644 --- a/packages/widget-toc/src/reducers.js +++ b/packages/widget-toc/src/reducers.js @@ -1,5 +1,5 @@ const tocReducer = (data, query) => { - const lenses = { getTitle: obj => obj.title, getUri: obj => obj.uri }; + const lenses = { getLabel: obj => obj.label, getUri: obj => obj.uri }; return { ...data, items: data.items.filter(obj => diff --git a/src/main.js b/src/main.js index 27ff049..b625e71 100644 --- a/src/main.js +++ b/src/main.js @@ -61,12 +61,9 @@ Vue.use(SkeletonPlugin, { ...tocIconMap, ...namedEntitesReaderIconMap, ...imageModeReaderIconMap, + ...tocIconMap, }, config: { - endpoints: { - // FIXME: GraphQL - tocEndpoint: 'http://localhost:8000', - }, entityMap: { accessToken: // eslint-disable-next-line max-len