Merge pull request #7583 from betagouv/revert/fix-event-polyfill

more fix other ie11 issues
This commit is contained in:
mfo 2022-07-19 10:57:14 +02:00 committed by GitHub
commit 8993c84eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 205 additions and 67 deletions

View file

@ -52,6 +52,7 @@ function lazyLoadNewControllers(application: Application) {
} }
} }
}).observe(application.element, { }).observe(application.element, {
attributes: true,
attributeFilter: [controllerAttribute], attributeFilter: [controllerAttribute],
subtree: true, subtree: true,
childList: true childList: true

View file

@ -1,6 +1,6 @@
// For links and requests done through rails-ujs (mostly data-remote links), // For links and requests done through rails-ujs (mostly data-remote links),
// redirect to the sign-in page when the server responds '401 Unauthorized'. // redirect to the sign-in page when the server responds '401 Unauthorized'.
document.body.addEventListener('ajax:error', (event) => { document.addEventListener('ajax:error', (event) => {
const [, , xhr] = event.detail; const [, , xhr] = event.detail;
if (xhr && xhr.status == 401) { if (xhr && xhr.status == 401) {
location.reload(); // reload whole page so Devise will redirect to sign-in location.reload(); // reload whole page so Devise will redirect to sign-in

View file

@ -18,6 +18,7 @@
"@webcomponents/template": "^1.5.0", "@webcomponents/template": "^1.5.0",
"chartkick": "^4.2.0", "chartkick": "^4.2.0",
"core-js": "^3.23.3", "core-js": "^3.23.3",
"custom-event-polyfill": "^1.0.7",
"debounce": "^1.2.1", "debounce": "^1.2.1",
"dom4": "^2.1.6", "dom4": "^2.1.6",
"email-butler": "^1.0.13", "email-butler": "^1.0.13",

View file

@ -1,11 +1,39 @@
diff --git a/node_modules/event-target-polyfill/index.js b/node_modules/event-target-polyfill/index.js diff --git a/node_modules/event-target-polyfill/index.js b/node_modules/event-target-polyfill/index.js
index 82f7f42..d198834 100644 index 82f7f42..8e29c96 100644
--- a/node_modules/event-target-polyfill/index.js --- a/node_modules/event-target-polyfill/index.js
+++ b/node_modules/event-target-polyfill/index.js +++ b/node_modules/event-target-polyfill/index.js
@@ -12,19 +12,6 @@ function isConstructor(fn) { @@ -1,7 +1,20 @@
return true; -const root =
} - (typeof globalThis !== "undefined" && globalThis) ||
- (typeof self !== "undefined" && self) ||
- (typeof global !== "undefined" && global);
+"use strict";
+
+function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
+
+function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
+
+function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
+
+function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
+
+function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
+
+function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
+
+function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
+
+var root = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || typeof global !== "undefined" && global;
function isConstructor(fn) {
try {
@@ -9,66 +22,49 @@ function isConstructor(fn) {
} catch (error) {
return false;
}
- return true;
-}
-
-if (typeof root.Event !== "function" || !isConstructor(root.Event)) { -if (typeof root.Event !== "function" || !isConstructor(root.Event)) {
- root.Event = (function () { - root.Event = (function () {
- function Event(type, options) { - function Event(type, options) {
@ -14,66 +42,167 @@ index 82f7f42..d198834 100644
- this.composed = !!options && !!options.composed; - this.composed = !!options && !!options.composed;
- this.type = type; - this.type = type;
- } - }
-
- return Event; - return Event;
- })(); - })();
-} + return true;
- }
if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) {
root.EventTarget = (function () { - root.EventTarget = (function () {
+ root.EventTarget = function () {
function EventTarget() { function EventTarget() {
@@ -40,7 +27,8 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { this.__listeners = new Map();
) { }
EventTarget.prototype = Object.create(Object.prototype);
- EventTarget.prototype.addEventListener = function (
- type,
- listener,
- options
- ) {
+ EventTarget.prototype.addEventListener = function (type, listener, options) {
if (arguments.length < 2) { if (arguments.length < 2) {
throw new TypeError( - throw new TypeError(
- `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
+ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " + - );
+ "but only " + arguments.length.toString() + "present." + throw new TypeError("TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ".concat(arguments.length, " present."));
);
} }
const __listeners = this.__listeners; - const __listeners = this.__listeners;
@@ -62,7 +50,8 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { - const actualType = type.toString();
) { +
+ var __listeners = this.__listeners;
+ var actualType = type.toString();
+
if (!__listeners.has(actualType)) {
__listeners.set(actualType, new Map());
}
- const listenersForType = __listeners.get(actualType);
+
+ var listenersForType = __listeners.get(actualType);
+
if (!listenersForType.has(listener)) {
// Any given listener is only registered once
listenersForType.set(listener, options);
}
};
- EventTarget.prototype.removeEventListener = function (
- type,
- listener,
- _options
- ) {
+ EventTarget.prototype.removeEventListener = function (type, listener, _options) {
if (arguments.length < 2) { if (arguments.length < 2) {
throw new TypeError( - throw new TypeError(
- `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
+ "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, " + - );
+ "but only " + arguments.length.toString() + "present." + throw new TypeError("TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ".concat(arguments.length, " present."));
);
} }
const __listeners = this.__listeners; - const __listeners = this.__listeners;
@@ -78,14 +67,14 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { - const actualType = type.toString();
+
+ var __listeners = this.__listeners;
+ var actualType = type.toString();
+
if (__listeners.has(actualType)) {
- const listenersForType = __listeners.get(actualType);
+ var listenersForType = __listeners.get(actualType);
+
if (listenersForType.has(listener)) {
listenersForType.delete(listener);
}
@@ -77,45 +73,61 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) {
EventTarget.prototype.dispatchEvent = function (event) { EventTarget.prototype.dispatchEvent = function (event) {
if (!(event instanceof Event)) { if (!(event instanceof Event)) {
throw new TypeError( - throw new TypeError(
- `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.` - `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.`
+ "Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'." - );
); + throw new TypeError("Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.");
} }
const type = event.type; - const type = event.type;
const __listeners = this.__listeners; - const __listeners = this.__listeners;
const listenersForType = __listeners.get(type); - const listenersForType = __listeners.get(type);
+
+ var type = event.type;
+ var __listeners = this.__listeners;
+
+ var listenersForType = __listeners.get(type);
+
if (listenersForType) { if (listenersForType) {
- for (const [listener, options] of listenersForType.entries()) { - for (const [listener, options] of listenersForType.entries()) {
+ listenersForType.forEach(function(options, listener) { - try {
try { - if (typeof listener === "function") {
if (typeof listener === "function") { - // Listener functions must be executed with the EventTarget as the `this` context.
// Listener functions must be executed with the EventTarget as the `this` context. - listener.call(this, event);
@@ -100,7 +89,7 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { - } else if (listener && typeof listener.handleEvent === "function") {
// Unfortunately, this is the best we can do, which isn't great, because the - // Listener objects have their handleEvent method called, if they have one
// native EventTarget will actually do this synchronously before moving to the next - listener.handleEvent(event);
// event in the loop. + var _iterator = _createForOfIteratorHelper(listenersForType.entries()),
+ _step;
+
+ try {
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
+ var _step$value = _slicedToArray(_step.value, 2),
+ listener = _step$value[0],
+ options = _step$value[1];
+
+ try {
+ if (typeof listener === "function") {
+ // Listener functions must be executed with the EventTarget as the `this` context.
+ listener.call(this, event);
+ } else if (listener && typeof listener.handleEvent === "function") {
+ // Listener objects have their handleEvent method called, if they have one
+ listener.handleEvent(event);
+ }
+ } catch (err) {
+ // We need to report the error to the global error handling event,
+ // but we do not want to break the loop that is executing the events.
+ // Unfortunately, this is the best we can do, which isn't great, because the
+ // native EventTarget will actually do this synchronously before moving to the next
+ // event in the loop.
+ setTimeout(function () {
+ throw err;
+ });
+ }
+
+ if (options && options.once) {
+ // If this was registered with { once: true }, we need
+ // to remove it now.
+ listenersForType.delete(listener);
}
- } catch (err) {
- // We need to report the error to the global error handling event,
- // but we do not want to break the loop that is executing the events.
- // Unfortunately, this is the best we can do, which isn't great, because the
- // native EventTarget will actually do this synchronously before moving to the next
- // event in the loop.
- setTimeout(() => { - setTimeout(() => {
+ setTimeout(function() { - throw err;
throw err; - });
}); - }
- if (options && options.once) {
- // If this was registered with { once: true }, we need
- // to remove it now.
- listenersForType.delete(listener);
} }
@@ -109,7 +98,7 @@ if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) { + } catch (err) {
// to remove it now. + _iterator.e(err);
listenersForType.delete(listener); + } finally {
} + _iterator.f();
- } }
+ }) - }
} - // Since there are no cancellable events on a base EventTarget,
// Since there are no cancellable events on a base EventTarget, + } // Since there are no cancellable events on a base EventTarget,
// this should always return true. // this should always return true.
+
+
return true;
};
return EventTarget;
- })();
+ }();
}

View file

@ -1,5 +1,5 @@
diff --git a/node_modules/formdata-polyfill/FormData.js b/node_modules/formdata-polyfill/FormData.js diff --git a/node_modules/formdata-polyfill/FormData.js b/node_modules/formdata-polyfill/FormData.js
index 8e73660..7b64ba4 100644 index 8e73660..133dcd0 100644
--- a/node_modules/formdata-polyfill/FormData.js --- a/node_modules/formdata-polyfill/FormData.js
+++ b/node_modules/formdata-polyfill/FormData.js +++ b/node_modules/formdata-polyfill/FormData.js
@@ -71,7 +71,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData @@ -71,7 +71,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
@ -7,7 +7,7 @@ index 8e73660..7b64ba4 100644
function ensureArgs (args, expected) { function ensureArgs (args, expected) {
if (args.length < expected) { if (args.length < expected) {
- throw new TypeError(`${expected} argument required, but only ${args.length} present.`) - throw new TypeError(`${expected} argument required, but only ${args.length} present.`)
+ throw new TypeError(expected + " argument required, but only " + args.length.toString() + " present.") + throw new TypeError("".concat(expected, " argument required, but only ").concat(args.length, " present."))
} }
} }
@ -16,46 +16,46 @@ index 8e73660..7b64ba4 100644
const boundary = '----formdata-polyfill-' + Math.random(), const boundary = '----formdata-polyfill-' + Math.random(),
chunks = [], chunks = [],
- p = `--${boundary}\r\nContent-Disposition: form-data; name="` - p = `--${boundary}\r\nContent-Disposition: form-data; name="`
+ p = "--" + boundary +" \r\nContent-Disposition: form-data; name=\"" - this.forEach((value, name) => typeof value == 'string'
this.forEach((value, name) => typeof value == 'string'
- ? chunks.push(p + escape(normalizeLinefeeds(name)) + `"\r\n\r\n${normalizeLinefeeds(value)}\r\n`) - ? chunks.push(p + escape(normalizeLinefeeds(name)) + `"\r\n\r\n${normalizeLinefeeds(value)}\r\n`)
- : chunks.push(p + escape(normalizeLinefeeds(name)) + `"; filename="${escape(value.name)}"\r\nContent-Type: ${value.type||"application/octet-stream"}\r\n\r\n`, value, `\r\n`)) - : chunks.push(p + escape(normalizeLinefeeds(name)) + `"; filename="${escape(value.name)}"\r\nContent-Type: ${value.type||"application/octet-stream"}\r\n\r\n`, value, `\r\n`))
- chunks.push(`--${boundary}--`) - chunks.push(`--${boundary}--`)
+ ? chunks.push(p + escape(normalizeLinefeeds(name)) + "\"\r\n\r\n" + normalizeLinefeeds(value) + "\r\n") + p = "--".concat(boundary, "\r\nContent-Disposition: form-data; name=\"");
+ : chunks.push(p + escape(normalizeLinefeeds(name)) + "\"; filename=\"" + escape(value.name) + "\r\nContent-Type: " + (value.type||"application/octet-stream") + "\r\n\r\n", value, "\r\n")) + this.forEach((value, name) => typeof value == 'string'
+ chunks.push("--"+boundary+"--") + ? chunks.push(p + escape(normalizeLinefeeds(name)) + "\"\r\n\r\n".concat(normalizeLinefeeds(value), "\r\n"))
+ : chunks.push(p + escape(normalizeLinefeeds(name)) + "\"; filename=\"".concat(escape(value.name), "\"\r\nContent-Type: ").concat(value.type || "application/octet-stream", "\r\n\r\n"), value, "\r\n"))
+ chunks.push("--".concat(boundary, "--"));
return new Blob(chunks, { return new Blob(chunks, {
type: "multipart/form-data; boundary=" + boundary type: "multipart/form-data; boundary=" + boundary
}) })
diff --git a/node_modules/formdata-polyfill/formdata-to-blob.js b/node_modules/formdata-polyfill/formdata-to-blob.js diff --git a/node_modules/formdata-polyfill/formdata-to-blob.js b/node_modules/formdata-polyfill/formdata-to-blob.js
index 5a0a517..0b7fbd7 100644 index 5a0a517..05d1aca 100644
--- a/node_modules/formdata-polyfill/formdata-to-blob.js --- a/node_modules/formdata-polyfill/formdata-to-blob.js
+++ b/node_modules/formdata-polyfill/formdata-to-blob.js +++ b/node_modules/formdata-polyfill/formdata-to-blob.js
@@ -16,22 +16,22 @@ const escape = (str, filename) => @@ -16,22 +16,17 @@ const escape = (str, filename) =>
export function formDataToBlob (formData, BlobClass = Blob) { export function formDataToBlob (formData, BlobClass = Blob) {
const boundary = ('----formdata-polyfill-' + Math.random()) const boundary = ('----formdata-polyfill-' + Math.random())
const chunks = [] const chunks = []
- const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="` - const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="`
+ const prefix = "--"+$boundary+"\r\nContent-Disposition: form-data; name=\"" + var prefix = "--".concat(boundary, "\r\nContent-Disposition: form-data; name=\"");
for (let [name, value] of formData) { for (let [name, value] of formData) {
if (typeof value === 'string') { if (typeof value === 'string') {
- chunks.push(prefix + escape(name) + `"\r\n\r\n${value.replace(/\r(?!\n)|(?<!\r)\n/g, '\r\n')}\r\n`) - chunks.push(prefix + escape(name) + `"\r\n\r\n${value.replace(/\r(?!\n)|(?<!\r)\n/g, '\r\n')}\r\n`)
+ chunks.push(prefix + escape(name) + "\"\r\n\r\n" + value.replace(/\r(?!\n)|(?<!\r)\n/g, '\r\n') + "\r\n") + chunks.push(prefix + escape(name) + "\"\r\n\r\n".concat(value.replace(/\r(?!\n)|(?<!\r)\n/g, '\r\n'), "\r\n"));
} else { } else {
chunks.push( - chunks.push(
- prefix + escape(name) + `"; filename="${escape(value.name, 1)}"\r\n` + - prefix + escape(name) + `"; filename="${escape(value.name, 1)}"\r\n` +
- `Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`, - `Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`,
+ prefix + escape(name) + "\"; filename=\"" + escape(value.name, 1) + "\r\n" + - value,
+ "Content-Type: " + (value.type || 'application/octet-stream') + "\r\n\r\n", - '\r\n'
value, - )
'\r\n' + chunks.push(prefix + escape(name) + "\"; filename=\"".concat(escape(value.name, 1), "\"\r\n") + "Content-Type: ".concat(value.type || 'application/octet-stream', "\r\n\r\n"), value, '\r\n');
)
} }
} }
- chunks.push(`--${boundary}--`) - chunks.push(`--${boundary}--`)
+ chunks.push("--" + boundary + "--") + chunks.push("--".concat(boundary, "--"));
return new BlobClass(chunks, { return new BlobClass(chunks, {
type: 'multipart/form-data; boundary=' + boundary type: 'multipart/form-data; boundary=' + boundary

View file

@ -27,6 +27,8 @@ if (shouldBuildLegacy()) {
'IE >= 11' 'IE >= 11'
], ],
additionalLegacyPolyfills: [ additionalLegacyPolyfills: [
'dom4',
'core-js/stable',
'@stimulus/polyfills', '@stimulus/polyfills',
'@webcomponents/custom-elements', '@webcomponents/custom-elements',
'@webcomponents/template', '@webcomponents/template',

View file

@ -1401,6 +1401,11 @@ csstype@^3.0.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.10.tgz#2ad3a7bed70f35b965707c092e5f30b327c290e5" resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.10.tgz#2ad3a7bed70f35b965707c092e5f30b327c290e5"
integrity sha512-2u44ZG2OcNUO9HDp/Jl8C07x6pU/eTR3ncV91SiK3dhG9TWvRVsCoJw14Ckx5DgWkzGA3waZWO3d7pgqpUI/XA== integrity sha512-2u44ZG2OcNUO9HDp/Jl8C07x6pU/eTR3ncV91SiK3dhG9TWvRVsCoJw14Ckx5DgWkzGA3waZWO3d7pgqpUI/XA==
custom-event-polyfill@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/custom-event-polyfill/-/custom-event-polyfill-1.0.7.tgz#9bc993ddda937c1a30ccd335614c6c58c4f87aee"
integrity sha512-TDDkd5DkaZxZFM8p+1I3yAlvM3rSr1wbrOliG4yJiwinMZN8z/iGL7BTlDkrJcYTmgUSb4ywVCc3ZaUtOtC76w==
dashdash@^1.12.0: dashdash@^1.12.0:
version "1.14.1" version "1.14.1"
resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"