// TODO: handle add and delete for arrays and objects
returnevents.reduce((data,event)=>{
data.keys.push(event.key);
data.operations.push(event.type);
data.oldValue[event.key]=event.oldValue;
data.newValue[event.key]=event.newValue;
returndata;
},{
oldValue:{},
keys:[],
operations:[],
newValue:{},
});
}
else{
return{
operation:formatDisplay(events.type),
key:formatDisplay(events.key),
oldValue:events.oldValue,
newValue:events.newValue,
};
}
}
functionformatMutationType(type){
switch(type){
caseexports.MutationType.direct:
return'mutation';
caseexports.MutationType.patchFunction:
return'$patch';
caseexports.MutationType.patchObject:
return'$patch';
default:
return'unknown';
}
}
// timeline can be paused when directly changing the state
letisTimelineActive=true;
constcomponentStateTypes=[];
constMUTATIONS_LAYER_ID='pinia:mutations';
constINSPECTOR_ID='pinia';
/**
* Gets the displayed name of a store in devtools
*
* @param id - id of the store
* @returns a formatted string
*/
constgetStoreType=(id)=>'🍍 '+id;
/**
* Add the pinia plugin without any store. Allows displaying a Pinia plugin tab
* as soon as it is added to the application.
*
* @param app - Vue application
* @param pinia - pinia instance
*/
functionregisterPiniaDevtools(app,pinia){
setupDevtoolsPlugin({
id:'dev.esm.pinia',
label:'Pinia 🍍',
logo:'https://pinia.vuejs.org/logo.svg',
packageName:'pinia',
homepage:'https://pinia.vuejs.org',
componentStateTypes,
app,
},(api)=>{
if(typeofapi.now!=='function'){
toastMessage('You seem to be using an outdated version of Vue Devtools. Are you still using the Beta release instead of the stable one? You can find the links at https://devtools.vuejs.org/guide/installation.html.');
}
api.addTimelineLayer({
id:MUTATIONS_LAYER_ID,
label:`Pinia 🍍`,
color:0xe5df88,
});
api.addInspector({
id:INSPECTOR_ID,
label:'Pinia 🍍',
icon:'storage',
treeFilterPlaceholder:'Search stores',
actions:[
{
icon:'content_copy',
action:()=>{
actionGlobalCopyState(pinia);
},
tooltip:'Serialize and copy the state',
},
{
icon:'content_paste',
action:async()=>{
awaitactionGlobalPasteState(pinia);
api.sendInspectorTree(INSPECTOR_ID);
api.sendInspectorState(INSPECTOR_ID);
},
tooltip:'Replace the state with the content of your clipboard',