From 4719bd7b5c18634fb45a2841660f266de1d92eb2 Mon Sep 17 00:00:00 2001 From: Lucca Date: Mon, 4 Sep 2023 11:05:00 +0200 Subject: [PATCH 1/3] only render annotations where from < to --- src/extension/rendering/engine.spec.ts | 98 +++++++++++++++++++++++++- src/extension/rendering/engine.ts | 13 ++-- 2 files changed, 104 insertions(+), 7 deletions(-) diff --git a/src/extension/rendering/engine.spec.ts b/src/extension/rendering/engine.spec.ts index 21c9226..66c7b3d 100644 --- a/src/extension/rendering/engine.spec.ts +++ b/src/extension/rendering/engine.spec.ts @@ -29,7 +29,7 @@ describe("Test conflicting annotation", () => { }); }); -describe("Test sorting of annotaiton list", () => { +describe("Test sorting of annotation list", () => { const testList: Annotation[] = [ { id: "abc", @@ -373,6 +373,102 @@ describe("Mapping the annotation list to a flat representation", () => { }, ], }, + { + name: "Exact overlap - from", + inputAnnotations: [ + { + id: "abc", + from: 0, + to: 8, + displayName: "Y", + tag: "Y", + }, + { + id: "abc", + from: 0, + to: 5, + displayName: "X", + tag: "X", + }, + { + id: "abc", + from: 10, + to: 15, + displayName: "Z", + tag: "Z", + }, + ], + flatMapping: [ + { + id: "abc", + from: 0, + to: 5, + displayName: "X", + tag: "X", + rendering: "normal", + }, + { + id: "abc", + from: 5, + to: 8, + displayName: "Y", + tag: "Y", + rendering: "fragment-right", + }, + { + id: "abc", + from: 10, + to: 15, + displayName: "Z", + tag: "Z", + rendering: "normal", + }, + ], + }, + { + name: "Exact overlap - from and to", + inputAnnotations: [ + { + id: "abc", + from: 0, + to: 8, + displayName: "X", + tag: "X", + }, + { + id: "abc", + from: 0, + to: 8, + displayName: "Y", + tag: "Y", + }, + { + id: "abc", + from: 10, + to: 15, + displayName: "Z", + tag: "Z", + }, + ], + flatMapping: [ + { + id: "abc", + from: 0, + to: 8, + displayName: "Y", + tag: "Y", + rendering: "normal", + }, + { + id: "abc", + from: 10, + to: 15, + displayName: "Z", + tag: "Z", + rendering: "normal", + }, + ], + }, ]; testCases.forEach((testCase) => { test( diff --git a/src/extension/rendering/engine.ts b/src/extension/rendering/engine.ts index 676d7c9..70ae9a4 100644 --- a/src/extension/rendering/engine.ts +++ b/src/extension/rendering/engine.ts @@ -29,12 +29,9 @@ export const createAnnotationRendering = ( ): AnnotationFragment[] => { const renderedAnnotations: AnnotationFragment[] = []; const openAnnotationStack: ActionKeyframe[] = []; - //const actionMap: Map = new Map(); const actionMap: ActionKeyframe[][] = []; const annotationFragmentation: boolean[] = []; - // annotations = sortAnnotationsByStart(annotations); - // STEP 1: Create a Map, containing the rendering actions for each index in the document. // this could be opening or closing an annotation annotations.forEach((term, index) => { @@ -87,7 +84,9 @@ export const createAnnotationRendering = ( from, rendering, }; - renderedAnnotations.push(normalTerm); + if (normalTerm.from < normalTerm.to) { + renderedAnnotations.push(normalTerm); + } } else if ( actionStackPeek.action === "open" && action.action === "close" @@ -131,11 +130,13 @@ export const createAnnotationRendering = ( rendering: "fragment-left", to: annotations[action.annotationIndex].from, }; - // mark the previous annotation as fragmented, by saving where the fragment ends + // mark the previous annotation as fragmented annotationFragmentation[actionStackPeek.annotationIndex] = true; } - renderedAnnotations.push(fragment); + if (fragment.from < fragment.to) { + renderedAnnotations.push(fragment); + } openAnnotationStack.push(action); } } else if (action.action === "open") { From 379a21ba2594649be7ede5057573639ff6e66a12 Mon Sep 17 00:00:00 2001 From: Lucca Date: Mon, 4 Sep 2023 11:15:01 +0200 Subject: [PATCH 2/3] add build and test workflow --- .github/workflows/default.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/default.yml diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000..ab8596d --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,19 @@ +name: Build and test + +on: + push: + branches: ['**'] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm run build + - run: npm test \ No newline at end of file From d2a20f490915984d9b8b1a3b092c670edd55b0db Mon Sep 17 00:00:00 2001 From: Lucca Date: Mon, 4 Sep 2023 11:28:34 +0200 Subject: [PATCH 3/3] 2.0.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8879a6..806812b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tiptap-annotation-magic", - "version": "2.0.0np", + "version": "2.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tiptap-annotation-magic", - "version": "2.0.0np", + "version": "2.0.1", "license": "MIT", "dependencies": { "@tiptap/core": "^2.1.7", diff --git a/package.json b/package.json index 735e840..7e262bb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "tiptap-annotation-magic", "author": "Lucca Baumgärtner ", "license": "MIT", - "version": "2.0.0", + "version": "2.0.1", "main": "build/index.js", "types": "build/index.d.ts", "scripts": {