External Libraries: Update polyfill libraries.

This updates two polyfill libraries to their latest versions.

- `polyfill-library` from `3.105.0` to `4.0.0`.
- `formdata-polyfill` from `4.0.0` to `4.0.10`.

This will affect the following script handles:
- `wp-polyfill-formdata`
- `wp-polyfill-node-contains`
- `wp-polyfill-dom-rect`

These polyfills are no longer used by WordPress Core, but are kept up to date as a courtesy for any plugins or themes still requiring them.

See #55547.
Built from https://develop.svn.wordpress.org/trunk@53165


git-svn-id: http://core.svn.wordpress.org/trunk@52754 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2022-04-12 17:35:27 +00:00
parent 35005412d0
commit 43ca7ac938
5 changed files with 57 additions and 71 deletions

View File

@ -1,3 +1,5 @@
/* formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
/* global FormData self Blob File */ /* global FormData self Blob File */
/* eslint-disable no-inner-declarations */ /* eslint-disable no-inner-declarations */
@ -40,16 +42,13 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
new File([], '') // eslint-disable-line new File([], '') // eslint-disable-line
} catch (a) { } catch (a) {
global.File = function File (b, d, c) { global.File = function File (b, d, c) {
const blob = new Blob(b, c) const blob = new Blob(b, c || {})
const t = c && void 0 !== c.lastModified ? new Date(c.lastModified) : new Date() const t = c && void 0 !== c.lastModified ? new Date(c.lastModified) : new Date()
Object.defineProperties(blob, { Object.defineProperties(blob, {
name: { name: {
value: d value: d
}, },
lastModifiedDate: {
value: t
},
lastModified: { lastModified: {
value: +t value: +t
}, },
@ -70,50 +69,52 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
} }
} }
function normalizeValue ([name, value, filename]) {
if (value instanceof Blob) {
// Should always returns a new File instance
// console.assert(fd.get(x) !== fd.get(x))
value = new File([value], filename, {
type: value.type,
lastModified: value.lastModified
})
}
return [name, value]
}
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.`)
} }
} }
/**
* @param {string} name
* @param {string | undefined} filename
* @returns {[string, File|string]}
*/
function normalizeArgs (name, value, filename) { function normalizeArgs (name, value, filename) {
return value instanceof Blob if (value instanceof Blob) {
// normalize name and filename if adding an attachment filename = filename !== undefined
? [String(name), value, filename !== undefined ? String(filename + '')
? filename + '' // Cast filename to string if 3th arg isn't undefined : typeof value.name === 'string'
: typeof value.name === 'string' // if name prop exist ? value.name
? value.name // Use File.name : 'blob'
: 'blob'] // otherwise fallback to Blob
// If no attachment, just cast the args to strings if (value.name !== filename || Object.prototype.toString.call(value) === '[object Blob]') {
: [String(name), String(value)] value = new File([value], filename)
}
return [String(name), value]
}
return [String(name), String(value)]
} }
// normalize linefeeds for textareas // normalize line feeds for textarea
// https://html.spec.whatwg.org/multipage/form-elements.html#textarea-line-break-normalisation-transformation // https://html.spec.whatwg.org/multipage/form-elements.html#textarea-line-break-normalisation-transformation
function normalizeLinefeeds (value) { function normalizeLinefeeds (value) {
return value.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n') return value.replace(/\r?\n|\r/g, '\r\n')
} }
/**
* @template T
* @param {ArrayLike<T>} arr
* @param {{ (elm: T): void; }} cb
*/
function each (arr, cb) { function each (arr, cb) {
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
cb(arr[i]) cb(arr[i])
} }
} }
const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
/** /**
* @implements {Iterable} * @implements {Iterable}
*/ */
@ -121,14 +122,14 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
/** /**
* FormData class * FormData class
* *
* @param {HTMLElement=} form * @param {HTMLFormElement=} form
*/ */
constructor (form) { constructor (form) {
/** @type {[string, string|File][]} */
this._data = [] this._data = []
const self = this const self = this
form && each(form.elements, (/** @type {HTMLInputElement} */ elm) => {
form && each(form.elements, elm => {
if ( if (
!elm.name || !elm.name ||
elm.disabled || elm.disabled ||
@ -196,7 +197,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
*/ */
* entries () { * entries () {
for (var i = 0; i < this._data.length; i++) { for (var i = 0; i < this._data.length; i++) {
yield normalizeValue(this._data[i]) yield this._data[i]
} }
} }
@ -205,7 +206,6 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
* *
* @param {Function} callback Executed for each item with parameters (value, name, thisArg) * @param {Function} callback Executed for each item with parameters (value, name, thisArg)
* @param {Object=} thisArg `this` context for callback function * @param {Object=} thisArg `this` context for callback function
* @return {undefined}
*/ */
forEach (callback, thisArg) { forEach (callback, thisArg) {
ensureArgs(arguments, 1) ensureArgs(arguments, 1)
@ -216,7 +216,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
/** /**
* Return first field value given name * Return first field value given name
* or null if non existen * or null if non existent
* *
* @param {string} name Field name * @param {string} name Field name
* @return {string|File|null} value Fields value * @return {string|File|null} value Fields value
@ -227,7 +227,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
name = String(name) name = String(name)
for (let i = 0; i < entries.length; i++) { for (let i = 0; i < entries.length; i++) {
if (entries[i][0] === name) { if (entries[i][0] === name) {
return normalizeValue(entries[i])[1] return entries[i][1]
} }
} }
return null return null
@ -244,7 +244,7 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
const result = [] const result = []
name = String(name) name = String(name)
each(this._data, data => { each(this._data, data => {
data[0] === name && result.push(normalizeValue(data)[1]) data[0] === name && result.push(data[1])
}) })
return result return result
@ -284,17 +284,17 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
* @param {string} name Filed name * @param {string} name Filed name
* @param {string} value Field value * @param {string} value Field value
* @param {string=} filename Filename (optional) * @param {string=} filename Filename (optional)
* @return {undefined}
*/ */
set (name, value, filename) { set (name, value, filename) {
ensureArgs(arguments, 2) ensureArgs(arguments, 2)
name = String(name) name = String(name)
/** @type {[string, string|File][]} */
const result = [] const result = []
const args = normalizeArgs(name, value, filename) const args = normalizeArgs(name, value, filename)
let replace = true let replace = true
// - replace the first occurrence with same name // - replace the first occurrence with same name
// - discards the remaning with same name // - discards the remaining with same name
// - while keeping the same order items where added // - while keeping the same order items where added
each(this._data, data => { each(this._data, data => {
data[0] === name data[0] === name
@ -340,30 +340,15 @@ if (typeof Blob !== 'undefined' && (typeof FormData === 'undefined' || !FormData
* @return {Blob} [description] * @return {Blob} [description]
*/ */
['_blob'] () { ['_blob'] () {
const boundary = '----formdata-polyfill-' + Math.random() const boundary = '----formdata-polyfill-' + Math.random(),
const chunks = [] chunks = [],
p = `--${boundary}\r\nContent-Disposition: form-data; name="`
for (const [name, value] of this) { this.forEach((value, name) => typeof value == 'string'
chunks.push(`--${boundary}\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`))
if (value instanceof Blob) {
chunks.push(
`Content-Disposition: form-data; name="${name}"; filename="${value.name}"\r\n` +
`Content-Type: ${value.type || 'application/octet-stream'}\r\n\r\n`,
value,
'\r\n'
)
} else {
chunks.push(
`Content-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`
)
}
}
chunks.push(`--${boundary}--`) chunks.push(`--${boundary}--`)
return new Blob(chunks, { return new Blob(chunks, {
type: 'multipart/form-data; boundary=' + boundary type: "multipart/form-data; boundary=" + boundary
}) })
} }

File diff suppressed because one or more lines are too long

View File

@ -109,10 +109,10 @@ function wp_default_packages_vendor( $scripts ) {
'moment' => '2.29.2', 'moment' => '2.29.2',
'lodash' => '4.17.19', 'lodash' => '4.17.19',
'wp-polyfill-fetch' => '3.6.2', 'wp-polyfill-fetch' => '3.6.2',
'wp-polyfill-formdata' => '4.0.0', 'wp-polyfill-formdata' => '4.0.10',
'wp-polyfill-node-contains' => '3.105.0', 'wp-polyfill-node-contains' => '4.0.0',
'wp-polyfill-url' => '3.6.4', 'wp-polyfill-url' => '3.6.4',
'wp-polyfill-dom-rect' => '3.104.0', 'wp-polyfill-dom-rect' => '4.0.0',
'wp-polyfill-element-closest' => '2.0.2', 'wp-polyfill-element-closest' => '2.0.2',
'wp-polyfill-object-fit' => '2.3.5', 'wp-polyfill-object-fit' => '2.3.5',
'wp-polyfill' => '3.15.0', 'wp-polyfill' => '3.15.0',

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-alpha-53164'; $wp_version = '6.0-alpha-53165';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.