Skip to content

Commit bbac23b

Browse files
committed
Better docs, small improvements, removed extraneous stuff
1 parent 8a34058 commit bbac23b

File tree

8 files changed

+293
-341
lines changed

8 files changed

+293
-341
lines changed

extensions/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"editor.rulers": [100],
77
"editor.wordWrapColumn": 100,
88

9-
"eslint.validate": ["javascript", "javascriptreact", "html", "typescriptreact"],
9+
"eslint.validate": ["html", "javascript", "javascriptreact", "typescript", "typescriptreact"],
1010

1111
"files.associations": {
1212
".eslintignore": "ignore",

extensions/src/platform-scripture-editor/src/main.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ class ScriptureEditorWebViewFactory extends WebViewFactory<typeof scriptureEdito
328328
throw new Error(`webViewDefinition.projectId is empty!`);
329329

330330
// Figure out the information needed to make the USJ range to give to the editor:
331-
// book, chapter, start jsonPath and offset, and end jsonPath and offset
332-
let startVerseRef = { book: '', chapterNum: 0, verseNum: 0 };
331+
// book, chapter, start jsonPath and offset, and end jsonPath and offset.
332+
// Also need to get the verse to set the scroll group verse to because the editor doesn't
333+
// do it automatically right now
334+
let startVerseRef = { book: '', chapterNum: 0, verseNum: -1 };
333335
let startJsonPath = '';
334336
let endJsonPath = '';
335337
// Start and end offsets based on the USJ JSONPath location
@@ -391,13 +393,14 @@ class ScriptureEditorWebViewFactory extends WebViewFactory<typeof scriptureEdito
391393
'Could not get targetScrRef from range! Selection range cannot (yet) span chapters or books',
392394
);
393395

394-
// If we don't have at least one of the USJ range properties, need to process the chapter
395-
// to find them based on what we have
396+
// If we don't have at least one of the USJ range properties or the verse number, need to
397+
// process the chapter to find them based on what we have
396398
if (
397399
!startJsonPath ||
398400
!endJsonPath ||
399401
startJsonPathOffset === undefined ||
400-
endJsonPathOffset === undefined
402+
endJsonPathOffset === undefined ||
403+
startVerseRef.verseNum === -1
401404
) {
402405
// Get the USJ chapter we're on so we can determine the missing USJ range properties
403406
const pdp = await papi.projectDataProviders.get(
@@ -480,6 +483,15 @@ class ScriptureEditorWebViewFactory extends WebViewFactory<typeof scriptureEdito
480483
// will not exist once the editor is updated
481484
endJsonPathOffset = 0;
482485
}
486+
487+
// If we don't have which verse we're setting the scroll group to, get it
488+
if (startVerseRef.verseNum === -1) {
489+
const startUsfmLocation = usjRW.usjDocumentLocationToUsfmVerseRefVerseLocation(
490+
(startContentLocation ?? usjRW.jsonPathToUsjNodeAndDocumentLocation(startJsonPath))
491+
.documentLocation,
492+
);
493+
startVerseRef.verseNum = startUsfmLocation.verseRef.verseNum;
494+
}
483495
}
484496

