From f720ff8348cfe2b0b548fe9683e02523ef2f378b Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 9 Feb 2023 14:33:09 +0000 Subject: [PATCH 1/4] Add three more colors --- src/en-us.strings.js | 3 +++ src/lib/colors.js | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/en-us.strings.js b/src/en-us.strings.js index 12c96880e..f4b0da19f 100644 --- a/src/en-us.strings.js +++ b/src/en-us.strings.js @@ -86,6 +86,9 @@ export default { 'general.green': 'Green', 'general.blue': 'Blue', 'general.purple': 'Purple', + 'general.magenta': 'Magenta', + 'general.orange': 'Orange', + 'general.gray': 'Gray', 'general.showInLibrary': 'Show in Library', 'pdfReader.annotations': 'Annotations', 'pdfReader.showAnnotations': 'Show Annotations', diff --git a/src/lib/colors.js b/src/lib/colors.js index d76dbacd0..d73856d85 100644 --- a/src/lib/colors.js +++ b/src/lib/colors.js @@ -5,7 +5,10 @@ export let annotationColors = [ ['general.red', '#ff6666'], ['general.green', '#5fb236'], ['general.blue', '#2ea8e5'], - ['general.purple', '#a28ae5'] + ['general.purple', '#a28ae5'], + ['general.magenta', '#e56eee'], + ['general.orange', '#f19837'], + ['general.gray', '#aaaaaa'] ]; export let selectionColor = navigator.platform.includes('Mac') ? '#71ADFD' : 'Highlight'; From a7bb7408743bfe0a8cfa38588add28b820c8aaea Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 16 Feb 2023 19:12:25 +0000 Subject: [PATCH 2/4] Avoid saving annotation item when only saving a rendered image --- src/annotations-store.js | 27 ++++++++++++++++++--------- src/index.dev.js | 3 +++ src/index.web.js | 2 ++ src/index.zotero.js | 3 +++ src/viewer.js | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/annotations-store.js b/src/annotations-store.js index e428c63b8..dd64db967 100644 --- a/src/annotations-store.js +++ b/src/annotations-store.js @@ -16,6 +16,7 @@ class AnnotationsStore { this._annotations = options.annotations; this._onSave = options.onSave; this._onDelete = options.onDelete; + this._onSaveImage = options.onSaveImage; this.render = () => { this._annotations.sort((a, b) => (a.sortIndex > b.sortIndex) - (a.sortIndex < b.sortIndex)); options.onRender(this._annotations); @@ -65,9 +66,7 @@ class AnnotationsStore { for (let annotation of annotations) { if (['image', 'ink'].includes(annotation.type) && !annotation.image) { - annotation.image = await this.getAnnotationImage(annotation.id); - this._save(annotation, true); - this.render(); + await this._renderAndSaveImageOnly(annotation); } } } @@ -248,6 +247,20 @@ class AnnotationsStore { return randomstring; } + async _renderAndSaveImageOnly(annotation) { + let image = await this.getAnnotationImage(annotation.id); + if (image) { + this._onSaveImage({ id: annotation.id, image }); + annotation.image = image; + let oldIndex = this._annotations.findIndex(x => x.id === annotation.id); + if (oldIndex !== -1) { + annotation = { ...annotation }; + this._annotations.splice(oldIndex, 1, annotation); + } + this.render(); + } + } + _save(annotation, instant) { let oldIndex = this._annotations.findIndex(x => x.id === annotation.id); if (oldIndex !== -1) { @@ -276,9 +289,7 @@ class AnnotationsStore { async _renderMissingImages() { for (let annotation of this._annotations) { if (['image', 'ink'].includes(annotation.type) && !annotation.image) { - annotation.image = await this.getAnnotationImage(annotation.id); - this._save(annotation, true); - this.render(); + await this._renderAndSaveImageOnly(annotation); } } } @@ -287,9 +298,7 @@ class AnnotationsStore { for (let annotation of this._annotations) { if (pageIndexes.includes(annotation.position.pageIndex) && ['image', 'ink'].includes(annotation.type)) { - annotation.image = await this.getAnnotationImage(annotation.id); - this._save(annotation, true); - this.render(); + await this._renderAndSaveImageOnly(annotation); } } } diff --git a/src/index.dev.js b/src/index.dev.js index e01b5ce49..accaaee26 100644 --- a/src/index.dev.js +++ b/src/index.dev.js @@ -121,6 +121,9 @@ class ViewerInstance { onDeleteAnnotations: function (ids) { console.log('Delete annotations', JSON.stringify(ids)); }, + onSaveImage: (annotation) => { + console.log('Saving image', annotation); + }, onSetState: function (state) { console.log('Set state', state); }, diff --git a/src/index.web.js b/src/index.web.js index aacd28c84..7bbe2b15f 100644 --- a/src/index.web.js +++ b/src/index.web.js @@ -69,6 +69,8 @@ class ViewerInstance { onDeleteAnnotations: (ids) => { this._postMessage({ action: 'deleteAnnotations', ids }); }, + onSaveImage: (annotation) => { + }, onSetState: (state) => { this._postMessage({ action: 'setState', state }); }, diff --git a/src/index.zotero.js b/src/index.zotero.js index 4c5ad53a7..aa0c7f483 100644 --- a/src/index.zotero.js +++ b/src/index.zotero.js @@ -59,6 +59,9 @@ class ViewerInstance { onDeleteAnnotations: (ids) => { this._postMessage({ action: 'deleteAnnotations', ids }); }, + onSaveImage: (annotation) => { + this._postMessage({ action: 'saveImage', annotation }); + }, onSetState: (state) => { this._postMessage({ action: 'setState', state }); }, diff --git a/src/viewer.js b/src/viewer.js index f6bef0878..b069c615b 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -35,6 +35,7 @@ class Viewer { annotations: options.annotations, onSave: options.onSaveAnnotations, onDelete: options.onDeleteAnnotations, + onSaveImage: options.onSaveImage, onRender: (annotations) => { this.annotatorRef.current.setAnnotations([...annotations]); } From 590af780053f198838c0f3b4afa3f197ef45453e Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 16 Feb 2023 19:44:02 +0000 Subject: [PATCH 3/4] Don't render annotation image multiple times --- src/annotations-store.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/annotations-store.js b/src/annotations-store.js index dd64db967..883aaf76e 100644 --- a/src/annotations-store.js +++ b/src/annotations-store.js @@ -287,6 +287,12 @@ class AnnotationsStore { } async _renderMissingImages() { + if (this._renderingTriggered) { + return; + } + else { + this._renderingTriggered = true; + } for (let annotation of this._annotations) { if (['image', 'ink'].includes(annotation.type) && !annotation.image) { await this._renderAndSaveImageOnly(annotation); From 0a7eaf191f3ca2de8856fc49d55d872deb72b361 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Feb 2023 21:00:55 +0000 Subject: [PATCH 4/4] Bump minimist and mkdirp Bumps [minimist](https://github.com/minimistjs/minimist), [minimist](https://github.com/minimistjs/minimist) and [mkdirp](https://github.com/isaacs/node-mkdirp). These dependencies needed to be updated together. Updates `minimist` from 1.2.5 to 1.2.8 - [Release notes](https://github.com/minimistjs/minimist/releases) - [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md) - [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.8) Updates `minimist` from 1.2.0 to 1.2.8 - [Release notes](https://github.com/minimistjs/minimist/releases) - [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md) - [Commits](https://github.com/minimistjs/minimist/compare/v1.2.5...v1.2.8) Updates `mkdirp` from 0.5.1 to 0.5.6 - [Release notes](https://github.com/isaacs/node-mkdirp/releases) - [Changelog](https://github.com/isaacs/node-mkdirp/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-mkdirp/compare/0.5.1...v0.5.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect - dependency-name: minimist dependency-type: indirect - dependency-name: mkdirp dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 126 +++++++--------------------------------------- 1 file changed, 18 insertions(+), 108 deletions(-) diff --git a/package-lock.json b/package-lock.json index c33e5cc17..c3a92c155 100644 --- a/package-lock.json +++ b/package-lock.json @@ -129,12 +129,6 @@ "node": ">=6" } }, - "node_modules/@babel/core/node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, "node_modules/@babel/core/node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -7883,10 +7877,13 @@ } }, "node_modules/minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/mississippi": { "version": "2.0.0", @@ -7945,24 +7942,17 @@ } }, "node_modules/mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)", + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", "dev": true, "dependencies": { - "minimist": "0.0.8" + "minimist": "^1.2.6" }, "bin": { "mkdirp": "bin/cmd.js" } }, - "node_modules/mkdirp/node_modules/minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - }, "node_modules/moment": { "version": "2.24.0", "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", @@ -8798,24 +8788,6 @@ "ms": "^2.1.1" } }, - "node_modules/portfinder/node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "node_modules/portfinder/node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/portfinder/node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -11990,24 +11962,6 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, - "node_modules/webpack/node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "node_modules/webpack/node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/websocket-driver": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz", @@ -12306,12 +12260,6 @@ "minimist": "^1.2.5" } }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -18321,9 +18269,9 @@ } }, "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "dev": true }, "mississippi": { @@ -18378,20 +18326,12 @@ } }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", "dev": true, "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } + "minimist": "^1.2.6" } }, "moment": { @@ -19058,21 +18998,6 @@ "ms": "^2.1.1" } }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -21380,21 +21305,6 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } } } },