Skip to content

Commit 6ea3efd

Browse files
Merge pull request #26 from istex/exploration
Setup fast-xml-parser and Viewer componennt displaying the title and body text (no css yet)
2 parents 6cbd8ce + 753abaa commit 6ea3efd

20 files changed

Lines changed: 324 additions & 22 deletions

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"@types/node": "catalog:",
1919
"husky": "catalog:",
2020
"playwright": "catalog:",
21-
"turbo": "catalog:"
21+
"turbo": "catalog:",
22+
"typescript": "catalog:"
2223
},
2324
"packageManager": "pnpm@10.25.0+sha512.5e82639027af37cf832061bcc6d639c219634488e0f2baebe785028a793de7b525ffcd3f7ff574f5e9860654e098fe852ba8ac5dd5cefe1767d23a020a92f501"
2425
}

packages/demo/src/App.spec.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,38 @@ describe("App", () => {
1515
it("should render the XML document when a file is uploaded", async () => {
1616
const screen = await render(<App />);
1717

18-
const file = new File(["<TEI></TEI>"], "example.tei", {
19-
type: "text/plain",
20-
});
18+
const file = new File(
19+
[
20+
`<?xml version="1.0" encoding="UTF-8"?>
21+
<TEI xmlns:ns1="https://xml-schema.delivery.istex.fr/formats/ns1.xsd"
22+
xmlns="http://www.tei-c.org/ns/1.0"
23+
xmlns:tei="http://www.tei-c.org/ns/1.0"
24+
xmlns:sa="http://www.elsevier.com/xml/common/struct-aff/dtd"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:noNamespaceSchemaLocation="https://xml-schema.delivery.istex.fr/formats/tei-istex.xsd"
27+
xml:lang="en"
28+
>
29+
<teiHeader>
30+
<fileDesc>
31+
<titleStmt>
32+
<title level="a" type="main">TEI Test Title</title>
33+
</titleStmt>
34+
</fileDesc>
35+
</teiHeader>
36+
</TEI>`,
37+
],
38+
"example.tei",
39+
{
40+
type: "text/plain",
41+
},
42+
);
2143

2244
const input = screen.getByTestId("file-selector-input");
2345

2446
await userEvent.upload(input, file);
2547

2648
await vi.waitFor(() => {
27-
expect(screen.getByText(/<TEI><\/TEI>/)).toBeInTheDocument();
49+
expect(screen.getByText("TEI Test Title")).toBeInTheDocument();
2850
});
2951
});
3052
});

packages/demo/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ function App() {
1515
</>
1616
);
1717
}
18-
1918
export default App;

packages/demo/src/viewer/ViewerPage.spec.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ import { ViewerPage } from "./ViewerPage.js";
55
vi.mock("./useViewerContext", () => {
66
return {
77
useViewerContext: vi.fn().mockReturnValue({
8-
document: "<tei>This is a test</tei>",
8+
document: `<?xml version="1.0" encoding="UTF-8"?>
9+
<TEI xmlns:ns1="https://xml-schema.delivery.istex.fr/formats/ns1.xsd"
10+
xmlns="http://www.tei-c.org/ns/1.0"
11+
xmlns:tei="http://www.tei-c.org/ns/1.0"
12+
xmlns:sa="http://www.elsevier.com/xml/common/struct-aff/dtd"
13+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
14+
xsi:noNamespaceSchemaLocation="https://xml-schema.delivery.istex.fr/formats/tei-istex.xsd"
15+
xml:lang="en"
16+
>
17+
<teiHeader>
18+
<fileDesc>
19+
<titleStmt>
20+
<title level="a" type="main">TEI Test Title</title>
21+
</titleStmt>
22+
</fileDesc>
23+
</teiHeader>
24+
</TEI>`,
925
}),
1026
};
1127
});
@@ -14,6 +30,6 @@ describe("ViewerPage", () => {
1430
it("should render Viewer when document is provided", async () => {
1531
const screen = await render(<ViewerPage />);
1632

17-
expect(screen.getByText("<tei>This is a test</tei>")).toBeInTheDocument();
33+
expect(screen.getByText("TEI Test Title")).toBeInTheDocument();
1834
});
1935
});

packages/e2e/src/document.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ test("open a document", async ({ page }) => {
1212
path.join(import.meta.dirname, "../testdata/document.tei"),
1313
);
1414

15-
expect(page.getByText("<TEI></TEI>")).toBeVisible();
15+
expect(page.getByText("TEI Test Title")).toBeVisible();
1616
});

packages/e2e/testdata/document.tei

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
<TEI></TEI>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TEI xmlns:ns1="https://xml-schema.delivery.istex.fr/formats/ns1.xsd"
3+
xmlns="http://www.tei-c.org/ns/1.0"
4+
xmlns:tei="http://www.tei-c.org/ns/1.0"
5+
xmlns:sa="http://www.elsevier.com/xml/common/struct-aff/dtd"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:noNamespaceSchemaLocation="https://xml-schema.delivery.istex.fr/formats/tei-istex.xsd"
8+
xml:lang="en"
9+
>
10+
<teiHeader>
11+
<fileDesc>
12+
<titleStmt>
13+
<title level="a" type="main">TEI Test Title</title>
14+
</titleStmt>
15+
</fileDesc>
16+
</teiHeader>
17+
</TEI>

packages/react-tei/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"@mui/icons-material": "catalog:",
1818
"@mui/material": "catalog:",
1919
"react": "catalog:",
20-
"react-dom": "catalog:"
20+
"react-dom": "catalog:",
21+
"fast-xml-parser": "catalog:"
2122
},
2223
"devDependencies": {
2324
"@types/node": "catalog:",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DocumentTag } from "./tags/DocumentTag.js";
2+
3+
export const DocumentBody = ({
4+
jsonDocument,
5+
}: {
6+
jsonDocument: {
7+
TEI: Record<string, unknown>;
8+
};
9+
}) => {
10+
return <DocumentTag name="TEI" data={jsonDocument.TEI} />;
11+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { createContext } from "react";
2+
3+
export type DocumentContextType = {
4+
jsonDocument: Record<string, unknown> | null;
5+
};
6+
7+
export const DocumentContext = createContext<DocumentContextType | undefined>(
8+
undefined,
9+
);
10+
11+
export function DocumentContextProvider({
12+
children,
13+
jsonDocument,
14+
}: {
15+
children: React.ReactNode;
16+
jsonDocument: Record<string, unknown> | null;
17+
}) {
18+
return (
19+
<DocumentContext.Provider
20+
value={{
21+
jsonDocument,
22+
}}
23+
>
24+
{children}
25+
</DocumentContext.Provider>
26+
);
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type DocumentDrawerProps = {
2+
teiHeader: Record<string, unknown>;
3+
};
4+
5+
export const DocumentDrawer = ({ teiHeader }: DocumentDrawerProps) => {
6+
return null;
7+
};

0 commit comments

Comments
 (0)