Skip to content

Commit 11195b7

Browse files
authored
fix losing attributes on unknown nodes (#417)
- fixes #391 - stop dropping known attributes on any marker
1 parent d236f2b commit 11195b7

File tree

19 files changed

+2108
-54
lines changed

19 files changed

+2108
-54
lines changed

demos/platform/src/app/app.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface Annotations {
4444

4545
const isTesting = process.env.NODE_ENV === "testing";
4646
const webUsj = usxStringToUsj(isTesting ? WEB_PSA_USX : WEB_PSA_CH1_USX);
47+
const editorUsj = webUsj; // isTesting ? webUsj : TJ_USJ;
4748
const defaultScrRef: SerializedVerseRef = { book: "PSA", chapterNum: 1, verseNum: 1 };
4849
// Word "man" inside first q1 of PSA 1:1.
4950
const annotationRange1 = {
@@ -327,7 +328,7 @@ export default function App() {
327328
useEffect(() => {
328329
const timeoutId = setTimeout(() => {
329330
marginalRef.current?.setComments?.(comments as Comments);
330-
marginalRef.current?.setUsj(webUsj);
331+
marginalRef.current?.setUsj(editorUsj);
331332
}, 0);
332333
return () => clearTimeout(timeoutId);
333334
}, []);
@@ -340,7 +341,7 @@ export default function App() {
340341

341342
return (
342343
<div style={{ display: "flex", flexDirection: "row", alignItems: "stretch", height: "80vh" }}>
343-
<div style={{ flex: 1 }}>
344+
<div style={{ flex: 1, minWidth: 0 }}>
344345
<div className="controls">
345346
<button onClick={toggleIsOptionsDefined}>
346347
{isOptionsDefined ? "Undefine" : "Define"} options

libs/shared/src/nodes/features/UnknownNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UnknownAttributes } from "../usj/node-constants.js";
2+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
23
import {
34
$applyNodeReplacement,
45
DOMConversionMap,
@@ -22,6 +23,9 @@ export type SerializedUnknownNode = Spread<
2223
SerializedElementNode
2324
>;
2425

26+
/** List of known properties of `MarkerObject` */
27+
export const UNKNOWN_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = ["type", "marker", "content"];
28+
2529
export const UNKNOWN_TAG_NAME = "unknown";
2630
export const UNKNOWN_VERSION = 1;
2731

libs/shared/src/nodes/usj/BookNode.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/doc/id.html */
22

3-
import { BookCode, isValidBookCode } from "@eten-tech-foundation/scripture-utilities";
3+
import { UnknownAttributes } from "./node-constants.js";
4+
import { BookCode, isValidBookCode, MarkerObject } from "@eten-tech-foundation/scripture-utilities";
45
import {
56
$applyNodeReplacement,
67
ElementNode,
@@ -11,7 +12,6 @@ import {
1112
SerializedLexicalNode,
1213
Spread,
1314
} from "lexical";
14-
import { UnknownAttributes } from "./node-constants.js";
1515

1616
export const BOOK_MARKER = "id";
1717
export const BOOK_VERSION = 1;
@@ -26,6 +26,14 @@ export type SerializedBookNode = Spread<
2626
SerializedElementNode
2727
>;
2828

29+
/** List of known properties of `MarkerObject` */
30+
export const BOOK_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [
31+
"type",
32+
"marker",
33+
"code",
34+
"content",
35+
];
36+
2937
export class BookNode extends ElementNode {
3038
__marker: BookMarker = BOOK_MARKER;
3139
__code: BookCode | "";

libs/shared/src/nodes/usj/ChapterNode.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/cv/c.html */
22

3+
import { CHAPTER_CLASS_NAME, UnknownAttributes } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
35
import {
46
$applyNodeReplacement,
57
ElementNode,
@@ -10,7 +12,6 @@ import {
1012
SerializedLexicalNode,
1113
Spread,
1214
} from "lexical";
13-
import { CHAPTER_CLASS_NAME, UnknownAttributes } from "./node-constants.js";
1415

1516
export const CHAPTER_MARKER = "c";
1617
export const CHAPTER_VERSION = 1;
@@ -28,6 +29,17 @@ export type SerializedChapterNode = Spread<
2829
SerializedElementNode
2930
>;
3031

32+
/** List of known properties of `MarkerObject` */
33+
export const CHAPTER_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [
34+
"type",
35+
"marker",
36+
"number",
37+
"sid",
38+
"altnumber",
39+
"pubnumber",
40+
"content",
41+
];
42+
3143
export class ChapterNode extends ElementNode {
3244
__marker: ChapterMarker;
3345
__number: string;

libs/shared/src/nodes/usj/CharNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/char/index.html */
22

3+
import { UnknownAttributes } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
35
import {
46
$applyNodeReplacement,
57
DOMConversionMap,
@@ -16,7 +18,6 @@ import {
1618
Spread,
1719
isHTMLElement,
1820
} from "lexical";
19-
import { UnknownAttributes } from "./node-constants.js";
2021

2122
/** @see https://docs.usfm.bible/usfm/3.1/char/notes/footnote/index.html */
2223
const VALID_CHAR_FOOTNOTE_MARKERS = [
@@ -117,6 +118,9 @@ export type SerializedCharNode = Spread<
117118
SerializedElementNode
118119
>;
119120

121+
/** List of known properties of `MarkerObject` */
122+
export const CHAR_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = ["type", "marker", "content"];
123+
120124
export class CharNode extends ElementNode {
121125
__marker: string;
122126
__unknownAttributes?: UnknownAttributes;

libs/shared/src/nodes/usj/MilestoneNode.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/ms/index.html */
22

3+
import { UnknownAttributes } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
35
import {
46
$applyNodeReplacement,
57
DecoratorNode,
@@ -9,7 +11,6 @@ import {
911
SerializedLexicalNode,
1012
Spread,
1113
} from "lexical";
12-
import { UnknownAttributes } from "./node-constants.js";
1314

1415
export const STARTING_MS_COMMENT_MARKER = "zmsc-s";
1516
export const ENDING_MS_COMMENT_MARKER = "zmsc-e";
@@ -53,6 +54,15 @@ export type SerializedMilestoneNode = Spread<
5354
SerializedLexicalNode
5455
>;
5556

57+
/** List of known properties of `MarkerObject` */
58+
export const MS_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [
59+
"type",
60+
"marker",
61+
"sid",
62+
"eid",
63+
"content",
64+
];
65+
5666
export class MilestoneNode extends DecoratorNode<void> {
5767
__marker: string;
5868
__sid?: string;

libs/shared/src/nodes/usj/NoteNode.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/note/index.html */
22

33
import { GENERATOR_NOTE_CALLER, HIDDEN_NOTE_CALLER, UnknownAttributes } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
45
import {
56
$applyNodeReplacement,
67
DOMConversionMap,
@@ -42,6 +43,15 @@ export type SerializedNoteNode = Spread<
4243
SerializedElementNode
4344
>;
4445

46+
/** List of known properties of `MarkerObject` */
47+
export const NOTE_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [
48+
"type",
49+
"marker",
50+
"caller",
51+
"category",
52+
"content",
53+
];
54+
4555
export const NOTE_VERSION = 1;
4656

4757
export class NoteNode extends ElementNode {

libs/shared/src/nodes/usj/ParaNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/para/index.html */
22

3+
import { PARA_MARKER_DEFAULT, UnknownAttributes } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
35
import {
46
$applyNodeReplacement,
57
DOMConversionMap,
@@ -17,7 +19,6 @@ import {
1719
Spread,
1820
isHTMLElement,
1921
} from "lexical";
20-
import { PARA_MARKER_DEFAULT, UnknownAttributes } from "./node-constants.js";
2122

2223
/** @see https://docs.usfm.bible/usfm/3.1/para/index.html */
2324
const VALID_PARA_MARKERS = [
@@ -158,6 +159,9 @@ export type SerializedParaNode = Spread<
158159
SerializedParagraphNode
159160
>;
160161

162+
/** List of known properties of `MarkerObject` */
163+
export const PARA_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = ["type", "marker", "content"];
164+
161165
export class ParaNode extends ParagraphNode {
162166
__marker: string;
163167
__unknownAttributes?: UnknownAttributes;

libs/shared/src/nodes/usj/VerseNode.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Conforms with USJ v3.1 @see https://docs.usfm.bible/usfm/3.1/cv/v.html */
22

33
import { UnknownAttributes, VERSE_CLASS_NAME } from "./node-constants.js";
4+
import { MarkerObject } from "@eten-tech-foundation/scripture-utilities";
45
import {
56
$applyNodeReplacement,
67
EditorConfig,
@@ -29,6 +30,17 @@ export type SerializedVerseNode = Spread<
2930
SerializedTextNode
3031
>;
3132

33+
/** List of known properties of `MarkerObject` */
34+
export const VERSE_MARKER_OBJECT_PROPS: (keyof MarkerObject)[] = [
35+
"type",
36+
"marker",
37+
"number",
38+
"sid",
39+
"altnumber",
40+
"pubnumber",
41+
"content",
42+
];
43+
3244
export class VerseNode extends TextNode {
3345
__marker: VerseMarker;
3446
__number: string;

libs/test-data/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
}
1717
},
1818
"dependencies": {
19+
"@eten-tech-foundation/scripture-utilities": "workspace:~",
1920
"tslib": "^2.8.1"
2021
}
2122
}

0 commit comments

Comments
 (0)