-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viewer: Lighthouse 2.0 support #2521
Changes from all commits
563ea11
b30ec9f
ab22bbc
4b52655
b4d31ab
b1d3df4
2039219
3358aa2
2b11d9e
0166be4
6dfeb40
edf7f70
ae2ed6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Typing externs file needed for Viewer compilation. | ||
* @externs | ||
*/ | ||
|
||
/** | ||
* @struct | ||
* @constructor | ||
*/ | ||
function ReportGenerator() {} | ||
|
||
/** | ||
* @param {!ReportRenderer.ReportJSON} reportJson | ||
* @return {string} | ||
*/ | ||
ReportGenerator.prototype.generateReportHtml = function(reportJson) {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,14 @@ class ReportRenderer { | |
/** | ||
* @param {!DOM} dom | ||
* @param {!CategoryRenderer} categoryRenderer | ||
* @param {?ReportUIFeatures=} uiFeatures | ||
*/ | ||
constructor(dom, categoryRenderer, uiFeatures = null) { | ||
constructor(dom, categoryRenderer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** @private {!DOM} */ | ||
this._dom = dom; | ||
/** @private {!CategoryRenderer} */ | ||
this._categoryRenderer = categoryRenderer; | ||
/** @private {!Document|!Element} */ | ||
this._templateContext = this._dom.document(); | ||
/** @private {ReportUIFeatures} */ | ||
this._uiFeatures = uiFeatures; | ||
} | ||
|
||
/** | ||
|
@@ -39,12 +36,6 @@ class ReportRenderer { | |
container.textContent = ''; // Remove previous report. | ||
const element = container.appendChild(this._renderReport(report)); | ||
|
||
// Hook in JS features and page-level event listeners after the report | ||
// is in the document. | ||
if (this._uiFeatures) { | ||
this._uiFeatures.initFeatures(report); | ||
} | ||
|
||
return /** @type {!Element} **/ (element); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Manages drag and drop file input for the page. | ||
*/ | ||
class DragAndDrop { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slightly simpler than the old FileUploader. Handles only drag and dropping of files (the hidden input is now just in the page and its handler and |
||
/** | ||
* @param {function(!File)} fileHandlerCallback Invoked when the user chooses a new file. | ||
*/ | ||
constructor(fileHandlerCallback) { | ||
this._dropZone = document.querySelector('.drop_zone'); | ||
this._fileHandlerCallback = fileHandlerCallback; | ||
this._dragging = false; | ||
|
||
this._addListeners(); | ||
} | ||
|
||
_addListeners() { | ||
// The mouseleave event is more reliable than dragleave when the user drops | ||
// the file outside the window. | ||
document.addEventListener('mouseleave', _ => { | ||
if (!this._dragging) { | ||
return; | ||
} | ||
this._resetDraggingUI(); | ||
}); | ||
|
||
document.addEventListener('dragover', e => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as an aside, what do each of these e.stopProgagation/preventDefaults do/why are they necessary? I built another drag/drop recently and I got away without some of them, but I don't know what exactly is required to pull this off... cc: @ebidel for the original impl :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dude told me to do it: https://www.html5rocks.com/en/tutorials/dnd/basics/ TBH, I don't think we need them anymore in a Anyways, doesn't hurt to be explicit the method is handing the event. |
||
e.dataTransfer.dropEffect = 'copy'; // Explicitly show as copy action. | ||
}); | ||
|
||
document.addEventListener('dragenter', _ => { | ||
this._dropZone.classList.add('dropping'); | ||
this._dragging = true; | ||
}); | ||
|
||
document.addEventListener('drop', e => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
this._resetDraggingUI(); | ||
|
||
// Note, this ignores multiple files in the drop, only taking the first. | ||
this._fileHandlerCallback(e.dataTransfer.files[0]); | ||
}); | ||
} | ||
|
||
_resetDraggingUI() { | ||
this._dropZone.classList.remove('dropping'); | ||
this._dragging = false; | ||
} | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = DragAndDrop; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than trying to compile
ReportGenerator
(with itsfs
use), just use externs for the one method we care about