Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 470x 106x 106x 106x 106x 106x 106x 106x 106x 106x 37x 106x 106x 106x 106x 106x 106x 106x 106x 21x 106x 106x 106x 106x 106x 106x 106x 106x 106x 334x 334x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 106x 6x 1x 1x 5x 5x 5x 5x 5x 6x 1x 1x 5x 5x 5x 6x 9x 9x 5x 5x 106x 106x 106x 106x 106x 106x 50x 50x 50x 50x 50x 50x 50x 21x 21x 50x 50x 50x 16x 16x 16x 16x 9x 16x 16x 16x 34x 34x 38x 3x 3x 3x 31x 31x 37x 23x 23x 23x 9x 23x 23x 23x 8x 8x 8x 106x 106x 106x 106x 106x 106x 106x 106x 26x 26x 26x 26x 26x 26x 26x 26x 26x 1x 1x 1x 1x 106x 106x 106x 106x 106x 106x 106x 106x 106x 6x 24x 5x 5x 24x 1x 106x 106x 106x 106x 106x 106x 106x 106x 106x 50x 106x 106x 106x 106x 106x 106x 106x 106x 106x 34x 106x 106x 106x 106x 106x 106x 106x 106x 106x 31x 31x 106x 106x | /*!
* WikiLambda Vue editor: Application store router (Pinia)
*
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const Constants = require( '../../Constants.js' );
const urlUtils = require( '../../utils/urlUtils.js' );
module.exports = {
state: {
currentPath: window.location.pathname,
currentView: Constants.VIEWS.Z_OBJECT_VIEWER,
queryParams: urlUtils.getQueryParamsFromUrl( window.location.href )
},
getters: {
getWikilambdaConfig: function () {
return mw.config.get( 'wgWikiLambda' ) || {};
},
/**
* Returns current loaded view if wikilambda Repo mode.
* Else returns undefined.
*
* @param {Object} state
* @return {string|undefined}
*/
getCurrentView: function ( state ) {
return state.currentView;
},
/**
* Returns Uri query parameters
*
* @param {Object} state
* @return {Object}
*/
getQueryParams: function ( state ) {
return state.queryParams;
},
/**
* Returns view mode flag if wikilambda Repo mode.
* Else returns undefined.
*
* @param {Object} state
* @return {boolean|undefined}
*/
getViewMode: function () {
return this.getWikilambdaConfig.viewmode;
}
},
actions: {
/**
* Changes the current View and Query params and updates the history state.
*
* @param {Object} payload
* @param {string} payload.to - Target view.
* @param {Object} [payload.params] - Additional query parameters.
*/
navigate: function ( { to, params } ) {
if ( !this.isValidView( to ) ) {
return;
}
this.currentView = to;
const url = new URL( window.location.href );
if ( params ) {
this.queryParams = Object.assign( {}, this.queryParams, params );
}
const newQuery = Object.assign( {}, this.queryParams, { view: this.currentView } );
url.pathname = this.currentPath;
for ( const key in newQuery ) {
url.searchParams.set( key, newQuery[ key ] );
}
const query = urlUtils.searchParamsToObject( url.searchParams );
window.history.pushState( { path: url.pathname, query }, null, url.toString() );
},
/**
* Evaluate the Uri path and determine what View should be displayed.
*/
evaluateUri: function () {
const url = new URL( window.location.href );
const params = url.searchParams;
const path = url.pathname;
// Set title if URL is in `/wiki/{{ title }}` format
let title = params.get( 'title' );
if ( !title && path.includes( '/wiki' ) ) {
title = path.slice( path.lastIndexOf( '/' ) + 1 );
}
// 1. if Special page Create
if ( this.isCreatePath( title ) ) {
const zid = params.get( 'zid' );
this.changeCurrentView(
zid && zid.toUpperCase() === Constants.Z_FUNCTION ?
Constants.VIEWS.FUNCTION_EDITOR :
Constants.VIEWS.DEFAULT
);
return;
}
// 2. if Special page Run Function
if ( this.isEvaluateFunctionCallPath( title ) ) {
this.changeCurrentView( Constants.VIEWS.FUNCTION_EVALUATOR );
return;
}
// 3. if Function page (edit or view)
if ( this.isFunctionRootObject() ) {
this.changeCurrentView(
this.getViewMode ?
Constants.VIEWS.FUNCTION_VIEWER :
Constants.VIEWS.FUNCTION_EDITOR
);
return;
}
// 4. Default view
this.changeCurrentView( Constants.VIEWS.DEFAULT );
},
/**
* Handle the changes of a view and replace the history state.
*
* @param {string} newView - The new view to set.
*/
changeCurrentView: function ( newView ) {
this.currentView = newView;
const url = new URL( window.location.href );
const path = url.pathname;
const params = url.searchParams;
const currentView = params.get( 'view' );
// should only replace history state if path query view is set and is different from new view
if ( currentView && currentView !== newView ) {
params.set( 'view', newView );
const query = urlUtils.searchParamsToObject( params );
window.history.replaceState( { path, query }, null, url.toString() );
}
},
/**
* Check if the given url path 'view' string is a known view in Constants.VIEWS
*
* @param {string} view
* @return {boolean}
*/
isValidView: function ( view ) {
for ( const key in Constants.VIEWS ) {
if ( Constants.VIEWS[ key ] === view ) {
return true;
}
}
return false;
},
/**
* Check if the path is for Special:CreateZObject
*
* @param {string} title
* @return {boolean}
*/
isCreatePath: function ( title ) {
return title === Constants.PATHS.CREATE_OBJECT_TITLE;
},
/**
* Check if the path is for Special:EvaluateFunctionCall
*
* @param {string} title
* @return {boolean}
*/
isEvaluateFunctionCallPath: function ( title ) {
return title === Constants.PATHS.RUN_FUNCTION_TITLE;
},
/**
* Check if the current ZObject is a Z8/Function
*
* @param {string} title
* @return {boolean}
*/
isFunctionRootObject: function () {
return this.getCurrentZObjectType === Constants.Z_FUNCTION;
}
}
};
|