diff --git a/polygerrit-ui/app/.eslintrc.js b/polygerrit-ui/app/.eslintrc.js index 8e10d1ef2c..0bd9eaea7c 100644 --- a/polygerrit-ui/app/.eslintrc.js +++ b/polygerrit-ui/app/.eslintrc.js @@ -179,7 +179,6 @@ module.exports = { "GrCountStringFormatter": "readonly", "GrDiffBuilderBinary": "readonly", "GrDiffBuilderImage": "readonly", - "GrDiffBuilderSideBySide": "readonly", "GrDiffBuilderUnified": "readonly", "GrDomHook": "readonly", "GrDomHooksManager": "readonly", diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.js b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.js index f4e9de4c14..48e6ce6bf5 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.js @@ -32,6 +32,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {htmlTemplate} from './gr-diff-builder-element_html.js'; import {GrAnnotation} from '../gr-diff-highlight/gr-annotation.js'; import {GrDiffBuilder} from './gr-diff-builder.js'; +import {GrDiffBuilderSideBySide} from './gr-diff-builder-side-by-side.js'; const DiffViewMode = { SIDE_BY_SIDE: 'SIDE_BY_SIDE', diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-image.js b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-image.js index a7a29db19f..6636b69470 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-image.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-image.js @@ -14,7 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -(function(window, GrDiffBuilderSideBySide) { + +import {GrDiffBuilderSideBySide} from './gr-diff-builder-side-by-side.js'; + +(function(window) { 'use strict'; // Prevent redefinition. @@ -180,4 +183,4 @@ }; window.GrDiffBuilderImage = GrDiffBuilderImage; -})(window, GrDiffBuilderSideBySide); +})(window); diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-side-by-side.js b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-side-by-side.js index 8fc214d030..8b73936f75 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-side-by-side.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-side-by-side.js @@ -17,106 +17,97 @@ import {GrDiffBuilder} from './gr-diff-builder.js'; -(function(window) { - 'use strict'; +/** @constructor */ +export function GrDiffBuilderSideBySide(diff, prefs, outputEl, layers) { + GrDiffBuilder.call(this, diff, prefs, outputEl, layers); +} +GrDiffBuilderSideBySide.prototype = Object.create(GrDiffBuilder.prototype); +GrDiffBuilderSideBySide.prototype.constructor = GrDiffBuilderSideBySide; - // Prevent redefinition. - if (window.GrDiffBuilderSideBySide) { return; } - - /** @constructor */ - function GrDiffBuilderSideBySide(diff, prefs, outputEl, layers) { - GrDiffBuilder.call(this, diff, prefs, outputEl, layers); +GrDiffBuilderSideBySide.prototype.buildSectionElement = function(group) { + const sectionEl = this._createElement('tbody', 'section'); + sectionEl.classList.add(group.type); + if (this._isTotal(group)) { + sectionEl.classList.add('total'); } - GrDiffBuilderSideBySide.prototype = Object.create(GrDiffBuilder.prototype); - GrDiffBuilderSideBySide.prototype.constructor = GrDiffBuilderSideBySide; + if (group.dueToRebase) { + sectionEl.classList.add('dueToRebase'); + } + if (group.ignoredWhitespaceOnly) { + sectionEl.classList.add('ignoredWhitespaceOnly'); + } + const pairs = group.getSideBySidePairs(); + for (let i = 0; i < pairs.length; i++) { + sectionEl.appendChild(this._createRow(sectionEl, pairs[i].left, + pairs[i].right)); + } + return sectionEl; +}; - GrDiffBuilderSideBySide.prototype.buildSectionElement = function(group) { - const sectionEl = this._createElement('tbody', 'section'); - sectionEl.classList.add(group.type); - if (this._isTotal(group)) { - sectionEl.classList.add('total'); - } - if (group.dueToRebase) { - sectionEl.classList.add('dueToRebase'); - } - if (group.ignoredWhitespaceOnly) { - sectionEl.classList.add('ignoredWhitespaceOnly'); - } - const pairs = group.getSideBySidePairs(); - for (let i = 0; i < pairs.length; i++) { - sectionEl.appendChild(this._createRow(sectionEl, pairs[i].left, - pairs[i].right)); - } - return sectionEl; - }; +GrDiffBuilderSideBySide.prototype.addColumns = function(outputEl, fontSize) { + const width = fontSize * 4; + const colgroup = document.createElement('colgroup'); - GrDiffBuilderSideBySide.prototype.addColumns = function(outputEl, fontSize) { - const width = fontSize * 4; - const colgroup = document.createElement('colgroup'); + // Add the blame column. + let col = this._createElement('col', 'blame'); + colgroup.appendChild(col); - // Add the blame column. - let col = this._createElement('col', 'blame'); - colgroup.appendChild(col); + // Add left-side line number. + col = document.createElement('col'); + col.setAttribute('width', width); + colgroup.appendChild(col); - // Add left-side line number. - col = document.createElement('col'); - col.setAttribute('width', width); - colgroup.appendChild(col); + // Add left-side content. + colgroup.appendChild(document.createElement('col')); - // Add left-side content. - colgroup.appendChild(document.createElement('col')); + // Add right-side line number. + col = document.createElement('col'); + col.setAttribute('width', width); + colgroup.appendChild(col); - // Add right-side line number. - col = document.createElement('col'); - col.setAttribute('width', width); - colgroup.appendChild(col); + // Add right-side content. + colgroup.appendChild(document.createElement('col')); - // Add right-side content. - colgroup.appendChild(document.createElement('col')); + outputEl.appendChild(colgroup); +}; - outputEl.appendChild(colgroup); - }; +GrDiffBuilderSideBySide.prototype._createRow = function(section, leftLine, + rightLine) { + const row = this._createElement('tr'); + row.classList.add('diff-row', 'side-by-side'); + row.setAttribute('left-type', leftLine.type); + row.setAttribute('right-type', rightLine.type); + row.tabIndex = -1; - GrDiffBuilderSideBySide.prototype._createRow = function(section, leftLine, - rightLine) { - const row = this._createElement('tr'); - row.classList.add('diff-row', 'side-by-side'); - row.setAttribute('left-type', leftLine.type); - row.setAttribute('right-type', rightLine.type); - row.tabIndex = -1; + row.appendChild(this._createBlameCell(leftLine)); - row.appendChild(this._createBlameCell(leftLine)); + this._appendPair(section, row, leftLine, leftLine.beforeNumber, + GrDiffBuilder.Side.LEFT); + this._appendPair(section, row, rightLine, rightLine.afterNumber, + GrDiffBuilder.Side.RIGHT); + return row; +}; - this._appendPair(section, row, leftLine, leftLine.beforeNumber, - GrDiffBuilder.Side.LEFT); - this._appendPair(section, row, rightLine, rightLine.afterNumber, - GrDiffBuilder.Side.RIGHT); - return row; - }; +GrDiffBuilderSideBySide.prototype._appendPair = function(section, row, line, + lineNumber, side) { + const lineNumberEl = this._createLineEl(line, lineNumber, line.type, side); + row.appendChild(lineNumberEl); + const action = this._createContextControl(section, line); + if (action) { + row.appendChild(action); + } else { + const textEl = this._createTextEl(lineNumberEl, line, side); + row.appendChild(textEl); + } +}; - GrDiffBuilderSideBySide.prototype._appendPair = function(section, row, line, - lineNumber, side) { - const lineNumberEl = this._createLineEl(line, lineNumber, line.type, side); - row.appendChild(lineNumberEl); - const action = this._createContextControl(section, line); - if (action) { - row.appendChild(action); - } else { - const textEl = this._createTextEl(lineNumberEl, line, side); - row.appendChild(textEl); - } - }; - - GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function( - content, side) { - let tr = content.parentElement.parentElement; - while (tr = tr.nextSibling) { - content = tr.querySelector( - 'td.content .contentText[data-side="' + side + '"]'); - if (content) { return content; } - } - return null; - }; - - window.GrDiffBuilderSideBySide = GrDiffBuilderSideBySide; -})(window); +GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function( + content, side) { + let tr = content.parentElement.parentElement; + while (tr = tr.nextSibling) { + content = tr.querySelector( + 'td.content .contentText[data-side="' + side + '"]'); + if (content) { return content; } + } + return null; +}; diff --git a/polygerrit-ui/app/elements/gr-app-global-var-init.js b/polygerrit-ui/app/elements/gr-app-global-var-init.js index 43fbf10aac..d86b47ba51 100644 --- a/polygerrit-ui/app/elements/gr-app-global-var-init.js +++ b/polygerrit-ui/app/elements/gr-app-global-var-init.js @@ -28,6 +28,7 @@ import {GrAttributeHelper} from './plugins/gr-attribute-helper/gr-attribute-help import {GrDiffLine} from './diff/gr-diff/gr-diff-line.js'; import {GrDiffGroup} from './diff/gr-diff/gr-diff-group.js'; import {GrDiffBuilder} from './diff/gr-diff-builder/gr-diff-builder.js'; +import {GrDiffBuilderSideBySide} from './diff/gr-diff-builder/gr-diff-builder-side-by-side.js'; export function initGlobalVariables() { window.GrDisplayNameUtils = GrDisplayNameUtils; @@ -36,4 +37,5 @@ export function initGlobalVariables() { window.GrDiffLine = GrDiffLine; window.GrDiffGroup = GrDiffGroup; window.GrDiffBuilder = GrDiffBuilder; + window.GrDiffBuilderSideBySide = GrDiffBuilderSideBySide; }