Get rid of global GrDiffBuilderSideBySide
* Replace the global GrDiffBuilderSideBySide variable with named imports. * Update gr-app-global-var-init.js Change-Id: I11d2480a2709d0037c255cf885b2375c2e7e1dbf
This commit is contained in:
@@ -179,7 +179,6 @@ module.exports = {
|
|||||||
"GrCountStringFormatter": "readonly",
|
"GrCountStringFormatter": "readonly",
|
||||||
"GrDiffBuilderBinary": "readonly",
|
"GrDiffBuilderBinary": "readonly",
|
||||||
"GrDiffBuilderImage": "readonly",
|
"GrDiffBuilderImage": "readonly",
|
||||||
"GrDiffBuilderSideBySide": "readonly",
|
|
||||||
"GrDiffBuilderUnified": "readonly",
|
"GrDiffBuilderUnified": "readonly",
|
||||||
"GrDomHook": "readonly",
|
"GrDomHook": "readonly",
|
||||||
"GrDomHooksManager": "readonly",
|
"GrDomHooksManager": "readonly",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
|||||||
import {htmlTemplate} from './gr-diff-builder-element_html.js';
|
import {htmlTemplate} from './gr-diff-builder-element_html.js';
|
||||||
import {GrAnnotation} from '../gr-diff-highlight/gr-annotation.js';
|
import {GrAnnotation} from '../gr-diff-highlight/gr-annotation.js';
|
||||||
import {GrDiffBuilder} from './gr-diff-builder.js';
|
import {GrDiffBuilder} from './gr-diff-builder.js';
|
||||||
|
import {GrDiffBuilderSideBySide} from './gr-diff-builder-side-by-side.js';
|
||||||
|
|
||||||
const DiffViewMode = {
|
const DiffViewMode = {
|
||||||
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
|
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
|
||||||
|
|||||||
@@ -14,7 +14,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
(function(window, GrDiffBuilderSideBySide) {
|
|
||||||
|
import {GrDiffBuilderSideBySide} from './gr-diff-builder-side-by-side.js';
|
||||||
|
|
||||||
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Prevent redefinition.
|
// Prevent redefinition.
|
||||||
@@ -180,4 +183,4 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.GrDiffBuilderImage = GrDiffBuilderImage;
|
window.GrDiffBuilderImage = GrDiffBuilderImage;
|
||||||
})(window, GrDiffBuilderSideBySide);
|
})(window);
|
||||||
|
|||||||
@@ -17,106 +17,97 @@
|
|||||||
|
|
||||||
import {GrDiffBuilder} from './gr-diff-builder.js';
|
import {GrDiffBuilder} from './gr-diff-builder.js';
|
||||||
|
|
||||||
(function(window) {
|
/** @constructor */
|
||||||
'use strict';
|
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.
|
GrDiffBuilderSideBySide.prototype.buildSectionElement = function(group) {
|
||||||
if (window.GrDiffBuilderSideBySide) { return; }
|
const sectionEl = this._createElement('tbody', 'section');
|
||||||
|
sectionEl.classList.add(group.type);
|
||||||
/** @constructor */
|
if (this._isTotal(group)) {
|
||||||
function GrDiffBuilderSideBySide(diff, prefs, outputEl, layers) {
|
sectionEl.classList.add('total');
|
||||||
GrDiffBuilder.call(this, diff, prefs, outputEl, layers);
|
|
||||||
}
|
}
|
||||||
GrDiffBuilderSideBySide.prototype = Object.create(GrDiffBuilder.prototype);
|
if (group.dueToRebase) {
|
||||||
GrDiffBuilderSideBySide.prototype.constructor = GrDiffBuilderSideBySide;
|
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) {
|
GrDiffBuilderSideBySide.prototype.addColumns = function(outputEl, fontSize) {
|
||||||
const sectionEl = this._createElement('tbody', 'section');
|
const width = fontSize * 4;
|
||||||
sectionEl.classList.add(group.type);
|
const colgroup = document.createElement('colgroup');
|
||||||
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) {
|
// Add the blame column.
|
||||||
const width = fontSize * 4;
|
let col = this._createElement('col', 'blame');
|
||||||
const colgroup = document.createElement('colgroup');
|
colgroup.appendChild(col);
|
||||||
|
|
||||||
// Add the blame column.
|
// Add left-side line number.
|
||||||
let col = this._createElement('col', 'blame');
|
col = document.createElement('col');
|
||||||
colgroup.appendChild(col);
|
col.setAttribute('width', width);
|
||||||
|
colgroup.appendChild(col);
|
||||||
|
|
||||||
// Add left-side line number.
|
// Add left-side content.
|
||||||
col = document.createElement('col');
|
colgroup.appendChild(document.createElement('col'));
|
||||||
col.setAttribute('width', width);
|
|
||||||
colgroup.appendChild(col);
|
|
||||||
|
|
||||||
// Add left-side content.
|
// Add right-side line number.
|
||||||
colgroup.appendChild(document.createElement('col'));
|
col = document.createElement('col');
|
||||||
|
col.setAttribute('width', width);
|
||||||
|
colgroup.appendChild(col);
|
||||||
|
|
||||||
// Add right-side line number.
|
// Add right-side content.
|
||||||
col = document.createElement('col');
|
colgroup.appendChild(document.createElement('col'));
|
||||||
col.setAttribute('width', width);
|
|
||||||
colgroup.appendChild(col);
|
|
||||||
|
|
||||||
// Add right-side content.
|
outputEl.appendChild(colgroup);
|
||||||
colgroup.appendChild(document.createElement('col'));
|
};
|
||||||
|
|
||||||
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,
|
row.appendChild(this._createBlameCell(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));
|
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,
|
GrDiffBuilderSideBySide.prototype._appendPair = function(section, row, line,
|
||||||
GrDiffBuilder.Side.LEFT);
|
lineNumber, side) {
|
||||||
this._appendPair(section, row, rightLine, rightLine.afterNumber,
|
const lineNumberEl = this._createLineEl(line, lineNumber, line.type, side);
|
||||||
GrDiffBuilder.Side.RIGHT);
|
row.appendChild(lineNumberEl);
|
||||||
return row;
|
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,
|
GrDiffBuilderSideBySide.prototype._getNextContentOnSide = function(
|
||||||
lineNumber, side) {
|
content, side) {
|
||||||
const lineNumberEl = this._createLineEl(line, lineNumber, line.type, side);
|
let tr = content.parentElement.parentElement;
|
||||||
row.appendChild(lineNumberEl);
|
while (tr = tr.nextSibling) {
|
||||||
const action = this._createContextControl(section, line);
|
content = tr.querySelector(
|
||||||
if (action) {
|
'td.content .contentText[data-side="' + side + '"]');
|
||||||
row.appendChild(action);
|
if (content) { return content; }
|
||||||
} else {
|
}
|
||||||
const textEl = this._createTextEl(lineNumberEl, line, side);
|
return null;
|
||||||
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);
|
|
||||||
|
|||||||
@@ -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 {GrDiffLine} from './diff/gr-diff/gr-diff-line.js';
|
||||||
import {GrDiffGroup} from './diff/gr-diff/gr-diff-group.js';
|
import {GrDiffGroup} from './diff/gr-diff/gr-diff-group.js';
|
||||||
import {GrDiffBuilder} from './diff/gr-diff-builder/gr-diff-builder.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() {
|
export function initGlobalVariables() {
|
||||||
window.GrDisplayNameUtils = GrDisplayNameUtils;
|
window.GrDisplayNameUtils = GrDisplayNameUtils;
|
||||||
@@ -36,4 +37,5 @@ export function initGlobalVariables() {
|
|||||||
window.GrDiffLine = GrDiffLine;
|
window.GrDiffLine = GrDiffLine;
|
||||||
window.GrDiffGroup = GrDiffGroup;
|
window.GrDiffGroup = GrDiffGroup;
|
||||||
window.GrDiffBuilder = GrDiffBuilder;
|
window.GrDiffBuilder = GrDiffBuilder;
|
||||||
|
window.GrDiffBuilderSideBySide = GrDiffBuilderSideBySide;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user