|
1 | | -import { Document } from './editor/types'; |
2 | | -import { next as Automerge } from '@automerge/automerge'; |
3 | | -import * as AutomergeStable from '@automerge/automerge'; |
| 1 | +import { Document, EditorDocument } from './editor/types'; |
| 2 | +// import { next as Automerge } from '@automerge/automerge'; |
| 3 | +// import * as AutomergeStable from '@automerge/automerge'; |
4 | 4 |
|
5 | | -function convertString(s: string): string { |
6 | | - // this typecasting is a hack to avoid having multiple types for different versions for now |
7 | | - return new AutomergeStable.Text(s.toString()) as unknown as string; |
| 5 | +export function documentToJSON(doc: EditorDocument): Document { |
| 6 | + return doc.toJSON().root; |
8 | 7 | } |
9 | 8 |
|
10 | | -export function migrateDocument(doc: Automerge.Doc<Document>): Automerge.Doc<Document> { |
11 | | - let theDoc = doc; |
12 | | - const v1 = theDoc.version === 1; |
13 | | - const actorID = Automerge.getActorId(doc); |
14 | | - if (v1) { |
15 | | - theDoc = AutomergeStable.load(Automerge.save(doc), actorID); |
16 | | - } |
17 | | - if (theDoc.version === 2) { |
18 | | - return doc; |
19 | | - } |
20 | | - const migratedDoc = AutomergeStable.change(theDoc, (doc: Document) => { |
21 | | - switch (doc.version) { |
22 | | - case 1: |
23 | | - for (const speakerID of Object.keys(doc.speaker_names)) { |
24 | | - doc.speaker_names[speakerID] = convertString(doc.speaker_names[speakerID]); |
25 | | - } |
| 9 | +// function convertString(s: string): string { |
| 10 | +// // this typecasting is a hack to avoid having multiple types for different versions for now |
| 11 | +// return new AutomergeStable.Text(s.toString()) as unknown as string; |
| 12 | +// } |
26 | 13 |
|
27 | | - doc.children.forEach((paragraph) => { |
28 | | - paragraph.type = convertString(paragraph.type) as 'paragraph'; |
29 | | - paragraph.speaker = paragraph.speaker ? convertString(paragraph.speaker) : null; |
30 | | - paragraph.lang = convertString(paragraph.lang.toString()); |
| 14 | +// export function migrateDocument(doc: Automerge.Doc<Document>): Automerge.Doc<Document> { |
| 15 | +// let theDoc = doc; |
| 16 | +// const v1 = theDoc.version === 1; |
| 17 | +// const actorID = Automerge.getActorId(doc); |
| 18 | +// if (v1) { |
| 19 | +// theDoc = AutomergeStable.load(Automerge.save(doc), actorID); |
| 20 | +// } |
| 21 | +// if (theDoc.version === 2) { |
| 22 | +// return doc; |
| 23 | +// } |
| 24 | +// const migratedDoc = AutomergeStable.change(theDoc, (doc: Document) => { |
| 25 | +// switch (doc.version) { |
| 26 | +// case 1: |
| 27 | +// for (const speakerID of Object.keys(doc.speaker_names)) { |
| 28 | +// doc.speaker_names[speakerID] = convertString(doc.speaker_names[speakerID]); |
| 29 | +// } |
31 | 30 |
|
32 | | - paragraph.children.forEach((child) => { |
33 | | - const start = child.start; |
34 | | - child.start = start; |
35 | | - const end = child.end; |
36 | | - child.end = end; |
37 | | - const conf = child.conf; |
38 | | - child.conf = conf; |
39 | | - child.text = convertString(child.text.toString()); |
40 | | - }); |
41 | | - }); |
42 | | - doc.version = 2; |
43 | | - // falls through |
44 | | - case 2: |
45 | | - break; |
46 | | - } |
47 | | - }); |
| 31 | +// doc.children.forEach((paragraph) => { |
| 32 | +// paragraph.type = convertString(paragraph.type) as 'paragraph'; |
| 33 | +// paragraph.speaker = paragraph.speaker ? convertString(paragraph.speaker) : null; |
| 34 | +// paragraph.lang = convertString(paragraph.lang.toString()); |
48 | 35 |
|
49 | | - if (v1) { |
50 | | - return Automerge.load(AutomergeStable.save(migratedDoc), actorID); |
51 | | - } else { |
52 | | - return migratedDoc; |
53 | | - } |
54 | | -} |
| 36 | +// paragraph.children.forEach((child) => { |
| 37 | +// const start = child.start; |
| 38 | +// child.start = start; |
| 39 | +// const end = child.end; |
| 40 | +// child.end = end; |
| 41 | +// const conf = child.conf; |
| 42 | +// child.conf = conf; |
| 43 | +// child.text = convertString(child.text.toString()); |
| 44 | +// }); |
| 45 | +// }); |
| 46 | +// doc.version = 2; |
| 47 | +// // falls through |
| 48 | +// case 2: |
| 49 | +// break; |
| 50 | +// } |
| 51 | +// }); |
| 52 | + |
| 53 | +// if (v1) { |
| 54 | +// return Automerge.load(AutomergeStable.save(migratedDoc), actorID); |
| 55 | +// } else { |
| 56 | +// return migratedDoc; |
| 57 | +// } |
| 58 | +// } |
0 commit comments