diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:56:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:56:49 +0000 |
commit | a415c29efee45520ae252d2aa28f1083a521cd7b (patch) | |
tree | f4ade4b6668ecc0765de7e1424f7c1427ad433ff /wp-includes/blocks/file | |
parent | Initial commit. (diff) | |
download | wordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.tar.xz wordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.zip |
Adding upstream version 6.4.3+dfsg1.upstream/6.4.3+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | wp-includes/blocks/file.php | 100 | ||||
-rw-r--r-- | wp-includes/blocks/file/block.json | 78 | ||||
-rw-r--r-- | wp-includes/blocks/file/editor-rtl.css | 38 | ||||
-rw-r--r-- | wp-includes/blocks/file/editor-rtl.min.css | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/editor.css | 38 | ||||
-rw-r--r-- | wp-includes/blocks/file/editor.min.css | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/style-rtl.css | 35 | ||||
-rw-r--r-- | wp-includes/blocks/file/style-rtl.min.css | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/style.css | 35 | ||||
-rw-r--r-- | wp-includes/blocks/file/style.min.css | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/view.asset.php | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/view.js | 82 | ||||
-rw-r--r-- | wp-includes/blocks/file/view.min.asset.php | 1 | ||||
-rw-r--r-- | wp-includes/blocks/file/view.min.js | 1 |
14 files changed, 413 insertions, 0 deletions
diff --git a/wp-includes/blocks/file.php b/wp-includes/blocks/file.php new file mode 100644 index 0000000..042ea89 --- /dev/null +++ b/wp-includes/blocks/file.php @@ -0,0 +1,100 @@ +<?php +/** + * Server-side rendering of the `core/file` block. + * + * @package WordPress + */ + +/** + * When the `core/file` block is rendering, check if we need to enqueue the `wp-block-file-view` script. + * + * @param array $attributes The block attributes. + * @param string $content The block content. + * @param WP_Block $block The parsed block. + * + * @return string Returns the block content. + */ +function render_block_core_file( $attributes, $content, $block ) { + $should_load_view_script = ! empty( $attributes['displayPreview'] ); + $view_js_file = 'wp-block-file-view'; + // If the script already exists, there is no point in removing it from viewScript. + if ( ! wp_script_is( $view_js_file ) ) { + $script_handles = $block->block_type->view_script_handles; + + // If the script is not needed, and it is still in the `view_script_handles`, remove it. + if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) { + $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) ); + } + // If the script is needed, but it was previously removed, add it again. + if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) { + $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) ); + } + } + + // Update object's aria-label attribute if present in block HTML. + + // Match an aria-label attribute from an object tag. + $pattern = '@<object.+(?<attribute>aria-label="(?<filename>[^"]+)?")@i'; + $content = preg_replace_callback( + $pattern, + static function ( $matches ) { + $filename = ! empty( $matches['filename'] ) ? $matches['filename'] : ''; + $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename; + $label = $has_filename ? + sprintf( + /* translators: %s: filename. */ + __( 'Embed of %s.' ), + $filename + ) + : __( 'PDF embed' ); + + return str_replace( $matches['attribute'], sprintf( 'aria-label="%s"', $label ), $matches[0] ); + }, + $content + ); + + // If it uses the Interactivity API, add the directives. + if ( $should_load_view_script ) { + $processor = new WP_HTML_Tag_Processor( $content ); + $processor->next_tag(); + $processor->set_attribute( 'data-wp-interactive', '' ); + $processor->next_tag( 'object' ); + $processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' ); + $processor->set_attribute( 'hidden', true ); + return $processor->get_updated_html(); + } + + return $content; +} + +/** + * Ensure that the view script has the `wp-interactivity` dependency. + * + * @since 6.4.0 + * + * @global WP_Scripts $wp_scripts + */ +function block_core_file_ensure_interactivity_dependency() { + global $wp_scripts; + if ( + isset( $wp_scripts->registered['wp-block-file-view'] ) && + ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-file-view']->deps, true ) + ) { + $wp_scripts->registered['wp-block-file-view']->deps[] = 'wp-interactivity'; + } +} + +add_action( 'wp_print_scripts', 'block_core_file_ensure_interactivity_dependency' ); + +/** + * Registers the `core/file` block on server. + */ +function register_block_core_file() { + register_block_type_from_metadata( + __DIR__ . '/file', + array( + 'render_callback' => 'render_block_core_file', + ) + ); +} +add_action( 'init', 'register_block_core_file' ); diff --git a/wp-includes/blocks/file/block.json b/wp-includes/blocks/file/block.json new file mode 100644 index 0000000..0cc20b3 --- /dev/null +++ b/wp-includes/blocks/file/block.json @@ -0,0 +1,78 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "core/file", + "title": "File", + "category": "media", + "description": "Add a link to a downloadable file.", + "keywords": [ "document", "pdf", "download" ], + "textdomain": "default", + "attributes": { + "id": { + "type": "number" + }, + "href": { + "type": "string" + }, + "fileId": { + "type": "string", + "source": "attribute", + "selector": "a:not([download])", + "attribute": "id" + }, + "fileName": { + "type": "string", + "source": "html", + "selector": "a:not([download])" + }, + "textLinkHref": { + "type": "string", + "source": "attribute", + "selector": "a:not([download])", + "attribute": "href" + }, + "textLinkTarget": { + "type": "string", + "source": "attribute", + "selector": "a:not([download])", + "attribute": "target" + }, + "showDownloadButton": { + "type": "boolean", + "default": true + }, + "downloadButtonText": { + "type": "string", + "source": "html", + "selector": "a[download]" + }, + "displayPreview": { + "type": "boolean" + }, + "previewHeight": { + "type": "number", + "default": 600 + } + }, + "supports": { + "anchor": true, + "align": true, + "spacing": { + "margin": true, + "padding": true + }, + "color": { + "gradients": true, + "link": true, + "text": false, + "__experimentalDefaultControls": { + "background": true, + "link": true + } + }, + "interactivity": true + }, + "viewScript": "file:./view.min.js", + "editorStyle": "wp-block-file-editor", + "style": "wp-block-file" +} diff --git a/wp-includes/blocks/file/editor-rtl.css b/wp-includes/blocks/file/editor-rtl.css new file mode 100644 index 0000000..a606f31 --- /dev/null +++ b/wp-includes/blocks/file/editor-rtl.css @@ -0,0 +1,38 @@ +.wp-block-file{ + align-items:center; + display:flex; + flex-wrap:wrap; + justify-content:space-between; + margin-bottom:0; +} +.wp-block[data-align=left]>.wp-block-file,.wp-block[data-align=right]>.wp-block-file{ + height:auto; +} +.wp-block-file .components-resizable-box__container{ + margin-bottom:1em; +} +.wp-block-file .wp-block-file__preview{ + height:100%; + margin-bottom:1em; + width:100%; +} +.wp-block-file .wp-block-file__preview-overlay{ + bottom:0; + left:0; + position:absolute; + right:0; + top:0; +} +.wp-block-file .wp-block-file__content-wrapper{ + flex-grow:1; +} +.wp-block-file a{ + min-width:1em; +} +.wp-block-file a:not(.wp-block-file__button){ + display:inline-block; +} +.wp-block-file .wp-block-file__button-richtext-wrapper{ + display:inline-block; + margin-right:.75em; +}
\ No newline at end of file diff --git a/wp-includes/blocks/file/editor-rtl.min.css b/wp-includes/blocks/file/editor-rtl.min.css new file mode 100644 index 0000000..cd00681 --- /dev/null +++ b/wp-includes/blocks/file/editor-rtl.min.css @@ -0,0 +1 @@ +.wp-block-file{align-items:center;display:flex;flex-wrap:wrap;justify-content:space-between;margin-bottom:0}.wp-block[data-align=left]>.wp-block-file,.wp-block[data-align=right]>.wp-block-file{height:auto}.wp-block-file .components-resizable-box__container{margin-bottom:1em}.wp-block-file .wp-block-file__preview{height:100%;margin-bottom:1em;width:100%}.wp-block-file .wp-block-file__preview-overlay{bottom:0;left:0;position:absolute;right:0;top:0}.wp-block-file .wp-block-file__content-wrapper{flex-grow:1}.wp-block-file a{min-width:1em}.wp-block-file a:not(.wp-block-file__button){display:inline-block}.wp-block-file .wp-block-file__button-richtext-wrapper{display:inline-block;margin-right:.75em}
\ No newline at end of file diff --git a/wp-includes/blocks/file/editor.css b/wp-includes/blocks/file/editor.css new file mode 100644 index 0000000..94638c0 --- /dev/null +++ b/wp-includes/blocks/file/editor.css @@ -0,0 +1,38 @@ +.wp-block-file{ + align-items:center; + display:flex; + flex-wrap:wrap; + justify-content:space-between; + margin-bottom:0; +} +.wp-block[data-align=left]>.wp-block-file,.wp-block[data-align=right]>.wp-block-file{ + height:auto; +} +.wp-block-file .components-resizable-box__container{ + margin-bottom:1em; +} +.wp-block-file .wp-block-file__preview{ + height:100%; + margin-bottom:1em; + width:100%; +} +.wp-block-file .wp-block-file__preview-overlay{ + bottom:0; + left:0; + position:absolute; + right:0; + top:0; +} +.wp-block-file .wp-block-file__content-wrapper{ + flex-grow:1; +} +.wp-block-file a{ + min-width:1em; +} +.wp-block-file a:not(.wp-block-file__button){ + display:inline-block; +} +.wp-block-file .wp-block-file__button-richtext-wrapper{ + display:inline-block; + margin-left:.75em; +}
\ No newline at end of file diff --git a/wp-includes/blocks/file/editor.min.css b/wp-includes/blocks/file/editor.min.css new file mode 100644 index 0000000..df5ac14 --- /dev/null +++ b/wp-includes/blocks/file/editor.min.css @@ -0,0 +1 @@ +.wp-block-file{align-items:center;display:flex;flex-wrap:wrap;justify-content:space-between;margin-bottom:0}.wp-block[data-align=left]>.wp-block-file,.wp-block[data-align=right]>.wp-block-file{height:auto}.wp-block-file .components-resizable-box__container{margin-bottom:1em}.wp-block-file .wp-block-file__preview{height:100%;margin-bottom:1em;width:100%}.wp-block-file .wp-block-file__preview-overlay{bottom:0;left:0;position:absolute;right:0;top:0}.wp-block-file .wp-block-file__content-wrapper{flex-grow:1}.wp-block-file a{min-width:1em}.wp-block-file a:not(.wp-block-file__button){display:inline-block}.wp-block-file .wp-block-file__button-richtext-wrapper{display:inline-block;margin-left:.75em}
\ No newline at end of file diff --git a/wp-includes/blocks/file/style-rtl.css b/wp-includes/blocks/file/style-rtl.css new file mode 100644 index 0000000..6b23129 --- /dev/null +++ b/wp-includes/blocks/file/style-rtl.css @@ -0,0 +1,35 @@ +.wp-block-file{ + box-sizing:border-box; +} +.wp-block-file:not(.wp-element-button){ + font-size:.8em; +} +.wp-block-file.aligncenter{ + text-align:center; +} +.wp-block-file.alignright{ + text-align:right; +} +.wp-block-file *+.wp-block-file__button{ + margin-right:.75em; +} + +:where(.wp-block-file){ + margin-bottom:1.5em; +} + +.wp-block-file__embed{ + margin-bottom:1em; +} + +:where(.wp-block-file__button){ + border-radius:2em; + display:inline-block; + padding:.5em 1em; +} +:where(.wp-block-file__button):is(a):active,:where(.wp-block-file__button):is(a):focus,:where(.wp-block-file__button):is(a):hover,:where(.wp-block-file__button):is(a):visited{ + box-shadow:none; + color:#fff; + opacity:.85; + text-decoration:none; +}
\ No newline at end of file diff --git a/wp-includes/blocks/file/style-rtl.min.css b/wp-includes/blocks/file/style-rtl.min.css new file mode 100644 index 0000000..c2b5651 --- /dev/null +++ b/wp-includes/blocks/file/style-rtl.min.css @@ -0,0 +1 @@ +.wp-block-file{box-sizing:border-box}.wp-block-file:not(.wp-element-button){font-size:.8em}.wp-block-file.aligncenter{text-align:center}.wp-block-file.alignright{text-align:right}.wp-block-file *+.wp-block-file__button{margin-right:.75em}:where(.wp-block-file){margin-bottom:1.5em}.wp-block-file__embed{margin-bottom:1em}:where(.wp-block-file__button){border-radius:2em;display:inline-block;padding:.5em 1em}:where(.wp-block-file__button):is(a):active,:where(.wp-block-file__button):is(a):focus,:where(.wp-block-file__button):is(a):hover,:where(.wp-block-file__button):is(a):visited{box-shadow:none;color:#fff;opacity:.85;text-decoration:none}
\ No newline at end of file diff --git a/wp-includes/blocks/file/style.css b/wp-includes/blocks/file/style.css new file mode 100644 index 0000000..2a00211 --- /dev/null +++ b/wp-includes/blocks/file/style.css @@ -0,0 +1,35 @@ +.wp-block-file{ + box-sizing:border-box; +} +.wp-block-file:not(.wp-element-button){ + font-size:.8em; +} +.wp-block-file.aligncenter{ + text-align:center; +} +.wp-block-file.alignright{ + text-align:right; +} +.wp-block-file *+.wp-block-file__button{ + margin-left:.75em; +} + +:where(.wp-block-file){ + margin-bottom:1.5em; +} + +.wp-block-file__embed{ + margin-bottom:1em; +} + +:where(.wp-block-file__button){ + border-radius:2em; + display:inline-block; + padding:.5em 1em; +} +:where(.wp-block-file__button):is(a):active,:where(.wp-block-file__button):is(a):focus,:where(.wp-block-file__button):is(a):hover,:where(.wp-block-file__button):is(a):visited{ + box-shadow:none; + color:#fff; + opacity:.85; + text-decoration:none; +}
\ No newline at end of file diff --git a/wp-includes/blocks/file/style.min.css b/wp-includes/blocks/file/style.min.css new file mode 100644 index 0000000..aa2fe3d --- /dev/null +++ b/wp-includes/blocks/file/style.min.css @@ -0,0 +1 @@ +.wp-block-file{box-sizing:border-box}.wp-block-file:not(.wp-element-button){font-size:.8em}.wp-block-file.aligncenter{text-align:center}.wp-block-file.alignright{text-align:right}.wp-block-file *+.wp-block-file__button{margin-left:.75em}:where(.wp-block-file){margin-bottom:1.5em}.wp-block-file__embed{margin-bottom:1em}:where(.wp-block-file__button){border-radius:2em;display:inline-block;padding:.5em 1em}:where(.wp-block-file__button):is(a):active,:where(.wp-block-file__button):is(a):focus,:where(.wp-block-file__button):is(a):hover,:where(.wp-block-file__button):is(a):visited{box-shadow:none;color:#fff;opacity:.85;text-decoration:none}
\ No newline at end of file diff --git a/wp-includes/blocks/file/view.asset.php b/wp-includes/blocks/file/view.asset.php new file mode 100644 index 0000000..a9c9136 --- /dev/null +++ b/wp-includes/blocks/file/view.asset.php @@ -0,0 +1 @@ +<?php return array('dependencies' => array(), 'version' => '3fd0154de23a0ecc28af'); diff --git a/wp-includes/blocks/file/view.js b/wp-includes/blocks/file/view.js new file mode 100644 index 0000000..9d66df5 --- /dev/null +++ b/wp-includes/blocks/file/view.js @@ -0,0 +1,82 @@ +"use strict"; +(self["__WordPressPrivateInteractivityAPI__"] = self["__WordPressPrivateInteractivityAPI__"] || []).push([[81],{ + +/***/ 149: +/***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { + + +// EXTERNAL MODULE: ./node_modules/@wordpress/interactivity/src/index.js + 15 modules +var src = __webpack_require__(754); +;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/file/utils/index.js +/** + * Uses a combination of user agent matching and feature detection to determine whether + * the current browser supports rendering PDFs inline. + * + * @return {boolean} Whether or not the browser supports inline PDFs. + */ +const browserSupportsPdfs = () => { + // Most mobile devices include "Mobi" in their UA. + if (window.navigator.userAgent.indexOf('Mobi') > -1) { + return false; + } + + // Android tablets are the noteable exception. + if (window.navigator.userAgent.indexOf('Android') > -1) { + return false; + } + + // iPad pretends to be a Mac. + if (window.navigator.userAgent.indexOf('Macintosh') > -1 && window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 2) { + return false; + } + + // IE only supports PDFs when there's an ActiveX object available for it. + if (!!(window.ActiveXObject || 'ActiveXObject' in window) && !(createActiveXObject('AcroPDF.PDF') || createActiveXObject('PDF.PdfCtrl'))) { + return false; + } + return true; +}; + +/** + * Helper function for creating ActiveX objects, catching any errors that are thrown + * when it's generated. + * + * @param {string} type The name of the ActiveX object to create. + * @return {window.ActiveXObject|undefined} The generated ActiveXObject, or null if it failed. + */ +const createActiveXObject = type => { + let ax; + try { + ax = new window.ActiveXObject(type); + } catch (e) { + ax = undefined; + } + return ax; +}; +;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/file/view.js +/** + * WordPress dependencies + */ + +/** + * Internal dependencies + */ + +(0,src/* store */.h)({ + selectors: { + core: { + file: { + hasPdfPreview: browserSupportsPdfs + } + } + } +}); + +/***/ }) + +}, +/******/ function(__webpack_require__) { // webpackRuntimeModules +/******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } +/******/ var __webpack_exports__ = (__webpack_exec__(149)); +/******/ } +]);
\ No newline at end of file diff --git a/wp-includes/blocks/file/view.min.asset.php b/wp-includes/blocks/file/view.min.asset.php new file mode 100644 index 0000000..990e381 --- /dev/null +++ b/wp-includes/blocks/file/view.min.asset.php @@ -0,0 +1 @@ +<?php return array('dependencies' => array(), 'version' => '8a0237493a27c0d781aa'); diff --git a/wp-includes/blocks/file/view.min.js b/wp-includes/blocks/file/view.min.js new file mode 100644 index 0000000..8015cb7 --- /dev/null +++ b/wp-includes/blocks/file/view.min.js @@ -0,0 +1 @@ +"use strict";(self.__WordPressPrivateInteractivityAPI__=self.__WordPressPrivateInteractivityAPI__||[]).push([[81],{149:function(i,t,e){var n=e(754);const o=i=>{let t;try{t=new window.ActiveXObject(i)}catch(i){t=void 0}return t};(0,n.h)({selectors:{core:{file:{hasPdfPreview:()=>!(window.navigator.userAgent.indexOf("Mobi")>-1)&&(!(window.navigator.userAgent.indexOf("Android")>-1)&&(!(window.navigator.userAgent.indexOf("Macintosh")>-1&&window.navigator.maxTouchPoints&&window.navigator.maxTouchPoints>2)&&!((window.ActiveXObject||"ActiveXObject"in window)&&!o("AcroPDF.PDF")&&!o("PDF.PdfCtrl"))))}}}})}},function(i){var t;t=149,i(i.s=t)}]);
\ No newline at end of file |