diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/js/clipboard.js --- a/wp/wp-includes/js/clipboard.js Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-includes/js/clipboard.js Tue Sep 27 16:37:53 2022 +0200 @@ -1,5 +1,5 @@ /*! - * clipboard.js v2.0.8 + * clipboard.js v2.0.10 * https://clipboardjs.com/ * * Licensed MIT © Zeno Rocha @@ -17,7 +17,7 @@ return /******/ (function() { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 134: +/***/ 686: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -36,265 +36,156 @@ // EXTERNAL MODULE: ./node_modules/select/src/select.js var src_select = __webpack_require__(817); var select_default = /*#__PURE__*/__webpack_require__.n(src_select); -;// CONCATENATED MODULE: ./src/clipboard-action.js +;// CONCATENATED MODULE: ./src/common/command.js +/** + * Executes a given operation type. + * @param {String} type + * @return {Boolean} + */ +function command(type) { + try { + return document.execCommand(type); + } catch (err) { + return false; + } +} +;// CONCATENATED MODULE: ./src/actions/cut.js + + +/** + * Cut action wrapper. + * @param {String|HTMLElement} target + * @return {String} + */ + +var ClipboardActionCut = function ClipboardActionCut(target) { + var selectedText = select_default()(target); + command('cut'); + return selectedText; +}; + +/* harmony default export */ var actions_cut = (ClipboardActionCut); +;// CONCATENATED MODULE: ./src/common/create-fake-element.js +/** + * Creates a fake textarea element with a value. + * @param {String} value + * @return {HTMLElement} + */ +function createFakeElement(value) { + var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; + var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS + + fakeElement.style.fontSize = '12pt'; // Reset box model + + fakeElement.style.border = '0'; + fakeElement.style.padding = '0'; + fakeElement.style.margin = '0'; // Move element out of screen horizontally + + fakeElement.style.position = 'absolute'; + fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically + + var yPosition = window.pageYOffset || document.documentElement.scrollTop; + fakeElement.style.top = "".concat(yPosition, "px"); + fakeElement.setAttribute('readonly', ''); + fakeElement.value = value; + return fakeElement; +} +;// CONCATENATED MODULE: ./src/actions/copy.js + + + +/** + * Copy action wrapper. + * @param {String|HTMLElement} target + * @param {Object} options + * @return {String} + */ + +var ClipboardActionCopy = function ClipboardActionCopy(target) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + container: document.body + }; + var selectedText = ''; + + if (typeof target === 'string') { + var fakeElement = createFakeElement(target); + options.container.appendChild(fakeElement); + selectedText = select_default()(fakeElement); + command('copy'); + fakeElement.remove(); + } else { + selectedText = select_default()(target); + command('copy'); + } + + return selectedText; +}; + +/* harmony default export */ var actions_copy = (ClipboardActionCopy); +;// CONCATENATED MODULE: ./src/actions/default.js function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + + +/** + * Inner function which performs selection from either `text` or `target` + * properties and then executes copy or cut operations. + * @param {Object} options + */ + +var ClipboardActionDefault = function ClipboardActionDefault() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + // Defines base properties passed from constructor. + var _options$action = options.action, + action = _options$action === void 0 ? 'copy' : _options$action, + container = options.container, + target = options.target, + text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'. + + if (action !== 'copy' && action !== 'cut') { + throw new Error('Invalid "action" value, use either "copy" or "cut"'); + } // Sets the `target` property using an element that will be have its content copied. + + + if (target !== undefined) { + if (target && _typeof(target) === 'object' && target.nodeType === 1) { + if (action === 'copy' && target.hasAttribute('disabled')) { + throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); + } + + if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { + throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); + } + } else { + throw new Error('Invalid "target" value, use a valid Element'); + } + } // Define selection strategy based on `text` property. + + + if (text) { + return actions_copy(text, { + container: container + }); + } // Defines which selection strategy based on `target` property. + + + if (target) { + return action === 'cut' ? actions_cut(target) : actions_copy(target, { + container: container + }); + } +}; + +/* harmony default export */ var actions_default = (ClipboardActionDefault); +;// CONCATENATED MODULE: ./src/clipboard.js +function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -/** - * Inner class which performs selection from either `text` or `target` - * properties and then executes copy or cut operations. - */ - -var ClipboardAction = /*#__PURE__*/function () { - /** - * @param {Object} options - */ - function ClipboardAction(options) { - _classCallCheck(this, ClipboardAction); - - this.resolveOptions(options); - this.initSelection(); - } - /** - * Defines base properties passed from constructor. - * @param {Object} options - */ - - - _createClass(ClipboardAction, [{ - key: "resolveOptions", - value: function resolveOptions() { - var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - this.action = options.action; - this.container = options.container; - this.emitter = options.emitter; - this.target = options.target; - this.text = options.text; - this.trigger = options.trigger; - this.selectedText = ''; - } - /** - * Decides which selection strategy is going to be applied based - * on the existence of `text` and `target` properties. - */ - - }, { - key: "initSelection", - value: function initSelection() { - if (this.text) { - this.selectFake(); - } else if (this.target) { - this.selectTarget(); - } - } - /** - * Creates a fake textarea element, sets its value from `text` property, - */ - - }, { - key: "createFakeElement", - value: function createFakeElement() { - var isRTL = document.documentElement.getAttribute('dir') === 'rtl'; - this.fakeElem = document.createElement('textarea'); // Prevent zooming on iOS - - this.fakeElem.style.fontSize = '12pt'; // Reset box model - - this.fakeElem.style.border = '0'; - this.fakeElem.style.padding = '0'; - this.fakeElem.style.margin = '0'; // Move element out of screen horizontally - - this.fakeElem.style.position = 'absolute'; - this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically - - var yPosition = window.pageYOffset || document.documentElement.scrollTop; - this.fakeElem.style.top = "".concat(yPosition, "px"); - this.fakeElem.setAttribute('readonly', ''); - this.fakeElem.value = this.text; - return this.fakeElem; - } - /** - * Get's the value of fakeElem, - * and makes a selection on it. - */ - - }, { - key: "selectFake", - value: function selectFake() { - var _this = this; - - var fakeElem = this.createFakeElement(); - - this.fakeHandlerCallback = function () { - return _this.removeFake(); - }; - - this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true; - this.container.appendChild(fakeElem); - this.selectedText = select_default()(fakeElem); - this.copyText(); - this.removeFake(); - } - /** - * Only removes the fake element after another click event, that way - * a user can hit `Ctrl+C` to copy because selection still exists. - */ - - }, { - key: "removeFake", - value: function removeFake() { - if (this.fakeHandler) { - this.container.removeEventListener('click', this.fakeHandlerCallback); - this.fakeHandler = null; - this.fakeHandlerCallback = null; - } - - if (this.fakeElem) { - this.container.removeChild(this.fakeElem); - this.fakeElem = null; - } - } - /** - * Selects the content from element passed on `target` property. - */ - - }, { - key: "selectTarget", - value: function selectTarget() { - this.selectedText = select_default()(this.target); - this.copyText(); - } - /** - * Executes the copy operation based on the current selection. - */ - - }, { - key: "copyText", - value: function copyText() { - var succeeded; - - try { - succeeded = document.execCommand(this.action); - } catch (err) { - succeeded = false; - } - - this.handleResult(succeeded); - } - /** - * Fires an event based on the copy operation result. - * @param {Boolean} succeeded - */ - - }, { - key: "handleResult", - value: function handleResult(succeeded) { - this.emitter.emit(succeeded ? 'success' : 'error', { - action: this.action, - text: this.selectedText, - trigger: this.trigger, - clearSelection: this.clearSelection.bind(this) - }); - } - /** - * Moves focus away from `target` and back to the trigger, removes current selection. - */ - - }, { - key: "clearSelection", - value: function clearSelection() { - if (this.trigger) { - this.trigger.focus(); - } - - document.activeElement.blur(); - window.getSelection().removeAllRanges(); - } - /** - * Sets the `action` to be performed which can be either 'copy' or 'cut'. - * @param {String} action - */ - - }, { - key: "destroy", - - /** - * Destroy lifecycle. - */ - value: function destroy() { - this.removeFake(); - } - }, { - key: "action", - set: function set() { - var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy'; - this._action = action; - - if (this._action !== 'copy' && this._action !== 'cut') { - throw new Error('Invalid "action" value, use either "copy" or "cut"'); - } - } - /** - * Gets the `action` property. - * @return {String} - */ - , - get: function get() { - return this._action; - } - /** - * Sets the `target` property using an element - * that will be have its content copied. - * @param {Element} target - */ - - }, { - key: "target", - set: function set(target) { - if (target !== undefined) { - if (target && _typeof(target) === 'object' && target.nodeType === 1) { - if (this.action === 'copy' && target.hasAttribute('disabled')) { - throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute'); - } - - if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) { - throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes'); - } - - this._target = target; - } else { - throw new Error('Invalid "target" value, use a valid Element'); - } - } - } - /** - * Gets the `target` property. - * @return {String|HTMLElement} - */ - , - get: function get() { - return this._target; - } - }]); - - return ClipboardAction; -}(); - -/* harmony default export */ var clipboard_action = (ClipboardAction); -;// CONCATENATED MODULE: ./src/clipboard.js -function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); } - -function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function clipboard_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) clipboard_defineProperties(Constructor, staticProps); return Constructor; } - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } @@ -312,6 +203,8 @@ + + /** * Helper function to retrieve attribute value. * @param {String} suffix @@ -345,7 +238,7 @@ function Clipboard(trigger, options) { var _this; - clipboard_classCallCheck(this, Clipboard); + _classCallCheck(this, Clipboard); _this = _super.call(this); @@ -362,7 +255,7 @@ */ - clipboard_createClass(Clipboard, [{ + _createClass(Clipboard, [{ key: "resolveOptions", value: function resolveOptions() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; @@ -394,18 +287,26 @@ key: "onClick", value: function onClick(e) { var trigger = e.delegateTarget || e.currentTarget; - - if (this.clipboardAction) { - this.clipboardAction = null; - } + var action = this.action(trigger) || 'copy'; + var text = actions_default({ + action: action, + container: this.container, + target: this.target(trigger), + text: this.text(trigger) + }); // Fires an event based on the copy operation result. - this.clipboardAction = new clipboard_action({ - action: this.action(trigger), - target: this.target(trigger), - text: this.text(trigger), - container: this.container, + this.emit(text ? 'success' : 'error', { + action: action, + text: text, trigger: trigger, - emitter: this + clearSelection: function clearSelection() { + if (trigger) { + trigger.focus(); + } + + document.activeElement.blur(); + window.getSelection().removeAllRanges(); + } }); } /** @@ -433,9 +334,10 @@ } } /** - * Returns the support of the given action, or all actions if no action is - * given. - * @param {String} [action] + * Allow fire programmatically a copy action + * @param {String|HTMLElement} target + * @param {Object} options + * @returns Text copied. */ }, { @@ -456,13 +358,33 @@ key: "destroy", value: function destroy() { this.listener.destroy(); - - if (this.clipboardAction) { - this.clipboardAction.destroy(); - this.clipboardAction = null; - } } }], [{ + key: "copy", + value: function copy(target) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { + container: document.body + }; + return actions_copy(target, options); + } + /** + * Allow fire programmatically a cut action + * @param {String|HTMLElement} target + * @returns Text cutted. + */ + + }, { + key: "cut", + value: function cut(target) { + return actions_cut(target); + } + /** + * Returns the support of the given action, or all actions if no action is + * given. + * @param {String} [action] + */ + + }, { key: "isSupported", value: function isSupported() { var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut']; @@ -948,7 +870,7 @@ /******/ // module exports must be returned from runtime so entry inlining is disabled /******/ // startup /******/ // Load entry module and return exports -/******/ return __webpack_require__(134); +/******/ return __webpack_require__(686); /******/ })() .default; }); \ No newline at end of file