mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Re-factor document.getElementsByName
lookups in the AnnotationLayer (issue 14003)
This replaces direct `document.getElementsByName` lookups with a helper method which: - Lets the AnnotationLayer use the data returned by the `PDFDocumentProxy.getFieldObjects` API-method, such that we can directly lookup only the necessary DOM elements. - Fallback to using `document.getElementsByName` as before, such that e.g. the standalone viewer components still work. Finally, to fix the problems reported in issue 14003, regardless of the code-path we now also enforce that the DOM elements found were actually created by the AnnotationLayer code. With these changes we'll thus be able to update form elements on all visible pages just as before, but we'll additionally update the AnnotationStorage for not-yet-rendered elements thus fixing a pre-existing bug.
This commit is contained in:
parent
8dc22f40c7
commit
6cba5509f2
6 changed files with 149 additions and 78 deletions
|
@ -1017,9 +1017,9 @@ class PDFDocumentProxy {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Array<Object> | null>} A promise that is resolved with an
|
||||
* {Array<Object>} containing /AcroForm field data for the JS sandbox,
|
||||
* or `null` when no field data is present in the PDF file.
|
||||
* @returns {Promise<Object<string, Array<Object>> | null>} A promise that is
|
||||
* resolved with an {Object} containing /AcroForm field data for the JS
|
||||
* sandbox, or `null` when no field data is present in the PDF file.
|
||||
*/
|
||||
getFieldObjects() {
|
||||
return this._transport.getFieldObjects();
|
||||
|
@ -2480,6 +2480,7 @@ class WorkerTransport {
|
|||
Promise.all(waitOn).then(() => {
|
||||
this.commonObjs.clear();
|
||||
this.fontLoader.clear();
|
||||
this._getFieldObjectsPromise = null;
|
||||
this._hasJSActionsPromise = null;
|
||||
|
||||
if (this._networkStream) {
|
||||
|
@ -2921,7 +2922,8 @@ class WorkerTransport {
|
|||
}
|
||||
|
||||
getFieldObjects() {
|
||||
return this.messageHandler.sendWithPromise("GetFieldObjects", null);
|
||||
return (this._getFieldObjectsPromise ||=
|
||||
this.messageHandler.sendWithPromise("GetFieldObjects", null));
|
||||
}
|
||||
|
||||
hasJSActions() {
|
||||
|
@ -3050,6 +3052,7 @@ class WorkerTransport {
|
|||
if (!keepLoadedFonts) {
|
||||
this.fontLoader.clear();
|
||||
}
|
||||
this._getFieldObjectsPromise = null;
|
||||
this._hasJSActionsPromise = null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue