Simplify VE data modules using 'packageFiles'

We can now serve the JSON data almost directly (although, curiously,
we need a main file in the module that is JavaScript, not JSON),
and without using global state in the JS code.

Change-Id: I203b3e396b28f4b4ef49c3c0918a4025082308c4
This commit is contained in:
Bartosz Dziewoński 2022-11-22 18:37:36 +01:00
parent e3d54827cf
commit 9207931f53
6 changed files with 12 additions and 93 deletions

View file

@ -304,26 +304,22 @@
"mobile"
]
},
"ext.math.visualEditor.mathSymbolsData": {
"class": "MediaWiki\\Extension\\Math\\MathMathSymbolsDataModule"
},
"ext.math.visualEditor.mathSymbols": {
"packageFiles": [
"ve-math/mathSymbols.js",
"ve-math/mathSymbols.json"
],
"styles": [
"ve-math/ve.ui.MWMathSymbols.css"
],
"dependencies": [
"ext.math.visualEditor.mathSymbolsData"
]
},
"ext.math.visualEditor.chemSymbolsData": {
"class": "MediaWiki\\Extension\\Math\\MathChemSymbolsDataModule"
},
"ext.math.visualEditor.chemSymbols": {
"packageFiles": [
"ve-math/chemSymbols.js",
"ve-math/chemSymbols.json"
],
"styles": [
"ve-math/ve.ui.MWChemSymbols.css"
],
"dependencies": [
"ext.math.visualEditor.chemSymbolsData"
]
}
},

View file

@ -0,0 +1 @@
module.exports = require( './chemSymbols.json' );

View file

@ -0,0 +1 @@
module.exports = require( './mathSymbols.json' );

View file

@ -31,21 +31,8 @@ ve.ui.MWLatexDialog.static.size = 'larger';
ve.ui.MWLatexDialog.static.dir = 'ltr';
ve.ui.MWLatexDialog.static.symbols = null;
ve.ui.MWLatexDialog.static.symbolsModule = null;
/* static methods */
/**
* Set the symbols property
*
* @param {Object} symbols The symbols and their group names
*/
ve.ui.MWLatexDialog.static.setSymbols = function ( symbols ) {
this.symbols = symbols;
};
/* Methods */
/**
@ -151,8 +138,8 @@ ve.ui.MWLatexDialog.prototype.initialize = function () {
continuous: true
} );
this.pages = [];
this.symbolsPromise = mw.loader.using( this.constructor.static.symbolsModule ).done( function () {
var symbols = dialog.constructor.static.symbols;
this.symbolsPromise = mw.loader.using( this.constructor.static.symbolsModule ).done( function ( require ) {
var symbols = require( dialog.constructor.static.symbolsModule );
for ( var category in symbols ) {
dialog.pages.push(
new ve.ui.MWLatexPage(

View file

@ -1,33 +0,0 @@
<?php
namespace MediaWiki\Extension\Math;
use MediaWiki\ResourceLoader as RL;
/**
* Resource loader module providing extra data from the server to Chem.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license MIT
*/
class MathChemSymbolsDataModule extends RL\Module {
/** @inheritDoc */
protected $targets = [ 'desktop', 'mobile' ];
public function getScript( RL\Context $context ) {
return 've.ui.MWChemDialog.static.setSymbols(' .
file_get_contents( __DIR__ . '/../modules/ve-math/chemSymbols.json' ) .
');';
}
public function getDependencies( RL\Context $context = null ) {
return [
'ext.math.visualEditor',
];
}
public function enableModuleContentVersion() {
return true;
}
}

View file

@ -1,33 +0,0 @@
<?php
namespace MediaWiki\Extension\Math;
use MediaWiki\ResourceLoader as RL;
/**
* Resource loader module providing extra data from the server to Math.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license MIT
*/
class MathMathSymbolsDataModule extends RL\Module {
/** @inheritDoc */
protected $targets = [ 'desktop', 'mobile' ];
public function getScript( RL\Context $context ) {
return 've.ui.MWMathDialog.static.setSymbols(' .
file_get_contents( __DIR__ . '/../modules/ve-math/mathSymbols.json' ) .
');';
}
public function getDependencies( RL\Context $context = null ) {
return [
'ext.math.visualEditor',
];
}
public function enableModuleContentVersion() {
return true;
}
}