From 09b241ee6eb1b5e90900570ff977fe1ff43e7815 Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Fri, 31 Jan 2025 16:49:10 +0100 Subject: [PATCH 1/6] Fix issue with button JavaScript execution by processing each annotation individually --- src/scripting_api/initialization.js | 97 ++++++++++++++++------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/src/scripting_api/initialization.js b/src/scripting_api/initialization.js index 946e6804862c7..61d41aa104e17 100644 --- a/src/scripting_api/initialization.js +++ b/src/scripting_api/initialization.js @@ -71,57 +71,66 @@ function initSandbox(params) { const appObjects = app._objects; if (data.objects) { - const annotations = []; - for (const [name, objs] of Object.entries(data.objects)) { - annotations.length = 0; - let container = null; - - for (const obj of objs) { - if (obj.type !== "") { - annotations.push(obj); - } else { - container = obj; + // Separate annotations and container + const annotations = objs.filter(obj => obj.type !== ""); + const container = objs.find(obj => obj.type === ""); + + // Process each annotation (button, checkbox, etc.) + for (const obj of annotations) { + obj.send = send; // Assign the send function to each annotation + obj.globalEval = globalEval; + obj.doc = _document; + obj.fieldPath = name; + obj.appObjects = appObjects; + + // Handle siblings (if any) + const otherFields = annotations.filter(x => x !== obj); + if (otherFields.length > 0) { + obj.siblings = otherFields.map(x => x.id); } - } - - let obj = container; - if (annotations.length > 0) { - obj = annotations[0]; - obj.send = send; - } - - obj.globalEval = globalEval; - obj.doc = _document; - obj.fieldPath = name; - obj.appObjects = appObjects; - const otherFields = annotations.slice(1); - - let field; - switch (obj.type) { - case "radiobutton": { - field = new RadioButtonField(otherFields, obj); - break; - } - case "checkbox": { - field = new CheckboxField(otherFields, obj); - break; + // Create a Field instance based on the type + let field; + switch (obj.type) { + case "radiobutton": + field = new RadioButtonField( + otherFields.map(x => x.id), + obj + ); // Pass sibling IDs + break; + case "checkbox": + field = new CheckboxField( + otherFields.map(x => x.id), + obj + ); // Pass sibling IDs + break; + default: + field = new Field(obj); } - default: - if (otherFields.length > 0) { - obj.siblings = otherFields.map(x => x.id); - } - field = new Field(obj); - } - const wrapped = new Proxy(field, proxyHandler); - const _object = { obj: field, wrapped }; - doc._addField(name, _object); - for (const object of objs) { - appObjects[object.id] = _object; + // Wrap the field in a Proxy and add it to doc and appObjects + const wrapped = new Proxy(field, proxyHandler); + const _object = { obj: field, wrapped }; + doc._addField(name, _object); + appObjects[obj.id] = _object; } + + // Handle the container (if it exists) if (container) { + container.send = send; + container.globalEval = globalEval; + container.doc = _document; + container.fieldPath = name; + container.appObjects = appObjects; + + // Create a Field instance for the container + const field = new Field(container); + const wrapped = new Proxy(field, proxyHandler); + const _object = { obj: field, wrapped }; + + // Add the container to doc and appObjects + doc._addField(name, _object); appObjects[container.id] = _object; } } From 5cf15bdc3749f8d7c9a265e8613adabd6cbe9dbd Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Fri, 31 Jan 2025 17:05:58 +0100 Subject: [PATCH 2/6] Fix issue with button JavaScript execution by processing each annotation individually --- test/unit/common_pdfstream_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/common_pdfstream_tests.js b/test/unit/common_pdfstream_tests.js index b96620df9f5c2..099c79e55dbdc 100644 --- a/test/unit/common_pdfstream_tests.js +++ b/test/unit/common_pdfstream_tests.js @@ -1,4 +1,4 @@ -/* Copyright 2024 Mozilla Foundation +git push origin updatesgit add test/unit/common_pdfstream_tests.js/* Copyright 2024 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 1046b232386a9d7c4fffd0c0f4eabbc85e445d6b Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Fri, 31 Jan 2025 17:07:34 +0100 Subject: [PATCH 3/6] Fix issue with button JavaScript execution by processing each annotation individually --- test/unit/common_pdfstream_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/common_pdfstream_tests.js b/test/unit/common_pdfstream_tests.js index 099c79e55dbdc..b96620df9f5c2 100644 --- a/test/unit/common_pdfstream_tests.js +++ b/test/unit/common_pdfstream_tests.js @@ -1,4 +1,4 @@ -git push origin updatesgit add test/unit/common_pdfstream_tests.js/* Copyright 2024 Mozilla Foundation +/* Copyright 2024 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From dbd30e5f8e9a3b7c0fa18fc8b524f41aa890053c Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Mon, 3 Feb 2025 11:15:25 +0100 Subject: [PATCH 4/6] updated --- gulpfile.mjs | 34 +++++++++++++++++++++++++++++++++- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index e119a570f8de7..505e3dc14e447 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -20,12 +20,13 @@ import { import { exec, execSync, spawn, spawnSync } from "child_process"; import autoprefixer from "autoprefixer"; import babel from "@babel/core"; +import chokidar from "chokidar"; import crypto from "crypto"; -import { fileURLToPath } from "url"; import fs from "fs"; import gulp from "gulp"; import hljs from "highlight.js"; import layouts from "@metalsmith/layouts"; +import lodash from "lodash"; // Destructure the required function import markdown from "@metalsmith/markdown"; import Metalsmith from "metalsmith"; import ordered from "ordered-read-streams"; @@ -45,6 +46,9 @@ import Vinyl from "vinyl"; import webpack2 from "webpack"; import webpackStream from "webpack-stream"; import zip from "gulp-zip"; +// eslint-disable-next-line sort-imports +import { fileURLToPath } from "url"; // Import the default export +const { debounce } = lodash; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -103,6 +107,27 @@ const BABEL_PRESET_ENV_OPTS = Object.freeze({ useBuiltIns: "usage", }); +// Task to rebuild the scripts +function rebuildScripts(done) { + console.log("Rebuilding scripts..."); + exec("npx gulp generic", (err, stdout, stderr) => { + if (err) { + console.error(`Error: ${stderr}`); + } else { + console.log(stdout); + } + done(); // Always call done() to ensure the watcher continues + }); +} + +// Debounced version of rebuildScripts +const debouncedRebuildScripts = debounce(rebuildScripts, 500); // 500ms debounce + +// Task to watch for changes in the source files +chokidar + .watch("src/**/*.js", { ignoreInitial: true }) + .on("all", debouncedRebuildScripts); + const DEFINES = Object.freeze({ SKIP_BABEL: true, TESTING: undefined, @@ -2539,3 +2564,10 @@ gulp.task("externaltest", function (done) { }); done(); }); + +// Export the watch task +function watchFiles() { + gulp.watch("src/**/*.js", rebuildScripts); +} + +export const watch = gulp.series(rebuildScripts, watchFiles); diff --git a/package-lock.json b/package-lock.json index d432df8d5ba75..e013a45c25286 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "autoprefixer": "^10.4.20", "babel-loader": "^9.2.1", "caniuse-lite": "^1.0.30001692", + "chokidar": "^4.0.3", "core-js": "^3.40.0", "eslint": "^9.18.0", "eslint-plugin-import": "^2.31.0", @@ -4022,6 +4023,21 @@ "url": "https://github.com/sponsors/fb55" } }, + "node_modules/chokidar": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", + "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", + "dev": true, + "dependencies": { + "readdirp": "^4.0.1" + }, + "engines": { + "node": ">= 14.16.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/chrome-trace-event": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", @@ -10256,6 +10272,19 @@ "util-deprecate": "~1.0.1" } }, + "node_modules/readdirp": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.1.tgz", + "integrity": "sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==", + "dev": true, + "engines": { + "node": ">= 14.18.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/rechoir": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", diff --git a/package.json b/package.json index 2e4dc7ec0665f..53b7b70273804 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "autoprefixer": "^10.4.20", "babel-loader": "^9.2.1", "caniuse-lite": "^1.0.30001692", + "chokidar": "^4.0.3", "core-js": "^3.40.0", "eslint": "^9.18.0", "eslint-plugin-import": "^2.31.0", From 48c2fd1522736cb10cfff765c493813512763c0f Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Mon, 3 Feb 2025 12:06:48 +0100 Subject: [PATCH 5/6] reverted chnages --- gulpfile.mjs | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index 505e3dc14e447..298f043df924d 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -20,13 +20,12 @@ import { import { exec, execSync, spawn, spawnSync } from "child_process"; import autoprefixer from "autoprefixer"; import babel from "@babel/core"; -import chokidar from "chokidar"; import crypto from "crypto"; +import { fileURLToPath } from "url"; import fs from "fs"; import gulp from "gulp"; import hljs from "highlight.js"; import layouts from "@metalsmith/layouts"; -import lodash from "lodash"; // Destructure the required function import markdown from "@metalsmith/markdown"; import Metalsmith from "metalsmith"; import ordered from "ordered-read-streams"; @@ -46,9 +45,6 @@ import Vinyl from "vinyl"; import webpack2 from "webpack"; import webpackStream from "webpack-stream"; import zip from "gulp-zip"; -// eslint-disable-next-line sort-imports -import { fileURLToPath } from "url"; // Import the default export -const { debounce } = lodash; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -107,27 +103,6 @@ const BABEL_PRESET_ENV_OPTS = Object.freeze({ useBuiltIns: "usage", }); -// Task to rebuild the scripts -function rebuildScripts(done) { - console.log("Rebuilding scripts..."); - exec("npx gulp generic", (err, stdout, stderr) => { - if (err) { - console.error(`Error: ${stderr}`); - } else { - console.log(stdout); - } - done(); // Always call done() to ensure the watcher continues - }); -} - -// Debounced version of rebuildScripts -const debouncedRebuildScripts = debounce(rebuildScripts, 500); // 500ms debounce - -// Task to watch for changes in the source files -chokidar - .watch("src/**/*.js", { ignoreInitial: true }) - .on("all", debouncedRebuildScripts); - const DEFINES = Object.freeze({ SKIP_BABEL: true, TESTING: undefined, @@ -2565,9 +2540,3 @@ gulp.task("externaltest", function (done) { done(); }); -// Export the watch task -function watchFiles() { - gulp.watch("src/**/*.js", rebuildScripts); -} - -export const watch = gulp.series(rebuildScripts, watchFiles); From e47981591648fdfc094da4780a785614ad6ee9f0 Mon Sep 17 00:00:00 2001 From: Nwamini Emmanuel Onyedikachi Date: Mon, 3 Feb 2025 12:55:56 +0100 Subject: [PATCH 6/6] updated --- package-lock.json | 29 ----------------------------- package.json | 1 - 2 files changed, 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index e013a45c25286..d432df8d5ba75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,6 @@ "autoprefixer": "^10.4.20", "babel-loader": "^9.2.1", "caniuse-lite": "^1.0.30001692", - "chokidar": "^4.0.3", "core-js": "^3.40.0", "eslint": "^9.18.0", "eslint-plugin-import": "^2.31.0", @@ -4023,21 +4022,6 @@ "url": "https://github.com/sponsors/fb55" } }, - "node_modules/chokidar": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", - "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", - "dev": true, - "dependencies": { - "readdirp": "^4.0.1" - }, - "engines": { - "node": ">= 14.16.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/chrome-trace-event": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", @@ -10272,19 +10256,6 @@ "util-deprecate": "~1.0.1" } }, - "node_modules/readdirp": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.1.tgz", - "integrity": "sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==", - "dev": true, - "engines": { - "node": ">= 14.18.0" - }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/rechoir": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", diff --git a/package.json b/package.json index 53b7b70273804..2e4dc7ec0665f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "autoprefixer": "^10.4.20", "babel-loader": "^9.2.1", "caniuse-lite": "^1.0.30001692", - "chokidar": "^4.0.3", "core-js": "^3.40.0", "eslint": "^9.18.0", "eslint-plugin-import": "^2.31.0",