From cbbff600a60c9e7a7407d6f2e4053309bf28b872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 3 Jun 2020 10:29:46 +0300 Subject: [PATCH 01/47] XUL -> JS tree megacommit - Just a single huge commit. This has been developed over too long a time, required many tiny changes across too many files and has seen too many iterations to be separated into separate commits. The original branch with all the messy commits will be kept around for posterity https://github.com/zotero/zotero/compare/bb220ad0f2d6bf0eca6df6d225d3d358cb50a27b...adomasven:feature/react-item-tree - Replaces XUL element across the whole zotero client codebase with a custom supermegafast virtualized-table inspired by react-virtualized yet mimicking old XUL treeview API. The virtualized-table sits on top on a raw-to-the-metal, interpreted-at-runtime JS based windowing solution inspired by react-window. React-based solutions could not be used because they were slow and Zotero UI needs to be responsive and be able to display thousands of rows in a treeview without any slowdowns. - Attempts were made at making this screen-reader friendly, but yet to be tested with something like JAWS - RTL-friendly - Styling and behaviour across all platforms was copied as closely as possible to the original XUL tree - Instead of row-based scroll snapping this has smooth-scrolling. If you're using arrow keys to browse through the tree then it effectively snap-scrolls. Current CSS snap scroll attributes do not seem to work in the way we would require even on up-to-date browsers, yet alone the ESR version of FX that Zotero is on. JS solutions are either terrible for performance or produce inexcusable jitter. - When dragging-and-dropping items the initial drag freezes the UI for a fairly jarring amount of time. Does not seem to be fixable due to the synchronous code that needs to be run in the dragstart handler. Used to be possible to run that code async with the XUL tree. - Item tree column picker no longer has a dedicated button. Just right-click the columns. The column preferences (width, order, etc) are no longer handled by XUL, which required a custom serialization and storage solution that throws warnings in the developer console due to the amount of data being stored. Might cause temporary freezing on HDDs upon column resize/reorder/visibility toggling. - Context menu handling code basically unchanged, but any UI changes that plugins may have wanted to do (including adding new columns) will have to be redone by them. No serious thought has gone into how plugin developers would achieve that yet. - Opens up the possibility for awesome alternative ways to render the tree items, including things like multiple-row view for the item tree, which has been requested for a long while especially by users switching from other referencing software --- .../content/zotero-platform/mac/overlay.css | 31 - .../content/zotero-platform/unix/overlay.css | 19 - .../content/zotero-platform/win/overlay.css | 24 - chrome/content/zotero/advancedSearch.js | 84 +- chrome/content/zotero/advancedSearch.xul | 25 +- chrome/content/zotero/bindings/relatedbox.xml | 8 +- .../content/zotero/components/draggable.jsx | 121 + chrome/content/zotero/components/icons.jsx | 184 +- chrome/content/zotero/components/js-window.js | 288 ++ chrome/content/zotero/components/utils.js | 77 +- .../zotero/components/virtualized-table.jsx | 1344 +++++++ .../zotero/containers/collectionTree.jsx | 2457 ++++++++++++ chrome/content/zotero/containers/itemTree.jsx | 3442 ++++++++++++++++ .../zotero/containers/itemTreeColumns.jsx | 289 ++ .../content/zotero/containers/libraryTree.js | 253 ++ .../containers/tagSelectorContainer.jsx | 17 +- chrome/content/zotero/fileInterface.js | 4 +- chrome/content/zotero/include.js | 8 +- .../zotero/integration/addCitationDialog.js | 2 +- .../zotero/integration/addCitationDialog.xul | 194 +- .../integration/editBibliographyDialog.js | 7 +- .../integration/editBibliographyDialog.xul | 53 +- chrome/content/zotero/itemPane.js | 7 +- chrome/content/zotero/itemPane.xul | 2 +- chrome/content/zotero/locateManager.jsx | 141 + chrome/content/zotero/locateManager.xul | 211 +- chrome/content/zotero/locateMenu.js | 2 +- .../zotero/preferences/librariesToSync.xul | 24 +- .../zotero/preferences/preferences.xul | 1 + ...eferences_cite.js => preferences_cite.jsx} | 102 +- .../zotero/preferences/preferences_cite.xul | 13 +- ...ences_export.js => preferences_export.jsx} | 141 +- .../zotero/preferences/preferences_export.xul | 19 +- .../preferences/preferences_firefox.xul | 95 - .../zotero/preferences/preferences_proxies.js | 169 - ...eferences_sync.js => preferences_sync.jsx} | 169 +- .../content/zotero/preferences/proxyEditor.js | 146 - .../zotero/preferences/proxyEditor.xul | 71 - chrome/content/zotero/progressQueueDialog.jsx | 134 + chrome/content/zotero/progressQueueDialog.xul | 18 +- .../zotero/{rtfScan.js => rtfScan.jsx} | 465 ++- chrome/content/zotero/rtfScan.xul | 35 +- chrome/content/zotero/selectItemsDialog.js | 131 +- chrome/content/zotero/selectItemsDialog.xul | 206 +- .../content/zotero/tools/data_generator.jsx | 4 +- .../content/zotero/xpcom/collectionTreeRow.js | 36 +- .../zotero/xpcom/collectionTreeView.js | 2478 ------------ .../xpcom/connector/server_connector.js | 2 +- chrome/content/zotero/xpcom/data/feed.js | 2 +- chrome/content/zotero/xpcom/data/group.js | 2 +- chrome/content/zotero/xpcom/data/item.js | 38 +- chrome/content/zotero/xpcom/data/library.js | 2 +- chrome/content/zotero/xpcom/debug.js | 3 + .../zotero/xpcom/fileDragDataProvider.js | 245 ++ chrome/content/zotero/xpcom/intl.js | 4 +- chrome/content/zotero/xpcom/itemTreeView.js | 3523 ----------------- .../content/zotero/xpcom/libraryTreeView.js | 545 --- chrome/content/zotero/xpcom/prefs.js | 57 + chrome/content/zotero/xpcom/progressQueue.js | 1 + .../zotero/xpcom/progressQueueDialog.js | 115 +- chrome/content/zotero/xpcom/retractions.js | 2 +- chrome/content/zotero/xpcom/utilities | 2 +- .../zotero/xpcom/utilities_internal.js | 146 +- chrome/content/zotero/xpcom/zotero.js | 25 +- chrome/content/zotero/zoteroPane.js | 847 +--- chrome/content/zotero/zoteroPane.xul | 246 +- chrome/locale/en-US/zotero/preferences.dtd | 1 + chrome/locale/en-US/zotero/zotero.properties | 2 + chrome/skin/default/zotero/overlay.css | 121 +- chrome/skin/default/zotero/zotero.css | 4 +- components/zotero-service.js | 4 +- resource/react-dom-server.js | 1 + resource/require.js | 8 +- scss/_zotero-react-client.scss | 3 + scss/components/_button.scss | 1 - scss/components/_collection-tree.scss | 45 + scss/components/_icons.scss | 18 +- scss/components/_item-tree.scss | 47 + scss/components/_tagSelector.scss | 1 + scss/components/_virtualized-table.scss | 251 ++ scss/linux/_collection-tree.scss | 8 + scss/linux/_item-tree.scss | 5 + scss/linux/_virtualized-table.scss | 28 + scss/mac/_collection-tree.scss | 54 + scss/mac/_item-tree.scss | 9 + scss/mac/_virtualized-table.scss | 24 + scss/win/_item-tree.scss | 33 + scss/win/_virtualized-table.scss | 50 + scss/zotero-react-client-mac.scss | 3 + scss/zotero-react-client-unix.scss | 3 + scss/zotero-react-client-win.scss | 2 + test/content/support.js | 32 +- test/tests/bibliographyTest.js | 18 +- ...nTreeViewTest.js => collectionTreeTest.js} | 160 +- test/tests/duplicatesTest.js | 8 +- .../{itemTreeViewTest.js => itemTreeTest.js} | 292 +- test/tests/libraryTest.js | 3 +- ...raryTreeViewTest.js => libraryTreeTest.js} | 2 +- test/tests/relatedboxTest.js | 14 +- test/tests/server_connectorTest.js | 13 + test/tests/tagSelectorTest.js | 3 +- test/tests/zoteroPaneTest.js | 65 +- 102 files changed, 11008 insertions(+), 9886 deletions(-) create mode 100644 chrome/content/zotero/components/draggable.jsx create mode 100644 chrome/content/zotero/components/js-window.js create mode 100644 chrome/content/zotero/components/virtualized-table.jsx create mode 100644 chrome/content/zotero/containers/collectionTree.jsx create mode 100644 chrome/content/zotero/containers/itemTree.jsx create mode 100644 chrome/content/zotero/containers/itemTreeColumns.jsx create mode 100644 chrome/content/zotero/containers/libraryTree.js create mode 100644 chrome/content/zotero/locateManager.jsx rename chrome/content/zotero/preferences/{preferences_cite.js => preferences_cite.jsx} (73%) rename chrome/content/zotero/preferences/{preferences_export.js => preferences_export.jsx} (75%) delete mode 100644 chrome/content/zotero/preferences/preferences_firefox.xul delete mode 100644 chrome/content/zotero/preferences/preferences_proxies.js rename chrome/content/zotero/preferences/{preferences_sync.js => preferences_sync.jsx} (88%) delete mode 100644 chrome/content/zotero/preferences/proxyEditor.js delete mode 100644 chrome/content/zotero/preferences/proxyEditor.xul create mode 100644 chrome/content/zotero/progressQueueDialog.jsx rename chrome/content/zotero/{rtfScan.js => rtfScan.jsx} (58%) delete mode 100644 chrome/content/zotero/xpcom/collectionTreeView.js create mode 100644 chrome/content/zotero/xpcom/fileDragDataProvider.js delete mode 100644 chrome/content/zotero/xpcom/itemTreeView.js delete mode 100644 chrome/content/zotero/xpcom/libraryTreeView.js create mode 120000 resource/react-dom-server.js create mode 100644 scss/components/_collection-tree.scss create mode 100644 scss/components/_item-tree.scss create mode 100644 scss/components/_virtualized-table.scss create mode 100644 scss/linux/_collection-tree.scss create mode 100644 scss/linux/_item-tree.scss create mode 100644 scss/linux/_virtualized-table.scss create mode 100644 scss/mac/_collection-tree.scss create mode 100644 scss/mac/_item-tree.scss create mode 100644 scss/mac/_virtualized-table.scss create mode 100644 scss/win/_item-tree.scss create mode 100644 scss/win/_virtualized-table.scss rename test/tests/{collectionTreeViewTest.js => collectionTreeTest.js} (92%) rename test/tests/{itemTreeViewTest.js => itemTreeTest.js} (84%) rename test/tests/{libraryTreeViewTest.js => libraryTreeTest.js} (96%) diff --git a/chrome/content/zotero-platform/mac/overlay.css b/chrome/content/zotero-platform/mac/overlay.css index 0553db9230..3cf7ba0a90 100644 --- a/chrome/content/zotero-platform/mac/overlay.css +++ b/chrome/content/zotero-platform/mac/overlay.css @@ -333,37 +333,6 @@ input { margin-inline-start: -1px; } -#zotero-items-tree -{ - -moz-appearance: none; - border: none; - margin: 0; - padding: 0; -} - -#zotero-items-tree treechildren::-moz-tree-cell, -#zotero-items-tree treechildren::-moz-tree-column { - border-right: 1px solid #d7dad7; -} - -treechildren::-moz-tree-twisty { - -moz-appearance: none; - width: 16px; - height: 16px; - list-style-image: url("chrome://zotero/skin/mac/twisty.svg"); - -moz-padding-start: 5px; - -moz-padding-end: 6px; -} - -treechildren::-moz-tree-twisty(open) { - -moz-appearance: none; - width: 16px; - height: 16px; - list-style-image: url("chrome://zotero/skin/mac/twisty-open.svg"); - -moz-padding-start: 4px; - -moz-padding-end: 7px; -} - /* How to get active twisty? treechildren::-moz-tree-twisty(active) { -moz-appearance: none; diff --git a/chrome/content/zotero-platform/unix/overlay.css b/chrome/content/zotero-platform/unix/overlay.css index dd0be502f5..4fcd4cd2eb 100644 --- a/chrome/content/zotero-platform/unix/overlay.css +++ b/chrome/content/zotero-platform/unix/overlay.css @@ -1,22 +1,3 @@ -/* - Override selected, unfocused tree row highlight color, which is too similar to the alternating - row color by default -*/ -#zotero-collections-tree treechildren::-moz-tree-row(selected), -#zotero-items-tree treechildren::-moz-tree-row(selected) { - background-color: #D4D4D4; -} - -#zotero-collections-tree treechildren::-moz-tree-row(selected, focus), -#zotero-items-tree treechildren::-moz-tree-row(selected, focus) { - background-color: Highlight; -} - -#zotero-collections-tree treechildren::-moz-tree-row { - height: 1.3em; -} - - @media (min-resolution: 1.25dppx) { #zotero-pane-stack .toolbarbutton-icon { width: 16px; diff --git a/chrome/content/zotero-platform/win/overlay.css b/chrome/content/zotero-platform/win/overlay.css index b378b30dd4..5c8349bc59 100644 --- a/chrome/content/zotero-platform/win/overlay.css +++ b/chrome/content/zotero-platform/win/overlay.css @@ -111,34 +111,10 @@ display: none; } -#zotero-collections-tree, #zotero-items-tree, .zotero-view-item { - -moz-appearance: none; - border-style: solid; - border-color: #818790; - margin: 0; - padding: 0; -} - -treechildren::-moz-tree-twisty { - padding: 0 4px; -} - -/* Undo tree row spacing change in Fx25 on Windows */ -#zotero-collections-tree treechildren::-moz-tree-row, -#zotero-items-tree treechildren::-moz-tree-row, -#zotero-prefs treechildren::-moz-tree-row { - height: 1.6em; -} - tree { border-width: 0; } -/* Restore row highlighting on drag over, though I'm not sure how we're losing it to begin with. */ -#zotero-collections-tree treechildren::-moz-tree-row(dropOn) { - background-color: Highlight; -} - #zotero-tag-selector groupbox { -moz-appearance: none; padding: 0; diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js index dd9eb17301..efacc96a50 100644 --- a/chrome/content/zotero/advancedSearch.js +++ b/chrome/content/zotero/advancedSearch.js @@ -25,16 +25,18 @@ Components.utils.import("resource://gre/modules/Services.jsm"); +import ItemTree from 'containers/itemTree'; +import { getDefaultColumnsByDataKeys } from 'containers/itemTreeColumns'; + var ZoteroAdvancedSearch = new function() { this.onLoad = onLoad; this.search = search; this.clear = clear; - this.onDblClick = onDblClick; - this.onUnload = onUnload; + this.onItemActivate = onItemActivate; this.itemsView = false; - + var _searchBox; var _libraryID; @@ -52,8 +54,21 @@ var ZoteroAdvancedSearch = new function() { .then(function () { _searchBox.search = io.dataIn.search; }); + + var elem = document.getElementById('zotero-items-tree'); + ItemTree.init(elem, { + id: "advanced-search", + dragAndDrop: true, + onActivate: this.onItemActivate.bind(this), + columns: getDefaultColumnsByDataKeys(['title', 'firstCreator']), + }).then((itemsView) => { + this.itemsView = itemsView; + }); } + this.onUnload = function () { + this.itemsView.unregister(); + } function search() { _searchBox.updateSearch(); @@ -74,30 +89,23 @@ var ZoteroAdvancedSearch = new function() { isCollection: function () { return false; }, isSearch: function () { return true; }, isPublications: () => false, + isDuplicates: () => false, isFeed: () => false, isShare: function () { return false; }, isTrash: function () { return false; } - } + }; - if (this.itemsView) { - this.itemsView.unregister(); - } - - this.itemsView = new Zotero.ItemTreeView(collectionTreeRow, false); - document.getElementById('zotero-items-tree').view = this.itemsView; + this.itemsView.changeCollectionTreeRow(collectionTreeRow); } function clear() { - if (this.itemsView) { - this.itemsView.unregister(); - } - document.getElementById('zotero-items-tree').view = null; + this.itemsView.changeCollectionTreeRow(null); var s = new Zotero.Search(); // Don't clear the selected library s.libraryID = _searchBox.search.libraryID; - s.addCondition('title', 'contains', '') + s.addCondition('title', 'contains', ''); _searchBox.search = s; _searchBox.active = false; } @@ -149,42 +157,18 @@ var ZoteroAdvancedSearch = new function() { } - // Adapted from: http://www.xulplanet.com/references/elemref/ref_tree.html#cmnote-9 - function onDblClick(event, tree) + function onItemActivate(event, items) { - if (event && tree && event.type == "dblclick") - { - var row = {}, col = {}, obj = {}; - tree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, obj); - // obj.value == cell/text/image - // TODO: handle collection double-click - if (obj.value && this.itemsView && this.itemsView.selection.currentIndex > -1) - { - var item = this.itemsView.getSelectedItems()[0]; - - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - - var lastWin = wm.getMostRecentWindow("navigator:browser"); - - if (!lastWin) { - window.open(); - var newWindow = wm.getMostRecentWindow("navigator:browser"); - var b = newWindow.getBrowser(); - return; - } - - lastWin.ZoteroPane.selectItem(item.getID(), false, true); - lastWin.focus(); - } - } - } - - - function onUnload() { - // Unregister search from Notifier - if (this.itemsView) { - this.itemsView.unregister(); + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + + var lastWin = wm.getMostRecentWindow("navigator:browser"); + + if (!lastWin) { + return; } + + lastWin.ZoteroPane.selectItems(items.map(item => item.id), false); + lastWin.focus(); } } diff --git a/chrome/content/zotero/advancedSearch.xul b/chrome/content/zotero/advancedSearch.xul index 953fd40be2..72287e84c7 100644 --- a/chrome/content/zotero/advancedSearch.xul +++ b/chrome/content/zotero/advancedSearch.xul @@ -3,6 +3,7 @@ + @@ -17,8 +18,9 @@ orient="vertical" persist="screenX screenY width height" onload="ZoteroAdvancedSearch.onLoad()" - onunload="ZoteroAdvancedSearch.onUnload()" + onunload="ZoteroAdvancedSearch.onUnload();" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:html="http://www.w3.org/1999/xhtml" windowtype="zotero:search"> +