485497
const convertedRange = {

extensions/src/platform-scripture-editor/src/platform-scripture-editor.web-view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ globalThis.webViewComponent = function PlatformScriptureEditor({
189189
// and scroll to the new scrRef before setting the range. Set the nextSelectionRange
190190
// which will set the range after a short wait time in a `useEffect` below
191191
setScrRefWithScroll(targetScrRef);
192-
if (range) nextSelectionRange.current = range;
192+
nextSelectionRange.current = range;
193193
}
194194
// We're on the right scr ref. Go ahead and set the selection
195-
else if (range) editorRef.current?.setSelection(range);
195+
else editorRef.current?.setSelection(range);
196196

197197
break;
198198
}

lib/platform-bible-utils/README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,63 @@
22

33
A set of utility functions, types, and classes for use inside Platform.Bible and extensions.
44

5-
## Development
5+
## Scripture Location Types Overview
66

7-
Inspired by https://github.com/jasonsturges/vite-typescript-npm-package
7+
There are many types exported from this package that describe specific positions in a Scripture project.
8+
9+
The types generally follow this name format:
10+
11+
```
12+
<scripture_format><location_format?><location_anchor?>Location
13+
```
14+
15+
- `<scripture_format>` - Which Scripture format the location information is specified against. For example, if the Scripture format is `Usfm`, offsets from the anchor to the specified position are string character index offsets within the USFM representation of the Scripture data.
16+
- `<location_format?>` - Particulars about the way the anchor is specified. If this is not included, this type is likely a catch-all containing a union of multiple subtypes that all include the same information in different location formats.
17+
- `<location_anchor?>` - `Book`, `Chapter`, `Verse`, or `Document` - Which kind of more general, well-known position this location is relative to. The more general location "anchor" may be an absolute position: the start of a specified chapter, book, verse; the data in this location type is expected to specify which chapter, book, or verse the location data is relative to. The anchor may also be a specific USJ document, in which case the location type is not expected to specify which document it is relative to. Document-relative positions are only interpretable if you have the document the position is based on; other location types layer over the document-relative types to indicate which document (and therefore which absolute position) the document-relative position is based on. If this is not specified, this type is a union of multiple subtypes that all specify positions in the same Scripture format.
18+
19+
Examples:
20+
21+
- `UsfmVerseLocation` - Locations relative to the start of a specified verse and at an offset in the USFM representation of the Scripture data
22+
23+
- `<scripture_format>` - `USFM` - the information specifying the position relative to the anchor is an offset based on the USFM representation of the Scripture data
24+
- `<location_format>` - None; this is a union type of multiple subtypes that all specify the same data.
25+
- `<location_anchor>` - `Verse` - this location specifies a specific verse that its position is relative to
26+
27+
- `UsjLocation` - Location whose JSONPath is specified on a USJ document which contains either the entire book or the entire chapter specified and whose offset information is in the USJ representation of the Scripture data
28+
29+
- `<scripture_format>` - `USFM` - the information specifying the position relative to the anchor is an offset based on the USFM representation of the Scripture data
30+
- `<location_format>` - None; this is a union type of multiple subtypes whose subtypes all specify the same data as one another.
31+
- `<location_anchor>` - None; this is a union type of multiple subtypes that all specify either a USJ book or chapter location
32+
33+
- Document-relative locations - various location types that specify a location within some USJ document which is not determinable based on the information in these types
34+
- `UsjDocumentLocation` - A JSONPath query to an object, string, or property within a USJ document and additional information that point to a specific location in that USJ document.
35+
- Note: The subtypes of this type do not conform to the naming format specified above. They are all different forms of USJ document-relative locations.
36+
- JSONPath types - subsets of [JSONPath](https://www.rfc-editor.org/rfc/rfc9535.html) that point to some object, string, or property in a USJ document
37+
- `ContentJsonPath` - JSON path to an object or text content string in a USJ document.
38+
- `PropertyJsonPath` - JSON path to a property on an object in a USJ document.
39+
- Types of USJ document locations - each type is a different format specifying various kinds of locations in a USJ document.
40+
- `UsjAttributeKeyLocation`
41+
- `UsjAttributeMarkerLocation`
42+
- `UsjClosingAttributeMarkerLocation`
43+
- `UsjClosingMarkerLocation`
44+
- `UsjMarkerLocation`
45+
- `UsjTextContentLocation`
46+
- `UsjNodeAndDocumentLocation` - An object or string in a USJ document and its location in that document.
47+
- Absolute locations - various location types that specify a location within a determinable document or relative to a specific point in the Scripture data.
48+
49+
- `UsfmVerseLocation` - A verse ref and an offset within that verse in USFM space that point to a specific location in USFM.
50+
- `UsfmVerseRefVerseLocation` - A particular format for specifying a verse ref and an offset within that verse in USFM space that point to a specific location in USFM.
51+
- `SerializedVerseRef` - Just a verse reference. The offset is implied to be 0, meaning this always points to the very beginning of a verse.
52+
- `UsjLocation` - A verse ref and a location in USJ space that point to a specific location in USJ. The location in USJ space should be interpreted as starting from either the start of the book or the chapter depending on the type of location used.
53+
54+
- `UsjBookLocation` - A verse ref and a location in USJ space that point to a specific location in USJ. The location in USJ space should be interpreted as starting from the start of the book specified.
55+
- `UsjFlatBookLocation`
56+
- `UsjVerseRefBookLocation`
57+
- `UsjChapterLocation` - A verse ref and a location in USJ space that point to a specific location in USJ. The location in USJ space should be interpreted as starting from the start of the chapter specified.
58+
- `UsjFlatChapterLocation`
59+
- `UsjVerseRefChapterLocation`
60+
61+
## Development
862

963
When we publish this npm package, then in the root `package.json`, a version can be given to `platform-bible-utils` instead of the existing file link. At that time we will likely need to use `npm link` and `npm unlink` to develop the components ([see here](https://github.com/jasonsturges/vite-typescript-npm-package#development)).
1064

@@ -44,3 +98,7 @@ npm run build:basic
4498
```
4599

46100
Do not commit changes after running this basic build. Before committing, always run a full build.
101+
102+
## Acknowledgements
103+
104+
Inspired by https://github.com/jasonsturges/vite-typescript-npm-package

lib/platform-bible-utils/dist/index.d.ts

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,10 +2800,12 @@ export interface IUsjReaderWriter {
28002800
* Convert a JSONPath query into a SerializedVerseRef and offset
28012801
*
28022802
* @param jsonPathQuery JSONPath search expression that indicates a node within this USJ data. If
2803-
* the expression matches more than one node, then only the first node found is considered.
2803+
* the expression matches more than one node, then only the first node found is considered. Note
2804+
* that this query must yield a {@link MarkerContent} or {@link Usj}; JSONPaths yielding
2805+
* properties on nodes are not currently supported.
28042806
* @param bookIdIfNotFound 3-letter ID of the book this USJ document is in (only used if a book ID
28052807
* is not found in the USJ document)
2806-
* @returns SerializedVerseRef and offset that represents the location within this USJ data
2808+
* @returns SerializedVerseRef and offset that represent the location within this USJ data
28072809
* indicated by `jsonPathQuery`
28082810
* @throws If not able to find a book ID in the USJ document and `bookIdIfNotFound` is not
28092811
* provided
@@ -2813,13 +2815,11 @@ export interface IUsjReaderWriter {
28132815
* Convert a JSONPath query into a USJ node, JSONPath, and offset
28142816
*
28152817
* @param jsonPathQuery JSONPath search expression that indicates a node within this USJ data. If
2816-
* the expression matches more than one node, then only the first node found is considered.
2817-
* @param bookIdIfNotFound 3-letter ID of the book this USJ document is in (only used if a book ID
2818-
* is not found in the USJ document)
2819-
* @returns SerializedVerseRef and offset that represents the location within this USJ data
2818+
* the expression matches more than one node, then only the first node found is considered. Note
2819+
* that this query must yield a {@link MarkerContent} or {@link Usj}; JSONPaths yielding
2820+
* properties on nodes are not currently supported.
2821+
* @returns USJ node, JSONPath, and offset that represent the location within this USJ data
28202822
* indicated by `jsonPathQuery`
2821-
* @throws If not able to find a book ID in the USJ document and `bookIdIfNotFound` is not
2822-
* provided
28232823
*/
28242824
jsonPathToUsjNodeAndDocumentLocation(jsonPathQuery: string): UsjNodeAndDocumentLocation;
28252825
/** Build a JSONPath query that uniquely identifies the given node with this USJ data. */
@@ -2942,26 +2942,6 @@ export interface IUsjReaderWriter {
29422942
* provided
29432943
*/
29442944
usjDocumentLocationToUsfmVerseRefVerseLocation(usjLocation: UsjDocumentLocation, bookIdIfNotFound?: string): UsfmVerseRefVerseLocation;
2945-
/**
2946-
* Transforms a relative USJ document location into an absolute chapter-based USJ location that
2947-
* includes which chapter the USJ location is relative to.
2948-
*
2949-
* Note: this method property transforms book-based USJ document locations to chapter-based USJ
2950-
* locations as well.
2951-
*
2952-
* Note: This may work with peripheral books as well, but these books have `periph` markers
2953-
* between `id` and chapters, so this may need to be revised when peripheral books are more fully
2954-
* supported
2955-
*
2956-
* @param usjLocation Location in USJ space relative to the USJ document
2957-
* @param bookIdIfNotFound 3-letter ID of the book this USJ document is in (only used if a book ID
2958-
* is not found in the USJ document)
2959-
* @returns Location in USJ space relative to the chapter that the USJ document location is in
2960-
* @throws If not able to find the location in the USJ document
2961-
* @throws If not able to find a book ID in the USJ document and `bookIdIfNotFound` is not
2962-
* provided
2963-
*/
2964-
usjDocumentLocationToUsjVerseRefChapterLocation<TDocumentLocation extends UsjDocumentLocation = UsjDocumentLocation>(usjLocation: TDocumentLocation, bookIdIfNotFound?: string): UsjVerseRefChapterLocation<TDocumentLocation>;
29652945
}
29662946
/** Gets the default caller sequence to use to generate callers for textual notes. */
29672947
export declare function getDefaultCallerSequence(): string[];
@@ -4957,20 +4937,6 @@ export declare class UsjReaderWriter implements IUsjReaderWriter {
49574937
private static jsonPathArrayToJsonPath;
49584938
/** "Normalize" the JSONPath passed in so we can use it for lookups in {@link FragmentsByJsonPath} */
49594939
private static normalizeJsonPath;
4960-
/**
4961-
* Move a JSONPath to be relative to a chapter marker JSONPath by removing the chapter path parts
4962-
* from the front of the JSONPath and adjusting the content index.
4963-
*
4964-
* @example Taking JSONPath `$.content[0].content[2].content[5].content[7]['caller']` and moving
4965-
* it relative to chapter JSONPath `$.content[0].content[2].content[3]` would return
4966-
* `$.content[2].content[7]['caller']`
4967-
*
4968-
* @param jsonPath JSONPath to move to be relative to the chapter
4969-
* @param chapterJsonPath JSONPath to use as the chapter from which to make the other JSONPath
4970-
* relative
4971-
* @returns `jsonPath` made relative to the chapter JSONPath
4972-
*/
4973-
private static moveJsonPathRelativeToChapter;
49744940
/**
49754941
* Returns a "normalized" JSONPath transformed from the working stack. We can use this JSONPath
49764942
* for lookups in {@link FragmentsByJsonPath}
@@ -5091,7 +5057,6 @@ export declare class UsjReaderWriter implements IUsjReaderWriter {
50915057
* JSONPath
50925058
*/
50935059
static usjBookLocationToUsjVerseRefBookLocation(usjBookLocation: UsjBookLocation): UsjVerseRefBookLocation;
5094-
usjDocumentLocationToUsjVerseRefChapterLocation<TDocumentLocation extends UsjDocumentLocation = UsjDocumentLocation>(usjLocation: TDocumentLocation, bookIdIfNotFound?: string): UsjVerseRefChapterLocation<TDocumentLocation>;
50955060
usfmVerseLocationToUsjNodeAndDocumentLocation(usfmVerseLocation: UsfmVerseLocation): UsjNodeAndDocumentLocation;
50965061
usfmVerseLocationToUsjDocumentLocation(usfmVerseLocation: UsfmVerseLocation | SerializedVerseRef): UsjDocumentLocation;
50975062
/**

0 commit comments

Comments
 (0)