diff --git a/extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx b/extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx index a5c46661d3..a8fa247c91 100644 --- a/extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx +++ b/extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx @@ -4,15 +4,14 @@ import { EditorRef, Marginal, MarginalRef, - Usj, } from '@biblionexus-foundation/platform-editor'; +import type { Usj } from '@biblionexus-foundation/scripture-utilities'; import { VerseRef } from '@sillsdev/scripture'; import { JSX, useCallback, useEffect, useMemo, useRef } from 'react'; import type { WebViewProps } from '@papi/core'; import { logger } from '@papi/frontend'; import { useProjectData, useSetting } from '@papi/frontend/react'; import { ScriptureReference, debounce } from 'platform-bible-utils'; -import { USJDocument } from 'platform-scripture'; /** The offset in pixels from the top of the window to scroll to show the verse number */ const VERSE_NUMBER_SCROLL_OFFSET = 80; @@ -29,7 +28,7 @@ const defaultScrRef: ScriptureReference = { verseNum: 1, }; -const usjDocumentDefault: USJDocument = { type: 'USJ', version: '0.2.1', content: [] }; +const usjDocumentDefault: Usj = { type: 'USJ', version: '0.2.1', content: [] }; function scrollToScrRef(scrRef: ScriptureReference) { const verseElement = document.querySelector( diff --git a/extensions/src/platform-scripture/package.json b/extensions/src/platform-scripture/package.json index fadb2ce60a..795405ce8b 100644 --- a/extensions/src/platform-scripture/package.json +++ b/extensions/src/platform-scripture/package.json @@ -35,6 +35,7 @@ "platform-bible-utils": "file:../../../lib/platform-bible-utils" }, "devDependencies": { + "@biblionexus-foundation/scripture-utilities": "^0.0.1", "@swc/core": "^1.4.11", "@types/node": "^20.12.2", "@types/react": "^18.2.73", @@ -42,7 +43,6 @@ "@types/webpack": "^5.28.5", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", - "@xmldom/xmldom": "^0.8.10", "concurrently": "^8.2.2", "copy-webpack-plugin": "^12.0.2", "cross-env": "^7.0.3", diff --git a/extensions/src/platform-scripture/src/project-data-provider/platform-scripture-extender-pdpe.model.ts b/extensions/src/platform-scripture/src/project-data-provider/platform-scripture-extender-pdpe.model.ts index 5e5610b01e..401a7c16af 100644 --- a/extensions/src/platform-scripture/src/project-data-provider/platform-scripture-extender-pdpe.model.ts +++ b/extensions/src/platform-scripture/src/project-data-provider/platform-scripture-extender-pdpe.model.ts @@ -6,9 +6,8 @@ import { DataProviderUpdateInstructions, IProjectDataProviderEngine } from '@pap import { VerseRef } from '@sillsdev/scripture'; import type { ProjectDataProviderInterfaces } from 'papi-shared-types'; import { UnsubscriberAsync, UnsubscriberAsyncList } from 'platform-bible-utils'; -import { USJChapterProjectInterfaceDataTypes, USJDocument } from 'platform-scripture'; -import { usjToUsxString } from './scripture-utils/usj-to-usx'; -import { usxStringToUsj } from './scripture-utils/usx-to-usj'; +import { USJChapterProjectInterfaceDataTypes } from 'platform-scripture'; +import { Usj, usjToUsxString, usxStringToUsj } from '@biblionexus-foundation/scripture-utilities'; /** The `projectInterface`s the Scripture Extender PDPF serves */ // TypeScript is upset without `satisfies` here because `as const` makes the array readonly but it @@ -74,7 +73,7 @@ class ScriptureExtenderProjectDataProviderEngine @papi.dataProviders.decorators.doNotNotify async setChapterUSJ( verseRef: VerseRef, - chapterUsj: USJDocument, + chapterUsj: Usj, ): Promise> { const didSucceed = await this.pdps['platformScripture.USX_Chapter'].setChapterUSX( verseRef, @@ -84,7 +83,7 @@ class ScriptureExtenderProjectDataProviderEngine return false; } - async getChapterUSJ(verseRef: VerseRef): Promise { + async getChapterUSJ(verseRef: VerseRef): Promise { const usx = await this.pdps['platformScripture.USX_Chapter'].getChapterUSX(verseRef); return usx ? usxStringToUsj(usx) : undefined; } diff --git a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj-to-usx.ts b/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj-to-usx.ts deleted file mode 100644 index 99af2fbcc5..0000000000 --- a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj-to-usx.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable */ -// COPIED DIRECTLY FROM https://github.com/BiblioNexus-Foundation/scripture-editors/blob/main/packages/shared/converters/usj/usj-to-usx.ts -// Please fix this when we can use that package without pulling in React on the backend - -/** - * Convert Scripture from USJ to USX. Adapted to TypeScript from this file: - * - * @see https://github.com/usfm-bible/tcdocs/blob/main/python/lib/usfmtc/usjproc.py - */ - -import { DOMImplementation } from '@xmldom/xmldom'; -import { MarkerContent, MarkerObject, Usj } from './usj.model'; -import { USX_TYPE, USX_VERSION } from './usx.model'; - -let chapterEid: string | undefined; -let verseEid: string | undefined; - -function createVerseEndElement(usxDoc: XMLDocument, verseEid: string): HTMLElement { - const eidElement = usxDoc.createElement('verse'); - eidElement.setAttribute('eid', verseEid); - return eidElement; -} - -function createChapterEndElement(usxDoc: XMLDocument, chapterEid: string): HTMLElement { - const eidElement = usxDoc.createElement('chapter'); - eidElement.setAttribute('eid', chapterEid); - return eidElement; -} - -function setAttributes(element: HTMLElement, markerContent: MarkerObject) { - element.setAttribute('style', markerContent.marker); - for (const [key, value] of Object.entries(markerContent)) { - if (value && !['type', 'marker', 'content'].includes(key)) { - element.setAttribute(key, value as string); - } - } -} - -function convertUsjRecurse( - markerContent: MarkerContent, - parentElement: HTMLElement, - usxDoc: XMLDocument, - isLastItem: boolean, -) { - let element: Text | HTMLElement; - let type: string | undefined; - let eidElement: HTMLElement | undefined; - if (typeof markerContent === 'string') element = usxDoc.createTextNode(markerContent); - else { - type = markerContent.type.replace('table:', ''); - element = usxDoc.createElement(type); - setAttributes(element, markerContent); - if (markerContent.content) { - for (const [index, item] of markerContent.content.entries()) { - const _isLastItem = index === markerContent.content.length - 1; - convertUsjRecurse(item, element, usxDoc, _isLastItem); - } - } - } - - // Create chapter and verse end elements from SID attributes. - if (verseEid && (type === 'verse' || (parentElement.tagName === 'para' && isLastItem))) { - eidElement = createVerseEndElement(usxDoc, verseEid); - verseEid = undefined; - } - if (type === 'verse' && typeof markerContent !== 'string' && markerContent.sid !== undefined) - verseEid = markerContent.sid; - - if (chapterEid && (type === 'chapter' || (type === 'para' && isLastItem))) { - eidElement = createChapterEndElement(usxDoc, chapterEid); - chapterEid = undefined; - } - if (type === 'chapter' && typeof markerContent !== 'string' && markerContent.sid !== undefined) - chapterEid = markerContent.sid; - - // Append to parent. - if (eidElement && !isLastItem) parentElement.appendChild(eidElement); - parentElement.appendChild(element); - if (eidElement && isLastItem) parentElement.appendChild(eidElement); - - // Allow for final chapter and verse end elements at the end of an implied para. - if (isLastItem && parentElement.nodeName === USX_TYPE) { - if (verseEid) parentElement.appendChild(createVerseEndElement(usxDoc, verseEid)); - if (chapterEid) parentElement.appendChild(createChapterEndElement(usxDoc, chapterEid)); - verseEid = undefined; - chapterEid = undefined; - } -} - -export function usjToUsxDom(usj: Usj, usxDoc: XMLDocument): HTMLElement { - for (const [index, markerContent] of usj.content.entries()) { - const isLastItem = index === usj.content.length - 1; - convertUsjRecurse(markerContent, usxDoc.documentElement, usxDoc, isLastItem); - } - return usxDoc.documentElement; -} - -export function usjToUsxString(usj: Usj): string { - const usxDoc = new DOMImplementation().createDocument('', USX_TYPE); - usxDoc.documentElement.setAttribute('version', USX_VERSION); - usjToUsxDom(usj, usxDoc); - return usxDoc.toString(); -} diff --git a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj.model.ts b/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj.model.ts deleted file mode 100644 index 58c71852a2..0000000000 --- a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usj.model.ts +++ /dev/null @@ -1,329 +0,0 @@ -/* eslint-disable */ -// COPIED DIRECTLY FROM https://github.com/BiblioNexus-Foundation/scripture-editors/blob/main/packages/shared/converters/usj/usj.model.ts -// Please fix this when we can use that package without pulling in React on the backend - -/** - * Unified Scripture JSON (USJ) - The JSON variant of USFM and USX data models. These types follow - * this schema: - * - * @see https://github.com/usfm-bible/tcdocs/blob/usj/grammar/usj.js - */ - -/** The USJ spec type */ -export const USJ_TYPE = 'USJ'; -/** The USJ spec version */ -export const USJ_VERSION = '0.2.1'; - -export const MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [ - 'type', - 'marker', - 'content', - 'sid', - 'eid', - 'number', - 'code', - 'altnumber', - 'pubnumber', - 'caller', - 'align', - 'category', -]; - -/** Single piece of Scripture content */ -export type MarkerContent = string | MarkerObject; - -/** A Scripture Marker and its contents */ -export type MarkerObject = { - /** - * The kind/category of node or element this is, corresponding the USFM marker and USX node - * - * @example `para`, `verse`, `char` - */ - type: string; - /** - * The corresponding marker in USFM or style in USX - * - * @example `p`, `v`, `nd` - */ - marker: string; - /** This marker's contents laid out in order */ - content?: MarkerContent[]; - /** Indicates the Book-chapter-verse value in the paragraph based structure */ - sid?: string; - /** Milestone end ID, matches start ID (not currently included in USJ spec) */ - eid?: string; - /** Chapter number or verse number */ - number?: string; - /** The 3-letter book code in ID element */ - code?: BookCode; - /** Alternate chapter number or verse number */ - altnumber?: string; - /** Published character of chapter or verse */ - pubnumber?: string; - /** Caller character for footnotes and cross-refs */ - caller?: string; - /** Alignment of table cells */ - align?: string; - /** Category of extended study bible sections */ - category?: string; -}; - -/** Scripture data represented in JSON format. Data compatible transformation from USX/USFM */ -export type Usj = { - /** The USJ spec type */ - type: typeof USJ_TYPE; - /** The USJ spec version */ - version: typeof USJ_VERSION; - /** The JSON representation of scripture contents from USFM/USX */ - content: MarkerContent[]; -}; - -export function isValidBookCode(code: string): boolean { - return VALID_BOOK_CODES.includes(code as BookCode); -} - -/** 3-letter Scripture book code */ -export type BookCode = - // Old Testament - | 'GEN' - | 'EXO' - | 'LEV' - | 'NUM' - | 'DEU' - | 'JOS' - | 'JDG' - | 'RUT' - | '1SA' - | '2SA' - | '1KI' - | '2KI' - | '1CH' - | '2CH' - | 'EZR' - | 'NEH' - | 'EST' - | 'JOB' - | 'PSA' - | 'PRO' - | 'ECC' - | 'SNG' - | 'ISA' - | 'JER' - | 'LAM' - | 'EZK' - | 'DAN' - | 'HOS' - | 'JOL' - | 'AMO' - | 'OBA' - | 'JON' - | 'MIC' - | 'NAM' - | 'HAB' - | 'ZEP' - | 'HAG' - | 'ZEC' - | 'MAL' - // New Testament - | 'MAT' - | 'MRK' - | 'LUK' - | 'JHN' - | 'ACT' - | 'ROM' - | '1CO' - | '2CO' - | 'GAL' - | 'EPH' - | 'PHP' - | 'COL' - | '1TH' - | '2TH' - | '1TI' - | '2TI' - | 'TIT' - | 'PHM' - | 'HEB' - | 'JAS' - | '1PE' - | '2PE' - | '1JN' - | '2JN' - | '3JN' - | 'JUD' - | 'REV' - // Deuterocanon - | 'TOB' - | 'JDT' - | 'ESG' - | 'WIS' - | 'SIR' - | 'BAR' - | 'LJE' - | 'S3Y' - | 'SUS' - | 'BEL' - | '1MA' - | '2MA' - | '3MA' - | '4MA' - | '1ES' - | '2ES' - | 'MAN' - | 'PS2' - | 'ODA' - | 'PSS' - | 'EZA' - | '5EZ' - | '6EZ' - | 'DAG' - | 'PS3' - | '2BA' - | 'LBA' - | 'JUB' - | 'ENO' - | '1MQ' - | '2MQ' - | '3MQ' - | 'REP' - | '4BA' - | 'LAO' - // Non scripture - | 'FRT' - | 'BAK' - | 'OTH' - | 'INT' - | 'CNC' - | 'GLO' - | 'TDX' - | 'NDX' - | 'XXA' - | 'XXB' - | 'XXC' - | 'XXD' - | 'XXE' - | 'XXF' - | 'XXG'; - -const VALID_BOOK_CODES = [ - // Old Testament - 'GEN', - 'EXO', - 'LEV', - 'NUM', - 'DEU', - 'JOS', - 'JDG', - 'RUT', - '1SA', - '2SA', - '1KI', - '2KI', - '1CH', - '2CH', - 'EZR', - 'NEH', - 'EST', - 'JOB', - 'PSA', - 'PRO', - 'ECC', - 'SNG', - 'ISA', - 'JER', - 'LAM', - 'EZK', - 'DAN', - 'HOS', - 'JOL', - 'AMO', - 'OBA', - 'JON', - 'MIC', - 'NAM', - 'HAB', - 'ZEP', - 'HAG', - 'ZEC', - 'MAL', - // New Testament - 'MAT', - 'MRK', - 'LUK', - 'JHN', - 'ACT', - 'ROM', - '1CO', - '2CO', - 'GAL', - 'EPH', - 'PHP', - 'COL', - '1TH', - '2TH', - '1TI', - '2TI', - 'TIT', - 'PHM', - 'HEB', - 'JAS', - '1PE', - '2PE', - '1JN', - '2JN', - '3JN', - 'JUD', - 'REV', - // Deuterocanon - 'TOB', - 'JDT', - 'ESG', - 'WIS', - 'SIR', - 'BAR', - 'LJE', - 'S3Y', - 'SUS', - 'BEL', - '1MA', - '2MA', - '3MA', - '4MA', - '1ES', - '2ES', - 'MAN', - 'PS2', - 'ODA', - 'PSS', - 'EZA', - '5EZ', - '6EZ', - 'DAG', - 'PS3', - '2BA', - 'LBA', - 'JUB', - 'ENO', - '1MQ', - '2MQ', - '3MQ', - 'REP', - '4BA', - 'LAO', - // Non scripture - 'FRT', - 'BAK', - 'OTH', - 'INT', - 'CNC', - 'GLO', - 'TDX', - 'NDX', - 'XXA', - 'XXB', - 'XXC', - 'XXD', - 'XXE', - 'XXF', - 'XXG', -] as const; diff --git a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx-to-usj.ts b/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx-to-usj.ts deleted file mode 100644 index e7100c1940..0000000000 --- a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx-to-usj.ts +++ /dev/null @@ -1,123 +0,0 @@ -/* eslint-disable */ -// COPIED DIRECTLY FROM https://github.com/BiblioNexus-Foundation/scripture-editors/blob/main/packages/shared/converters/usj/usx-to-usj.ts -// Please fix this when we can use that package without pulling in React on the backend - -/** - * Convert Scripture from USX to USJ. Adapted to TypeScript from this file: - * - * @see https://github.com/mvh-solutions/nice-usfm-json/blob/main/javascript/lib/usx-to-usj.js - * And kept updated with changes from this file: - * @see https://github.com/usfm-bible/tcdocs/blob/main/python/scripts/usx2usj.py - */ - -import { DOMParser } from '@xmldom/xmldom'; -import { MarkerObject, USJ_TYPE, USJ_VERSION, Usj } from './usj.model'; -import { USX_TYPE } from './usx.model'; - -type Action = 'append' | 'merge' | 'ignore'; -type Attribs = { [name: string]: string }; - -function usxDomToUsjRecurse( - inputUsxElement: HTMLElement, -): [outputJson: T, action: Action] { - const attribs: Attribs = {}; - let type: string = inputUsxElement.tagName; - let marker: string | undefined; - let text: string | undefined; - let action: Action = 'append'; - - if (['row', 'cell'].includes(type)) type = 'table:' + type; - if (inputUsxElement.attributes) { - for (let i = 0; i < inputUsxElement.attributes.length; i++) { - const attrib = inputUsxElement.attributes[i]; - attribs[attrib.name] = attrib.value; - } - } - - if (attribs.style) { - marker = attribs.style; - delete attribs.style; - } - // dropping because presence of vid in para elements is not consistent in USX - if (attribs.vid) delete attribs.vid; - if (attribs.closed) delete attribs.closed; - if (attribs.status) delete attribs.status; - - let outObj: T = { type } as T; - if (marker) (outObj as MarkerObject).marker = marker; - outObj = { ...outObj, ...attribs }; - - if ( - inputUsxElement.firstChild && - inputUsxElement.firstChild.nodeType === inputUsxElement.firstChild.TEXT_NODE && - inputUsxElement.firstChild.nodeValue && - inputUsxElement.firstChild.nodeValue.trim() !== '' - ) { - text = inputUsxElement.firstChild.nodeValue; - } - - const children = Array.from(inputUsxElement.childNodes); - outObj.content = []; - - if (text) { - outObj.content.push(text); - } - - for (const child of children) { - // ChildNodes are Elements. - if ((child as HTMLElement).tagName === undefined) { - continue; - } - // ChildNodes are Elements. - const [childDict, whatToDo] = usxDomToUsjRecurse(child as HTMLElement); - - switch (whatToDo) { - case 'append': - outObj.content.push(childDict); - break; - case 'merge': - outObj.content = outObj.content.concat(childDict); - break; - case 'ignore': - break; - default: - break; - } - - if ( - child.nextSibling && - child.nextSibling.nodeType === child.nextSibling.TEXT_NODE && - child.nextSibling.nodeValue && - (child.nextSibling.nodeValue.trim() !== '' || child.nextSibling.nodeValue === ' ') - ) { - outObj.content.push(child.nextSibling.nodeValue); - } - } - - if ( - (outObj.content.length === 0 && outObj.type !== USX_TYPE) || - ['chapter', 'verse', 'optbreak', 'ms'].includes(type) || - (marker && ['va', 'ca', 'b'].includes(marker)) - ) { - delete outObj.content; - } - - if ('eid' in outObj && ['verse', 'chapter'].includes(type)) { - action = 'ignore'; - } - - return [outObj, action]; -} - -export function usxDomToUsj(inputUsxDom: HTMLElement): Usj { - const [outputJson] = usxDomToUsjRecurse(inputUsxDom); - outputJson.type = USJ_TYPE; - outputJson.version = USJ_VERSION; - return outputJson; -} - -export function usxStringToUsj(usxString: string): Usj { - const parser = new DOMParser(); - const inputUsxDom = parser.parseFromString(usxString, 'text/xml'); - return usxDomToUsj(inputUsxDom.documentElement); -} diff --git a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx.model.ts b/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx.model.ts deleted file mode 100644 index a5fde5e5b3..0000000000 --- a/extensions/src/platform-scripture/src/project-data-provider/scripture-utils/usx.model.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* eslint-disable */ -// COPIED DIRECTLY FROM https://github.com/BiblioNexus-Foundation/scripture-editors/blob/main/packages/shared/converters/usj/usx.model.ts -// Please fix this when we can use that package without pulling in React on the backend - -/** - * Unified Scripture XML (USX). These types follow this schema: - * - * @see https://github.com/usfm-bible/tcdocs/blob/main/grammar/usx.rng - */ - -/** The USX spec type */ -export const USX_TYPE = 'usx'; -/** The USX spec version */ -export const USX_VERSION = '3.0'; diff --git a/extensions/src/platform-scripture/src/types/platform-scripture.d.ts b/extensions/src/platform-scripture/src/types/platform-scripture.d.ts index 6fd1db52a5..231080017e 100644 --- a/extensions/src/platform-scripture/src/types/platform-scripture.d.ts +++ b/extensions/src/platform-scripture/src/types/platform-scripture.d.ts @@ -8,6 +8,7 @@ declare module 'platform-scripture' { } from '@papi/core'; import type { IProjectDataProvider } from 'papi-shared-types'; import { UnsubscriberAsync } from 'platform-bible-utils'; + import type { Usj } from '@biblionexus-foundation/scripture-utilities'; /** Provides Scripture data in USFM format by book, chapter, or verse */ export type USFMBookChapterVerseProjectInterfaceDataTypes = { @@ -32,7 +33,7 @@ declare module 'platform-scripture' { * * WARNING: USJ is in very early stages of proposal, so it will likely change over time. */ - ChapterUSJ: DataProviderDataType; + ChapterUSJ: DataProviderDataType; }; /** @@ -50,7 +51,7 @@ declare module 'platform-scripture' { * over time. Additionally, USJ is in very early stages of proposal, so it will likely also * change over time. */ - BookUSJ: DataProviderDataType; + BookUSJ: DataProviderDataType; /** * Gets the tokenized USJ data for the specified verse * @@ -58,7 +59,7 @@ declare module 'platform-scripture' { * over time. Additionally, USJ is in very early stages of proposal, so it will likely also * change over time. */ - VerseUSJ: DataProviderDataType; + VerseUSJ: DataProviderDataType; }; /** @@ -77,7 +78,7 @@ declare module 'platform-scripture' { * over time. Additionally, USJ is in very early stages of proposal, so it will likely also * change over time. */ - getBookUSJ(verseRef: VerseRef): Promise; + getBookUSJ(verseRef: VerseRef): Promise; /** * Sets the tokenized USJ data for the specified book * @@ -87,7 +88,7 @@ declare module 'platform-scripture' { */ setBookUSJ( verseRef: VerseRef, - usj: USJDocument, + usj: Usj, ): Promise>; /** * Subscribe to run a callback function when the tokenized USJ data is changed @@ -103,7 +104,7 @@ declare module 'platform-scripture' { */ subscribeBookUSJ( verseRef: VerseRef, - callback: (usj: USJDocument | undefined) => void, + callback: (usj: Usj | undefined) => void, options?: DataProviderSubscriberOptions, ): Promise; @@ -114,7 +115,7 @@ declare module 'platform-scripture' { * over time. Additionally, USJ is in very early stages of proposal, so it will likely also * change over time. */ - getVerseUSJ(verseRef: VerseRef): Promise; + getVerseUSJ(verseRef: VerseRef): Promise; /** * Sets the tokenized USJ data for the specified verse * @@ -124,7 +125,7 @@ declare module 'platform-scripture' { */ setVerseUSJ( verseRef: VerseRef, - usj: USJDocument, + usj: Usj, ): Promise>; /** * Subscribe to run a callback function when the tokenized USJ data is changed @@ -140,7 +141,7 @@ declare module 'platform-scripture' { */ subscribeVerseUSJ( verseRef: VerseRef, - callback: (usj: USJDocument | undefined) => void, + callback: (usj: Usj | undefined) => void, options?: DataProviderSubscriberOptions, ): Promise; @@ -288,7 +289,7 @@ declare module 'platform-scripture' { * * WARNING: USJ is in very early stages of proposal, so it will likely change over time. */ - getChapterUSJ(verseRef: VerseRef): Promise; + getChapterUSJ(verseRef: VerseRef): Promise; /** * Sets the tokenized USJ data for the specified chapter * @@ -296,7 +297,7 @@ declare module 'platform-scripture' { */ setChapterUSJ( verseRef: VerseRef, - usj: USJDocument, + usj: Usj, ): Promise>; /** * Subscribe to run a callback function when the tokenized USJ data is changed @@ -310,67 +311,12 @@ declare module 'platform-scripture' { */ subscribeChapterUSJ( verseRef: VerseRef, - callback: (usj: USJDocument | undefined) => void, + callback: (usj: Usj | undefined) => void, options?: DataProviderSubscriberOptions, ): Promise; }; // #region USJ types - - /** - * Scripture data represented in JSON format. Transformation from USX - * - * [See more information - * here](https://github.com/paranext/paranext-core/issues/480#issuecomment-1751094148) - */ - export type USJDocument = { - /** The Scripture data serialization format used for this document */ - type: 'USJ'; - /** The USJ spec version */ - // Temporarily changed to 0.2.1 until we get the shared Scripture utils package which will have types that replace these - version: '0.2.1'; - /** Scripture contents laid out in a linear fashion */ - content: MarkerContent[]; - }; - - /** One piece of Scripture content. Can be a simple string or a marker and its contents */ - export type MarkerContent = string | MarkerObject; - - /** A Scripture Marker and its contents */ - export type MarkerObject = { - /** - * The kind of node or element this is, corresponding to each marker in USFM or each node in USX - * - * Its format is `type:style` - * - * @example `para:p`, `verse:v`, `char:nd` - */ - type: `${string}:${string}`; - /** This marker's contents laid out in a linear fashion */ - content?: MarkerContent[]; - /** Indicates the Book-chapter-verse value in the paragraph based structure */ - sid?: string; - /** Chapter number or verse number */ - number?: string; - /** The 3-letter book code in the id element */ - code?: BookCode; - /** Alternate chapter number or verse number */ - altnumber?: string; - /** Published character of chapter or verse */ - pubnumber?: string; - /** Caller character for footnotes and cross-refs */ - caller?: string; - /** Alignment of table cells */ - align?: string; - /** Category of extended study bible sections */ - category?: string; - }; - - /** Three-letter Scripture book code */ - // prettier-ignore - export type BookCode = "GEN" | "EXO" | "LEV" | "NUM" | "DEU" | "JOS" | "JDG" | "RUT" | "1SA" | "2SA" | "1KI" | "2KI" | "1CH" | "2CH" | "EZR" | "NEH" | "EST" | "JOB" | "PSA" | "PRO" | "ECC" | "SNG" | "ISA" | "JER" | "LAM" | "EZK" | "DAN" | "HOS" | "JOL" | "AMO" | "OBA" | "JON" | "MIC" | "NAM" | "HAB" | "ZEP" | "HAG" | "ZEC" | "MAL" | "MAT" | "MRK" | "LUK" | "JHN" | "ACT" | "ROM" | "1CO" | "2CO" | "GAL" | "EPH" | "PHP" | "COL" | "1TH" | "2TH" | "1TI" | "2TI" | "TIT" | "PHM" | "HEB" | "JAS" | "1PE" | "2PE" | "1JN" | "2JN" | "3JN" | "JUD" | "REV" | "TOB" | "JDT" | "ESG" | "WIS" | "SIR" | "BAR" | "LJE" | "S3Y" | "SUS" | "BEL" | "1MA" | "2MA" | "3MA" | "4MA" | "1ES" | "2ES" | "MAN" | "PS2" | "ODA" | "PSS" | "EZA" | "5EZ" | "6EZ" | "DAG" | "PS3" | "2BA" | "LBA" | "JUB" | "ENO" | "1MQ" | "2MQ" | "3MQ" | "REP" | "4BA" | "LAO" | "FRT" | "BAK" | "OTH" | "INT" | "CNC" | "GLO" | "TDX" | "NDX" | "XXA" | "XXB" | "XXC" | "XXD" | "XXE" | "XXF" | "XXG"; - - // #endregion } declare module 'papi-shared-types' { diff --git a/package-lock.json b/package-lock.json index b2c01d21ab..2966e4bf34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -392,6 +392,7 @@ "platform-bible-utils": "file:../../../lib/platform-bible-utils" }, "devDependencies": { + "@biblionexus-foundation/scripture-utilities": "^0.0.1", "@swc/core": "^1.4.11", "@types/node": "^20.12.2", "@types/react": "^18.2.73", @@ -399,7 +400,6 @@ "@types/webpack": "^5.28.5", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", - "@xmldom/xmldom": "^0.8.10", "concurrently": "^8.2.2", "copy-webpack-plugin": "^12.0.2", "cross-env": "^7.0.3", @@ -3046,6 +3046,15 @@ "react-dom": ">=18.3.1" } }, + "node_modules/@biblionexus-foundation/scripture-utilities": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@biblionexus-foundation/scripture-utilities/-/scripture-utilities-0.0.1.tgz", + "integrity": "sha512-LjCIn8JYYH/SzHfNiAjZw4wMno7kf73lAJcBEBEZMM+jyTBQfpbqD3i5WofQwleO1HvbdKOtxFV6wZa0vownNg==", + "dev": true, + "dependencies": { + "@xmldom/xmldom": "^0.8.10" + } + }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -32201,6 +32210,15 @@ "yjs": "^13.6.15" } }, + "@biblionexus-foundation/scripture-utilities": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@biblionexus-foundation/scripture-utilities/-/scripture-utilities-0.0.1.tgz", + "integrity": "sha512-LjCIn8JYYH/SzHfNiAjZw4wMno7kf73lAJcBEBEZMM+jyTBQfpbqD3i5WofQwleO1HvbdKOtxFV6wZa0vownNg==", + "dev": true, + "requires": { + "@xmldom/xmldom": "^0.8.10" + } + }, "@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -46248,6 +46266,7 @@ "platform-scripture": { "version": "file:extensions/src/platform-scripture", "requires": { + "@biblionexus-foundation/scripture-utilities": "^0.0.1", "@sillsdev/scripture": "^1.4.3", "@swc/core": "^1.4.11", "@types/node": "^20.12.2", @@ -46256,7 +46275,6 @@ "@types/webpack": "^5.28.5", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", - "@xmldom/xmldom": "^0.8.10", "concurrently": "^8.2.2", "copy-webpack-plugin": "^12.0.2", "cross-env": "^7.0.3",