diff --git a/extension.json b/extension.json index e7eb70e02..3947fa9e8 100644 --- a/extension.json +++ b/extension.json @@ -152,6 +152,15 @@ "resources/ext.popups/index.js" ] }, + "ext.popups.referencePreviews": { + "styles": [ + "resources/ext.popups.referencePreviews/referencePreview.less" + ], + "scripts": [ + "resources/dist/referencePreviews.js", + "resources/ext.popups.referencePreviews/index.js" + ] + }, "ext.popups.main": { "scripts": [ "resources/dist/index.js" diff --git a/includes/PopupsHooks.php b/includes/PopupsHooks.php index 0876abc31..59c6a42de 100644 --- a/includes/PopupsHooks.php +++ b/includes/PopupsHooks.php @@ -67,9 +67,11 @@ class PopupsHooks implements * @return array */ public static function getCustomPopupTypes(): array { - return ExtensionRegistry::getInstance()->getAttribute( + return array_merge( ExtensionRegistry::getInstance()->getAttribute( 'PopupsPluginModules' - ); + ), [ + 'ext.popups.referencePreviews' + ] ); } /** diff --git a/package.json b/package.json index dc81fb8fc..cfbe9c988 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,11 @@ "bundlesize": [ { "path": "resources/dist/index.js", - "maxSize": "15.1kB" + "maxSize": "13.5kB" + }, + { + "path": "resources/dist/referencePreviews.js", + "maxSize": "2.7kB" } ] } diff --git a/resources/dist/index.js b/resources/dist/index.js index 72f74773f..23925fd15 100644 Binary files a/resources/dist/index.js and b/resources/dist/index.js differ diff --git a/resources/dist/index.js.map.json b/resources/dist/index.js.map.json index a3e1b1f2b..6fe62011b 100644 Binary files a/resources/dist/index.js.map.json and b/resources/dist/index.js.map.json differ diff --git a/resources/dist/referencePreviews.js b/resources/dist/referencePreviews.js new file mode 100644 index 000000000..b64b5f1af Binary files /dev/null and b/resources/dist/referencePreviews.js differ diff --git a/resources/dist/referencePreviews.js.map.json b/resources/dist/referencePreviews.js.map.json new file mode 100644 index 000000000..2adfe35e5 Binary files /dev/null and b/resources/dist/referencePreviews.js.map.json differ diff --git a/resources/ext.popups.referencePreviews/index.js b/resources/ext.popups.referencePreviews/index.js new file mode 100644 index 000000000..0071f360f --- /dev/null +++ b/resources/ext.popups.referencePreviews/index.js @@ -0,0 +1 @@ +module.exports = window.refPreviews; diff --git a/src/ui/templates/referencePreview/referencePreview.less b/resources/ext.popups.referencePreviews/referencePreview.less similarity index 57% rename from src/ui/templates/referencePreview/referencePreview.less rename to resources/ext.popups.referencePreviews/referencePreview.less index bd5e1dd43..bc81b0b84 100644 --- a/src/ui/templates/referencePreview/referencePreview.less +++ b/resources/ext.popups.referencePreviews/referencePreview.less @@ -1,11 +1,36 @@ @import 'mediawiki.skin.variables.less'; +@import '../../src/ui/variables.less'; -// Don't do any event bubbling on childs like [2], see T214693 +.popups-icon--reference-generic { + .cdx-mixin-css-icon( @cdx-icon-reference ); +} + +.popups-icon--reference-book { + .cdx-mixin-css-icon( @cdx-icon-book ); +} + +.popups-icon--reference-journal { + .cdx-mixin-css-icon( @cdx-icon-journal ); +} + +.popups-icon--reference-news { + .cdx-mixin-css-icon( @cdx-icon-newspaper ); +} + +.popups-icon--reference-web { + .cdx-mixin-css-icon( @cdx-icon-browser ); +} + +.popups-icon--preview-disambiguation { + .cdx-mixin-css-icon( @cdx-icon-articles ); +} + +// Don't do any event bubbling on childs like [2] +// see https://phabricator.wikimedia.org/T214693 #mw-content-text .reference a[ href*='#' ] * { pointer-events: none; } - -.mwe-popups.mwe-popups-type-reference { +.mwe-popups.mwe-popups-type-reference .mwe-popups-container { .mwe-popups-title .popups-icon--reference-note { // There is currently no "reference-note" icon specified in extension.json display: none; @@ -14,13 +39,12 @@ .mwe-popups-extract { margin-right: 0; max-height: inherit; - .mwe-popups-scroll { - // This is how the `margin-bottom: 47px` in popup.less is calculated - @marginBottom: 2 * @lineHeight + 7px; - // Same as the --pointer-height in popup.less + // This is how the @previewFooterHeight in popup.less is calculated + @marginBottom: @popupPadding + 34px; + // Same as @previewPointerHeight in popup.less @pointerHeight: 8px; - max-height: 403px - @popupPadding - @marginBottom + @pointerHeight; + max-height: 401px - @popupPadding - @marginBottom + @pointerHeight; overflow: auto; padding-right: @popupPadding; } @@ -49,7 +73,6 @@ opacity: 1; } } - .mwe-collapsible-placeholder { font-weight: bold; margin: 1em 0; diff --git a/src/OWNERS.md b/src/OWNERS.md new file mode 100644 index 000000000..7c5f6cffa --- /dev/null +++ b/src/OWNERS.md @@ -0,0 +1 @@ +Code in this folder and subfolders is maintained by the Web Team unless stated. diff --git a/src/constants.js b/src/constants.js index 8f8cc2edb..919a33458 100644 --- a/src/constants.js +++ b/src/constants.js @@ -20,11 +20,6 @@ export const FETCH_COMPLETE_TARGET_DELAY = 350 + FETCH_START_DELAY; // ms. export const PREVIEW_SEEN_DURATION = 1000; // ms export const ABANDON_END_DELAY = 300; -// -// Reference previews specific config -// -export const FETCH_DELAY_REFERENCE_TYPE = 150; // ms. - export default { BRACKETED_DEVICE_PIXEL_RATIO: bpr, // See https://phabricator.wikimedia.org/T272169: requesting a larger thumbnail to avoid bluriness diff --git a/src/ext.popups.referencePreviews/OWNERS.md b/src/ext.popups.referencePreviews/OWNERS.md new file mode 100644 index 000000000..ebf9c0bb0 --- /dev/null +++ b/src/ext.popups.referencePreviews/OWNERS.md @@ -0,0 +1 @@ +Code in this folder and subfolders is maintained by WMDE. diff --git a/src/ext.popups.referencePreviews/constants.js b/src/ext.popups.referencePreviews/constants.js new file mode 100644 index 000000000..03b0e44de --- /dev/null +++ b/src/ext.popups.referencePreviews/constants.js @@ -0,0 +1,2 @@ +export const TYPE_REFERENCE = 'reference'; +export const FETCH_DELAY_REFERENCE_TYPE = 150; // ms. diff --git a/src/gateway/reference.js b/src/ext.popups.referencePreviews/createReferenceGateway.js similarity index 95% rename from src/gateway/reference.js rename to src/ext.popups.referencePreviews/createReferenceGateway.js index 5fba69a79..856131f16 100644 --- a/src/gateway/reference.js +++ b/src/ext.popups.referencePreviews/createReferenceGateway.js @@ -2,8 +2,8 @@ * @module gateway/reference */ -import { previewTypes } from '../preview/model'; -import { abortablePromise } from './index.js'; +import { TYPE_REFERENCE } from './constants.js'; +import { abortablePromise } from '../gateway/index.js'; /** * @return {Gateway} @@ -77,7 +77,7 @@ export default function createReferenceGateway() { const model = { url: `#${ id }`, extract: referenceNode.innerHTML, - type: previewTypes.TYPE_REFERENCE, + type: TYPE_REFERENCE, referenceType: scrapeReferenceType( referenceNode ), // Note: Even the top-most HTMLHtmlElement is guaranteed to have a parent. sourceElementId: el.parentNode.id diff --git a/src/ui/templates/referencePreview/referencePreview.js b/src/ext.popups.referencePreviews/createReferencePreview.js similarity index 92% rename from src/ui/templates/referencePreview/referencePreview.js rename to src/ext.popups.referencePreviews/createReferencePreview.js index 15af80eef..620f894d5 100644 --- a/src/ui/templates/referencePreview/referencePreview.js +++ b/src/ext.popups.referencePreviews/createReferencePreview.js @@ -1,9 +1,9 @@ /** * @module referencePreview */ -import { isTrackingEnabled, LOGGING_SCHEMA } from '../../../instrumentation/referencePreviews'; -import { renderPopup } from '../popup/popup'; -import { createNodeFromTemplate, escapeHTML } from '../templateUtil'; +import { isTrackingEnabled, LOGGING_SCHEMA } from './referencePreviews'; +import { renderPopup } from '../ui/templates/popup/popup'; +import { createNodeFromTemplate, escapeHTML } from '../ui/templates/templateUtil'; const templateHTML = `